AddInvalidLog.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\command;
  3. use app\model\CustomerVisitLog;
  4. use app\model\Employee;
  5. use app\model\Org;
  6. use app\model\Customer;
  7. use think\console\Command;
  8. use think\console\Input;
  9. use think\console\Output;
  10. use app\model\CustomerInvalidLog;
  11. class AddInvalidLog extends Command
  12. {
  13. protected function configure()
  14. {
  15. $this->setName('addinvalidlog')
  16. ->setDescription('addinvalidlog');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. $root_id = 1700;
  21. $orgids = orgSubIds($root_id);
  22. $list = CustomerVisitLog::where([['org_id','in',$orgids],['state','in',CustomerVisitLog::changeState('无效','chaos')]])->column('id,state,customer_id,employee_id,customer_employee_id,customer_org_id,org_id');
  23. foreach($list as $key=>$val){
  24. $cus = Customer::where('id',$val['customer_id'])->field('addtime,org_id,source_id')->find();
  25. if(empty($cus)) continue;
  26. $org_id = !empty($val['customer_org_id']) ? $val['customer_org_id'] : $val['org_id'];
  27. $org_id = $org_id ? $org_id : $cus['org_id'];
  28. $add[]=[
  29. 'customer_id' => $val['customer_id'],
  30. 'employee_id' => !empty($val['customer_employee_id']) ? $val['customer_employee_id'] : $val['employee_id'],
  31. 'org_id' => $org_id,
  32. 'root_id' => $root_id,
  33. 'cus_addtime' => $cus['addtime'],
  34. 'visitlog_id' => $val['id'],
  35. 'assigned_personnel' => '',
  36. 'source_id' => !empty($cus['source_id']) ? $cus['source_id'] : 0
  37. ];
  38. }
  39. $addlog = new CustomerInvalidLog;
  40. $addlog->saveAll($add);
  41. $output->writeln("添加无效记录处理完成");
  42. }
  43. }
  44. ?>