Defreshcust.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use app\model\Customer;
  7. use app\model\CustomerVisitLog;
  8. class Defreshcust extends Command
  9. {
  10. protected function configure()
  11. {
  12. $this->setName('defreshcust')
  13. ->setDescription('deal old customer data');
  14. }
  15. protected function execute(Input $input, Output $output)
  16. {
  17. $where = [];
  18. $records = Customer::where($where)->field('id,phone')->select();
  19. $i = 0;
  20. foreach($records as $item){
  21. if(strlen($item->phone) == 11){
  22. $output->writeln($item->phone);
  23. $cypherhone = cypherphone($item->phone);
  24. $output->writeln($i);
  25. $output->writeln($cypherhone);
  26. $i++;
  27. Customer::where('id',$item->id)->update(['phone' => $cypherhone]);
  28. }
  29. //
  30. //if(CustomerVisitLog::where('customer_id', $item->id)->find()){
  31. // $customer = Customer::find($item->id);
  32. // $customer->fresh = 0;
  33. // if($customer->save()){
  34. // $output->writeln($i);
  35. // $i++;
  36. // }
  37. //
  38. //}
  39. }
  40. $output->writeln($i." 条记录处理完毕");
  41. }
  42. }