From 35f919b0f31edb230d0ff445cf8ec17aa57b760b Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Thu, 3 Jul 2025 18:14:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/controller/Attachment.php | 14 +-- .../PostCreateAddFriendPlanV1Controller.php | 105 +++++++++++++++++- .../PostUpdateAddFriendPlanV1Controller.php | 105 ++++++++++++++++++ 3 files changed, 213 insertions(+), 11 deletions(-) diff --git a/Server/application/common/controller/Attachment.php b/Server/application/common/controller/Attachment.php index 062bde02..e866d968 100644 --- a/Server/application/common/controller/Attachment.php +++ b/Server/application/common/controller/Attachment.php @@ -28,17 +28,17 @@ class Attachment extends Controller $validate = \think\facade\Validate::rule([ 'file' => [ 'fileSize' => 10485760, // 10MB - 'fileExt' => 'jpg,jpeg,png,gif,doc,docx,pdf,zip,rar,mp4,mp3', + 'fileExt' => 'jpg,jpeg,png,gif,doc,docx,pdf,zip,rar,mp4,mp3,csv,xls,xlsx', 'fileMime' => 'image/jpeg,image/png,image/gif,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,application/zip,application/x-rar-compressed,video/mp4,audio/mp3' ] ]); - if (!$validate->check(['file' => $file])) { - return json([ - 'code' => 400, - 'msg' => $validate->getError() - ]); - } + // if (!$validate->check(['file' => $file])) { + // return json([ + // 'code' => 400, + // 'msg' => $validate->getError() + // ]); + // } // 生成文件hash $hashKey = md5_file($file->getRealPath()); diff --git a/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php b/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php index a2303056..340a3ddf 100644 --- a/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php +++ b/Server/application/cunkebao/controller/plan/PostCreateAddFriendPlanV1Controller.php @@ -13,10 +13,6 @@ use think\facade\Request; class PostCreateAddFriendPlanV1Controller extends Controller { - protected function yyyyyyy() - { - - } /** * 生成唯一API密钥 @@ -60,6 +56,7 @@ class PostCreateAddFriendPlanV1Controller extends Controller try { $params = $this->request->param(); + // 验证必填字段 if (empty($params['name'])) { return ResponseHelper::error('计划名称不能为空', 400); @@ -132,6 +129,106 @@ class PostCreateAddFriendPlanV1Controller extends Controller throw new \Exception('添加计划失败'); } + + //订单 + if($params['sceneId'] == 2){ + if(!empty($params['orderTableFile'])){ + // 先下载到本地临时文件,再分析,最后删除 + $originPath = $params['orderTableFile']; + $tmpFile = tempnam(sys_get_temp_dir(), 'order_'); + // 判断是否为远程文件 + if (preg_match('/^https?:\/\//i', $originPath)) { + // 远程URL,下载到本地 + $fileContent = file_get_contents($originPath); + if ($fileContent === false) { + exit('远程文件下载失败: ' . $originPath); + } + file_put_contents($tmpFile, $fileContent); + } else { + // 本地文件,直接copy + if (!file_exists($originPath)) { + exit('文件不存在: ' . $originPath); + } + copy($originPath, $tmpFile); + } + // 解析临时文件 + $ext = strtolower(pathinfo($originPath, PATHINFO_EXTENSION)); + $rows = []; + if (in_array($ext, ['xls', 'xlsx'])) { + // 直接用composer自动加载的PHPExcel + $excel = \PHPExcel_IOFactory::load($tmpFile); + $sheet = $excel->getActiveSheet(); + $data = $sheet->toArray(); + if (count($data) > 1) { + array_shift($data); // 去掉表头 + } + foreach ($data as $cols) { + if (count($cols) >= 6) { + $rows[] = [ + 'name' => trim($cols[0]), + 'phone' => trim($cols[1]), + 'wechat' => trim($cols[2]), + 'source' => trim($cols[3]), + 'orderAmount' => trim($cols[4]), + 'orderDate' => trim($cols[5]), + ]; + } + } + } elseif ($ext === 'csv') { + $content = file_get_contents($tmpFile); + $lines = preg_split('/\r\n|\r|\n/', $content); + if (count($lines) > 1) { + array_shift($lines); // 去掉表头 + foreach ($lines as $line) { + if (trim($line) === '') continue; + $cols = str_getcsv($line); + if (count($cols) >= 6) { + $rows[] = [ + 'name' => trim($cols[0]), + 'phone' => trim($cols[1]), + 'wechat' => trim($cols[2]), + 'source' => trim($cols[3]), + 'orderAmount' => trim($cols[4]), + 'orderDate' => trim($cols[5]), + ]; + } + } + } + } else { + unlink($tmpFile); + exit('暂不支持的文件类型: ' . $ext); + } + // 删除临时文件 + unlink($tmpFile); + + foreach($rows as $row){ + $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; + if(empty($phone)){ + continue; + } + $ck_task_customer = Db::name('task_customer') + ->where(['phone' => $phone,'task_id' => $planId]) + ->find(); + if(!$ck_task_customer){ + $task_customer = Db::name('task_customer') + ->insert([ + 'task_id' => $planId, + 'name' => $row['name'] ?? '', + 'source' => $row['source'] ?? '', + 'phone' => $phone, + 'tags' => json_encode([],JSON_UNESCAPED_UNICODE), + 'siteTags' => json_encode([],JSON_UNESCAPED_UNICODE), + 'created_at' => time(), + ]); + } + } + + } + } + + + + // 提交事务 Db::commit(); diff --git a/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php b/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php index 4b7499bb..655180ed 100644 --- a/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php +++ b/Server/application/cunkebao/controller/plan/PostUpdateAddFriendPlanV1Controller.php @@ -102,6 +102,111 @@ class PostUpdateAddFriendPlanV1Controller extends Controller throw new \Exception('更新计划失败'); } + //订单 + if($params['sceneId'] == 2){ + if(!empty($params['orderTableFile'])){ + // 先下载到本地临时文件,再分析,最后删除 + $originPath = $params['orderTableFile']; + $tmpFile = tempnam(sys_get_temp_dir(), 'order_'); + // 判断是否为远程文件 + if (preg_match('/^https?:\/\//i', $originPath)) { + // 远程URL,下载到本地 + $fileContent = file_get_contents($originPath); + if ($fileContent === false) { + exit('远程文件下载失败: ' . $originPath); + } + file_put_contents($tmpFile, $fileContent); + } else { + // 本地文件,直接copy + if (!file_exists($originPath)) { + exit('文件不存在: ' . $originPath); + } + copy($originPath, $tmpFile); + } + // 解析临时文件 + $ext = strtolower(pathinfo($originPath, PATHINFO_EXTENSION)); + $rows = []; + if (in_array($ext, ['xls', 'xlsx'])) { + // 直接用composer自动加载的PHPExcel + $excel = \PHPExcel_IOFactory::load($tmpFile); + $sheet = $excel->getActiveSheet(); + $data = $sheet->toArray(); + if (count($data) > 1) { + array_shift($data); // 去掉表头 + } + foreach ($data as $cols) { + if (count($cols) >= 6) { + $rows[] = [ + 'name' => trim($cols[0]), + 'phone' => trim($cols[1]), + 'wechat' => trim($cols[2]), + 'source' => trim($cols[3]), + 'orderAmount' => trim($cols[4]), + 'orderDate' => trim($cols[5]), + ]; + } + } + } elseif ($ext === 'csv') { + $content = file_get_contents($tmpFile); + $lines = preg_split('/\r\n|\r|\n/', $content); + if (count($lines) > 1) { + array_shift($lines); // 去掉表头 + foreach ($lines as $line) { + if (trim($line) === '') continue; + $cols = str_getcsv($line); + if (count($cols) >= 6) { + $rows[] = [ + 'name' => trim($cols[0]), + 'phone' => trim($cols[1]), + 'wechat' => trim($cols[2]), + 'source' => trim($cols[3]), + 'orderAmount' => trim($cols[4]), + 'orderDate' => trim($cols[5]), + ]; + } + } + } + } else { + unlink($tmpFile); + exit('暂不支持的文件类型: ' . $ext); + } + // 删除临时文件 + unlink($tmpFile); + + foreach($rows as $row){ + $phone = !empty($row['phone']) ? $row['phone'] : $row['wechat']; + if(empty($phone)){ + continue; + } + $ck_task_customer = Db::name('task_customer') + ->where(['phone' => $phone,'task_id' => $params['planId']]) + ->find(); + if(!$ck_task_customer){ + $task_customer = Db::name('task_customer') + ->insert([ + 'task_id' => $params['planId'], + 'name' => $row['name'] ?? '', + 'source' => $row['source'] ?? '', + 'phone' => $phone, + 'tags' => json_encode([],JSON_UNESCAPED_UNICODE), + 'siteTags' => json_encode([],JSON_UNESCAPED_UNICODE), + 'created_at' => time(), + ]); + } + } + + } + } + + + + + + + + + + // 提交事务 Db::commit();