Просмотр исходного кода

客户批量打标签处理 调试

shensong00 22 часов назад
Родитель
Сommit
d55eda41c5

+ 7 - 6
app/Console/Commands/ChatGroup/GroupBasicInfo.php

@@ -84,12 +84,13 @@ class GroupBasicInfo extends Command
84 84
     private function getGroupInfo($corpid, $userIds, $source)
85 85
     {
86 86
         # owner_filter参数处理
87
-        $userIdList = DjUser::select(['user_id'])->where('corpid', $corpid)->where('enable', 1)
88
-            ->where(function($query) use($userIds) {
89
-                if($userIds) $query->whereIn('user_id', $userIds);
90
-            })
91
-            ->where('status', 1)->orderBy('id')
92
-            ->distinct()->pluck('user_id')->toArray();
87
+//        $userIdList = DjUser::select(['user_id'])->where('corpid', $corpid)->where('enable', 1)
88
+//            ->where(function($query) use($userIds) {
89
+//                if($userIds) $query->whereIn('user_id', $userIds);
90
+//            })
91
+//            ->where('status', 1)->orderBy('id')
92
+//            ->distinct()->pluck('user_id')->toArray();
93
+        $userIdList = DjUser::getActiveUserListById($corpid, $userIds);
93 94
 
94 95
         $userCount = count($userIdList);
95 96
         # 需要截取的段数

+ 19 - 35
app/Console/Commands/CorpInformation/BatchMarkTagNew.php

@@ -77,39 +77,26 @@ class BatchMarkTagNew extends Command
77 77
         $taskInfo = json_decode(json_encode($taskInfo), 1);
78 78
         BatchMarkTag::updateStatus($taskId, 2);
79 79
 
80
-        # 客服许可(兼容新授权到系统的企微,此种企微的客服没有许可,但是会有75天的试用期)
81
-        $corpInfo = AuthorizeCorp::getCorpInfo($taskInfo['corpid']);
82
-        if(!empty($corpInfo)) {
83
-            $chargeActiveType = 1;
84
-            $activeUserList = [];
85
-            if (strtotime($corpInfo->created_at) <= strtotime('-75 days')) {
86
-                $chargeActiveType = 2;
87
-                $activeUserList = DjUser::getActiveUserListById($taskInfo['corpid'], []);
88
-                $activeUserList = json_decode(json_encode($activeUserList), 1);
89
-                if(empty($activeUserList)) {
90
-                    # 选择的客服列表全部没有许可,不去查询客户列表,直接更新状态
91
-                    $status = -1;
92
-                    BatchMarkTag::updateStatus($taskId, $status);
93
-                    Log::logError('所属企微的客服全部没有许可信息', ['task_id' => $taskId, 'corpid' => $taskInfo['corpid']], $this->logName);
94
-                    return false;
95
-                }
96
-            }
97
-
98
-            # 直接筛选出要处理的客户列表,方便生成记录表数据
99
-            if(0 == $taskInfo['select_all']) {
100
-                $this->dealSelectTask($taskInfo, $chargeActiveType, $activeUserList);
101
-            } else {
102
-                $this->dealFilterTask($taskInfo, $chargeActiveType, $activeUserList);
103
-            }
104
-        } else {
80
+        $activeUserList = DjUser::getActiveUserListById($taskInfo['corpid']);
81
+        if(empty($activeUserList)) {
82
+            # 选择的客服列表全部没有许可,不去查询客户列表,直接更新状态
105 83
             $status = -1;
106 84
             BatchMarkTag::updateStatus($taskId, $status);
107
-            Log::logError('企微信息异常', ['task_id' => $taskId], $this->logName);
108
-            EmailQueue::rPush('客户批量打标签-企微信息查询异常', 'task_id:'.$taskId, $this->emailReceiver, $this->emailSender);
85
+            Log::logError('所属企微的客服全部没有许可信息', ['task_id' => $taskId, 'corpid' => $taskInfo['corpid']], $this->logName);
86
+            return false;
109 87
         }
88
+
89
+
90
+        # 直接筛选出要处理的客户列表,方便生成记录表数据
91
+        if(0 == $taskInfo['select_all']) {
92
+            $this->dealSelectTask($taskInfo, $activeUserList);
93
+        } else {
94
+            $this->dealFilterTask($taskInfo, $activeUserList);
95
+        }
96
+
110 97
     }
111 98
 
112
-    private function dealSelectTask($taskInfo, $chargeActiveType, $activeUserList) {
99
+    private function dealSelectTask($taskInfo, $activeUserList) {
113 100
         $customerList = json_decode($taskInfo['customer_list'], 1);
114 101
         $taskId = $taskInfo['id'];
115 102
         $corpid = $taskInfo['corpid'];
@@ -125,7 +112,7 @@ class BatchMarkTagNew extends Command
125 112
         }
126 113
 
127 114
         foreach ($userCustomerList as $userId => $childCustomerIdListArr) {
128
-            if(2 == $chargeActiveType && !in_array($userId, $activeUserList)) {
115
+            if(!in_array($userId, $activeUserList)) {
129 116
                 Log::logInfo('客服无许可,跳过', ['user_id' => $userId, 'customer_list' => $childCustomerIdListArr], $this->logName);
130 117
                 continue;
131 118
             }
@@ -180,10 +167,11 @@ class BatchMarkTagNew extends Command
180 167
         return $data;
181 168
     }
182 169
 
183
-    private function dealFilterTask($taskInfo, $chargeActiveType, $activeUserList)
170
+    private function dealFilterTask($taskInfo, $activeUserList)
184 171
     {
185 172
         $params = json_decode($taskInfo['params'], 1);
186 173
         $params['corpid'] = $taskInfo['corpid'];
174
+        $params['user_id_list'] = !is_array($params['user_id_list']) ? json_decode($params['user_id_list']) : $params['user_id_list'];
187 175
         $source = 1;
188 176
 
189 177
         $filterCustomerList = json_decode($taskInfo['filter_customer_list'], 1);
@@ -196,11 +184,7 @@ class BatchMarkTagNew extends Command
196 184
         # 先查询出所有需要执行的客服,再按照客服来查询客户列表
197 185
         $userIdList = $params['user_id_list'];
198 186
         if (empty($userIdList)) {
199
-            if (1 == $chargeActiveType) {
200
-                $userIdList = DjUser::query()->where('corpid', $taskInfo['corpid'])->where('enable', 1)->pluck('user_id')->toArray();
201
-            } else {
202
-                $userIdList = $activeUserList;
203
-            }
187
+            $userIdList = $activeUserList;
204 188
         } else {
205 189
             $userIdList = array_intersect($params['user_id_list'], $activeUserList);
206 190
         }

+ 16 - 5
app/Models/DjUser.php

@@ -225,11 +225,22 @@ class DjUser extends Model
225 225
             ->where('corpid', $corpid)->get()->pluck('user_id');
226 226
     }
227 227
 
228
-    public static function getActiveUserListById($corpid, $userIdList)  {
229
-        return self::query()->where('corpid', $corpid)->where(function($query) use($userIdList){
230
-            if(!empty($userIdList)) $query->whereIn('user_id', $userIdList);
231
-        })->where('enable', 1)->where('status', 1)->where('is_active', 1)
232
-            ->pluck('user_id');
228
+    public static function getActiveUserListById($corpid, $userIdList = null)  {
229
+        $corpInfo = AuthorizeCorp::getCorpInfo($corpid);
230
+        # 客服许可(兼容新授权到系统的企微,此种企微的客服没有许可,但是会有75天的试用期)
231
+        if(!empty($corpInfo)) {
232
+            $model = self::query()->where('corpid', $corpid)->where(function ($query) use ($userIdList) {
233
+                if (!empty($userIdList)) $query->whereIn('user_id', $userIdList);
234
+            })->where('enable', 1)->where('status', 1);
235
+
236
+            if (strtotime($corpInfo->created_at) <= strtotime('-75 days')) {
237
+                $model = $model->where('is_active', 1);
238
+            }
239
+
240
+            return $model->pluck('user_id')->toArray();
241
+        } else {
242
+            return [];
243
+        }
233 244
     }
234 245
 
235 246
     public static function getActiveUserListByPage($startId, $limit, $corpid = null) {

+ 4 - 3
app/Service/ChatGroup/ChatGroupService.php

@@ -848,9 +848,10 @@ class ChatGroupService
848 848
         Log::logInfo('start', [time()], 'syncCorpChatGroup');
849 849
         try{
850 850
             # owner_filter参数处理
851
-            $userIdList = DjUser::select(['user_id'])->where('corpid', $corpid)->where('enable', 1)
852
-                ->where('status', 1)->orderBy('id')
853
-                ->distinct()->pluck('user_id')->toArray();
851
+//            $userIdList = DjUser::select(['user_id'])->where('corpid', $corpid)->where('enable', 1)
852
+//                ->where('status', 1)->orderBy('id')
853
+//                ->distinct()->pluck('user_id')->toArray();
854
+            $userIdList = DjUser::getActiveUserListById($corpid);
854 855
 
855 856
             if(empty($userIdList)) {
856 857
                 return ['待同步成员列表为空', 2014];