22 Commits 8c41fe3432 ... d2aef38f94

Auteur SHA1 Message Date
  shensong00 d2aef38f94 客户批量打标签上线 il y a 19 heures
  shensong00 4ae85f4e34 Merge branch 'priority' il y a 19 heures
  shensong00 875b3fbb2c 调试 il y a 19 heures
  shensong00 28c2ea3e53 调试 il y a 19 heures
  shensong00 2a7f22985c 调试 il y a 19 heures
  shensong00 80c2eb514b 调试 il y a 19 heures
  shensong00 d55eda41c5 客户批量打标签处理 调试 il y a 19 heures
  shensong00 d65943afd2 客户批量打标签处理 调试 il y a 22 heures
  shensong00 011b7deb37 m il y a 1 jour
  shensong00 f51e8c2846 客户批量打标签 调试 il y a 1 jour
  shensong00 28a906f3fd 客户批量打标签 调试 il y a 1 jour
  shensong00 8393664af2 客户批量打标签 调试 il y a 1 jour
  shensong00 08858ac187 客户批量打标签 调试 il y a 1 jour
  shensong00 8862de7bd6 客户批量打标签 调试 il y a 1 jour
  shensong00 b6e55be1c5 客户批量打标签 调试 il y a 1 jour
  shensong00 58c36a5a13 客户批量打标签 调试 il y a 1 jour
  shensong00 d3491ff83e 客户批量打标签 调试 il y a 1 jour
  shensong00 0b4786f768 客户批量打标签 调试 il y a 1 jour
  shensong00 d0e4749a95 客户批量打标签 调试 il y a 1 jour
  shensong00 4dbf0d4729 客户批量打标签 调试 il y a 1 jour
  shensong00 e7607e897c 客户批量打标签 调试 il y a 1 jour
  shensong00 4217f5f981 客户批量打标签 il y a 2 jours

+ 2 - 0
app/Console/Commands/BatchMarkTag.php

@@ -45,6 +45,8 @@ class BatchMarkTag extends Command
45 45
 
46 46
     public function handle()
