DefreshEmp.php 912 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\command;
  3. use app\model\Employee;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. class DefreshEmp extends Command
  8. {
  9. protected function configure()
  10. {
  11. $this->setName('defreshemp')
  12. ->setDescription('deal old Employee data');
  13. }
  14. protected function execute(Input $input, Output $output)
  15. {
  16. $records = Employee::field('id,phone')->select();
  17. $i = 0;
  18. foreach($records as $item){
  19. if(strlen($item->phone) == 11){
  20. $output->writeln($item->phone);
  21. $cypherhone = cypherphone($item->phone);
  22. $output->writeln($i);
  23. $output->writeln($cypherhone);
  24. $i++;
  25. Employee::where('id',$item->id)->update(['phone' => $cypherhone]);
  26. }
  27. }
  28. $output->writeln($i." 条记录处理完毕");
  29. }
  30. }