123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2023/3/13
- * Time: 18:17
- */
- namespace App\Console\Repair;
- use App\Models\CustomerAssignmentRecord;
- use App\Models\CustomerAssignmentTotal;
- use Illuminate\Console\Command;
- class ErrCodeManage extends Command
- {
- protected $signature = 'ErrCodeManage {type?}';
- protected $description = '失败信息展示';
- public function __construct()
- {
- parent::__construct();
- }
- public function handle()
- {
- $type = $this->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]);
- }
- }
- }
- }
- }
- }
|