47 47
     {
48
+        //脚本废弃
49
+        return false;
48 50
         $this->info('开始执行');
49 51
         $time = time();
50 52
         $d = true;

+ 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
         # 需要截取的段数

+ 219 - 0
app/Console/Commands/CorpInformation/BatchMarkTagDeal.php

@@ -0,0 +1,219 @@
1
+<?php
2
+
3
+namespace App\Console\Commands\CorpInformation;
4
+
5
+use App\Log;
6
+use App\Models\AuthorizeCorp;
7
+use App\Models\BatchMarkTag;
8
+use App\Models\BatchMarkTagRecord;
9
+use App\Models\CustomerDetails;
10
+use App\Models\DjUser;
11
+use App\Models\Tag;
12
+use App\RedisModel;
13
+use App\Service\TagService;
14
+use App\Support\EmailQueue;
15
+use App\Support\qyApi\QyCommon;
16
+use Illuminate\Console\Command;
17
+
18
+class BatchMarkTagDeal extends Command
19
+{
20
+    protected $signature = 'BatchMarkTagDeal';
21
+    protected $description = '客户批量打标签处理';
22
+
23
+    protected $emailSender = '猎羽-批量打标签';
24
+    protected $emailReceiver = ['song.shen@kuxuan-inc.com'];
25
+    protected $logName = 'BatchMarkTagDeal';
26
+
27
+    public function handle()
28
+    {
29
+        \DB::connection()->disableQueryLog();
30
+
31
+        $beginTime = time();
32
+        $this->info(date('m-d H:i:s') . ' 开始整理');
33
+
34
+        while(true) {
35
+            $result = $this->taskDeal();
36
+            if(!$result) sleep(1);
37
+            $now = time();
38
+            // 超过10分钟,主动停止循环
39
+            if ($now - $beginTime > 600) {
40
+                break;
41
+            }
42
+
43
+            sleep(1);
44
+        }
45
+
46
+        $this->info(date('Y-m-d H:i:s') . ' 整理结束');
47
+    }
48
+
49
+    private function taskDeal()
50
+    {
51
+        # 取出数据
52
+        $redisVal = RedisModel::rPop(BatchMarkTagRecord::BATCH_MARK_TAG_RECORD);
53
+        if(empty($redisVal))
54
+            return false;
55
+        try {
56
+            $this->createTask($redisVal);
57
+        } catch (\Exception $e) {
58
+            EmailQueue::rPush('客户批量打标签处理任务出现异常', $e->getTraceAsString(), $this->emailReceiver, $this->emailSender);
59
+            Log::logError('程序异常', [
60
+                'line'  => $e->getLine(), 'msg'   => $e->getMessage(), 'param' => $redisVal
61
+            ], $this->logName);
62
+
63
+            return false;
64
+        }
65
+
66
+        return true;
67
+    }
68
+
69
+    private function createTask($redisVal) {
70
+        $redisData = json_decode($redisVal, 1);
71
+        if(empty($redisData) || empty($redisData['task_id']) || empty($redisData['record_id'])) {
72
+            Log::logError('队列数据异常', [$redisData], $this->logName);
73
+            EmailQueue::rPush('处理客户批量打标签 - 队里数据异常', $redisVal, $this->emailReceiver, $this->emailSender);
74
+            return false;
75
+        }
76
+
77
+        $taskId = $redisData['task_id'];
78
+        $recordId = $redisData['record_id'];
79
+        $taskInfo = BatchMarkTag::getTaskInfoById($redisData['task_id']);
80
+        if(empty($taskInfo)) {
81
+            Log::logError('根据任务ID查询任务信息失败', ['task_id' => $taskId], $this->logName);
82
+            EmailQueue::rPush('处理客户批量打标签 - 根据任务ID查询任务信息失败', $redisVal, $this->emailReceiver, $this->emailSender);
83
+            $status = -1;
84
+            BatchMarkTagRecord::updateData($recordId, ['status' => $status]);
85
+            return false;
86
+        }
87
+
88
+        $taskInfo = json_decode(json_encode($taskInfo), 1);
89
+
90
+        $recordInfo = BatchMarkTagRecord::getInfoById($recordId);
91
+        if(empty($recordInfo)) {
92
+            Log::logError('根据记录ID查询记录信息失败', ['record_id' => $recordId], $this->logName);
93
+            EmailQueue::rPush('处理客户批量打标签 - 根据记录ID查询记录信息失败', $redisVal, $this->emailReceiver, $this->emailSender);
94
+            $status = -1;
95
+            BatchMarkTagRecord::updateData($recordId, ['status' => $status]);
96
+            return false;
97
+        }
98
+
99
+        $recordInfo = json_decode(json_encode($recordInfo), 1);
100
+
101
+        $this->dealTask($taskInfo, $recordInfo);
102
+    }
103
+
104
+    private function dealTask($taskInfo, $recordInfo) {
105
+        $externalUserIdList = explode(',', $recordInfo['external_userid_list']);
106
+        if(empty($externalUserIdList)) {
107
+            Log::logError('根据记录ID查询记录信息失败', ['record_id' => $recordInfo['id']], $this->logName);
108
+            EmailQueue::rPush('处理客户批量打标签 - 根据记录ID查询记录信息失败', 'task_id:'.$taskInfo['id'].'; record_id:'.$recordInfo['id'], $this->emailReceiver, $this->emailSender);
109
+            $status = -1;
110
+            BatchMarkTagRecord::updateData($recordInfo['id'], ['status' => $status]);
111
+            return false;
112
+        }
113
+
114
+        $tagList = json_decode($taskInfo['tag_list'], 1);
115
+        // 标签转化
116
+        $newTagList = Tag::query()->where('corpid', $taskInfo['corpid'])->where('enable', 1)
117
+            ->whereIn('tag_md5', $tagList)->get();
118
+        $newTagList = $newTagList->isNotEmpty() ? array_column($newTagList->toArray(), 'tag_id') : [];
119
+
120
+        $update = ['exec_success' => 0, 'exec_fail' => 0];
121
+        foreach ($externalUserIdList as $externalUserId) {
122
+            if(1 == $taskInfo['type']) {
123
+                $newAddTagIdList = $newTagList;
124
+                $newRemoveTagIdList = [];
125
+            } else if(2 == $taskInfo['type']) {
126
+                $newAddTagIdList = [];
127
+                $newRemoveTagIdList = $newTagList;
128
+            }
129
+
130
+            $res = $this->markTag($taskInfo['corpid'], $recordInfo['user_id'], $externalUserId, $newAddTagIdList, $newRemoveTagIdList);
131
+            if($res) {
132
+                $update['exec_success']++;
133
+            } else {
134
+                $update['exec_fail']++;
135
+            }
136
+        }
137
+
138
+        # 验证总数
139
+        if($update['exec_success'] + $update['exec_fail'] != $recordInfo['exec_total']) {
140
+            Log::logError('程序异常', ['record_id' => $recordInfo['id'], 'stat' => $update], $this->logName);
141
+            EmailQueue::rPush('客户批量打标签 - 处理数据总数与待处理数据总数不一致', json_encode(['record_id' => $recordInfo['id'], 'stat' => $update]), $this->emailReceiver, $this->emailSender);
142
+        }
143
+
144
+        # 更新任务状态
145
+        if($update['exec_fail'] == $recordInfo['exec_total']) {
146
+            $update['status'] = -1;
147
+        } else {
148
+            $update['status'] = 1;
149
+        }
150
+        $res = BatchMarkTagRecord::updateData($recordInfo['id'], $update);
151
+        if(!$res) {
152
+            Log::logError('数据更新失败', ['record_id' => $recordInfo['id'], 'update' => $update], $this->logName);
153
+        }
154
+
155
+        # 判断总体任务是否执行完成
156
+        $this->chargeTaskStatus($taskInfo['id']);
157
+    }
158
+
159
+    private function markTag($corpid, $userId, $externalUserId, $newAddTagIdList, $newRemoveTagIdList, $retry = 0) {
160
+        $responseData = QyCommon::mark_tag($corpid, $userId, $externalUserId, $newAddTagIdList, $newRemoveTagIdList);
161
+
162
+        if(isset($responseData['errcode']) && $responseData['errcode'] == 0) {
163
+            // 编辑成功了
164
+            TagService::updateLocalCustomerTagSecond($corpid, $userId, $externalUserId, $newAddTagIdList, $newRemoveTagIdList);
165
+
166
+            $state = $data['state'] ?? null;
167
+            if (!is_null($state)) {
168
+                // 客户详情10s同步一遍
169
+                RedisModel::lPush(CustomerDetails::CUSTOMER_DATA_SYNC_RDS, json_encode([
170
+                    'corpid' => $corpid,
171
+                    'user_id' => $userId,
172
+                    'external_userid' => $externalUserId,
173
+                    'exec_time' => time() + 10
174
+                ]));
175
+            }
176
+
177
+            return true;
178
+        } else {
179
+           if( $responseData['errcode'] != 84061 ) { # 无法处理的状态码:没有好友关系
180
+                // 判断重试次数
181
+                if($retry <= 5) {
182
+                    $retry++;
183
+                    return $this->markTag($corpid, $userId, $externalUserId, $newAddTagIdList, $newRemoveTagIdList, $retry);
184
+                } else {
185
+                    $params = ['corpid' => $corpid, 'user_id' => $userId, 'external_userid' => $externalUserId, 'add_tag_id_list' => $newAddTagIdList, 'remove_tag_id_list' => $newRemoveTagIdList];
186
+                    // 还是一直失败,则不再请求,日志记录一下
187
+                    Log::logError('请求企微打标签接口3次重试均失败', [
188
+                        'param' => $params,
189
+                        'response' => $responseData,
190
+                    ], $this->logName);
191
+                    EmailQueue::rPush('请求企微打标签接口3次重试均失败', json_encode(['params' => $params, 'res' => $responseData], 256), $this->emailReceiver, $this->emailSender);
192
+                    return false;
193
+                }
194
+            } else {
195
+               //todo 隔1小时报警一次
196
+
197
+               return false;
198
+           }
199
+        }
200
+    }
201
+
202
+    private function chargeTaskStatus($taskId) {
203
+        $countData = BatchMarkTagRecord::recordCount($taskId);
204
+        $total = 0; $exec = 0;
205
+        if($countData->isNotEmpty()) {
206
+            foreach ($countData as $countInfo) {
207
+                if(0 == $countInfo->status) {
208
+                    $exec += $countInfo->count;
209
+                }
210
+
211
+                $total += $countInfo->count;
212
+            }
213
+        }
214
+
215
+        if($exec == 0) {
216
+            BatchMarkTag::updateStatus($taskId, 3);
217
+        }
218
+    }
219
+}

+ 227 - 0
app/Console/Commands/CorpInformation/BatchMarkTagNew.php

@@ -0,0 +1,227 @@
1
+<?php
2
+
3
+namespace App\Console\Commands\CorpInformation;
4
+
5
+use App\Log;
6
+use App\Models\AuthorizeCorp;
7
+use App\Models\BatchMarkTag;
8
+use App\Models\BatchMarkTagRecord;
9
+use App\Models\Customer;
10
+use App\Models\CustomerDetails;
11
+use App\Models\DjUser;
12
+use App\RedisModel;
13
+use App\Support\EmailQueue;
14
+use Illuminate\Console\Command;
15
+
16
+class BatchMarkTagNew extends Command
17
+{
18
+    protected $signature = 'BatchMarkTagNew';
19
+    protected $description = '执行客户批量打标签';
20
+
21
+    protected $page = 1;
22
+    protected $limit = 500; // 限制记录中的客户条数
23
+    protected $emailSender = '猎羽-批量打标签';
24
+    protected $emailReceiver = ['song.shen@kuxuan-inc.com'];
25
+    protected $logName = 'BatchMarkTagNew';
26
+
27
+    public function handle()
28
+    {
29
+        \DB::connection()->disableQueryLog();
30
+
31
+        $beginTime = time();
32
+        $this->info(date('m-d H:i:s') . ' 开始整理');
33
+
34
+        while(true) {
35
+            $result = $this->taskDeal();
36
+            if(!$result) sleep(1);
37
+            $now = time();
38
+            // 超过10分钟,主动停止循环
39
+            if ($now - $beginTime > 600) {
40
+                break;
41
+            }
42
+
43
+            sleep(1);
44
+        }
45
+
46
+        $this->info(date('Y-m-d H:i:s') . ' 整理结束');
47
+    }
48
+
49
+    private function taskDeal()
50
+    {
51
+        # 取出数据
52
+        $taskId = RedisModel::rPop(BatchMarkTag::BATCH_MARK_TAG);
53
+        if(empty($taskId))
54
+            return false;
55
+        try {
56
+            $this->createTask($taskId);
57
+        } catch (\Exception $e) {
58
+            EmailQueue::rPush('创建客户批量打标签出现异常', $e->getTraceAsString(), $this->emailReceiver, $this->emailSender);
59
+            Log::logError('创建客户批量打标签出现异常', [
60
+                'line'  => $e->getLine(), 'msg'   => $e->getMessage(), 'param' => $taskId
61
+            ], $this->logName);
62
+
63
+            return false;
64
+        }
65
+
66
+        return true;
67
+    }
68
+
69
+    private function createTask($taskId) {
70
+        $taskInfo = BatchMarkTag::getTaskInfoById($taskId);
71
+        if(empty($taskInfo)) {
72
+            Log::logError('根据任务ID查询任务信息失败', ['task_id' => $taskId], $this->logName);
73
+            EmailQueue::rPush('根据任务ID查询任务信息失败', 'task_id : ' . $taskId, $this->emailReceiver, $this->emailSender);
74
+            return false;
75
+        }
76
+
77
+        $taskInfo = json_decode(json_encode($taskInfo), 1);
78
+        BatchMarkTag::updateStatus($taskId, 2);
79
+
80
+        $activeUserList = DjUser::getActiveUserListById($taskInfo['corpid']);
81
+        if(empty($activeUserList)) {
82
+            # 选择的客服列表全部没有许可,不去查询客户列表,直接更新状态
83
+            $status = -1;
84
+            BatchMarkTag::updateStatus($taskId, $status);
85
+            Log::logError('所属企微的客服全部没有许可信息', ['task_id' => $taskId, 'corpid' => $taskInfo['corpid']], $this->logName);
86
+            return false;
87
+        }
88
+
89
+        # 直接筛选出要处理的客户列表,方便生成记录表数据
90
+        if(0 == $taskInfo['select_all']) {
91
+            $this->dealSelectTask($taskInfo, $activeUserList);
92
+        } else {
93
+            $this->dealFilterTask($taskInfo, $activeUserList);
94
+        }
95
+
96
+    }
97
+
98
+    private function dealSelectTask($taskInfo, $activeUserList) {
99
+        $customerList = json_decode($taskInfo['customer_list'], 1);
100
+        $taskId = $taskInfo['id'];
101
+        $corpid = $taskInfo['corpid'];
102
+
103
+        if(!empty($customerList)) {
104
+            $userCustomerList = $this->dealSelectCustomerList($customerList, $this->limit);
105
+        } else {
106
+            Log::logError('所选择客户列表为空', ['task_id' => $taskId], $this->logName);
107
+            EmailQueue::rPush('客户批量打标签-所选择客户列表为空', 'task_id:'.$taskId, $this->emailReceiver, $this->emailSender);
108
+            $status = -1;
109
+            BatchMarkTag::updateStatus($taskId, $status);
110
+            return false;
111
+        }
112
+
113
+        foreach ($userCustomerList as $userId => $childCustomerIdListArr) {
114
+            if(!in_array($userId, $activeUserList)) {
115
+                Log::logInfo('客服无许可,跳过', ['user_id' => $userId, 'customer_list' => $childCustomerIdListArr], $this->logName);
116
+                continue;
117
+            }
118
+
119
+            foreach ($childCustomerIdListArr['list'] as $childCustomerIdList) {
120
+                $externalUserDataList = Customer::getCustomerInfoByIdList($corpid, $childCustomerIdList);
121
+
122
+                if($externalUserDataList->count() != count($childCustomerIdList)) {
123
+                    Log::logError('查询客户结果与预处理数据不一致', [
124
+                        'task_id' => $taskId, 'user_id' => $userId,
125
+                        'external_userid_list' => $externalUserDataList->toArray(),
126
+                        'child_customer_id_list' => $childCustomerIdList], $this->logName);
127
+                    EmailQueue::rPush('客户批量打标签-查询客户结果与预处理数据不一致', 'task_id:'.$taskId.'  user_id:'.$userId
128
+                        , $this->emailReceiver, $this->emailSender);
129
+                }
130
+
131
+                if($externalUserDataList->isNotEmpty()) {
132
+                    $externalUserIdList = $externalUserDataList->pluck('external_userid')->toArray();
133
+                    $result = BatchMarkTagRecord::savedData($taskId, $corpid, $userId, $externalUserIdList);
134
+
135
+                    if(!$result) {
136
+                        Log::logError('记录写入失败', ['task_info' => $taskInfo], $this->logName);
137
+                    } else {
138
+                        RedisModel::rPush(BatchMarkTagRecord::BATCH_MARK_TAG_RECORD, json_encode(['task_id' => $taskId, 'record_id' => $result->id]));
139
+                    }
140
+                }
141
+            }
142
+        }
143
+    }
144
+
145
+    # 遍历所选客户列表,按客服分组后数据分割,便于后续数据入库
146
+    private function dealSelectCustomerList($customerList, $limit): array
147
+    {
148
+        $data = [];
149
+        foreach ($customerList as $customerInfo) {
150
+            if(isset($data[$customerInfo['user_id']])) {
151
+                if ($limit != 0 && $data[$customerInfo['user_id']]['total'] % $limit == 0) {
152
+                    $key = count($data[$customerInfo['user_id']]['list']);
153
+                } else {
154
+                    $key = count($data[$customerInfo['user_id']]['list']) - 1;
155
+                }
156
+
157
+                $data[$customerInfo['user_id']]['list'][$key][] = $customerInfo['customer_id'];
158
+                $data[$customerInfo['user_id']]['total']++;
159
+            } else {
160
+                $key = 0;
161
+                $data[$customerInfo['user_id']]['list'][$key][] = $customerInfo['customer_id'];
162
+                $data[$customerInfo['user_id']]['total'] = 1;
163
+            }
164
+        }
165
+
166
+        return $data;
167
+    }
168
+
169
+    private function dealFilterTask($taskInfo, $activeUserList)
170
+    {
171
+        $params = json_decode($taskInfo['params'], 1);
172
+        $params['corpid'] = $taskInfo['corpid'];
173
+        $params['user_id_list'] = !is_array($params['user_id_list']) ? json_decode($params['user_id_list']) : $params['user_id_list'];
174
+        $source = 1;
175
+
176
+        $filterCustomerList = json_decode($taskInfo['filter_customer_list'], 1);
177
+        if(!empty($filterCustomerList)) {
178
+            $newFilterCustomerList = $this->dealSelectCustomerList($filterCustomerList, 0);
179
+        } else {
180
+            $newFilterCustomerList = [];
181
+        }
182
+
183
+        # 先查询出所有需要执行的客服,再按照客服来查询客户列表
184
+        $userIdList = $params['user_id_list'];
185
+        if (empty($userIdList)) {
186
+            $userIdList = $activeUserList;
187
+        } else {
188
+            $userIdList = array_intersect($params['user_id_list'], $activeUserList);
189
+        }
190
+
191
+        foreach ($userIdList as $userId) {
192
+            $params['user_id_list'] = [$userId];
193
+            $page = 1;
194
+            $limit = 5000;
195
+            do {
196
+                $customerQuery = CustomerDetails::getCustomerBySearchNew($params, $source);
197
+                $count = $customerQuery->count();
198
+                if($count > 0) {
199
+                    $customerList = $customerQuery->selectRaw("customer_id, external_userid")
200
+                        ->offset(($page - 1) * $limit)->limit($limit)->get();
201
+
202
+                    $userFilterCustomerList = $newFilterCustomerList[$userId]['list'][0] ?? [];
203
+                    if (!empty($userFilterCustomerList)) {
204
+                        $newCustomerList = $customerList->whereNotIn('customer_id', $userFilterCustomerList)->all();
205
+                    } else {
206
+                        $newCustomerList = $customerList->all();
207
+                    }
208
+
209
+                    $userExternalUserIdList = array_column($newCustomerList, 'external_userid');
210
+                    $externalUserIdArr = array_chunk($userExternalUserIdList, $this->limit);
211
+                    foreach ($externalUserIdArr as $externalUserIdList) {
212
+                        $result = BatchMarkTagRecord::savedData($taskInfo['id'], $taskInfo['corpid'], $userId, $externalUserIdList);
213
+
214
+                        if (!$result) {
215
+                            Log::logError('记录写入失败', ['task_info' => $taskInfo], $this->logName);
216
+                        } else {
217
+                            RedisModel::rPush(BatchMarkTagRecord::BATCH_MARK_TAG_RECORD, json_encode(['task_id' => $taskInfo['id'], 'record_id' => $result->id]));
218
+                        }
219
+                    }
220
+                }
221
+
222
+
223
+                $page++;
224
+            } while ($count == $limit);
225
+        }
226
+    }
227
+}

+ 4 - 0
app/Console/Kernel.php

@@ -48,6 +48,8 @@ use App\Console\Commands\CleanData;
48 48
 use App\Console\Commands\ContactChangeRecycle;
49 49
 use App\Console\Commands\CorpAccessTokenRefresh;
50 50
 use App\Console\Commands\CorpDataSync;
51
+use App\Console\Commands\CorpInformation\BatchMarkTagDeal;
52
+use App\Console\Commands\CorpInformation\BatchMarkTagNew;
51 53
 use App\Console\Commands\CorpInformation\CustomerPayTagDeal;
52 54
 use App\Console\Commands\CorpInformation\LossContactCntStat;
53 55
 use App\Console\Commands\CorpInformation\LossContactDeal;
@@ -477,6 +479,8 @@ class Kernel extends ConsoleKernel
477 479
         SyncYunXuanOrder::class,                // 同步云选联盟订单
478 480
         ECommerceUserActionsDataUpload::class,  // 电商直投订单数据回传
479 481
         OrganizationAccountGet::class,          // 查询组织下的广告主信息
482
+        BatchMarkTagNew::class,                 // 客户批量打标签任务分发(新)
483
+        BatchMarkTagDeal::class,                // 客户批量打标签任务处理
480 484
     ];
