Browse Source

线上订单导入

cqpCow 11 months ago
parent
commit
4a33e83bbb
2 changed files with 37 additions and 33 deletions
  1. 33 29
      app/Service/ImportService.php
  2. 4 4
      config/excel/salesOnlineTable.php

+ 33 - 29
app/Service/ImportService.php

@@ -600,9 +600,9 @@ class ImportService extends Service
         $basic_list = [];
         foreach ($basic as $value){
             if($value['type'] == 18){
-                $basic_list[10][$value['title']] = $value['id'];
+                $basic_list[9][$value['title']] = $value['id'];
             }elseif ($value['type'] == 23){
-                $basic_list[11][$value['title']] = $value['id'];
+                $basic_list[10][$value['title']] = $value['id'];
             }elseif ($value['type'] == 24){
                 $basic_list[3][$value['title']] = $value['id'];
             }elseif ($value['type'] == 29){
@@ -616,7 +616,7 @@ class ImportService extends Service
             $rowData = array_filter($value);
             if (empty($rowData)) {
                 unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1]) || empty($value[2]) || empty($value[3]) || empty($value[4]) || empty($value[5]) || empty($value[6]) || empty($value[7])) {
+            } elseif(empty($value[0]) || empty($value[1]) || empty($value[2]) || empty($value[3]) || empty($value[4]) || empty($value[5]) || empty($value[6])) {
                 return [false, '带*号的字段项必填'];
             }else{
                 foreach ($value as $k => $v){
@@ -625,34 +625,38 @@ class ImportService extends Service
                 if(! isset($basic_list[2][$value[2]])) return [false, '客户简称:' . $value[2] .'不存在'];
                 if(! isset($basic_list[3][$value[3]])) return [false, '店铺(平台类型):' . $value[3] .'不存在'];
                 $value[3] = $basic_list[3][$value[3]];
+
+                if(! is_numeric($value[5])) return [false, '货品数量请填写正确的数值'];
+                if(! is_numeric($value[6])) return [false, '产品合同金额请填写正确的数值'];
+                if(! empty($value[8]) && ! is_numeric($value[8])) return [false, '订单优惠金额请填写正确的数值'];
+                if(! empty($value[9])){
+                    if(! isset($basic_list[9][$value[9]])) return [false, '安装方式:' . $value[9] .'不存在'];
+                    $value[9] = $basic_list[9][$value[9]];
+                }
                 if(! empty($value[10])){
-                    if(! isset($basic_list[10][$value[10]])) return [false, '安装方式:' . $value[3] .'不存在'];
+                    if(! isset($basic_list[10][$value[10]])) return [false, '安装地点:' . $value[10] .'不存在'];
                     $value[10] = $basic_list[10][$value[10]];
                 }
-                if(! empty($value[11])){
-                    if(! isset($basic_list[11][$value[11]])) return [false, '安装地点:' . $value[3] .'不存在'];
-                    $value[11] = $basic_list[11][$value[11]];
-                }
 
                 if(! isset(SalesOrder::$order_type_name[$value[1]])) return [false, '产品类型填写错误'];
                 $value[1] = SalesOrder::$order_type_name[$value[1]];
 
-                if(! empty($value[12])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[12]);
+                if(! empty($value[11])) {
+                    list($status,$msg) = $this->changeAndReturnDate($value[11]);
                     if(! $status) return [false,"施工日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[12] = $msg;
+                    $value[11] = $msg;
                 }
 
-                if(! empty($value[13])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[13]);
+                if(! empty($value[12])) {
+                    list($status,$msg) = $this->changeAndReturnDate($value[12]);
                     if(! $status) return [false,"交车日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[13] = $msg;
+                    $value[12] = $msg;
                 }
 
                 $array[$key] = $value;
-                $search .= "(code = '".$value[4]."' and title ='".$value[5]."') or";
+                $search .= "(code = '".$value[4]."') or";
 
-                if(! empty($value[8]) && ! in_array($value[8], $customer)) $customer[] = $value[8];
+                if(! empty($value[7]) && ! in_array($value[7], $customer)) $customer[] = $value[7];
             }
         }
         if(empty($array)) return [false, '导入数据不能为空'];
@@ -732,15 +736,15 @@ class ImportService extends Service
         $insert = $insert_detail = $insert_detail_man =  [];
         $prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
         foreach ($array as $value){
-            $product_str = $value[4] . $value[5];
-            if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[4]. ']' . '[' . $value[5]. ']' . '不存在'];
+            $product_str = $value[4];
+            if(! isset($product_map[$product_str])) return [false, '产品:' . '[' . $value[4]. ']' . '不存在'];
             $product_tmp = $product_map[$product_str] ?? [];
 
             $customer_tmp = 0;
             $customer_contact_tmp = "";
             $customer_man_tmp = [];
-            if(! empty($value[8])){
-                $customer_tmp = $customer_map[$value[8]] ?? 0;
+            if(! empty($value[7])){
+                $customer_tmp = $customer_map[$value[7]] ?? 0;
                 $customer_contact_tmp = $customer_contact[$customer_tmp] ?? "";
                 $customer_man_tmp = $customer_man[$customer_tmp] ?? [];
             }
@@ -761,23 +765,23 @@ class ImportService extends Service
                 $tmp['customer_contact'] = $customer_contact_tmp;
                 $tmp['plat_type'] = $value[3];
                 $tmp['plat_order'] = $value[0];
-                $tmp['discount_fee'] = $value[9] ?: 0;
-                $tmp['product_total'] += $value[7];
-                $tmp['contract_fee'] += $value[7] - $tmp['discount_fee'];
-                $tmp['construction_time'] = $value[12] ?? 0;
-                $tmp['handover_time'] = $value[13] ?? 0;
+                $tmp['discount_fee'] = $value[8] ?: 0;
+                $tmp['product_total'] += $value[6];
+                $tmp['contract_fee'] += $value[6] - $tmp['discount_fee'];
+                $tmp['construction_time'] = $value[11] ?? 0;
+                $tmp['handover_time'] = $value[12] ?? 0;
                 $insert[$keys] = $tmp;
             }else{
-                $insert[$keys]['product_total'] += $value[7];
-                $insert[$keys]['contract_fee'] += $value[7];
+                $insert[$keys]['product_total'] += $value[6];
+                $insert[$keys]['contract_fee'] += $value[6];
             }
 
             $tmp_detail['product_id'] = $product_tmp['id'];
             $tmp_detail['cost'] = $product_tmp['cost'];
             $tmp_detail['retail_price'] = $product_tmp['retail_price'];
             $tmp_detail['price'] = $product_tmp['retail_price'];
-            $tmp_detail['final_amount'] = $value[7];
-            $tmp_detail['number'] = $value[6];
+            $tmp_detail['final_amount'] = $value[6];
+            $tmp_detail['number'] = $value[5];
 
             $insert_detail[$keys][] = $tmp_detail;
         }

+ 4 - 4
config/excel/salesOnlineTable.php

@@ -26,10 +26,10 @@ return [
         'key' => 'code',
         'value' => '* 货品编码(产品编码)',
     ],
-    [
-        'key' => 'title',
-        'value' => '* 货品名称(产品名称)',
-    ],
+//    [
+//        'key' => 'title',
+//        'value' => '* 货品名称(产品名称)',
+//    ],
     [
         'key' => 'num',
         'value' => '* 货品数量',