12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\command;
- use app\model\Employee;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- class DefreshEmp extends Command
- {
- protected function configure()
- {
- $this->setName('defreshemp')
- ->setDescription('deal old Employee data');
- }
- protected function execute(Input $input, Output $output)
- {
- $records = Employee::field('id,phone')->select();
- $i = 0;
- foreach($records as $item){
- if(strlen($item->phone) == 11){
- $output->writeln($item->phone);
- $cypherhone = cypherphone($item->phone);
- $output->writeln($i);
- $output->writeln($cypherhone);
- $i++;
- Employee::where('id',$item->id)->update(['phone' => $cypherhone]);
- }
- }
- $output->writeln($i." 条记录处理完毕");
- }
- }
|