481 485
 
482 486
     /**

+ 44 - 50
app/Http/Controllers/Api/CustomerController.php

@@ -181,34 +181,31 @@ class CustomerController extends Controller
181 181
             return self::returnValue($validator->getMessageBag(), 1102);
182 182
         }
183 183
 
184
-        $customerName = $request->input('customer_name'); // 客户名关键字
185
-        $userIdList = $request->input('user_id_list'); // 所属客服
186
-        $addDateStart = $request->input('add_date_start'); // 起始添加日期
187
-        $addDateEnd = $request->input('add_date_end'); // 截止添加日期
188
-        $lastPayTimeStart = $request->input('last_pay_time_start'); // 最近一次充值时间起始
189
-        $lastPayTimeEnd = $request->input('last_pay_time_end'); // 最近一次充值时间截止
190
-        $addWay = $request->input('add_way'); // 添加渠道
191
-        $gender = $request->input('gender'); // 客户性别
192
-        $payStatus = $request->input('pay_status'); // 付费状态
193
-        $payNumMin = $request->input('pay_num_min'); // 最小付费次数
194
-        $payNumMax = $request->input('pay_num_max'); // 最高付费次数
195
-        $tagType = $request->input('tag_type', 0); // 标签筛选类型 0未筛选 1满足其一 2同时满足 3无标签
196
-        $tagIdList = $request->input('tag_id_list'); // 标签列表
197
-        $lossStatus = $request->input('loss_status'); // 客户流失状态
198
-        $corpid = $request->input('corpid');
184
+        $params['customer_name'] = $request->input('customer_name'); // 客户名关键字
185
+        $params['user_id_list'] = $request->input('user_id_list'); // 所属客服
186
+        $params['add_date_start'] = $request->input('add_date_start'); // 起始添加日期
187
+        $params['add_date_end'] = $request->input('add_date_end'); // 截止添加日期
188
+        $params['last_pay_time_start'] = $request->input('last_pay_time_start'); // 最近一次充值时间起始
189
+        $params['last_pay_time_end'] = $request->input('last_pay_time_end'); // 最近一次充值时间截止
190
+        $params['add_way'] = $request->input('add_way'); // 添加渠道
191
+        $params['gender'] = $request->input('gender'); // 客户性别
192
+        $params['pay_status'] = $request->input('pay_status'); // 付费状态
193
+        $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
194
+        $params['pay_num_max'] = $request->input('pay_num_max'); // 最高付费次数
195
+        $params['tag_type'] = $request->input('tag_type', 0); // 标签筛选类型 0未筛选 1满足其一 2同时满足 3无标签
196
+        $params['tag_id_list'] = $request->input('tag_id_list'); // 标签列表
197
+        $params['loss_status'] = $request->input('loss_status'); // 客户流失状态
198
+        $params['corpid'] = $request->input('corpid');
199 199
         $page = $request->input('page', 1);
200 200
         $pageSize = $request->input('page_size', 20);
201 201
         $source = $request->input('source', 1);
202
-        $lossTimeStart = $request->input('loss_time_start');
203
-        $lossTimeEnd = $request->input('loss_time_end');
204
-        $isNewCustomerNoLoss = $request->input('is_new_customer_no_loss');# 是否为新用户 0复粉 1新用户
205
-        $canReceive = $request->input('can_receive');       // 是否可正常接收群发消息 0否 1是
206
-        $retainedStatus = $request->input('retained_status');       // 是否在当前主体内还有留存 0否 1是
207
-
208
-        list($data, $count, $extra) = CustomerService::customerList($customerName, $userIdList, $addDateStart, $addDateEnd,
209
-            $addWay, $gender, $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $page,
210
-            $pageSize, $source, $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd,
211
-            $isNewCustomerNoLoss, $canReceive, $retainedStatus);
202
+        $params['loss_time_start'] = $request->input('loss_time_start');
203
+        $params['loss_time_end'] = $request->input('loss_time_end');
204
+        $params['is_new_customer_no_loss'] = $request->input('is_new_customer_no_loss');# 是否为新用户 0复粉 1新用户
205
+        $params['can_receive'] = $request->input('can_receive');       // 是否可正常接收群发消息 0否 1是
206
+        $params['retained_status'] = $request->input('retained_status');       // 是否在当前主体内还有留存 0否 1是
207
+
208
+        list($data, $count, $extra) = CustomerService::customerList($params, $page, $pageSize, $source);
212 209
         return self::returnPageValue($data, $count, $pageSize, $page, $extra);
213 210
     }
214 211
 
@@ -239,31 +236,28 @@ class CustomerController extends Controller
239 236
             return self::returnValue($validator->getMessageBag(), 1102);
240 237
         }
241 238
 
242
-        $customerName = $request->input('customer_name'); // 客户名关键字
243
-        $userIdList = $request->input('user_id_list'); // 所属客服
244
-        $addDateStart = $request->input('add_date_start'); // 起始添加日期
245
-        $addDateEnd = $request->input('add_date_end'); // 截止添加日期
246
-        $lastPayTimeStart = $request->input('last_pay_time_start'); // 最近一次充值时间起始
247
-        $lastPayTimeEnd = $request->input('last_pay_time_end'); // 最近一次充值时间截止
248
-        $addWay = $request->input('add_way'); // 添加渠道
249
-        $gender = $request->input('gender'); // 客户性别
250
-        $payStatus = $request->input('pay_status'); // 付费状态
251
-        $payNumMin = $request->input('pay_num_min'); // 最小付费次数
252
-        $payNumMax = $request->input('pay_num_max'); // 最高付费次数
253
-        $tagType = $request->input('tag_type', 0); // 标签筛选类型 0未筛选 1满足其一 2同时满足 3无标签
254
-        $tagIdList = $request->input('tag_id_list'); // 标签列表
255
-        $lossStatus = $request->input('loss_status'); // 客户流失状态
256
-        $corpid = $request->input('corpid');
257
-        $lossTimeStart = $request->input('loss_time_start');
258
-        $lossTimeEnd = $request->input('loss_time_end');
259
-        $isNewCustomerNoLoss = $request->input('is_new_customer_no_loss');# 是否为新用户 0复粉 1新用户
260
-        $canReceive = $request->input('can_receive');       // 是否可正常接收群发消息 0否 1是
261
-        $retainedStatus = $request->input('retained_status');       // 是否在当前主体内还有留存 0否 1是
262
-
263
-        $data = CustomerService::customerCountStat($customerName, $userIdList, $addDateStart, $addDateEnd,
264
-            $addWay, $gender, $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid,
265
-            $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive,
266
-            $retainedStatus);
239
+        $params['customer_name'] = $request->input('customer_name'); // 客户名关键字
240
+        $params['user_id_list'] = $request->input('user_id_list'); // 所属客服
241
+        $params['add_date_start'] = $request->input('add_date_start'); // 起始添加日期
242
+        $params['add_date_end'] = $request->input('add_date_end'); // 截止添加日期
243
+        $params['last_pay_time_start'] = $request->input('last_pay_time_start'); // 最近一次充值时间起始
244
+        $params['last_pay_time_end'] = $request->input('last_pay_time_end'); // 最近一次充值时间截止
245
+        $params['add_way'] = $request->input('add_way'); // 添加渠道
246
+        $params['gender'] = $request->input('gender'); // 客户性别
247
+        $params['pay_status'] = $request->input('pay_status'); // 付费状态
248
+        $params['pay_num_min'] = $request->input('pay_num_min'); // 最小付费次数
249
+        $params['pay_num_max'] = $request->input('pay_num_max'); // 最高付费次数
250
+        $params['tag_type'] = $request->input('tag_type', 0); // 标签筛选类型 0未筛选 1满足其一 2同时满足 3无标签
251
+        $params['tag_id_list'] = $request->input('tag_id_list'); // 标签列表
252
+        $params['loss_status'] = $request->input('loss_status'); // 客户流失状态
253
+        $params['corpid'] = $request->input('corpid');
254
+        $params['loss_time_start'] = $request->input('loss_time_start');
255
+        $params['loss_time_end'] = $request->input('loss_time_end');
256
+        $params['is_new_customer_no_loss'] = $request->input('is_new_customer_no_loss');# 是否为新用户 0复粉 1新用户
257
+        $params['can_receive'] = $request->input('can_receive');       // 是否可正常接收群发消息 0否 1是
258
+        $params['retained_status'] = $request->input('retained_status');       // 是否在当前主体内还有留存 0否 1是
259
+
260
+        $data = CustomerService::customerCountStat($params);
267 261
         return self::returnValue($data);
268 262
     }
269 263
 

+ 1 - 0
app/Http/Controllers/Api/TagController.php

@@ -58,6 +58,7 @@ class TagController extends Controller
58 58
         $params['loss_time_end'] = $request->input('loss_time_end');
59 59
         $params['is_new_customer_no_loss'] = $request->input('is_new_customer_no_loss');# 是否为新用户 0复粉 1新用户
60 60
         $params['can_receive'] = $request->input('can_receive');       // 是否可正常接收群发消息 0否 1是
61
+        $params['retained_status'] = $request->input('retained_status');       // 是否在当前主体内还有留存 0否 1是
61 62
 
62 63
         # 验证是否含有相同标签的任务
63 64
         $flag = TagService::getSameTaskStatus($corpid, $tagList, $type, $customerList, $selectAll, $filterCustomerList, $params);

+ 9 - 1
app/Models/BatchMarkTag.php

@@ -17,5 +17,13 @@ class BatchMarkTag extends Model
17 17
     public $timestamps = false;
18 18
     protected static $unguarded = true;
19 19
 
20
-    const BATCH_MARK_TAG = 'Playlet::batch_mark_tag';
20
+    const BATCH_MARK_TAG = 'Playlet::batchMarkTag';
21
+
22
+    public static function getTaskInfoById($taskId) {
23
+        return self::query()->where('enable', 1)->where('id', $taskId)->first();
24
+    }
25
+
26
+    public static function updateStatus($taskId, $status) {
27
+        return self::query()->where('id', $taskId)->update(['status' => $status]);
28
+    }
21 29
 }

+ 40 - 0
app/Models/BatchMarkTagRecord.php

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class BatchMarkTagRecord extends Model
8
+{
9
+    protected $table = 'dj_batch_mark_tag_record';
10
+    public $timestamps = false;
11
+    protected static $unguarded = true;
12
+
13
+    const BATCH_MARK_TAG_RECORD = 'Playlet::batchMarkTagRecord';
14
+
15
+    public static function savedData($taskId, $corpid, $userId, $externalUserIdList) {
16
+        $model = new BatchMarkTagRecord();
17
+
18
+        $model->task_id = $taskId;
19
+        $model->corpid = $corpid;
20
+        $model->user_id = $userId;
21
+        $model->external_userid_list = implode(',', $externalUserIdList);
22
+        $model->exec_total = count($externalUserIdList);
23
+        $model->save();
24
+
25
+        return $model;
26
+    }
27
+
28
+    public static function getInfoById($recordId) {
29
+        return self::query()->where('enable', 1)->where('id', $recordId)->first();
30
+    }
31
+
32
+    public static function updateData($recordId, $update) {
33
+        return self::query()->where('id', $recordId)->update($update);
34
+    }
35
+
36
+    public static function recordCount($taskId) {
37
+        $model = self::query()->where('enable', 1)->where('task_id', $taskId);
38
+        return $model->selectRaw('status, count(1) as count')->groupBy(['status'])->get();
39
+    }
40
+}

+ 4 - 0
app/Models/Customer.php

@@ -430,4 +430,8 @@ class Customer extends Model
430 430
 
431 431
         return $model->get();
432 432
     }
433
+
434
+    public static function getCustomerInfoByIdList($corpid, $customerIdList) {
435
+        return self::suffix($corpid)->where('corpid', $corpid)->where('enable', 1)->whereIn('id', $customerIdList)->get();
436
+    }
433 437
 }

+ 33 - 35
app/Models/CustomerDetails.php

@@ -651,7 +651,7 @@ class CustomerDetails extends Model
651 651
     public static function getCustomerModel($corpid, $source) {
652 652
         if(2 == $source) {
653 653
             // 在职迁移列表
654
-            $customerQuery = CustomerDetails::suffix($corpid)->where('loss_status', 1)->where('enable', 1);
654
+            $customerQuery = CustomerDetails::suffix($corpid)->whereIn('loss_status', [0, 1])->where('enable', 1);
655 655
         } else if(1 == $source) {
656 656
             // 客户列表 0已流失 1正常状态 2待分配
657 657
             $customerQuery = CustomerDetails::suffix($corpid)->where('enable', 1);
@@ -661,64 +661,62 @@ class CustomerDetails extends Model
661 661
         return $customerQuery;
662 662
     }
663 663
 
664
-    public static function getCustomerBySearch($customerName, $userIdList, $addDateStart, $addDateEnd, $addWay, $gender
665
-        , $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $source
666
-        , $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive, $retainedStatus) {
667
-        $customerQuery = CustomerDetails::getCustomerModel($corpid, $source);
664
+    public static function getCustomerBySearchNew ($search, $source) {
665
+        $customerQuery = CustomerDetails::getCustomerModel($search['corpid'], $source);
668 666
 
669
-        $customerQuery = $customerQuery->where('corpid', $corpid);
667
+        $customerQuery = $customerQuery->where('corpid', $search['corpid']);
670 668
 
671
-        if(!empty($customerName)) {$customerQuery = $customerQuery->where('name', 'like', '%'.$customerName.'%');}
672
-        if(!empty($userIdList)) {$customerQuery = $customerQuery->whereIn('user_id', $userIdList);}
673
-        if(!empty($addDateStart)) {$customerQuery = $customerQuery->where('createtime', '>=', strtotime($addDateStart . ' 00:00:00'));}
674
-        if(!empty($addDateEnd)) {$customerQuery = $customerQuery->where('createtime', '<=', strtotime($addDateEnd . ' 23:59:59'));}
675
-        if(!empty($lastPayTimeStart)) {$customerQuery = $customerQuery->where('last_pay_time', '>=', $lastPayTimeStart . ' 00:00:00');}
676
-        if(!empty($lastPayTimeEnd)) {$customerQuery = $customerQuery->where('last_pay_time', '<=', $lastPayTimeEnd . ' 23:59:59');}
669
+        if(!empty($search['customer_name'])) { $customerQuery = $customerQuery->where('name', 'like', '%'.$search['customer_name'].'%'); }
670
+        if(!empty($search['user_id_list'])) { $customerQuery = $customerQuery->whereIn('user_id', $search['user_id_list']); }
671
+        if(!empty($search['add_date_start'])) { $customerQuery = $customerQuery->where('createtime', '>=', strtotime($search['add_date_start'] . ' 00:00:00')); }
672
+        if(!empty($search['add_date_end'])) { $customerQuery = $customerQuery->where('createtime', '<=', strtotime($search['add_date_end'] . ' 23:59:59')); }
673
+        if(!empty($search['last_pay_time_start'])) { $customerQuery = $customerQuery->where('last_pay_time', '>=', $search['last_pay_time_start'] . ' 00:00:00'); }
674
+        if(!empty($search['last_pay_time_end'])) { $customerQuery = $customerQuery->where('last_pay_time', '<=', $search['last_pay_time_end'] . ' 23:59:59'); }
677 675
 
678
-        if(is_numeric($addWay)) {$customerQuery = $customerQuery->where('add_way', $addWay);}
679
-        if(is_numeric($canReceive)) {$customerQuery = $customerQuery->where('can_receive', $canReceive);}
680
-        if(is_numeric($retainedStatus)) {$customerQuery = $customerQuery->where('retained_status', $retainedStatus);}
681
-        if(is_array($addWay) && !empty($addWay)) {$customerQuery = $customerQuery->whereIn('add_way', $addWay);}
682
-        if(is_numeric($gender)) {$customerQuery = $customerQuery->where('gender', $gender);}
683
-        if(is_numeric($isNewCustomerNoLoss)) {
684
-            if(1 == $isNewCustomerNoLoss){$customerQuery = $customerQuery->whereIn('is_new_customer_no_loss', [1, 3]);}
685
-            else{$customerQuery = $customerQuery->where('is_new_customer_no_loss', 0);}
676
+        if(is_numeric($search['add_way'])) { $customerQuery = $customerQuery->where('add_way', $search['add_way']); }
677
+        if(is_numeric($search['can_receive'])) { $customerQuery = $customerQuery->where('can_receive', $search['can_receive']); }
678
+        if(is_numeric($search['retained_status'])) { $customerQuery = $customerQuery->where('retained_status', $search['retained_status']); }
679
+        if(is_array($search['add_way']) && !empty($search['add_way'])) { $customerQuery = $customerQuery->whereIn('add_way', $search['add_way']); }
680
+        if(is_numeric($search['gender'])) { $customerQuery = $customerQuery->where('gender', $search['gender']); }
681
+        if(is_numeric($search['is_new_customer_no_loss'])) {
682
+            if(1 == $search['is_new_customer_no_loss']){ $customerQuery = $customerQuery->whereIn('is_new_customer_no_loss', [1, 3]);
683
+            } else { $customerQuery = $customerQuery->where('is_new_customer_no_loss', 0); }
686 684
         }
687 685
 
688 686
         // 付款状态,付款次数筛选
689
-        if(is_numeric($payStatus)) {
690
-            if(0 == $payStatus) {$customerQuery->where('is_paid', 0);
691
-            }else {$customerQuery->where('is_paid', 1);}
692
-            if(is_numeric($payNumMax)) {$customerQuery = $customerQuery->where('pay_num', '<=', $payNumMax);}
693
-            if(is_numeric($payNumMin)) {$customerQuery = $customerQuery->where('pay_num', '>=', $payNumMin);}
687
+        if(is_numeric($search['pay_status'])) {
688
+            if(0 == $search['pay_status']) { $customerQuery->where('is_paid', 0);
689
+            } else {$customerQuery->where('is_paid', 1);}
690
+            if (is_numeric($search['pay_num_max'])) { $customerQuery = $customerQuery->where('pay_num', '<=', $search['pay_num_max']); }
691
+            if (is_numeric($search['pay_num_min'])) { $customerQuery = $customerQuery->where('pay_num', '>=', $search['pay_num_min']); }
694 692
         }
695 693
 
696
-        if(1 == $tagType) {
694
+        if(1 == $search['tag_type']) {
697 695
             $tagRaw = '';
698
-            foreach($tagIdList as $k=>$tagId) {
696
+            foreach($search['tag_id_list'] as $k => $tagId) {
699 697
                 $tagRaw .= $tagId;
700
-                if($k < count($tagIdList) -1){
698
+                if($k < count($search['tag_id_list']) -1){
701 699
                     $tagRaw = $tagRaw.' ';
702 700
                 }
703 701
             }
704 702
 
705 703
             $customerQuery = $customerQuery->whereRaw('match(`tag_list`) against ("'.$tagRaw.'" in boolean mode)');
706 704
         }
707
-        if(2 == $tagType) {
705
+        if(2 == $search['tag_type']) {
708 706
             $tagRaw = '';
709
-            foreach($tagIdList as $k=>$tagId) {
707
+            foreach($search['tag_id_list'] as $k => $tagId) {
710 708
                 $tagRaw .= '+'.$tagId;
711
-                if($k < count($tagIdList) -1){
709
+                if($k < count($search['tag_id_list']) -1){
712 710
                     $tagRaw = $tagRaw.' ';
713 711
                 }
714 712
             }
715 713
 
716 714
             $customerQuery = $customerQuery->whereRaw('match(`tag_list`) against ("'.$tagRaw.'" in boolean mode)');
717 715
         }
718
-        if(3 == $tagType) {$customerQuery = $customerQuery->whereNull('tag_list');}
719
-        if(!empty($lossTimeStart)) {$customerQuery->where('loss_time', '>=', $lossTimeStart);}
720
-        if(!empty($lossTimeEnd)) {$customerQuery->where('loss_time', '<=', $lossTimeEnd);}
721
-        if(is_numeric($lossStatus)) {$customerQuery = $customerQuery->where('loss_status', $lossStatus);}
716
+        if(3 == $search['tag_type']) { $customerQuery = $customerQuery->whereNull('tag_list'); }
717
+        if(!empty($search['loss_time_start'])) { $customerQuery->where('loss_time', '>=', $search['loss_time_start']); }
718
+        if(!empty($search['loss_time_end'])) { $customerQuery->where('loss_time', '<=', $search['loss_time_end']); }
719
+        if(is_numeric($search['loss_status'])) { $customerQuery = $customerQuery->where('loss_status', $search['loss_status']); }
722 720
 
723 721
         return $customerQuery;
724 722
     }

+ 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];

+ 7 - 15
app/Service/CustomerService.php

@@ -124,14 +124,11 @@ class CustomerService
124 124
     }
125 125
 
126 126
     // 客户管理列表
127
-    public static function customerList($customerName, $userIdList, $addDateStart, $addDateEnd, $addWay, $gender
128
-        , $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $page, $pageSize, $source
129
-        , $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive, $retainedStatus)
127
+    public static function customerList($search, $page, $pageSize, $source)
130 128
     {
131 129
         $extra = '';    // 当用户筛选了客户关注起止时间时,返回列表中客户对应的客服列表
132
-        $customerQuery = CustomerDetails::getCustomerBySearch($customerName, $userIdList, $addDateStart, $addDateEnd, $addWay, $gender
133
-            , $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $source
134
-            , $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive, $retainedStatus);
130
+        $customerQuery = CustomerDetails::getCustomerBySearchNew($search, $source);
131
+        $corpid = $search['corpid'];
135 132
 
136 133
         $customerRelationCount = clone $customerQuery;
137 134
         $followCount = $customerRelationCount->selectRaw('count(distinct(`con_user_cus`)) as count')->first();
@@ -144,7 +141,7 @@ class CustomerService
144 141
         $lossCountInfo = $customerLossQ->where('loss_status', 0)->selectRaw('count(distinct(`external_userid`)) as count')->first();
145 142
         $loss_count = $lossCountInfo->count ?? 0;
146 143
 
147
-        if($addDateStart && $addDateEnd) {
144
+        if($search['add_date_start'] && $search['add_date_end']) {
148 145
             $userListQuery = clone $customerQuery;
149 146
             $userIdList = $userListQuery->selectRaw('distinct(user_id) as user_id')->pluck('user_id');
150 147
 
@@ -3080,20 +3077,15 @@ class CustomerService
3080 3077
 
3081 3078
     }
3082 3079
 
3083
-    public static function customerCountStat($customerName, $userIdList, $addDateStart, $addDateEnd, $addWay, $gender
3084
-        , $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $lastPayTimeStart, $lastPayTimeEnd
3085
-        , $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive, $retainedStatus) {
3086
-
3080
+    public static function customerCountStat($search) {
3087 3081
         $source = 1;
3088
-        $customerQuery = CustomerDetails::getCustomerBySearch($customerName, $userIdList, $addDateStart, $addDateEnd, $addWay, $gender
3089
-            , $payStatus, $payNumMin, $payNumMax, $tagType, $tagIdList, $lossStatus, $corpid, $source
3090
-            , $lastPayTimeStart, $lastPayTimeEnd, $lossTimeStart, $lossTimeEnd, $isNewCustomerNoLoss, $canReceive, $retainedStatus);
3082
+        $customerQuery = CustomerDetails::getCustomerBySearchNew($search, $source);
3091 3083
 
3092 3084
         $data = $customerQuery->selectRaw("user_id, count(1) as count")->groupBy('user_id')->orderByDesc('count')->get();
3093 3085
         $insideUserIdList = array_unique(array_column($data->toArray(), 'user_id'));
3094 3086
 
3095 3087
         // 查询客服基本信息
3096
-        $search = ['corpid' => $corpid, 'user_list' => $insideUserIdList];
3088
+        $search = ['corpid' => $search['corpid'], 'user_list' => $insideUserIdList];
3097 3089
         $userDataList = DjUser::getUserBySearch($search);
3098 3090
 
3099 3091
         $result = [];

+ 1 - 0
app/Service/TagService.php

@@ -369,6 +369,7 @@ class TagService
369 369
         ];
370 370
 
371 371
         if(isset($res->id)) {
372
+            RedisModel::rPush(BatchMarkTag::BATCH_MARK_TAG, $res->id);
372 373
             return ['id' => $res->id];
373 374
         } else {
374 375
             Log::logInfo('batchCustomerTag 操作失败 request:'.json_encode($requestData, JSON_UNESCAPED_UNICODE), ['id' => 0], 'interface');