企微短剧业务系统

ErrCodeManage.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2023/3/13
  6. * Time: 18:17
  7. */
  8. namespace App\Console\Repair;
  9. use App\Models\CustomerAssignmentRecord;
  10. use App\Models\CustomerAssignmentTotal;
  11. use Illuminate\Console\Command;
  12. class ErrCodeManage extends Command
  13. {
  14. protected $signature = 'ErrCodeManage {type?}';
  15. protected $description = '失败信息展示';
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. }
  20. public function handle()
  21. {
  22. $type = $this->argument('type');
  23. $type = !empty($type) ? $type : 1;
  24. switch($type) {
  25. case 1: // 查询所有迁移记录,然后将记录详情中存在迁移时间的明细errcode更新为1,status跟新为1
  26. $this->updateCustomerAssignmentRecordStatus();
  27. break;
  28. case 2:
  29. break;
  30. case 3:
  31. break;
  32. case 4:
  33. break;
  34. }
  35. }
  36. public function updateCustomerAssignmentRecordStatus()
  37. {
  38. $id = 0;
  39. while(true) {
  40. $recordList = CustomerAssignmentTotal::query()->where('enable', 1)->where('id', '>', $id)
  41. ->orderBy('id', 'asc')->limit(500)->get();
  42. if($recordList->isEmpty()) {
  43. $this->info(date('H:i:s') . ' 处理完成');
  44. return ;
  45. }
  46. $total = $recordList->count();
  47. $this->info(date('H:i:s') . ' 开始处理,本次共查询记录'.$total.'条');
  48. $id = $recordList->max('id');
  49. foreach($recordList as $key => $recordInfo) {
  50. $recordId = $recordInfo->id;
  51. $corpid = $recordInfo->corpid;
  52. if(0 != $key && $key%100 == 0) {
  53. $this->info('H:i:s' . ' 已处理'.$key.'条数据');
  54. }
  55. CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId)->where('takeover_time', '>', '')
  56. ->update(['errcode' => 0, 'status' => 1]);
  57. $externalUserIdList = $recordInfo->external_userid;
  58. $customerNumber = count(json_decode($externalUserIdList, 1));
  59. CustomerAssignmentTotal::query()->where('id', $recordId)->update(['customer_number' => $customerNumber]);
  60. // 查询记录是否仍有未分配完成的数据
  61. $count = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId)
  62. ->where('enable', 1)->whereIn('status', [0, 2])->count();
  63. if(0 == $count) {
  64. $errCount = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId)
  65. ->where('enable', 1)->where('status', -1)->count();
  66. $totalCount = CustomerAssignmentRecord::suffix($corpid)->where('record_id', $recordId)
  67. ->where('enable', 1)->count();
  68. if($errCount > 0 && $errCount == $totalCount) {
  69. CustomerAssignmentTotal::query()->where('id', $recordId)->update(['status' => -1]);
  70. } else {
  71. CustomerAssignmentTotal::query()->where('id', $recordId)->update(['status' => 3]);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }