123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\command;
- use app\model\CustomerVisitLog;
- use app\model\Employee;
- use app\model\Org;
- use app\model\Customer;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use app\model\CustomerInvalidLog;
- class AddInvalidLog extends Command
- {
- protected function configure()
- {
- $this->setName('addinvalidlog')
- ->setDescription('addinvalidlog');
- }
- protected function execute(Input $input, Output $output)
- {
- $root_id = 1700;
- $orgids = orgSubIds($root_id);
- $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');
- foreach($list as $key=>$val){
- $cus = Customer::where('id',$val['customer_id'])->field('addtime,org_id,source_id')->find();
- if(empty($cus)) continue;
- $org_id = !empty($val['customer_org_id']) ? $val['customer_org_id'] : $val['org_id'];
- $org_id = $org_id ? $org_id : $cus['org_id'];
- $add[]=[
- 'customer_id' => $val['customer_id'],
- 'employee_id' => !empty($val['customer_employee_id']) ? $val['customer_employee_id'] : $val['employee_id'],
- 'org_id' => $org_id,
- 'root_id' => $root_id,
- 'cus_addtime' => $cus['addtime'],
- 'visitlog_id' => $val['id'],
- 'assigned_personnel' => '',
- 'source_id' => !empty($cus['source_id']) ? $cus['source_id'] : 0
- ];
- }
- $addlog = new CustomerInvalidLog;
- $addlog->saveAll($add);
- $output->writeln("添加无效记录处理完成");
- }
- }
- ?>
|