Procházet zdrojové kódy

fixbug:调整导入功能

yb před 2 měsíci
rodič
revize
18e23f67aa
1 změnil soubory, kde provedl 27 přidání a 8 odebrání
  1. 27 8
      app/admin/service/consultant/CustomService.php

+ 27 - 8
app/admin/service/consultant/CustomService.php

@@ -1210,6 +1210,7 @@ class CustomService
                 $sucNums = 0;
                 $errNums = 0;
                 $validate = '/^1\d{10}$/';
+                $errorData = [];
                 Db::beginTransaction();
                 try {
                     foreach ($data as $key => $val) {
@@ -1217,20 +1218,27 @@ class CustomService
                         $line = '姓名:'.$val[1].' 第'.($key + 2).'行:';
                         $mobile = $val[2] ?? '';
                         $mobile = trim($mobile);
+                        $error = [];
+                        $msg = '';
                         if (empty($val[7]) && empty($val[8])) {
+                            $msg = $line.'报备人和顾问必须存在其中之一';
                             throw new \Exception($line.'报备人和顾问必须存在其中之一');
                         }
                         if (empty($val[9])) {
+                            $msg = $line.'无团队信息';
                             throw new \Exception($line.'无团队信息');
                         }
                         if ($val[0] == '1970-01-01 08:00:00') {
-                            throw new \Exception($line.'日期格式错误');
+                            $msg = $line.'日期格式错误';
+//                            throw new \Exception($line.'日期格式错误');
                         }
                         if (empty($mobile)) {
-                            throw new \Exception($line.'手机号不能为空');
+                            $msg = $line.'手机号不能为空';
+//                            throw new \Exception($line.'手机号不能为空');
                         }
                         if (!preg_match($validate, $mobile)) {
-                            throw new \Exception($line.'手机号格式非法');
+                            $msg = $line.'手机号格式非法';
+//                            throw new \Exception($line.'手机号格式非法');
                         }
                         $consultantName = $val[7];
                         $reportName = $val[8];
@@ -1240,7 +1248,8 @@ class CustomService
                         $reportKey = $reportName.'-'.$teamName;
                         $reportConsultantId = $teamKeys[$reportKey]['consultant_id'] ?? 0;
                         if ($consultantId <= 0 && $reportConsultantId <= 0) {
-                            throw new \Exception($line.'健康顾问或报备人都不存在');
+                            $msg = $line.'健康顾问或报备人都不存在';
+//                            throw new \Exception($line.'健康顾问或报备人都不存在');
                         }
                         if ($consultantId > 0) {
                             $deptId = $teamKeys[$consultantKey]['dept_id'] ?? 0;
@@ -1253,10 +1262,12 @@ class CustomService
                             }
                         }
                         if (empty($deptId)) {
-                            throw new \Exception($line.'团队不存在');
+                            $msg =  $line.'健康顾问或报备人都不存在';
+//                            throw new \Exception($line.'团队不存在');
                         }
                         if (MarketCustomer::checkCustomExists($val[2])) {
-                            throw new \Exception($line.'客户已转到访,无法二次录入');
+                            $msg =  $line.'客户已转到访,无法二次录入';
+//                            throw new \Exception($line.'客户已转到访,无法二次录入');
                         }
                         //查看手机号是否存在
                         $insertData = [
@@ -1275,7 +1286,15 @@ class CustomService
                             'visit_time' => strtotime('2024-08-31 00:00:00'),
                             'created_at' => strtotime('2024-08-31 00:00:00')
                         ];
-                        $result = Db::table('market_customer')->insert($insertData);
+                        $result = false;
+                        if (empty($msg)) {
+                            $result = Db::table('market_customer')->insert($insertData);
+                        } else {
+                            $errorData[] = [
+                                'msg' => $msg,
+                                'val' => $val
+                            ];
+                        }
                         if ($result) {
                             $sucNums++;
                         } else {
@@ -1293,7 +1312,7 @@ class CustomService
             return json_fail('文件不存在');
         }
         $total = count($data);
-        return json_success("全部数据:{$total},成功:{$sucNums},失败:{$errNums}");
+        return json_success("全部数据:{$total},成功:{$sucNums},失败:{$errNums}", ['data' => $errorData]);
     }
 
     /**