Browse Source

客户批量打标签 调试

shensong00 1 month ago
parent
commit
b6e55be1c5
1 changed files with 27 additions and 24 deletions
  1. 27 24
      app/Console/Commands/CorpInformation/BatchMarkTagNew.php

+ 27 - 24
app/Console/Commands/CorpInformation/BatchMarkTagNew.php

@@ -192,8 +192,6 @@ class BatchMarkTagNew extends Command
192 192
             $newFilterCustomerList = [];
193 193
         }
194 194
 
195
-        Log::logInfo('过滤客户记录', $newFilterCustomerList, $this->logName);
196
-
197 195
         # 先查询出所有需要执行的客服,再按照客服来查询客户列表
198 196
         $userIdList = $params['user_id_list'];
199 197
         if (empty($userIdList)) {
@@ -206,8 +204,6 @@ class BatchMarkTagNew extends Command
206 204
             $userIdList = array_intersect($params['user_id_list'], $activeUserList);
207 205
         }
208 206
 
209
-        Log::logInfo('激活客服记录', $userIdList, $this->logName);
210
-
211 207
         foreach ($userIdList as $userId) {
212 208
             $params['user_id_list'] = [$userId];
213 209
             $page = 1;
@@ -215,30 +211,37 @@ class BatchMarkTagNew extends Command
215 211
             do {
216 212
                 $customerQuery = CustomerDetails::getCustomerBySearchNew($params, $source);
217 213
                 $count = $customerQuery->count();
218
-                $customerList = $customerQuery->selectRaw("customer_id, external_userid")
219
-                    ->offset(($page - 1) * $limit)->limit($limit)->get();
220
-                Log::logInfo('初始客户列表', [$customerList->toArray()], $this->logName);
221
-
222
-                $userFilterCustomerList = $newFilterCustomerList[$userId]['list'] ?? [];
223
-                if (!empty($userFilterCustomerList)) {
224
-                    $newCustomerList = $customerList->whereNotIn('customer_id', $userFilterCustomerList)->all()->toArray();
225
-                } else {
226
-                    $newCustomerList = $customerList->all()->toArray();
227
-                }
228
-                Log::logInfo('过滤后客户列表', [$newCustomerList], $this->logName);
229
-
230
-                $userExternalUserIdList = array_column($newCustomerList, 'external_userid');
231
-                $externalUserIdArr = array_chunk($userExternalUserIdList, $this->limit);
232
-                foreach ($externalUserIdArr as $externalUserIdList) {
233
-                    $result = BatchMarkTagRecord::savedData($taskInfo['id'], $taskInfo['corpid'], $userId, $externalUserIdList);
234
-
235
-                    if (!$result) {
236
-                        Log::logError('记录写入失败', ['task_info' => $taskInfo], $this->logName);
214
+                if($count > 0) {
215
+                    $customerList = $customerQuery->selectRaw("customer_id, external_userid")
216
+                        ->offset(($page - 1) * $limit)->limit($limit)->get();
217
+                    Log::logInfo('初始客户列表', ['user_id' => $userId, 'customer_list' => $customerList->toArray()], $this->logName);
218
+
219
+                    $userFilterCustomerList = $newFilterCustomerList[$userId]['list'] ?? [];
220
+                    Log::logInfo('待过滤客户列表', ['user_id' => $userId, 'customer_list' => $userFilterCustomerList], $this->logName);
221
+                    if (!empty($userFilterCustomerList)) {
222
+                        $customerIdList = array_column($customerList->toArray(), 'customer_id');
223
+                        $newCustomerIdList = array_diff($customerIdList, $userFilterCustomerList);
224
+                        $newCustomerList = $customerList->whereIn('customer_id', $newCustomerIdList)->all();
225
+                        $newCustomerList = json_decode(json_encode($newCustomerList), 1);
237 226
                     } else {
238
-                        RedisModel::rPush(BatchMarkTagRecord::BATCH_MARK_TAG_RECORD, $result->id);
227
+                        $newCustomerList = $customerList->toArray();
239 228
                     }
229
+                    Log::logInfo('过滤后客户列表', [$newCustomerList], $this->logName);
230
+
231
+//                $userExternalUserIdList = array_column($newCustomerList, 'external_userid');
232
+//                $externalUserIdArr = array_chunk($userExternalUserIdList, $this->limit);
233
+//                foreach ($externalUserIdArr as $externalUserIdList) {
234
+//                    $result = BatchMarkTagRecord::savedData($taskInfo['id'], $taskInfo['corpid'], $userId, $externalUserIdList);
235
+//
236
+//                    if (!$result) {
237
+//                        Log::logError('记录写入失败', ['task_info' => $taskInfo], $this->logName);
238
+//                    } else {
239
+//                        RedisModel::rPush(BatchMarkTagRecord::BATCH_MARK_TAG_RECORD, $result->id);
240
+//                    }
241
+//                }
240 242
                 }
241 243
 
244
+
242 245
                 $page++;
243 246
             } while ($count == $limit);
244 247
         }