From f5dd5e8191d1d5a2aafbe3e665bd59792f24862c Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 13 Aug 2025 17:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=AF=9D=E8=8E=B7=E5=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/common/TaskServer.php | 22 +- .../PostCreateAddFriendPlanV1Controller.php | 257 ++++++++---------- .../PostUpdateAddFriendPlanV1Controller.php | 184 +++++-------- ...PotentialListWithInCompanyV1Controller.php | 2 +- .../Adapters/ChuKeBao/Adapter.php | 125 +++++---- 5 files changed, 262 insertions(+), 328 deletions(-) diff --git a/Server/application/common/TaskServer.php b/Server/application/common/TaskServer.php index 5a6d2aa4..5af9303e 100644 --- a/Server/application/common/TaskServer.php +++ b/Server/application/common/TaskServer.php @@ -16,8 +16,8 @@ class TaskServer extends Server protected $socket = 'text://0.0.0.0:2980'; protected $option = [ - 'count' => self::PROCESS_COUNT, - 'name' => 'ckb_task_server' + 'count' => self::PROCESS_COUNT, + 'name' => 'ckb_task_server' ]; /** @@ -31,11 +31,17 @@ class TaskServer extends Server Log::record("error $code $msg"); } - public function onMessage($connection, $data) {} + public function onMessage($connection, $data) + { + } - public function onClose($connection) {} + public function onClose($connection) + { + } - public function onConnect($connection) {} + public function onConnect($connection) + { + } public function onWorkerStart($worker) { @@ -52,7 +58,7 @@ class TaskServer extends Server // 在一个进程里处理获客任务新是数据 if ($current_worker_id == 4) { - Timer::add(60, function () use($adapter) { + Timer::add(60, function () use ($adapter) { $adapter->handleCustomerTaskNewUser(); }); } @@ -60,7 +66,7 @@ class TaskServer extends Server // 在一个进程里处理获客任务添加后的相关逻辑 if ($current_worker_id == 3) { - Timer::add(60, function () use($adapter) { + Timer::add(60, function () use ($adapter) { $adapter->handleCustomerTaskWithStatusIsCreated(); }); } @@ -74,6 +80,6 @@ class TaskServer extends Server // 更多其他后台任务 // ...... - + } } diff --git a/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php b/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php index abead6c1..63cddf97 100644 --- a/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php +++ b/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php @@ -16,7 +16,7 @@ class PostCreateAddFriendPlanV1Controller extends BaseController /** * 生成唯一API密钥 - * + * * @return string */ public function generateApiKey() @@ -24,7 +24,7 @@ class PostCreateAddFriendPlanV1Controller extends BaseController // 生成5组随机字符串,每组5个字符 $chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $apiKey = ''; - + for ($i = 0; $i < 5; $i++) { $segment = ''; for ($j = 0; $j < 5; $j++) { @@ -32,17 +32,17 @@ class PostCreateAddFriendPlanV1Controller extends BaseController } $apiKey .= ($i > 0 ? '-' : '') . $segment; } - + // 检查是否已存在 $exists = Db::name('customer_acquisition_task') ->where('apiKey', $apiKey) ->find(); - + if ($exists) { // 如果已存在,递归重新生成 return $this->generateApiKey(); } - + return $apiKey; } @@ -60,29 +60,29 @@ class PostCreateAddFriendPlanV1Controller extends BaseController if (empty($params['name'])) { return ResponseHelper::error('计划名称不能为空', 400); } - + if (empty($params['sceneId'])) { return ResponseHelper::error('场景ID不能为空', 400); } - + if (empty($params['deveiceGroups'])) { return ResponseHelper::error('请选择设备', 400); } - + // 归类参数 $msgConf = isset($params['messagePlans']) ? $params['messagePlans'] : []; $tagConf = [ 'scenarioTags' => $params['scenarioTags'] ?? [], - 'customTags' => $params['customTags'] ?? [], + 'customTags' => $params['customTags'] ?? [], ]; $reqConf = [ - 'device' => $params['deveiceGroups'] ?? [], - 'remarkType' => $params['remarkType'] ?? '', - 'greeting' => $params['greeting'] ?? '', + 'device' => $params['deveiceGroups'] ?? [], + 'remarkType' => $params['remarkType'] ?? '', + 'greeting' => $params['greeting'] ?? '', 'addFriendInterval' => $params['addFriendInterval'] ?? '', - 'startTime' => $params['startTime'] ?? '', - 'endTime' => $params['endTime'] ?? '', + 'startTime' => $params['startTime'] ?? '', + 'endTime' => $params['endTime'] ?? '', ]; // 其余参数归为sceneConf $sceneConf = $params; @@ -111,18 +111,18 @@ class PostCreateAddFriendPlanV1Controller extends BaseController // 构建数据 $data = [ - 'name' => $params['name'], - 'sceneId' => $params['sceneId'], + 'name' => $params['name'], + 'sceneId' => $params['sceneId'], 'sceneConf' => json_encode($sceneConf, JSON_UNESCAPED_UNICODE), - 'reqConf' => json_encode($reqConf, JSON_UNESCAPED_UNICODE), - 'msgConf' => json_encode($msgConf, JSON_UNESCAPED_UNICODE), - 'tagConf' => json_encode($tagConf, JSON_UNESCAPED_UNICODE), - 'userId' => $this->getUserInfo('id'), + 'reqConf' => json_encode($reqConf, JSON_UNESCAPED_UNICODE), + 'msgConf' => json_encode($msgConf, JSON_UNESCAPED_UNICODE), + 'tagConf' => json_encode($tagConf, JSON_UNESCAPED_UNICODE), + 'userId' => $this->getUserInfo('id'), 'companyId' => $this->getUserInfo('companyId'), - 'status' => !empty($params['status']) ? 1 : 0, - 'apiKey' => $this->generateApiKey(), // 生成API密钥 - 'createTime'=> time(), - 'updateTime'=> time(), + 'status' => !empty($params['status']) ? 1 : 0, + 'apiKey' => $this->generateApiKey(), // 生成API密钥 + 'createTime' => time(), + 'updateTime' => time(), ]; @@ -130,15 +130,15 @@ class PostCreateAddFriendPlanV1Controller extends BaseController Db::startTrans(); // 插入数据 $planId = Db::name('customer_acquisition_task')->insertGetId($data); - + if (!$planId) { throw new \Exception('添加计划失败'); } //订单 - if($params['sceneId'] == 2){ - if(!empty($params['orderTableFile'])){ + if ($params['sceneId'] == 2) { + if (!empty($params['orderTableFile'])) { // 先下载到本地临时文件,再分析,最后删除 $originPath = $params['orderTableFile']; $tmpFile = tempnam(sys_get_temp_dir(), 'order_'); @@ -171,12 +171,12 @@ class PostCreateAddFriendPlanV1Controller extends BaseController foreach ($data as $cols) { $rows[] = [ - 'name' => isset($cols[0]) ? trim($cols[0]) : '', - 'phone' => isset($cols[1]) ? trim($cols[1]) : '', - 'wechat' => isset($cols[2]) ? trim($cols[2]) : '', - 'source' => isset($cols[3]) ? trim($cols[3]) : '', + 'name' => isset($cols[0]) ? trim($cols[0]) : '', + 'phone' => isset($cols[1]) ? trim($cols[1]) : '', + 'wechatId' => isset($cols[2]) ? trim($cols[2]) : '', + 'source' => isset($cols[3]) ? trim($cols[3]) : '', 'orderAmount' => isset($cols[4]) ? trim($cols[4]) : '', - 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', + 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', ]; } } elseif ($ext === 'csv') { @@ -189,12 +189,12 @@ class PostCreateAddFriendPlanV1Controller extends BaseController $cols = str_getcsv($line); if (count($cols) >= 6) { $rows[] = [ - 'name' => isset($cols[0]) ? trim($cols[0]) : '', - 'phone' => isset($cols[1]) ? trim($cols[1]) : '', - 'wechat' => isset($cols[2]) ? trim($cols[2]) : '', - 'source' => isset($cols[3]) ? trim($cols[3]) : '', + 'name' => isset($cols[0]) ? trim($cols[0]) : '', + 'phone' => isset($cols[1]) ? trim($cols[1]) : '', + 'wechatId' => isset($cols[2]) ? trim($cols[2]) : '', + 'source' => isset($cols[3]) ? trim($cols[3]) : '', 'orderAmount' => isset($cols[4]) ? trim($cols[4]) : '', - 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', + 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', ]; } } @@ -205,62 +205,19 @@ class PostCreateAddFriendPlanV1Controller extends BaseController } // 删除临时文件 unlink($tmpFile); - - // 1000条为一组进行批量处理 - $batchSize = 1000; - $totalRows = count($rows); - - for ($i = 0; $i < $totalRows; $i += $batchSize) { - $batchRows = array_slice($rows, $i, $batchSize); - - if (!empty($batchRows)) { - // 1. 提取当前批次的phone - $phones = []; - foreach ($batchRows as $row) { - $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; - if (!empty($phone)) { - $phones[] = $phone; - } - } - - // 2. 批量查询已存在的phone - $existingPhones = []; - if (!empty($phones)) { - $existing = Db::name('task_customer') - ->where('task_id', $planId) - ->where('phone', 'in', $phones) - ->field('phone') - ->select(); - $existingPhones = array_column($existing, 'phone'); - } - - // 3. 过滤出新数据,批量插入 - $newData = []; - foreach ($batchRows as $row) { - $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; - if (!empty($phone) && !in_array($phone, $existingPhones)) { - $newData[] = [ - 'task_id' => $planId, - 'name' => $row['name'] ?? '', - 'source' => $row['source'] ?? '', - 'phone' => $phone, - 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'createTime' => time(), - ]; - } - } - - // 4. 批量插入新数据 - if (!empty($newData)) { - Db::name('task_customer')->insertAll($newData); - } - } - } - } } + //电话获客 + if ($params['sceneId'] == 5) { + $rows = Db::name('call_recording') + ->where('companyId', $this->getUserInfo('companyId')) + ->group('phone') + ->field('id,phone') + ->select(); + } + + //群获客 if ($params['sceneId'] == 7) { if (!empty($params['wechatGroups']) && is_array($params['wechatGroups'])) { @@ -270,69 +227,71 @@ class PostCreateAddFriendPlanV1Controller extends BaseController ->whereIn('gm.groupId', $params['wechatGroups']) ->group('gm.identifier') ->column('wa.id,wa.wechatId,wa.alias,wa.phone'); + } + } - // 1000条为一组进行批量处理 - $batchSize = 1000; - $totalRows = count($rows); + if (in_array($params['sceneId'], [2, 5, 7]) && !empty($rows) && is_array($rows)) { + // 1000条为一组进行批量处理 + $batchSize = 1000; + $totalRows = count($rows); - for ($i = 0; $i < $totalRows; $i += $batchSize) { - $batchRows = array_slice($rows, $i, $batchSize); + for ($i = 0; $i < $totalRows; $i += $batchSize) { + $batchRows = array_slice($rows, $i, $batchSize); - if (!empty($batchRows)) { - // 1. 提取当前批次的phone - $phones = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone)) { - $phones[] = $phone; - } + if (!empty($batchRows)) { + // 1. 提取当前批次的phone + $phones = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = $row['phone']; + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } - - // 2. 批量查询已存在的phone - $existingPhones = []; - if (!empty($phones)) { - $existing = Db::name('task_customer') - ->where('task_id', $planId) - ->where('phone', 'in', $phones) - ->field('phone') - ->select(); - $existingPhones = array_column($existing, 'phone'); + if (!empty($phone)) { + $phones[] = $phone; } + } - // 3. 过滤出新数据,批量插入 - $newData = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone) && !in_array($phone, $existingPhones)) { - $newData[] = [ - 'task_id' => $planId, - 'name' => '', - 'source' => '场景获客_' . $params['name'] ?? '', - 'phone' => $phone, - 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'createTime' => time(), - ]; - } - } + // 2. 批量查询已存在的phone + $existingPhones = []; + if (!empty($phones)) { + $existing = Db::name('task_customer') + ->where('task_id', $planId) + ->where('phone', 'in', $phones) + ->field('phone') + ->select(); + $existingPhones = array_column($existing, 'phone'); + } - // 4. 批量插入新数据 - if (!empty($newData)) { - Db::name('task_customer')->insertAll($newData); + // 3. 过滤出新数据,批量插入 + $newData = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = $row['phone']; + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } + if (!empty($phone) && !in_array($phone, $existingPhones)) { + $newData[] = [ + 'task_id' => $planId, + 'name' => '', + 'source' => '场景获客_' . $params['name'] ?? '', + 'phone' => $phone, + 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'createTime' => time(), + ]; + } + } + + // 4. 批量插入新数据 + if (!empty($newData)) { + Db::name('task_customer')->insertAll($newData); } } } @@ -340,21 +299,21 @@ class PostCreateAddFriendPlanV1Controller extends BaseController Db::commit(); - + return ResponseHelper::success(['planId' => $planId], '添加计划任务成功'); - + } catch (\Exception $e) { // 回滚事务 Db::rollback(); throw $e; } - + } catch (\Exception $e) { return ResponseHelper::error('系统错误: ' . $e->getMessage(), 500); } } - /** + /** * 验证JSON格式是否正确 * * @param string $string @@ -365,7 +324,7 @@ class PostCreateAddFriendPlanV1Controller extends BaseController if (empty($string)) { return true; } - + json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } diff --git a/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php b/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php index 7d3014d6..1e70104a 100644 --- a/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php +++ b/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php @@ -10,7 +10,7 @@ use think\Db; /** * 更新获客计划控制器 */ -class PostUpdateAddFriendPlanV1Controller extends BaseController +class PostUpdateAddFriendPlanV1Controller extends BaseController { /** * 更新计划任务 @@ -96,12 +96,11 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController 'reqConf' => json_encode($reqConf, JSON_UNESCAPED_UNICODE), 'msgConf' => json_encode($msgConf, JSON_UNESCAPED_UNICODE), 'tagConf' => json_encode($tagConf, JSON_UNESCAPED_UNICODE), - 'status' => !empty($params['status']) ? 1 : 0, + 'status' => !empty($params['status']) ? 1 : 0, 'updateTime' => time(), ]; - try { // 更新数据 $result = Db::name('customer_acquisition_task') @@ -149,7 +148,7 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController $rows[] = [ 'name' => isset($cols[0]) ? trim($cols[0]) : '', 'phone' => isset($cols[1]) ? trim($cols[1]) : '', - 'wechat' => isset($cols[2]) ? trim($cols[2]) : '', + 'wechatId' => isset($cols[2]) ? trim($cols[2]) : '', 'source' => isset($cols[3]) ? trim($cols[3]) : '', 'orderAmount' => isset($cols[4]) ? trim($cols[4]) : '', 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', @@ -167,7 +166,7 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController $rows[] = [ 'name' => isset($cols[0]) ? trim($cols[0]) : '', 'phone' => isset($cols[1]) ? trim($cols[1]) : '', - 'wechat' => isset($cols[2]) ? trim($cols[2]) : '', + 'wechatId' => isset($cols[2]) ? trim($cols[2]) : '', 'source' => isset($cols[3]) ? trim($cols[3]) : '', 'orderAmount' => isset($cols[4]) ? trim($cols[4]) : '', 'orderDate' => isset($cols[5]) ? trim($cols[5]) : '', @@ -181,62 +180,19 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController } // 删除临时文件 unlink($tmpFile); - - // 1000条为一组进行批量处理 - $batchSize = 1000; - $totalRows = count($rows); - - for ($i = 0; $i < $totalRows; $i += $batchSize) { - $batchRows = array_slice($rows, $i, $batchSize); - - if (!empty($batchRows)) { - // 1. 提取当前批次的phone - $phones = []; - foreach ($batchRows as $row) { - $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; - if (!empty($phone)) { - $phones[] = $phone; - } - } - - // 2. 批量查询已存在的phone - $existingPhones = []; - if (!empty($phones)) { - $existing = Db::name('task_customer') - ->where('task_id', $params['planId']) - ->where('phone', 'in', $phones) - ->field('phone') - ->select(); - $existingPhones = array_column($existing, 'phone'); - } - - // 3. 过滤出新数据,批量插入 - $newData = []; - foreach ($batchRows as $row) { - $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; - if (!empty($phone) && !in_array($phone, $existingPhones)) { - $newData[] = [ - 'task_id' => $params['planId'], - 'name' => $row['name'] ?? '', - 'source' => $row['source'] ?? '', - 'phone' => $phone, - 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'createTime' => time(), - ]; - } - } - - // 4. 批量插入新数据 - if (!empty($newData)) { - Db::name('task_customer')->insertAll($newData); - } - } - } - } } + + //电话获客 + if ($params['sceneId'] == 5) { + $rows = Db::name('call_recording') + ->where('companyId', $this->getUserInfo('companyId')) + ->group('phone') + ->field('id,phone') + ->select(); + } + //群获客 if ($params['sceneId'] == 7) { if (!empty($params['wechatGroups']) && is_array($params['wechatGroups'])) { @@ -246,74 +202,76 @@ class PostUpdateAddFriendPlanV1Controller extends BaseController ->whereIn('gm.groupId', $params['wechatGroups']) ->group('gm.identifier') ->column('wa.id,wa.wechatId,wa.alias,wa.phone'); + } + } - // 1000条为一组进行批量处理 - $batchSize = 1000; - $totalRows = count($rows); + if (in_array($params['sceneId'], [2, 5, 7]) && !empty($rows) && is_array($rows)) { + // 1000条为一组进行批量处理 + $batchSize = 1000; + $totalRows = count($rows); - for ($i = 0; $i < $totalRows; $i += $batchSize) { - $batchRows = array_slice($rows, $i, $batchSize); - - if (!empty($batchRows)) { - // 1. 提取当前批次的phone - $phones = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone)) { - $phones[] = $phone; - } + for ($i = 0; $i < $totalRows; $i += $batchSize) { + $batchRows = array_slice($rows, $i, $batchSize); + if (!empty($batchRows)) { + // 1. 提取当前批次的phone + // 1. 提取当前批次的phone + $phones = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = $row['phone']; + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } - - // 2. 批量查询已存在的phone - $existingPhones = []; - if (!empty($phones)) { - $existing = Db::name('task_customer') - ->where('task_id', $params['planId']) - ->where('phone', 'in', $phones) - ->field('phone') - ->select(); - $existingPhones = array_column($existing, 'phone'); + if (!empty($phone)) { + $phones[] = $phone; } + } + // 2. 批量查询已存在的phone + $existingPhones = []; + if (!empty($phones)) { + $existing = Db::name('task_customer') + ->where('task_id', $params['planId']) + ->where('phone', 'in', $phones) + ->field('phone') + ->select(); + $existingPhones = array_column($existing, 'phone'); + } - // 3. 过滤出新数据,批量插入 - $newData = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone) && !in_array($phone, $existingPhones)) { - $newData[] = [ - 'task_id' => $params['planId'], - 'name' => '', - 'source' => '场景获客_' . $params['name'] ?? '', - 'phone' => $phone, - 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'createTime' => time(), - ]; - } + // 3. 过滤出新数据,批量插入 + $newData = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = $row['phone']; + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } + if (!empty($phone) && !in_array($phone, $existingPhones)) { + $newData[] = [ + 'task_id' => $params['planId'], + 'name' => !empty($row['name']) ? $row['name'] : '', + 'source' => '场景获客_' . $params['name'] ?? '', + 'phone' => $phone, + 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'createTime' => time(), + ]; + } + } - // 4. 批量插入新数据 - if (!empty($newData)) { - Db::name('task_customer')->insertAll($newData); - } + // 4. 批量插入新数据 + if (!empty($newData)) { + Db::name('task_customer')->insertAll($newData); } } } } + return ResponseHelper::success(['planId' => $params['planId']], '更新计划任务成功'); } catch (\Exception $e) { diff --git a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php index ec35f503..4085727d 100644 --- a/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php +++ b/Server/application/cunkebao/controller/traffic/GetPotentialListWithInCompanyV1Controller.php @@ -43,7 +43,7 @@ class GetPotentialListWithInCompanyV1Controller extends BaseController } - if ($device = $this->request->param('device')) { + if ($device = $this->request->param('deviceId')) { $where['d.deviceId'] = $device; } diff --git a/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php b/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php index 4879e277..1998a070 100644 --- a/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php +++ b/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php @@ -339,7 +339,7 @@ class Adapter implements WeChatServiceInterface { $task = Db::name('customer_acquisition_task') ->where(['status' => 1, 'deleteTime' => 0]) - ->whereIn('sceneId', [7]) + ->whereIn('sceneId', [5, 7]) ->order('id desc') ->select(); @@ -349,7 +349,17 @@ class Adapter implements WeChatServiceInterface foreach ($task as $item) { $sceneConf = json_decode($item['sceneConf'], true); - //群获客 + //电话 + if ($item['sceneId'] == 5) { + $rows = Db::name('call_recording') + ->where('companyId', $item['companyId']) + ->group('phone') + ->field('id,phone') + ->order('id asc') + ->limit(0, 100) + ->select(); + } + if ($item['sceneId'] == 7) { if (!empty($sceneConf['groupSelected']) && is_array($sceneConf['groupSelected'])) { $rows = Db::name('wechat_group_member')->alias('gm') @@ -358,76 +368,77 @@ class Adapter implements WeChatServiceInterface ->whereIn('gm.groupId', $sceneConf['groupSelected']) ->group('gm.identifier') ->column('wa.id,wa.wechatId,wa.alias,wa.phone'); + } + } - // 1000条为一组进行批量处理 - $batchSize = 1000; - $totalRows = count($rows); + if (in_array($item['sceneId'], [5, 7]) && !empty($rows) && is_array($rows)) { + // 1000条为一组进行批量处理 + $batchSize = 1000; + $totalRows = count($rows); - for ($i = 0; $i < $totalRows; $i += $batchSize) { - $batchRows = array_slice($rows, $i, $batchSize); + for ($i = 0; $i < $totalRows; $i += $batchSize) { + $batchRows = array_slice($rows, $i, $batchSize); - if (!empty($batchRows)) { - // 1. 提取当前批次的phone - $phones = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone)) { - $phones[] = $phone; - } + if (!empty($batchRows)) { + // 1. 提取当前批次的phone + $phones = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = !empty($row['phone']); + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } - - // 2. 批量查询已存在的phone - $existingPhones = []; - if (!empty($phones)) { - $existing = Db::name('task_customer') - ->where('task_id', $item['id']) - ->where('phone', 'in', $phones) - ->field('phone') - ->select(); - $existingPhones = array_column($existing, 'phone'); + if (!empty($phone)) { + $phones[] = $phone; } + } - // 3. 过滤出新数据,批量插入 - $newData = []; - foreach ($batchRows as $row) { - if (!empty($row['phone'])) { - $phone = !empty($row['phone']); - } elseif (!empty($row['alias'])) { - $phone = $row['alias']; - } else { - $phone = $row['wechatId']; - } - if (!empty($phone) && !in_array($phone, $existingPhones)) { - $newData[] = [ - 'task_id' => $item['id'], - 'name' => '', - 'source' => '场景获客_' . $item['name'], - 'phone' => $phone, - 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), - 'createTime' => time(), - ]; - } - } + // 2. 批量查询已存在的phone + $existingPhones = []; + if (!empty($phones)) { + $existing = Db::name('task_customer') + ->where('task_id', $item['id']) + ->where('phone', 'in', $phones) + ->field('phone') + ->select(); + $existingPhones = array_column($existing, 'phone'); + } - // 4. 批量插入新数据 - if (!empty($newData)) { - Db::name('task_customer')->insertAll($newData); + // 3. 过滤出新数据,批量插入 + $newData = []; + foreach ($batchRows as $row) { + if (!empty($row['phone'])) { + $phone = !empty($row['phone']); + } elseif (!empty($row['alias'])) { + $phone = $row['alias']; + } else { + $phone = $row['wechatId']; } + if (!empty($phone) && !in_array($phone, $existingPhones)) { + $newData[] = [ + 'task_id' => $item['id'], + 'name' => '', + 'source' => '场景获客_' . $item['name'], + 'phone' => $phone, + 'tags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'siteTags' => json_encode([], JSON_UNESCAPED_UNICODE), + 'createTime' => time(), + ]; + } + } + + // 4. 批量插入新数据 + if (!empty($newData)) { + Db::name('task_customer')->insertAll($newData); } } } } - exit_data($sceneConf); } }