cqpCow 1 рік тому
батько
коміт
4bab4956d8

+ 51 - 0
app/Exports/TableHeadExport.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Exports;
+
+
+use Illuminate\Support\Collection;
+use Maatwebsite\Excel\Concerns\FromCollection;
+use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
+use Maatwebsite\Excel\Concerns\WithHeadings;
+use Maatwebsite\Excel\Concerns\WithStrictNullComparison;    // 导出 0 原样显示,不为 null
+use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
+
+
+class TableHeadExport extends DefaultValueBinder implements WithCustomValueBinder , FromCollection, WithStrictNullComparison,withHeadings
+{
+    /**
+     * @return \Illuminate\Support\Collection
+     */
+    public function __construct($data,$headers)
+    {
+        $this->data = $data;
+        $this->headers = $headers;
+    }
+
+    //数组转集合
+    public function collection()
+    {
+        return new Collection($this->createData());
+    }
+    //业务代码
+    public function createData()
+    {
+        $data = $this->export();
+        return $data;
+    }
+
+    // 自定义表头,需实现withHeadings接口
+    public function headings(): array
+    {
+        return $this->headers;
+    }
+
+    private function export(){
+        $list = [];
+//        dump($this->data);die;
+        foreach ($this->data as $v){
+            $list[] = $v;
+        }
+        return $list;
+    }
+}

+ 26 - 0
app/Http/Controllers/Api/ImportController.php

@@ -19,4 +19,30 @@ class ImportController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function getTableTitleXls(Request $request)
+    {
+        $service = new ImportService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->getTableTitleXls($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function importAll(Request $request)
+    {
+        $service = new ImportService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->importAll($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 49 - 0
app/Import/ImportAll.php

@@ -0,0 +1,49 @@
+<?php
+
+
+namespace  App\Import;
+
+use App\Service\ImportService;
+use Maatwebsite\Excel\Concerns\ToArray;
+
+class ImportAll implements ToArray {
+    private $msg = '';
+    public $crt_id = 0;
+    public $type = "";
+    public $user = [];
+
+    public function array (array $array){
+        $this->handleData($array);
+    }
+
+    public function setCrt($crt_id){
+        $this->crt_id = $crt_id;
+    }
+
+    public function setType($type){
+        $this->type = $type;
+    }
+
+    public function setUser($user){
+        $this->user = $user;
+    }
+
+    public function getMsg(){
+        return $this->msg;
+    }
+
+    public function setMsg($msg){
+        $this->msg = $msg;
+    }
+
+    public function handleData (array $array) {
+        $func = $this->type . "Import";
+        if(! $func) {
+            $this->setMsg("意外错误");
+            return;
+        }
+
+        list($status,$msg) = (new ImportService())->$func($array,$this->user);
+        if(empty($status)) $this->setMsg($msg);
+    }
+}

+ 4 - 0
app/Model/Customer.php

@@ -14,6 +14,10 @@ class Customer extends UseScopeBaseModel
         self::Model_type_one,
         self::Model_type_two
     ];
+    const dk = [
+        'T9改装' => self::Model_type_one,
+        'T9二手车' => self::Model_type_two
+    ];
 
     public static $user = [];
     public static $search = [];

+ 55 - 0
config/excel/customerTable.php

@@ -0,0 +1,55 @@
+<?php
+return [
+    [
+        'key' =>'model_type',
+        'value' =>'* 客户模板',
+    ],
+    [
+        'key' =>'title',
+        'value' =>'* 客户名称',
+    ],
+    [
+        'key' =>'customer_intention',
+        'value' => '客户意向度',
+    ],
+    [
+        'key' =>'customer_from',
+        'value' => '客户来源',
+    ],
+    [
+        'key' =>'customer_type',
+        'value' => '客户类别',
+    ],
+    [
+        'key' =>'consulting_product',
+        'value' =>'咨询产品',
+    ],
+    [
+        'key' =>'intention_product',
+        'value' =>'意向产品',
+    ],
+    [
+        'key' =>'progress_stage',
+        'value' =>'进展阶段',
+    ],
+    [
+        'key' =>'state_type',
+        'value' =>'状态',
+    ],
+    [
+        'key' =>'car_type',
+        'value' =>'车型',
+    ],
+    [
+        'key' =>'mark',
+        'value' =>'备注',
+    ],
+//    [
+//        'key' =>'man_fz',
+//        'value' =>'负责人',
+//    ],
+//    [
+//        'key' =>'man_xt',
+//        'value' =>'协同人',
+//    ],
+];

+ 9 - 5
config/excel/product.php

@@ -5,6 +5,15 @@ return [
             'key' =>'title',
             'rule' =>'',
             'other_rule' => 'require|unique:Product',
+            'search_raw' => 'top_depart_id = ? AND (top_depart_id = ? OR top_depart_id = ?)',
+            'search_field' => ['top_depart_id']
+        ],
+        '产品编码' => [
+            'key' =>'code',
+            'rule' => '',
+            'other_rule' => 'require|unique:Product',
+            'search_raw' => 'top_depart_id = ? AND (top_depart_id = ? OR top_depart_id = ?)',
+            'search_field' => ['top_depart_id']
         ],
         '产品分类' => [
             'key' =>'product_category_id',
@@ -15,11 +24,6 @@ return [
             ],
             'other_rule' => 'require',
         ],
-        '产品编码' => [
-            'key' =>'code',
-            'rule' => '',
-            'other_rule' => 'require|unique:Product',
-        ],
         '规格' => [
             'key' =>'size',
             'rule' =>'',

+ 35 - 0
config/excel/productTable.php

@@ -0,0 +1,35 @@
+<?php
+return [
+    [
+        'key' =>'title',
+        'value' => '* 产品名称',
+    ],
+    [
+        'key' =>'code',
+        'value' => '* 产品编码',
+    ],
+    [
+        'key' =>'product_category_id',
+        'value' => '* 产品分类',
+    ],
+    [
+        'key' =>'size',
+        'value' => '产品规格',
+    ],
+    [
+        'key' =>'unit',
+        'value' => '产品单位',
+    ],
+    [
+        'key' =>'bar_code',
+        'value' => '条码',
+    ],
+    [
+        'key' =>'cost',
+        'value' => '成本',
+    ],
+    [
+        'key' =>'retail_price',
+        'value' => '零售价',
+    ],
+];