From 58243d9c17b74864f4dca76fd005a551193f804e Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Thu, 13 Nov 2025 16:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=BD=95=E5=85=A5=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E6=96=B0=E5=A2=9E=E5=A4=87=E6=B3=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/PosterWeChatMiniProgram.php | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/Server/application/cunkebao/controller/plan/PosterWeChatMiniProgram.php b/Server/application/cunkebao/controller/plan/PosterWeChatMiniProgram.php index dd1539a4..485e30f5 100644 --- a/Server/application/cunkebao/controller/plan/PosterWeChatMiniProgram.php +++ b/Server/application/cunkebao/controller/plan/PosterWeChatMiniProgram.php @@ -148,11 +148,11 @@ class PosterWeChatMiniProgram extends Controller { $taskId = request()->param('id'); - $phoneData = request()->param('phone'); - if (!$phoneData) { + $rawInput = trim((string)request()->param('phone', '')); + if ($rawInput === '') { return json([ 'code' => 400, - 'message' => '手机号不能为空' + 'message' => '手机号或微信号不能为空' ]); } $task = Db::name('customer_acquisition_task')->where('id', $taskId)->find(); @@ -165,31 +165,69 @@ class PosterWeChatMiniProgram extends Controller } - $phoneData = explode("\n", $phoneData); - foreach ($phoneData as $phone) { - if (empty($phone)) { + $lines = preg_split('/\r\n|\r|\n/', $rawInput); + foreach ($lines as $line) { + $line = trim($line); + if ($line === '') { continue; } - $trafficPool = Db::name('traffic_pool')->where('identifier', $phone)->find(); + $parts = array_map('trim', explode(',', $line, 2)); + $identifier = $parts[0] ?? ''; + $remark = $parts[1] ?? ''; + if ($identifier === '') { + continue; + } + $isPhone = preg_match('/^\+?\d{6,}$/', $identifier); + $trafficPool = Db::name('traffic_pool')->where('identifier', $identifier)->find(); if (!$trafficPool) { - Db::name('traffic_pool')->insert([ - 'identifier' => $phone, - 'mobile' => $phone, + $insertData = [ + 'identifier' => $identifier, 'createTime' => time() - ]); + ]; + if ($isPhone) { + $insertData['mobile'] = $identifier; + } else { + $insertData['wechatId'] = $identifier; + } + Db::name('traffic_pool')->insert($insertData); + } else { + $updates = []; + if ($isPhone && empty($trafficPool['mobile'])) { + $updates['mobile'] = $identifier; + } + if (!$isPhone && empty($trafficPool['wechatId'])) { + $updates['wechatId'] = $identifier; + } + if (!empty($updates)) { + $updates['updateTime'] = time(); + Db::name('traffic_pool')->where('id', $trafficPool['id'])->update($updates); + } } - $taskCustomer = Db::name('task_customer')->where('task_id', $taskId)->where('phone', $phone)->find(); + $taskCustomer = Db::name('task_customer') + ->where('task_id', $taskId) + ->where('phone', $identifier) + ->find(); if (empty($taskCustomer)) { - Db::name('task_customer')->insert([ + $insertCustomer = [ 'task_id' => $taskId, - // 'identifier' => $phone, - 'phone' => $phone, + 'phone' => $identifier, 'source' => $task['name'], 'createTime' => time(), 'tags' => json_encode([]), 'siteTags' => json_encode([]), - ]); + ]; + if ($remark !== '') { + $insertCustomer['remark'] = $remark; + } + Db::name('task_customer')->insert($insertCustomer); + } elseif ($remark !== '' && $taskCustomer['remark'] !== $remark) { + Db::name('task_customer') + ->where('id', $taskCustomer['id']) + ->update([ + 'remark' => $remark, + 'updateTime' => time() + ]); } }