argument('type'); $type = !empty($type) ? $type : 1; switch($type) { case 1: // 查询所有迁移记录,然后将记录详情中存在迁移时间的明细errcode更新为1,status跟新为1 $this->updateCustomerAssignmentRecordStatus(); break; case 2: break; case 3: break; case 4: break; } } public function updateCustomerAssignmentRecordStatus() { $id = 0; while(true) { $recordList = CustomerAssignmentTotal::query()->where('enable', 1)->where('id', '>', $id) ->orderBy('id', 'asc')->limit(500)->get(); if($recordList->isEmpty()) { $this->info(date('H:i:s') . ' 处理完成'); return ; } $total = $recordList->count(); $this->info(date('H:i:s') . ' 开始处理,本次共查询记录'.$total.'条'); $id = $recordList->max('id'); foreach($recordList as $key => $recordInfo) { $recordId = $recordInfo->id; $corpid = $recordInfo->corpid; if(0 != $key && $key%100 == 0) { $this->info('H:i:s' . ' 已处理'.$key.'条数据'); } CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId)->where('takeover_time', '>', '') ->update(['errcode' => 0, 'status' => 1]); $externalUserIdList = $recordInfo->external_userid; $customerNumber = count(json_decode($externalUserIdList, 1)); CustomerAssignmentTotal::query()->where('id', $recordId)->update(['customer_number' => $customerNumber]); // 查询记录是否仍有未分配完成的数据 $count = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId) ->where('enable', 1)->whereIn('status', [0, 2])->count(); if(0 == $count) { $errCount = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId) ->where('enable', 1)->where('status', -1)->count(); $totalCount = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId) ->where('enable', 1)->count(); if($errCount > 0 && $errCount == $totalCount) { CustomerAssignmentTotal::query()->where('id', $recordId)->update(['status' => -1]); } else { CustomerAssignmentTotal::query()->where('id', $recordId)->update(['status' => 3]); } } } } } }