cqp преди 1 месец
родител
ревизия
4faaf52b9f
променени са 6 файла, в които са добавени 150 реда и са изтрити 3506 реда
  1. 0 156
      app/Http/Controllers/Api/ProductController.php
  2. 1 53
      app/Model/Product.php
  3. 101 1893
      app/Service/ImportService.php
  4. 35 1401
      app/Service/ProductService.php
  5. 10 0
      config/excel/productTable.php
  6. 3 3
      routes/api.php

+ 0 - 156
app/Http/Controllers/Api/ProductController.php

@@ -8,19 +8,6 @@ use Illuminate\Http\Request;
 
 class ProductController extends BaseController
 {
-    public function setIsEditUnitPrice(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->setIsEditUnitPrice($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
     public function productCategoryEdit(Request $request)
     {
         $service = new ProductService();
@@ -73,19 +60,6 @@ class ProductController extends BaseController
         }
     }
 
-    public function productCategoryList2(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productCategoryList2($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
     public function productEdit(Request $request)
     {
         $service = new ProductService();
@@ -127,123 +101,6 @@ class ProductController extends BaseController
 
     }
 
-    public function productListIndex(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productListIndex($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productGroupByList(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productGroupByList($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productUpdateByItemCode(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productUpdateByItemCode($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productUpdateProductBasicInfo(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productUpdateProductBasicInfo($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productGroupByListDetail(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productGroupByListDetail($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function updateTopStock(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->updateTopStock($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function batchUploadImg(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->batchUploadImg($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function batchBuildFee(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->batchBuildFee($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function batchUnitInfo(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->batchUnitInfo($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
     public function productList(Request $request)
     {
         $service = new ProductService();
@@ -257,19 +114,6 @@ class ProductController extends BaseController
         }
     }
 
-    public function productList2(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productList2($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
     public function productDetail(Request $request)
     {
         $service = new ProductService();

+ 1 - 53
app/Model/Product.php

@@ -8,58 +8,6 @@ class Product extends UseScopeBaseModel
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
-    const State_zero = 0;
-    const State_one = 1;
-    const State_two = 2;
-    public static $state = [
-        self::State_zero => '新增',
-        self::State_one => '上架',
-        self::State_two => '下架',
-    ];
 
-    const range_function = 'productRangeNot';
-
-    const Product_attribute_zero = 0;
-    const Product_attribute_one = 1;
-    const Product_attribute_two = 2;
-    const Product_attribute_three = 3;
-    const Product_attribute_four = 4;
-    const Product_attribute_five = 5;
-    const Product_attribute_six = 6;
-    public static $product_attribute = [
-        self::Product_attribute_zero => '无',
-        self::Product_attribute_one => '其他',
-        self::Product_attribute_two => '主推款',
-        self::Product_attribute_three => '严选',
-        self::Product_attribute_four => '热门畅销',
-        self::Product_attribute_five => 'NEW',
-        self::Product_attribute_six => '含税产品',
-    ];
-    public static $product_attribute_color = [
-        self::Product_attribute_zero => [
-            'background_color' => 'white',
-            'font_color' => 'black',
-        ],
-        self::Product_attribute_one => [
-            'background_color' => 'white',
-            'font_color' => 'black',
-        ],
-        self::Product_attribute_two => [
-            'background_color' => 'white',
-            'font_color' => 'black',
-        ],
-        self::Product_attribute_three => [
-            'background_color' => 'white',
-            'font_color' => 'black',
-        ],
-    ];
-
-    const is_use_zero = 0;
-    const is_use_one = 1;
-    public static $is_use = [
-        self::is_use_zero => '停用',
-        self::is_use_one => '启用',
-    ];
-
-    public static $field = ['title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id','install_time','product_attribute','is_use','build_fee','item_code','unit_2','main_number','second_number','warranty_time'];
+    public static $field = ['title','id','category','code','size','unit','business_cost','write_off_price','cost','write_off_price','crt_id','crt_time','mark','return_change_price'];
 }

+ 101 - 1893
app/Service/ImportService.php

@@ -3,31 +3,8 @@
 namespace App\Service;
 
 use App\Exports\TableHeadExport;
-use App\Import\Import;
 use App\Import\ImportAll;
-use App\Model\BasicType;
-use App\Model\BasicTypeAllUse;
-use App\Model\Customer;
-use App\Model\CustomerInfo;
-use App\Model\CustomerPerFormance;
-use App\Model\CustomerRemain;
-use App\Model\CustomerRepeat;
-use App\Model\Depart;
-use App\Model\Employee;
-use App\Model\Inventory;
-use App\Model\InventorySub;
-use App\Model\LastJc;
 use App\Model\Product;
-use App\Model\ProductAdjustment;
-use App\Model\ProductAdjustmentSub;
-use App\Model\ProductCategory;
-use App\Model\ProductInventorySet;
-use App\Model\ProductItemCodeMessage;
-use App\Model\ProductPriceDetail;
-use App\Model\SalesOrder;
-use App\Model\SalesOrderInfo;
-use App\Model\SalesOrderProductInfo;
-use App\Model\Storehouse;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use Maatwebsite\Excel\Facades\Excel;
@@ -36,233 +13,41 @@ use PhpOffice\PhpSpreadsheet\Shared\Date;
 
 class ImportService extends Service
 {
-
     public static $type = [
-        'product', //产品
-        'customer', //客户
-        'salesOnline', //线上订单
-        'btOnline', //补贴订单
-        'lastJc', //上月结存
-        'inventory', // 盘点
-        'productAdjustment', // 产品金额调整单
-        'customerPerformance', // 客资金额
+        'product', //存货
     ];
 
-    //写活的导入------------------- 暂时不好用
-    //导入入口
-    public function import($data,$user){
-        if(empty($data['type'])) return [false,'缺少导入类型,导入失败'];
-        if(! in_array($data['type'],self::$type)) return [false,'导入类型不存在,导入失败'];
-        if(empty($data['file'])) return [false,'导入文件不能为空'];
-
-        //导入的数据并且校验写入
-        list($status,$msg) = $this->importMain($data,$user);
-        if(! $status) return [false, $msg];
-
-        return [true, ''];
-    }
-
-    //主方法
-    public function importMain($data,$user){
-        //获取配置文件
-        $config = "excel." . $data['type'];
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在'];
-
-        //(特殊 额外的表头数据)
-        $config_array = $this->getTableTitle($config_array,$user,$data);
-
-        //获取合并单元格范围
-        $uploadedFile = $_FILES['file']['tmp_name']; // 获取上传文件的临时路径
-        $spreadsheet = IOFactory::load($uploadedFile); // 加载上传的 Excel 文件
-        $worksheet = $spreadsheet->getActiveSheet(); // 获取第一个工作表
-        $mergedCells = $worksheet->getMergeCells(); // 获取单元格合并范围
-
-        // 需要导入的公用数据
-        $msg['user_id'] = $user['id'];
-        $msg['depart_id'] = $this->getDepart($user);
-        $msg['top_depart_id'] = $user['depart_map'][$msg['depart_id']] ?? 0;
-
-        //导入
-        $import = new Import();
-        $import->setConfig($config_array, $mergedCells,$msg);
-        \Maatwebsite\Excel\Facades\Excel::import($import,$data['file']);
-
-        //异常提示报错
-        if($import->getMsg()) return [false, $import->getMsg()];
-
-        return [true, ''];
-    }
-
-    //表头入口
-    public function getTableTitle($config_array,$user,$data){
-        if(! empty($config_array['dynamics_field'])){
-            $func = $config_array['dynamics_field']['func'];
-            return $this->$func($config_array,$user,$data);
-        }
-
-        return $config_array;
-    }
-
-    //产品导入的额外表头
-    public function productTitle($config_array,$user,$data){
-        $model = BasicType::TopClear($user,$data);
-        $result = $model->whereRaw('type = 22 And del_time = 0')->get()->toArray();
-        if(! empty($result)){
-            foreach ($result as $value){
-                $config_array['field'][$value['title']] = [
-                    "key" => $config_array['dynamics_field']['name'],
-                    "key_array" => [
-                        "basic_type_id" => $value['id'],
-                        "price" => 0,
-                    ],
-                    "rule" => "",
-                    "other_rule" => "is_numeric",
-                    "multiple" => true,
-                    "map" => [
-                        $value['title'] => "price",
-                    ],
-                ];
-            }
-        }
-
-        return $config_array;
-    }
-
-    //产品导入的额外数据
-    public function fillInsertProductData($time){
-        $last_insert_data = Product::where('crt_time',$time)
-            ->where('del_time',0)
-            ->select("id","product_category_id")
-            ->get()->toArray();
-        if(empty($last_insert_data)) return;
-
-        $list = ProductCategory::where('del_time',0)
-            ->select('id','parent_id')
-            ->get()->toArray();
-
-        foreach ($last_insert_data as $value){
-            $parentsId = $this->findParentIds($value['product_category_id'], $list);
-            array_unshift($parentsId, $value['product_category_id']);
-            $result = array_reverse($parentsId);
-            Product::where('id',$value['id'])->update([
-                'product_category' => json_encode($result)
-            ]);
-        }
-    }
-    //写活的导入------------------- 暂时不好用
-
-    //写死的导入
     public function getTableTitleXls($data,$user){
         if(empty($data['type'])) return [false,'缺少类型'];
         if(! in_array($data['type'],self::$type)) return [false,'类型不存在'];
 
         //获取配置文件
         $fuc = $data['type'];
-        list($status,$msg,$filename) = $this->$fuc($data,$user);
-        if(!$status) return [false, $msg];
+        list($status,$return) = $this->$fuc($data,$user);
+        list($msg,$filename) = $return;
+        if(! $status) return [false, $msg];
 
         $headers = array_column($msg,'value');
         Excel::store(new TableHeadExport([], $headers),"/public/export/{$filename}", null, 'Xlsx', []);
         return [true, ['file' => $filename]];
     }
 
-    private function customer($data,$user){
-        //生成下载文件
-        $filename =  "客户模板_" . time() . '.' . 'xlsx';
+    private function getTableConfig($type = ""){
+        if(empty($type)) return [];
 
         //获取配置文件
-        $config = "excel.customerTable";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
+        $config = "excel." . $type . "Table";
+        return config($config) ?? [];
     }
 
     private function product($data,$user){
-        //获取配置文件
-        $config = "excel.productTable";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在', ''];
-
-        $result = (new BasicTypeService())->getMyBasicList($user, 22);
-        if(! empty($result)){
-            foreach ($result as $value){
-                $config_array[] = [
-                    'key' => 'table_id.' . $value['id'],
-                    'value' => $value['title'],
-                ];
-            }
-        }
-        //生成下载文件
-        $filename =  "产品模板_" . time() . '.' . 'xlsx';
-
-        return [true, $config_array,$filename];
-    }
-
-    private function salesOnline($data,$user){
-        //生成下载文件
-        $filename =  "线上订单模板_" . time() . '.' . 'xlsx';
-
-        //获取配置文件
-        $config = "excel.salesOnlineTable";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
-    }
-
-    private function btOnline($data,$user){
-        //生成下载文件
-        $filename =  "补贴订单模板_" . time() . '.' . 'xlsx';
-
-        //获取配置文件
-        $config = "excel.salesOnlineTable";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
-    }
-
-    private function lastJc($data,$user){
-        //生成下载文件
-        $filename =  "上月结存数据更新模板_" . time() . '.' . 'xlsx';
-
-        //获取配置文件
-        $config = "excel.lastJc";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
-    }
-
-    private function inventory($data,$user){
-        //生成下载文件
-        $filename =  "盘点单导入模板_" . time() . '.' . 'xlsx';
-
-        //获取配置文件
-        $config = "excel.inventory";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
-    }
-
-    private function productAdjustment($data,$user){
-        //生成下载文件
-        $filename =  "产品金额调整单导入模板_" . time() . '.' . 'xlsx';
-
-        //获取配置文件
-        $config = "excel.productAdjustment";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
-    }
+        $config_array = $this->getTableConfig($data['type']);
+        if(empty($config_array)) return [false, ['导入配置表头文件不存在','']];
 
-    private function customerPerformance($data,$user){
         //生成下载文件
-        $filename =  "客资业绩导入模板_" . time() . '.' . 'xlsx';
+        $filename =  "存货导入模板_" . time() . '.' . 'xlsx';
 
-        //获取配置文件
-        $config = "excel.customerPerformanceTable";
-        $config_array = config($config) ?? [];
-        if(empty($config_array)) return [false, '配置文件不存在',''];
-        return [true, $config_array,$filename];
+        return [true, [$config_array, $filename]];
     }
 
     //导入入口
@@ -317,137 +102,61 @@ class ImportService extends Service
         return [true, ''];
     }
 
-    public function customerImport($array, $user){
-        $time = time();
-
-        $head = $user['depart_top'][0] ?? [];
-        $head = $head['depart_id'] ?? 0;
-        if(empty($head)) return [false, '导入异常错误,门店信息丢失'];
+    public function productImport($array, $user, $other_param){
+        $upload = $array[0];
+        list($status, $msg) = $this->compareTableAndReturn($upload, $other_param);
+        if(! $status) return [false, $msg];
+        $table_config = $msg;
 
         // 去除表头
         unset($array[0]);
         if(empty($array)) return [false, '导入数据不能为空'];
 
-        //第一次表格数据校验 非空  已经过滤数据
-        list($status, $msg) = $this->customerFilterFirst($array, $time);
-        if(! $status) return [0, $msg];
-        list($contact_info, $fz, $fp) = $msg;
-
+        list($array, $error) = $this->checkCommon($array, $table_config);
+        if(! empty($error)) return [0, $error];
         if(empty($array)) return [false, '导入数据不能为空'];
 
-        //客户
-        $model = Customer::Clear($user,[]);
-        $customer = $model->where('del_time',0)
-            ->whereIn('title',array_unique(array_column($array,'1')))
-            ->pluck('id','title')
+        //查找产品
+        $product_map = Product::whereIn("code", array_column($array,0))
+            ->where('del_time',0)
+            ->pluck('id','code')
             ->toArray();
 
-        $basic = (new BasicTypeService())->getMyBasicList($user, [1,2,3,4,5,9,10,30]);
-        $basic_list = [];
-        foreach ($basic as $value){
-            if($value['type'] == 1){
-                $basic_list[2][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 2){
-                $basic_list[3][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 3){
-                $basic_list[41][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 30){
-                $basic_list[42][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 4){
-                $basic_list[12][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 5){
-                $basic_list[7][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 9){
-                $basic_list[8][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 10){
-                $basic_list[9][$value['title']] = $value['id'];
+        $time = time();
+        $insert = $update = [];
+        foreach ($array as $value){
+            $tmp = [];
+            foreach ($value as $k => $val){
+                $field = $table_config[$k]['key'];
+                $tmp[$field] = $val;
             }
-        }
-
-//        $model = Product::ProductClear($user,[]);
-//        $product = $model->where('del_time',0)
-//            ->whereIn('title',array_unique(array_column($array,'6')))
-//            ->pluck('id','title')
-//            ->toArray();
 
-        $basic_use = BasicTypeAllUse::where('del_time',0)
-            ->where('type', BasicTypeAllUse::type_one)
-            ->whereIn('title',array_unique(array_column($array,'5')))
-            ->pluck('id','title')
-            ->toArray();
+            if(isset($product_map[$tmp['code']])){
+                $product_id = $product_map[$tmp['code']];
+                //产品主表
+                $update[$product_id] = $tmp;
+            }else{
+                $tmp['crt_id'] = $user['id'];
+                $tmp['crt_time'] = $time;
 
-        $empList = Employee::where('del_time',0)
-            ->when(! empty($fz), function($query) use($fz) {
-                return $query->where(function ($q) use ($fz) {
-                    $q->whereIn('emp_name', $fz)
-                        ->orWhereIn("number", $fz);
-                });
-            })
-            ->select('id','number','emp_name as name')
-            ->get()->toArray();
-        $emp_map = $emp_map1 = [];
-        foreach ($empList as $value){
-            $emp_map[$value['name']][] = $value['id'];
-            $emp_map1[$value['number']] = $value['id'];
+                //产品主表
+                $insert[$tmp['code']] = $tmp;
+            }
         }
 
-        $departList = Depart::where('del_time',0)
-            ->where('parent_id', 0)
-            ->whereIn('title', $fp)
-            ->select('title','id','notify_id')
-            ->get()->toArray();
-        $depart = array_column($departList,null,'title');
-
-        $top_depart_id = $user['depart_top'][0] ?? [];
-        $top_depart_id = $top_depart_id['depart_id'] ?? 0;
-        $contact_info_array = CustomerInfo::from('customer_info as a')
-            ->join('customer as b','b.id','a.customer_id')
-            ->where('a.del_time',0)
-            ->where('b.del_time',0)
-            ->where('b.top_depart_id',$top_depart_id)
-            ->whereIn('a.contact_info', $contact_info)
-            ->select('a.contact_info')->get()->toArray();
-        $contact_info_array = array_column($contact_info_array,'contact_info');
-
-        list($status, $msg) = $this->customerFilterSecond($array,$time,$head,$user,$contact_info_array,$customer,$basic_list,$emp_map,$emp_map1,$basic_use,$depart);
-        if(! $status) return [0, $msg];
-        list($insert, $insert_detail, $insert_detail2, $insert_detail3) = $msg;
-
         try{
-            DB::beginTransaction();
-            if(! empty($insert)) Customer::insert($insert);
-
-            //获取上一次所有id
-            $last_insert_id = Customer::where('crt_time',$time)
-                ->where('crt_time',$time)
-                ->where('depart_id',$head)
-                ->where('top_depart_id',$head)
-                ->where('crt_id',$user['id'])
-                ->select('id')->get()->toArray();
-            $last_insert_id = array_column($last_insert_id,'id');
-
-            //组织数据 写入与主表的关联id
-            $insert_detail_1 = [];
-            foreach ($insert_detail as $key => $value){
-                if(empty($value['contact_type']) && empty($value['contact_info'])) continue;
-                $value['customer_id'] = $last_insert_id[$key];
-                $insert_detail_1[] = $value;
-            }unset($insert_detail);
-            $insert_detail_2 = [];
-            foreach ($insert_detail2 as $key => $value){
-                if(empty($value['data_id'])) continue;
-                $value['customer_id'] = $last_insert_id[$key];
-                $insert_detail_2[] = $value;
-            }unset($insert_detail2);
-            $insert_detail_3 = [];
-            foreach ($insert_detail3 as $key => $value){
-                $value['customer_id'] = $last_insert_id[$key];
-                $insert_detail_3[] = $value;
-            }unset($insert_detail3);
+            //新增
+            if(! empty($insert)){
+                Product::insert($insert);
+            }
 
-            if(! empty($insert_detail_1)) CustomerInfo::insert($insert_detail_1);
-            if(! empty($insert_detail_2)) CustomerInfo::insert($insert_detail_2);
-            if(! empty($insert_detail_3)) CustomerRemain::insert($insert_detail_3);
+            //编辑
+            if(! empty($update)){
+                foreach ($update as $p_id => $value){
+                    Product::where('id',$p_id)
+                        ->update($value);
+                }
+            }
 
             DB::commit();
         }catch (\Exception $e){
@@ -458,1582 +167,81 @@ class ImportService extends Service
         return [true, ''];
     }
 
-    function customerFilterFirst(&$array, $time){
-        $array_clean = $contact_info = $fz = $fp =[];
-
+    //公共校验
+    private function checkCommon($array, $table_config){
         $error = [];
-        foreach ($array as $key => $value){
-            $line = '第' . $key . '行';
-            $rowData = array_filter($value);
-            if (empty($rowData)) {
-                unset($array[$key]);
-            } else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-
-                if(empty($value[0])){
-                    $error[] = $line . '客户模板字段项必填';
-                }else{
-                    if(! isset(Customer::dk[$value[0]])) {
-                        $error[] = $line . '客户模板填写错误';
-                    }else{
-                        $value[0] = Customer::dk[$value[0]];
-                    }
-                }
-                if(empty($value[1])){
-                    $error[] = $line . '客户名称字段项必填';
-                }else{
-                    if(in_array($value[1],$array_clean)) {
-                        $error[] = $line . '客户名称' . $value[1] .'在导入文件中重复出现';
-                    }else{
-                        $array_clean[] = $value[1];
-                    }
-                }
-
-                if(! empty($value[12])){
-                    if(in_array($value[12],$contact_info)) {
-                        $error[] = $line . '联系方式内容'. $value[12] .'在导入文件内重复出现';
-                    }else{
-                        $contact_info[] = $value[12];
-                    }
-                }
-
-                if(! empty($value[14])){
-                    list($status, $msg) = $this->convertExcelCellToDate($value[14]);
-                    if(! $status) {
-                        $error[] = $line . $msg;
-                    }else{
-                        $value[14] = $msg;
-                    }
-                } else{
-                    $value[14] = $time;
-                }
-
-                if(empty($value[15])) {
-                    if(empty($value[13])) {
-                        $error[] = $line . '(分配门店为空时)负责人名或负责人工号必须填写';
-                    }else{
-                        if(! in_array($value[13], $fz)) $fz[] = $value[13];
-                    }
-                }else{
-                    if(! in_array($value[15], $fp)) $fp[] = $value[15];
-                }
-
-                $array[$key] = $value;
-            }
-        }unset($array_clean);
-
-        if(! empty($error)){
-            $error = implode(',', $error);
-            return [false, $error];
-        }
-
-        return [true, [$contact_info, $fz, $fp]];
-    }
-
-    function customerFilterSecond($array, $time, $head, $user, $contact_info_array,$customer,$basic_list,$emp_name,$emp_number,$basic_use,$depart){
-        $error = $insert = $insert_detail = $insert_detail2 = $insert_detail3 = $repeat_array = [];
-        foreach ($array as $key => $value){
-            $line = '第' . $key . '行';
-            $tmp = [
-                'model_type' => '',
-                'title' => '',
-                'customer_intention' => '',
-                'customer_from' => '',
-                'customer_type' => '',
-                'car_type' => '',
-                'consulting_product_new' => '',
-//                'intention_product' => '',
-                'progress_stage' => '',
-                'state_type' => '',
-                'address2' => '',
-                'mark' => '',
-                'depart_id' => $head,
-                'top_depart_id' => $head,
-                'crt_id' => $user['id'],
-                'crt_time' => $time,
-                'upd_time' => $time,
-                'enter_time' => $value['14'],
-            ];
-            $tmp['model_type'] = $value['0'];
-            $tmp['mark'] = $value['9'];
-            $tmp['address2'] = $value['10'];
-            $repeat = 0;//是否重复
-
-            if(! empty($customer[$value['1']])) {
-//                $error[] = $line . '客户名称:' . $value['1'] . '已存在';
-//                $repeat = 1;
-            }else{
-                $tmp['title'] = $value['1'];
-            }
-            if($value['2']){
-                if(empty($basic_list[2][$value['2']])) {
-                    $error[] = $line . '客户意向度:' . $value['2'] . '不存在';
-                }else{
-                    $tmp['customer_intention'] = $basic_list[2][$value['2']];
-                }
-            }
-            if($value['3']){
-                if(empty($basic_list[3][$value['3']])) {
-                    $error[] = $line . '客户来源:' . $value['3'] . '不存在';
-                }else{
-                    $tmp['customer_from'] = $basic_list[3][$value['3']];
-                }
-            }
-            if($value['4']){
-                $keys = 4 . $value[0];
-                $model_title = Customer::dk2[$value[0]] ?? "";
-                if(empty($basic_list[$keys][$value['4']])) {
-                    $error[] = $line . '模板:' . $model_title . '下客户类别:' . $value['4'] . '不存在';
-                }else{
-                    $tmp['customer_type'] = $basic_list[$keys][$value['4']];
-                }
-            }
-            if($value['5']){
-                if(empty($basic_use[$value['5']])) {
-                    $error[] = $line . '咨询产品:' . $value['5'] . '不存在';
-                }else{
-                    $tmp['consulting_product_new'] = $basic_use[$value['5']];
-                }
-            }
-//            if($value['6']){
-//                if(empty($product[$value['6']])) {
-//                    $error[] = $line . '意向产品:' . $value['6'] . '不存在';
-//                }else{
-//                    $tmp['intention_product'] = $product[$value['6']];
-//                }
-//            }
-            if($value['6']){
-                if(empty($basic_list[7][$value['6']])) {
-                    $error[] = $line . '进展阶段:' . $value['6'] . '不存在';
-                }else{
-                    $tmp['progress_stage'] = $basic_list[7][$value['6']];
-                }
-            }
-            if($value['7']){
-                if(empty($basic_list[8][$value['7']])) {
-                    $error[] = $line . '状态:' . $value['7'] . '不存在';
-                }else{
-                    $tmp['state_type'] = $basic_list[8][$value['7']];
-                }
-            }
-            if($value['8']){
-                if(empty($basic_list[9][$value['8']])) {
-                    $error[] = $line . '车型:' . $value['8'] . '不存在';
-                }else{
-                    $tmp['car_type'] = $basic_list[9][$value['8']];
-                }
-            }
-            $contact_id = 0;
-            if($value['11']){
-                if(empty($basic_list[12][$value['11']])) {
-                    $error[] = $line . '联系方式类型:' . $value['11'] . '不存在';
-                }else{
-                    $contact_id = $basic_list[12][$value['11']];
-                }
-            }
-            if($value['12'] && in_array($value['12'],$contact_info_array)){
-                $repeat = 1;
-                $error[] = $line . '联系方式内容:' . $value['12'] . '已存在';
-            }
 
-            $fp = $man =  0;
-            if(empty($value['15'])){
-                //分配门店为空 负责人必填
-                list($return_man, $return_error) = $this->returnMan($emp_name, $emp_number, $value['13'], $line);
-                if(! empty($return_error)) $error[] = $return_error;
-                if(! empty($return_man)) $man = $return_man;
-            }else{
-                if(empty($depart[$value['15']])) {
-                    $error[] = $line . '分配门店:' . $value['15'] . '不存在';
-                }else{
-                    $d_t = $depart[$value['15']];
-                    $fp = $d_t['id']; //门店id
-                    $fp_man = $d_t['notify_id']; //门店负责人
-                    if(empty($fp_man)) {
-                        $error[] = $line . '分配门店:' . $value['15'] . '门店负责人暂未设置';
-                    }else{
-                        if(! empty($value['13'])){
-                            list($return_man, $return_error) = $this->returnMan($emp_name, $emp_number, $value['13'], $line);
-                            if(! empty($return_error)) $error[] = $return_error;
-                            if(! empty($return_man)) $man = $return_man;
-                            if($fp_man != $man) $error[] = $line . '分配门店:' . $value['15'] . '门店负责人与用户填写的负责人不一致';
-                        }
-                    }
-                    $man = $fp_man;
+        $uniqueValues = []; // 用于存储需要唯一性检查的值
+        // 第一次遍历:收集所有唯一字段的值
+        foreach ($array as $key => $value) {
+            foreach ($value as $k => $v) {
+                if (isset($table_config[$k]) && ! empty($table_config[$k]['unique'])) {
+                    $uniqueValues[$k][] = [
+                        'value' => trim($v),
+                        'line' => $key
+                    ];
                 }
             }
-
-            $insert[] = $tmp;
-            $insert_detail[] = [
-                'customer_id' => 0,
-                'contact_type' => $contact_id,
-                'contact_info' => $value['12'],
-                'crt_time' => $time,
-                'type' => CustomerInfo::type_one
-            ];
-            $insert_detail2[] = [
-                'customer_id' => 0,
-                'data_id' => $man,
-                'crt_time' => $time,
-                'type' => CustomerInfo::type_two
-            ];
-            $insert_detail3[] = [
-                'customer_id' => 0,
-                'fp' => $fp,
-                'fz' => $man,
-                'crt_time' => $time,
-            ];
-            if($repeat){
-                $tmp['contact_type'] = $contact_id;
-                $tmp['contact'] = $value['12'];
-                $tmp['fz_man'] = $man;
-                $repeat_array[] = $tmp;
-            }
-        }
-
-        //重复录入数据记录
-        if($repeat_array) CustomerRepeat::insert($repeat_array);
-
-        if(! empty($error)){
-            $error = implode(',', $error);
-            return [false, $error];
-        }
-
-        return [true, [$insert, $insert_detail, $insert_detail2, $insert_detail3]];
-    }
-
-    function returnMan($emp_name, $emp_number, $value, $line){
-        $return = [];
-        $type = 0;
-        if(! empty($emp_name[$value])){
-            $return = $emp_name[$value];
-            $type = 1;
-        }else{
-            if(! empty($emp_number[$value])) $return = $emp_number[$value];
         }
-
-        $man = 0;$error = "";
-        if($type){
-            if(count($return) > 1) {
-                $error = $line . '负责人名:' . $value . '在系统中多次出现,请填写工号精准定位负责人';
-            }else{
-                $man = $return[0];
-            }
-        }else{
-            if(! empty($return)){
-                $man = $return;
-            }else{
-                $error = $line . '负责人工号:' . $value . '不存在';
+        // 检查唯一性
+        foreach ($uniqueValues as $column => $values) {
+            $valueCount = [];
+            foreach ($values as $item) {
+                $valueCount[$item['value']][] = $item['line'];
             }
-        }
-
-        return [$man, $error];
-    }
-
-    function convertExcelCellToDate($cellValue) {
-        // 尝试将单元格值转换为浮点数(Excel 日期序列号)
-        $excelTimestamp = filter_var($cellValue, FILTER_VALIDATE_FLOAT);
-
-        if ($excelTimestamp !== false && $excelTimestamp > 0) {
-            // 如果成功转换并且值大于0,则认为是Excel日期序列号
-            try {
-                $dateTimeObject = Date::excelToDateTimeObject($cellValue);
-
-                if ($dateTimeObject->format('H:i:s') === '00:00:00') {
-                    // 如果是,则将时间设置为 '23:59:00'
-                    $dateTimeObject->setTime(23, 59);
+            foreach ($valueCount as $value => $lines) {
+                if (count($lines) > 1) {
+                    $lineNumbers = implode(',', $lines);
+                    $error[] = $table_config[$column]['value'] . "重复,在第{$lineNumbers}行出现重复值:{$value}";
                 }
-
-                // 现在你可以格式化这个日期了
-                $formattedDate = $dateTimeObject->format('Y-m-d H:i:s');
-                if(! strtotime($formattedDate)) return [false, '录入日期请填写正确的日期'];
-
-                return [true,  strtotime($formattedDate)];
-            } catch (\Exception $e) {
-                // 处理转换失败的情况
-                return [false, '单元格日期格式转换时间戳失败'];
             }
         }
-
-        // 如果不是有效的浮点数,则尝试按照多种日期格式解析
-        if(! strtotime($cellValue)) return [false, '单元格文本格式转换时间戳失败'];
-
-        return [true, strtotime($cellValue)];
-    }
-
-    public function productImport($array, $user){
-        //当前门店
-        $depart_id = $this->getDepart($user);
-        $top_depart_id = $user['depart_map'][$depart_id] ?? 0;
-
-        // 去除表头
-        $upload = $array[0];
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        //第一次表格数据校验 非空  已经过滤数据
-        $array_clean = [];
-        $search = "";
-        $map_attr = array_flip(Product::$product_attribute);
+        
+        // 第二次遍历:进行其他验证
         foreach ($array as $key => $value){
+            $line = '第' . $key . '行';
             $rowData = array_filter($value);
             if (empty($rowData)) {
                 unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1]) || empty($value[2])) {
-                return [false, '带*号的字段项必填'];
-            }else{
+            } else{
                 foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                $t = $value[1];
-                if(in_array($t,$array_clean)) return [false, '产品编码:'. $value[1] .'在文件中重复出现'];
-                $array_clean[] = $t;
+                    $row = '第' . $k . '列';
+                    $tmp_v = trim($v);
+                    if(! isset($table_config[$k])){
+                        $error[] = $line . $row . "数据不存在";
+                    }else{
+                        $table_tmp = $table_config[$k] ?? [];
+                        if(! empty($table_tmp['required']) && empty($tmp_v)) $error[] = $line . $table_tmp['value'] . "必填";
+                    }
 
-                if(! empty($value[8])){
-                    if(! isset($map_attr[$value[8]])) return [false, '产品属性不存在' . $value[8]];
-                    $value[8] = $map_attr[$value[8]];
-                }else{
-                    $value[8] = Product::Product_attribute_zero;
+                    if(empty($tmp_v) && isset($table_tmp['default'])) $tmp_v = $table_tmp['default'];
+                    $value[$k] = $tmp_v;
                 }
-                $array[$key] = $value;
-                $search .= "(binary code ='".$value[1]."') or";
-            }
-        }unset($array_clean);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $search = rtrim($search,' or');
-        $search = "($search)";
-        $product = Product::whereRaw($search)
-            ->where('del_time',0)
-            ->select('code','top_depart_id','id')
-            ->get()->toArray();
-        $product_array = [];
-        foreach ($product as $value){
-            $product_array[$value['code']] = [
-                'id' => $value['id'],
-                'top_depart_id' => $value['top_depart_id']
-            ];
-        }
 
-        //产品分类
-        $category_list = ProductCategory::where('del_time',0)
-            ->select('id','title','parent_id')
-            ->where('top_depart_id',$top_depart_id)
-            ->get()->toArray();
-
-        // 创建一个以 id 为键的数据映射
-        $idMap = [];
-        foreach ($category_list as $item) {
-            $idMap[$item['id']] = $item;
-        }
-        // 创建最终的结果数组
-        $category_parent = [];
-        foreach ($idMap as $id => $item) {
-            // 如果没有子项,则处理
-            if (! $this->hasChildren($id, $idMap)) {
-                $category_parent[$id] = $this->getAncestors($id, $idMap);
+                $array[$key] = $value;
             }
         }
-        $category_map = array_column($category_list,'id','title');
 
-        //基础类型
-        $basic = (new BasicTypeService())->getMyBasicList($user, 20);
-        $basic = array_column($basic,'id','title');
+        $error_string = "";
+        if(! empty($error)) $error_string = implode('|', $error);
 
-        $time = time();
-        //表头
-        $table_head = $this->product([],$user);
-        $heads = $table_head[1];
-        $head_value = array_column($heads,'value');
-        if($head_value !== $upload) return [false, '产品模板错误,请重新下载模板导入'];
+        return [$array, $error_string];
+    }
 
-        //写入数据库的字段
-        $tmp = array_column($heads,'key');
-        $tmp = array_fill_keys($tmp, '');
-        $tmp['product_category'] = '';
-        $tmp['upd_time'] = $time;
+    //模板校验
+    private function compareTableAndReturn($upload, $param){
+        if(empty($upload)) return [false, '表头不能为空'];
+        $config_array = $this->getTableConfig($param['type']);
+        if(empty($config_array)) return [false, '导入配置表头文件不存在'];
 
-        $top_message = Depart::where('parent_id',0)
-            ->pluck('title','id')
-            ->toArray();
-        $upload = array_flip($upload);
-        $map = [];
-        foreach ($heads as $value){
-            if(strpos($value['key'], 'table_id.') !== false && isset($upload[$value['value']])){
-                $map[$value['key']] = [
-                    'col' => $upload[$value['value']],
-                    'name' => $value['value']
-                ];
-            }
+        foreach ($config_array as $key => $value){
+            $key_position = $key + 1;
+            if(! isset($upload[$key])) return [false, "第" . $key_position . "列表头缺失"];
+            $tmp_v = trim($upload[$key]);
+            if($tmp_v != $value['value']) return [false, "第" . $key_position . "列表头与模板不符合,请重新下载模板"];
         }
 
-        $array = array_values($array);
-        $insert = $insert2 = $insert_detail = $update = $update2 = $update_detail = [];
-        foreach ($array as $value){
-            if(isset($product_array[$value['1']])){
-                $pro_tmp = $product_array[$value['1']] ?? [];
-                if($pro_tmp['top_depart_id'] != $top_depart_id){
-                    $belong = $top_message[$pro_tmp['top_depart_id']] ?? "";
-                    $now = $top_message[$top_depart_id] ?? "";
-                    return [false, '产品编码:' . $value['1'] . '属于门店:' . $belong . ',当前门店:' . $now . ',不允许跨门店操作更新产品!'];
-                }
-            }
-            $tmp['title'] = $value['0'];
-            $tmp['code'] = $value['1'];
-
-            if(empty($category_map[$value['2']])) return [false,'产品分类:' . $value['2'] . '不存在'];
-            $tmp['product_category_id'] = $category_map[$value['2']];
-            if(! isset($category_parent[$tmp['product_category_id']])) return [false,'产品分类:' . $value['2'] . '下存在子分类,请将产品建与最底层分类下'];
-            $parentsId = $category_parent[$tmp['product_category_id']];
-            $tmp['product_category'] = json_encode($parentsId);
-            $tmp['size'] = $value['3'];
-            if($value['4']){
-                if(empty($basic[$value['4']])) return [false, '单位:' . $value['4'] . '不存在'];
-                $tmp['unit'] = $basic[$value['4']];
-            }
-            $tmp['bar_code'] = $value['5'];
-            $tmp['cost'] = $value['6'] ?? 0;
-            $tmp['retail_price'] = $value['7'] ?? 0;
-            $tmp['product_attribute'] = $value['8'] ?? 0;
-            $tmp['build_fee'] = $value['9'] ?? 0;
-            $tmp['item_code'] = $value['10'] ?? "";
-            $tmp['warranty_time'] = $value['11'] ?? 0;
-            $tmp['product_item_code_title'] = $value['12'] ?? "";
-            foreach ($map as $m => $v){
-                if($value[$v['col']]){
-                    if(! is_numeric($value[$v['col']])) return [false,$v['name'] . ': 请输入数字且最多两位小数'];
-                    $formattedNumber = number_format($value[$v['col']], 2, '.', '');
-                    if($formattedNumber != $value[$v['col']]) return [false,$v['name'] . ': 请输入数字且最多两位小数'];
-                }
-                $tmp[$m] = $value[$v['col']];
-            }
-
-            if(isset($product_array[$value['1']])){
-                //更新
-                $pro_tmp = $product_array[$value['1']] ?? [];
-                $product_id = $pro_tmp['id'];
-
-                //产品价格子表
-                foreach ($tmp as $k => $v){
-                    if(strpos($k, 'table_id.') !== false){
-                        $tmp2 = [];
-                        $k_n = str_replace('table_id.', "", $k);
-                        $tmp2['product_id'] = $product_id;
-                        $tmp2['basic_type_id'] = $k_n;
-                        $tmp2['price'] = $v;
-//                        $tmp2['crt_time'] = $time;
-//                        $tmp2['upd_time'] = $time;
-                        $update2[] = $tmp2;
-                        unset($tmp[$k]);
-                    }
-                }
-
-                //规格
-                if($tmp['size'] == "") unset($tmp['size']);
-                //单位
-                if($tmp['unit'] == "") unset($tmp['unit']);
-                //条码
-                if($tmp['bar_code'] == "") unset($tmp['bar_code']);
-                //成本
-                if($tmp['cost'] == "") unset($tmp['cost']);
-                //零售
-                if($tmp['retail_price'] == "") unset($tmp['retail_price']);
-                //产品属性
-                if($tmp['product_attribute'] == "") unset($tmp['product_attribute']);
-                //安装费
-                if($tmp['build_fee'] == "") unset($tmp['build_fee']);
-                //商品编码
-                if($tmp['item_code'] == "") unset($tmp['item_code']);
-
-                if(! empty($tmp['item_code']) && $tmp['product_item_code_title'] != "" && ! isset($update_detail[$tmp['item_code']])) $update_detail[$tmp['item_code']] = [
-                    'item_code' => $tmp['item_code'],
-                    'title' => $tmp['product_item_code_title']
-                ];
-                unset($tmp['product_item_code_title']);
-
-                //质保年月
-                if($tmp['warranty_time'] == "") unset($tmp['warranty_time']);
-
-                //产品主表
-                $update[$product_id] = $tmp;
-            }else{
-                $tmp['depart_id'] = $depart_id;
-                $tmp['top_depart_id'] = $top_depart_id;
-                $tmp['crt_id'] = $user['id'];
-                $tmp['crt_time'] = $time;
-                //产品价格子表
-                foreach ($tmp as $k => $v){
-                    if(strpos($k, 'table_id.') !== false){
-                        $tmp2 = [];
-                        $k_n = str_replace('table_id.', "", $k);
-                        $tmp2['basic_type_id'] = $k_n;
-                        $tmp2['price'] = $v;
-//                        $tmp2['crt_time'] = $time;
-//                        $tmp2['upd_time'] = $time;
-                        $insert2[$tmp['code']][] = $tmp2;
-                        unset($tmp[$k]);
-                    }
-                }
-
-                if(! empty($tmp['item_code']) && $tmp['product_item_code_title'] != "" && ! isset($insert_detail[$tmp['item_code']])) $insert_detail[$tmp['item_code']] = [
-                    'item_code' => $tmp['item_code'],
-                    'title' => $tmp['product_item_code_title']
-                ];
-                unset($tmp['product_item_code_title']);
-
-                //产品主表
-                $insert[$tmp['code']] = $tmp;
-            }
-        }
-
-        try{
-            DB::beginTransaction();
-            //新增
-            if(! empty($insert)){
-                Product::insert($insert);
-                if(! empty($insert2)){
-                    $insert_detail_d = [];
-                    $last_insert_id = Product::where('crt_time',$time)
-                        ->pluck('id','code')
-                        ->toArray();
-                    foreach ($insert2 as $code => $val){
-                        foreach ($val as $v2){
-                            $v2['product_id'] = $last_insert_id[$code] ?? 0;
-                            $insert_detail_d[] = $v2;
-                        }
-                    }
-                    ProductPriceDetail::insert($insert_detail_d);
-                }
-                if(! empty($insert_detail)) ProductItemCodeMessage::insert(array_values($insert_detail));
-            }
-
-            //编辑
-            if(! empty($update)){
-                foreach ($update as $p_id => $value){
-                    Product::where('id',$p_id)
-                        ->update($value);
-                }
-
-                if(! empty($update2)){
-                    $product_id_array = array_keys($update);
-                    ProductPriceDetail::whereIn('product_id',$product_id_array)
-                        ->where('del_time',0)
-                        ->update(['del_time' => $time]);
-                    ProductPriceDetail::insert($update2);
-                }
-
-                if(! empty($update_detail)) {
-                    $item_code = array_keys($update_detail);
-                    ProductItemCodeMessage::where('del_time',0)
-                        ->whereIn('item_code',$item_code)
-                        ->update(['del_time' => $time]);
-                    ProductItemCodeMessage::insert(array_values($update_detail));
-                }
-            }
-            DB::commit();
-        }catch (\Exception $e){
-            DB::rollBack();
-            return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    function convertHyphens($string) {
-        // 定义要被替换的字符
-        $search = array('-', '-', '—');  // 全角连字符、半角连字符 和 破折号
-        $replace = '-';             // 替换成半角连字符
-
-        // 执行替换
-        $res = str_replace($search, $replace, $string);
-        return $res;
-    }
-
-    function generateTitleToIdMap($tree, $prefix = '') {
-        $result = [];
-
-        foreach ($tree as $node) {
-            $currentTitle = $prefix . $node['title'];
-            $result[$currentTitle] = $node['id'];
-
-            if (!empty($node['children'])) {
-                $result = array_merge(
-                    $result,
-                    $this->generateTitleToIdMap($node['children'], $currentTitle . '-')
-                );
-            }
-        }
-
-        return $result;
-    }
-
-    function getAncestors($id, &$idMap) {
-        if (!isset($idMap[$id])) return [];
-
-        $ancestors = [$id];
-        $parentId = $idMap[$id]['parent_id'];
-
-        if ($parentId !== null) {
-            // 递归调用自己来添加父级 ID
-            $ancestors = array_merge($this->getAncestors($parentId, $idMap), $ancestors);
-        }
-
-        return $ancestors;
-    }
-
-    // 检查是否拥有子项
-    function hasChildren($id, &$idMap) {
-        foreach ($idMap as $item) {
-            if ($item['parent_id'] == $id) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public function salesOnlineImport($array, $user){
-        $head = $user['head']['id'] ?? 0;
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $basic = (new BasicTypeService())->getMyBasicList($user, [18,23,24,29]);
-        $basic_list = [];
-        foreach ($basic as $value){
-            if($value['type'] == 18){
-                $basic_list[9][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 23){
-                $basic_list[10][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 24){
-                $basic_list[3][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 29){
-                $basic_list[2][$value['title']] = $value['id'];
-            }
-        }
-
-        $search = "";
-        $customer = [];
-        foreach ($array as $key => $value){
-            $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]) || $value[6] === null) {
-                return [false, '带*号的字段项必填'];
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                if(! isset($basic_list[2][$value[2]])) return [false, '客户简称:' . $value[2] .'不存在'];
-                $value[2] = $basic_list[2][$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[10] .'不存在'];
-                    $value[10] = $basic_list[10][$value[10]];
-                }
-
-                if(! isset(SalesOrder::$order_type_name[$value[1]])) return [false, '产品类型填写错误'];
-                $value[1] = SalesOrder::$order_type_name[$value[1]];
-
-                if(! empty($value[11])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[11]);
-                    if(! $status) return [false,"施工日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[11] = $msg;
-                }
-
-                if(! empty($value[12])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[12]);
-                    if(! $status) return [false,"交车日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[12] = $msg;
-                }
-
-                $array[$key] = $value;
-                $search .= "(code = '".$value[4]."') or";
-
-                if(! empty($value[7]) && ! in_array($value[7], $customer)) $customer[] = $value[7];
-            }
-        }
-        if(empty($array)) return [false, '导入数据不能为空'];
-        $search = rtrim($search,' or');
-        $search = "($search)";
-        $model = Product::ProductClear($user,[]);
-        $product = $model->whereRaw($search)
-            ->where('del_time',0)
-            ->select('title','id','code','cost','retail_price')
-            ->get()->toArray();
-//        $pro = (new ProductService())->productList(['product_id' => array_column($product,'id'), 'type' => 2],$user);
-
-        $product_map = [];
-        foreach ($product as $value){
-            $product_map[$value['code']] = [
-                'id' => $value['id'],
-                'cost' => $value['cost'],
-                'retail_price' => $value['retail_price'],
-            ];
-        }
-
-        $time = time();
-
-        $model = Customer::Clear($user,[]);
-        $customer_map = $model->where('del_time',0)
-            ->whereIn('title',$customer)
-            ->pluck('id','title')
-            ->toArray();
-
-        $customer_info = CustomerInfo::where('del_time',0)
-            ->whereIn('customer_id',array_values($customer_map))
-            ->whereIn('type',[CustomerInfo::type_one,CustomerInfo::type_two])
-            ->select('customer_id','type','contact_info','data_id')
-            ->orderBy('id','asc')
-            ->get()->toArray();
-        $customer_contact = $customer_man = [];
-        foreach ($customer_info as $value){
-            if($value['type'] == CustomerInfo::type_one && ! isset($customer_contact[$value['customer_id']])){
-                $customer_contact[$value['customer_id']] = $value['contact_info'];
-            }elseif ($value['type'] == CustomerInfo::type_two){
-                $customer_man[$value['customer_id']][] = [
-                    'type' => SalesOrderInfo::type_two,
-                    'data_id' => $value['data_id'],
-                    'crt_time' => $time,
-                ];
-            }
-        }
-
-        $tmp = [
-            'model_type' => SalesOrder::Model_type_four,
-            'sales_order_type' => 0,
-            'order_number' => '',
-            'customer_short_name' => '',
-            'plat_type' => '',
-            'plat_order' => '',
-            'sign_time' => $time,
-            'product_total' => 0,
-            'contract_fee' => 0,
-            'discount_fee' => 0,
-            'cdefine29' => '',//分社施工
-            'cdefine32' => '',//达人昵称
-            'cdefine30' => '',//业务员
-            'rate' => 100,
-            'depart_id' => $head,
-            'top_depart_id' => $head,
-            'crt_id' => $user['id'],
-            'crt_time' => $time,
-            'upd_time' => $time,
-        ];
-        $tmp_detail = [
-            'sales_order_id' => 0,
-            'product_id' => 0,
-            'cost' => 0,
-            'retail_price' => 0,
-            'basic_type_id' => 0,
-            'price' => 0,
-            'final_amount' => 0,
-            'number' => '',
-            'crt_time' => $time,
-        ];
-        $insert = $insert_detail = $insert_detail_man =  [];
-        $prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
-        foreach ($array as $value){
-            $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[7])){
-                $customer_tmp = $customer_map[$value[7]] ?? 0;
-                $customer_contact_tmp = $customer_contact[$customer_tmp] ?? "";
-                $customer_man_tmp = $customer_man[$customer_tmp] ?? [];
-            }
-            $customer_man_tmp[] = [
-                'type' => SalesOrderInfo::type_one,
-                'data_id' => $user['id'],
-                'crt_time' => $time,
-            ];
-
-            $tmp['product_total'] = $tmp['contract_fee'] = 0;
-            $keys = $value[0] . $value[1];
-            $insert_detail_man[$keys] = $customer_man_tmp;
-            if(! isset($insert[$keys])){
-                $tmp['order_number'] = OrderNoService::createSalesOrderNumberImport($prefix);
-                $tmp['sales_order_type'] = $value[1];
-                $tmp['customer_short_name'] = $value[2];
-                $tmp['customer_id'] = $customer_tmp;
-                $tmp['customer_contact'] = $customer_contact_tmp;
-                $tmp['plat_type'] = $value[3];
-                $tmp['plat_order'] = $value[0];
-                $tmp['discount_fee'] = $value[8] ?: 0;
-                $tmp['cdefine29'] = $value[13] ?? "";//分社施工
-                $tmp['cdefine32'] = $value[14] ?? "";//达人昵称
-                $tmp['cdefine30'] = $value[15] ?? "";//业务员
-                $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[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[6];
-            $tmp_detail['number'] = $value[5];
-
-            $insert_detail[$keys][] = $tmp_detail;
-        }
-
-        $insert_detail = array_values($insert_detail);
-        $insert_detail_man = array_values($insert_detail_man);
-        try{
-            DB::beginTransaction();
-            if(! empty($insert)) SalesOrder::insert($insert);
-            $last_insert_id = SalesOrder::where('crt_time',$time)
-                ->select('id')
-                ->get()->toArray();
-            $last_insert_id = array_column($last_insert_id,'id');
-            if(! empty($insert_detail)){
-                $insert2 = [];
-                foreach ($last_insert_id as $key => $value){
-                    if(isset($insert_detail[$key])) {
-                        foreach ($insert_detail[$key] as $val){
-                            $val['sales_order_id'] = $value;
-                            $insert2[] = $val;
-                        }
-                    }
-                }
-                SalesOrderProductInfo::insert($insert2);
-            }
-            if(! empty($insert_detail_man)){
-                $insert3 = [];
-                foreach ($last_insert_id as $key => $value){
-                    if(isset($insert_detail_man[$key])) {
-                        foreach ($insert_detail_man[$key] as $val){
-                            $val['sales_order_id'] = $value;
-                            $insert3[] = $val;
-                        }
-                    }
-                }
-                SalesOrderInfo::insert($insert3);
-            }
-            DB::commit();
-        }catch (\Exception $e){
-            DB::rollBack();
-            return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    public function btOnlineImport($array, $user){
-        $head = $user['head']['id'] ?? 0;
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $basic = (new BasicTypeService())->getMyBasicList($user, [18,23,24,29]);
-        $basic_list = [];
-        foreach ($basic as $value){
-            if($value['type'] == 18){
-                $basic_list[9][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 23){
-                $basic_list[10][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 24){
-                $basic_list[3][$value['title']] = $value['id'];
-            }elseif ($value['type'] == 29){
-                $basic_list[2][$value['title']] = $value['id'];
-            }
-        }
-
-        $search = "";
-        $customer = [];
-        foreach ($array as $key => $value){
-            $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]) || $value[6] === null) {
-                return [false, '带*号的字段项必填'];
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                if(! isset($basic_list[2][$value[2]])) return [false, '客户简称:' . $value[2] .'不存在'];
-                $value[2] = $basic_list[2][$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[10] .'不存在'];
-                    $value[10] = $basic_list[10][$value[10]];
-                }
-
-                if(! isset(SalesOrder::$order_type_name[$value[1]])) return [false, '产品类型填写错误'];
-                $value[1] = SalesOrder::$order_type_name[$value[1]];
-
-                if(! empty($value[11])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[11]);
-                    if(! $status) return [false,"施工日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[11] = $msg;
-                }
-
-                if(! empty($value[12])) {
-                    list($status,$msg) = $this->changeAndReturnDate($value[12]);
-                    if(! $status) return [false,"交车日期请填写正确的日期格式,例如2023-05-01"];
-                    $value[12] = $msg;
-                }
-
-                $array[$key] = $value;
-                $search .= "(code = '".$value[4]."') or";
-
-                if(! empty($value[7]) && ! in_array($value[7], $customer)) $customer[] = $value[7];
-            }
-        }
-        if(empty($array)) return [false, '导入数据不能为空'];
-        $search = rtrim($search,' or');
-        $search = "($search)";
-        $model = Product::ProductClear($user,[]);
-        $product = $model->whereRaw($search)
-            ->where('del_time',0)
-            ->select('title','id','code','cost','retail_price')
-            ->get()->toArray();
-
-        $product_map = [];
-        foreach ($product as $value){
-            $product_map[$value['code']] = [
-                'id' => $value['id'],
-                'cost' => $value['cost'],
-                'retail_price' => $value['retail_price'],
-            ];
-        }
-
-        $time = time();
-
-        $model = Customer::Clear($user,[]);
-        $customer_map = $model->where('del_time',0)
-            ->whereIn('title',$customer)
-            ->pluck('id','title')
-            ->toArray();
-
-        $customer_info = CustomerInfo::where('del_time',0)
-            ->whereIn('customer_id',array_values($customer_map))
-            ->whereIn('type',[CustomerInfo::type_one,CustomerInfo::type_two])
-            ->select('customer_id','type','contact_info','data_id')
-            ->orderBy('id','asc')
-            ->get()->toArray();
-        $customer_contact = $customer_man = [];
-        foreach ($customer_info as $value){
-            if($value['type'] == CustomerInfo::type_one && ! isset($customer_contact[$value['customer_id']])){
-                $customer_contact[$value['customer_id']] = $value['contact_info'];
-            }elseif ($value['type'] == CustomerInfo::type_two){
-                $customer_man[$value['customer_id']][] = [
-                    'type' => SalesOrderInfo::type_two,
-                    'data_id' => $value['data_id'],
-                    'crt_time' => $time,
-                ];
-            }
-        }
-
-        $tmp = [
-            'model_type' => SalesOrder::Model_type_seven,
-            'sales_order_type' => 0,
-            'order_number' => '',
-            'customer_short_name' => '',
-            'plat_type' => '',
-            'plat_order' => '',
-            'sign_time' => $time,
-            'product_total' => 0,
-            'contract_fee' => 0,
-            'discount_fee' => 0,
-            'cdefine29' => '',//分社施工
-            'cdefine32' => '',//达人昵称
-            'cdefine30' => '',//业务员
-            'rate' => 100,
-            'depart_id' => $head,
-            'top_depart_id' => $head,
-            'crt_id' => $user['id'],
-            'crt_time' => $time,
-            'upd_time' => $time,
-        ];
-        $tmp_detail = [
-            'sales_order_id' => 0,
-            'product_id' => 0,
-            'cost' => 0,
-            'retail_price' => 0,
-            'basic_type_id' => 0,
-            'price' => 0,
-            'final_amount' => 0,
-            'number' => '',
-            'crt_time' => $time,
-        ];
-        $insert = $insert_detail = $insert_detail_man =  [];
-        $prefix = SalesOrder::$prefix[salesOrder::Model_type_four];
-        foreach ($array as $value){
-            $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[7])){
-                $customer_tmp = $customer_map[$value[7]] ?? 0;
-                $customer_contact_tmp = $customer_contact[$customer_tmp] ?? "";
-                $customer_man_tmp = $customer_man[$customer_tmp] ?? [];
-            }
-            $customer_man_tmp[] = [
-                'type' => SalesOrderInfo::type_one,
-                'data_id' => $user['id'],
-                'crt_time' => $time,
-            ];
-
-            $tmp['product_total'] = $tmp['contract_fee'] = 0;
-            $keys = $value[0] . $value[1];
-            $insert_detail_man[$keys] = $customer_man_tmp;
-            if(! isset($insert[$keys])){
-                $tmp['order_number'] = OrderNoService::createSalesOrderNumberImport($prefix);
-                $tmp['sales_order_type'] = $value[1];
-                $tmp['customer_short_name'] = $value[2];
-                $tmp['customer_id'] = $customer_tmp;
-                $tmp['customer_contact'] = $customer_contact_tmp;
-                $tmp['plat_type'] = $value[3];
-                $tmp['plat_order'] = $value[0];
-                $tmp['discount_fee'] = $value[8] ?: 0;
-                $tmp['cdefine29'] = $value[13] ?? "";//分社施工
-                $tmp['cdefine32'] = $value[14] ?? "";//达人昵称
-                $tmp['cdefine30'] = $value[15] ?? "";//业务员
-                $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[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[6];
-            $tmp_detail['number'] = $value[5];
-
-            $insert_detail[$keys][] = $tmp_detail;
-        }
-
-        $insert_detail = array_values($insert_detail);
-        $insert_detail_man = array_values($insert_detail_man);
-        try{
-            DB::beginTransaction();
-            if(! empty($insert)) SalesOrder::insert($insert);
-            $last_insert_id = SalesOrder::where('crt_time',$time)
-                ->select('id')
-                ->get()->toArray();
-            $last_insert_id = array_column($last_insert_id,'id');
-            if(! empty($insert_detail)){
-                $insert2 = [];
-                foreach ($last_insert_id as $key => $value){
-                    if(isset($insert_detail[$key])) {
-                        foreach ($insert_detail[$key] as $val){
-                            $val['sales_order_id'] = $value;
-                            $insert2[] = $val;
-                        }
-                    }
-                }
-                SalesOrderProductInfo::insert($insert2);
-            }
-            if(! empty($insert_detail_man)){
-                $insert3 = [];
-                foreach ($last_insert_id as $key => $value){
-                    if(isset($insert_detail_man[$key])) {
-                        foreach ($insert_detail_man[$key] as $val){
-                            $val['sales_order_id'] = $value;
-                            $insert3[] = $val;
-                        }
-                    }
-                }
-                SalesOrderInfo::insert($insert3);
-            }
-            DB::commit();
-        }catch (\Exception $e){
-            DB::rollBack();
-            return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    public function lastJcImport($array, $user){
-        $head = $user['head']['id'] ?? 0;
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $shop_name = $product_code = [];
-        foreach ($array as $key => $value){
-            $rowData = array_filter($value);
-            if (empty($rowData)) {
-                unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1])) {
-                return [false, '带*号的字段项必填'];
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                if(! is_numeric($value[2])) return [false, '* 上月结存数量请填写正确的数值'];
-                if(! is_numeric($value[3])) return [false, '* 上月结存单价请填写正确的数值'];
-                if(! is_numeric($value[4])) return [false, '* 上月结存金额请填写正确的数值'];
-                if(! in_array($value[0],$shop_name)) $shop_name[] = $value[0];
-                if(! in_array($value[1],$product_code)) $product_code[] = $value[1];
-            }
-        }
-        $model = Product::ProductClear($user,[]);
-        $product_map = $model->whereIn('code',$product_code)
-            ->where('del_time',0)
-            ->pluck('id','code')
-            ->toArray();
-
-        $depart_map = Depart::whereIn('title',$shop_name)
-            ->where('del_time',0)
-            ->pluck('id','title')
-            ->toArray();
-        $storehouse_map = Storehouse::whereIn('top_depart_id',array_values($depart_map))
-            ->where('del_time',0)
-            ->pluck('id','top_depart_id')
-            ->toArray();
-        $time = time();
-        $insert = [];
-
-        $last_month_stamp = strtotime(date('Y-m-t 23:59:59', strtotime('last month')));
-        foreach ($array as $value){
-            $depart_tmp = $depart_map[$value[0]] ?? 0;
-            if($depart_tmp <= 0) return [false, "门店:" . $value[0] . "不存在或已被删除"];
-            $product_tmp = $product_map[$value[1]] ?? 0;
-            if($product_tmp <= 0) return [false, "产品编码:" . $value[1] . "不存在或已被删除"];
-            $storehouse_tmp = $storehouse_map[$depart_tmp] ?? 0;
-            $insert[] = [
-                'top_depart_id' => $depart_tmp,
-                'product_id' => $product_tmp,
-                'storehouse_id' => $storehouse_tmp,
-                'number' => $value[2],
-                'price' => $value[3],
-                'total' => $value[4],
-                'crt_time' => $time,
-                'time' => $last_month_stamp
-            ];
-        }
-        if(empty($insert)) return [false, '暂无更新的数据'];
-
-        try{
-            DB::beginTransaction();
-
-            //更新数据为删除
-            foreach ($insert as $value){
-                LastJc::where('del_time',0)
-                    ->where('time', $last_month_stamp)
-                    ->where('top_depart_id',$value['top_depart_id'])
-                    ->where('storehouse_id',$value['storehouse_id'])
-                    ->where('product_id',$value['product_id'])
-                    ->update(['del_time' => $time]);
-            }
-            //写入数据
-            LastJc::insert($insert);
-            DB::commit();
-        }catch (\Exception $e){
-            DB::rollBack();
-            return [false, $e->getMessage() . $e->getLine() . $e->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    public function inventoryImport($array, $user){
-        $head = $user['head']['id'] ?? 0;
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $shop_name = $product_code = [];
-        foreach ($array as $key => $value){
-            $rowData = array_filter($value);
-            if (empty($rowData)) {
-                unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1])) {
-                if($key != 1){
-                    if(empty($value[1])) return [false, '带*号的字段项必填'];
-                } else{
-                    return [false, '带*号的字段项必填'];
-                }
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                if($value[0] && ! in_array($value[0],$shop_name)) $shop_name[] = $value[0];
-                if(! in_array($value[1],$product_code)) {
-                    $product_code[] = $value[1];
-                }else{
-                    return [false, '产品编号:' . $value[1] .'已存在'];
-                }
-                if(! is_numeric($value[2])) return [false, '* 盘点数量请填写正确的数值'];
-
-                if(! empty($value[3])){
-                    $bool = $this->checkNumber($value[3]);
-                    if(! $bool) return [false, '盘点单价请输入大于等于0的两位小数的数字'];
-                }
-            }
-        }
-        if(count($shop_name) != 1) return [false, '只允许单门店盘点'];
-
-        //门店信息
-        $depart = Depart::whereIn('title',$shop_name)
-            ->where('del_time',0)
-            ->where('parent_id',0)
-            ->select('id','title','basic_type_id')
-            ->first();
-        if(empty($depart)) return [false, "门店:" .$shop_name . "不存在或已被删除"];
-        $depart = $depart->toArray();
-        $top_depart_id = $depart['id'];
-        $basic_type_id = $depart['basic_type_id'];
-
-        //门店的仓库
-        $storehouse = Storehouse::where('top_depart_id', $top_depart_id)
-            ->where('del_time',0)
-            ->select('id')
-            ->first();
-        if(empty($storehouse)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
-        $storehouse = $storehouse->toArray();
-        $storehouse_id = $storehouse['id'];
-        if(empty($storehouse_id)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
-
-        //产品
-        $model = Product::ProductClear($user,[]);
-        $product = $model->whereIn('code',$product_code)
-            ->where('del_time',0)
-            ->select('id','code','retail_price')
-            ->get()->toArray();
-        $product_map = array_column($product,'id','code');
-        $product_map_2 = array_column($product,'retail_price','id');
-
-        //产品使用价格
-        $product_use = [];
-        if(! empty($basic_type_id)){
-            $product_id = array_column($product,'id');
-            $service = new ProductService();
-            $detail_map = $service->getProductPrice($product_id, 1, $basic_type_id);
-            foreach ($detail_map as $key => $value){
-                if(isset($value[$basic_type_id]) && ! empty($value[$basic_type_id]['price'])) {
-                    $product_use[$key] = $value[$basic_type_id]['price'];
-                }else{
-                    $product_use[$key] = $product_map_2[$key] ?? 0;
-                }
-            }
-        }else{
-            $product_use = $product_map_2;
-        }
-
-        $time = time();
-        $product_submit = $product_id = $sub = [];
-        foreach ($array as $value){
-            $product_tmp = $product_map[$value[1]] ?? 0;
-            if($product_tmp <= 0) return [false, "产品编码:" . $value[1] . "不存在或已被删除"];
-
-            if(isset($value[3])){
-                $bool = $this->checkNumber($value[3]);
-                if(! $bool) return [false, '盘点单价不合法,需是大于等于0的两位数值'];
-                $price = $value[3];
-            }else{
-                if(! isset($product_use[$product_tmp]) || floatval($product_use[$product_tmp]) < 0) return [false, "产品编码:" . $value[1] . "获取单价所得小于0,请检查门店所设置价格以及产品零售价"];
-                $price = $product_use[$product_tmp];
-            }
-
-            $key = $product_tmp . ',' . $storehouse_id;
-            if(! isset($product_submit[$key])) $product_submit[$key] = 0;
-
-            //总的产品id
-            $product_id[] = $product_tmp;
-
-            $sub[] = [
-                'product_id' => $product_tmp,
-                'storehouse_id' => $storehouse_id,
-                'order_number' => "",
-                'counted_num' => $value[2],
-                'book_num' => 0,
-                'final_num' => 0,
-                'inventory_id' => 0,
-                'price' => $price,
-            ];
-        }
-
-        //库存校验
-        $set = ProductInventorySet::where('top_depart_id',$top_depart_id)->where('del_time',0)->first();
-        if(empty($set)) return [false, '门店是否校验库存设置缺失'];
-        $set = $set->toArray();
-        $is_check_stock = $set['param_one'] <= 0 ? ProductInventorySet::type_one : $set['param_one'];
-
-        //获取库存
-        $inventory_map = [];
-        $inventory = ProductInventoryService::getRealStock($product_id, $storehouse_id);
-        foreach ($inventory as $value){
-            $key = $value['product_id'] . ',' . $value['storehouse_id'];
-            $inventory_map[$key] = $value['real_number'];
-        }
-
-        $order_number = (new OrderNoService())->createOrderNumber(Inventory::prefix);
-        $product_submit_reduce = $product_reduce_id = [];
-        //盘点详情
-        foreach ($sub as $key => $value){
-            $sub[$key]['order_number'] = $order_number;
-            $keys = $value['product_id'] . ',' . $value['storehouse_id'];
-            if(isset($inventory_map[$keys])){
-                $sub[$key]['book_num'] = $inventory_map[$keys];
-                $num = bcsub($value['counted_num'], $inventory_map[$keys],4);
-                $sub[$key]['final_num'] = $num;
-            }else{
-                $sub[$key]['final_num'] = $value['counted_num'];
-            }
-
-            $final_amount = bcmul($sub[$key]['final_num'], $value['price'],2);
-            $sub[$key]['final_amount'] = $final_amount;
-
-            if($sub[$key]['final_num'] < 0) {
-                $product_reduce_id[] = $value['product_id'];
-                $product_submit_reduce[$keys] = $sub[$key]['final_num'];
-            }
-        }
-
-        //校验是否存在产品盘点
-        list($status, $msg) = (new InventoryService())->issetProduct(['top_depart_id' => $top_depart_id], $product_submit);
-        if(! $status) return [false, $msg];
-
-        if(! empty($product_submit_reduce)){
-            //校验库存
-            list($status,$msg) = (new ProductInventoryService())->compareStock($user,$product_reduce_id, $product_submit_reduce);
-            if(! $status) return [false, $msg];
-        }
-
-        if(empty($sub)) return [false, '暂无需要写入的盘点数据'];
-
-        try{
-            DB::beginTransaction();
-
-            $inventory_model = new Inventory();
-            $inventory_model->order_number = $order_number;
-            $inventory_model->storehouse_id = $storehouse_id;
-            $inventory_model->counted_id = $user['id'];
-            $inventory_model->counted_time = $time;
-            $inventory_model->depart_id = $top_depart_id;
-            $inventory_model->top_depart_id = $top_depart_id;
-            $inventory_model->crt_id = $user['id'];
-            $inventory_model->save();
-
-            foreach ($sub as $key => $value){
-                $sub[$key]['inventory_id'] = $inventory_model->id;
-            }
-
-            //写入数据
-            InventorySub::insert($sub);
-
-            //单据创建时是否校验库存
-            (new CheckService())->orderInventoryInsert(['order_number' => $order_number, 'is_check_stock' => $is_check_stock]);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
-                return [false, '网络波动,请重新操作!'];
-            }
-            return [false, $exception->getMessage() . $exception->getLine() . $exception->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    public function productAdjustmentImport($array, $user){
-        $head = $user['head']['id'] ?? 0;
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $shop_name = $product_code = [];
-        foreach ($array as $key => $value){
-            $rowData = array_filter($value);
-            if (empty($rowData)) {
-                unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1]) || empty($value[2])) {
-                if($key != 1){
-                    if(empty($value[1])) return [false, '带*号的字段项必填'];
-                } else{
-                    return [false, '带*号的字段项必填'];
-                }
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-                if($value[0] && ! in_array($value[0],$shop_name)) $shop_name[] = $value[0];
-                if(! in_array($value[1],$product_code)) {
-                    $product_code[] = $value[1];
-                }else{
-                    return [false, '产品编号:' . $value[1] .'已存在'];
-                }
-                if(! is_numeric($value[2])) return [false, '调整金额请填写正确的数值'];
-            }
-        }
-        if(count($shop_name) != 1) return [false, '只允许单门店创建调整金额'];
-
-        //门店信息
-        $depart = Depart::whereIn('title',$shop_name)
-            ->where('del_time',0)
-            ->where('parent_id',0)
-            ->select('id','title')
-            ->first();
-        if(empty($depart)) return [false, "门店:" .$shop_name . "不存在或已被删除"];
-        $depart = $depart->toArray();
-        $top_depart_id = $depart['id'];
-
-        //门店的仓库
-        $storehouse = Storehouse::where('top_depart_id', $top_depart_id)
-            ->where('del_time',0)
-            ->select('id')
-            ->first();
-        if(empty($storehouse)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
-        $storehouse = $storehouse->toArray();
-        $storehouse_id = $storehouse['id'];
-        if(empty($storehouse_id)) return [false, "门店:" .$shop_name . "的仓库不存在或已被删除"];
-
-        //产品
-        $model = Product::ProductClear($user,[]);
-        $product = $model->whereIn('code',$product_code)
-            ->where('del_time',0)
-            ->select('id','code')
-            ->get()->toArray();
-        $product_map = array_column($product,'id','code');
-
-        $product_submit = [];
-        foreach ($product as $value){
-            $key = $value['id'] . ',' . $storehouse_id;
-            if(! isset($product_submit[$key])) $product_submit[$key] = 0;
-        }
-        //校验是否存在产品调整
-        list($status, $msg) = (new ProductAdjustService())->issetProduct(['top_depart_id' => $top_depart_id], $product_submit);
-        if(! $status) return [false, $msg];
-
-        $time = time();
-        $sub = [];
-        foreach ($array as $value){
-            $product_tmp = $product_map[$value[1]] ?? 0;
-            if($product_tmp <= 0) return [false, "产品编码:" . $value[1] . "不存在或已被删除"];
-
-            $sub[] = [
-                'product_id' => $product_tmp,
-                'storehouse_id' => $storehouse_id,
-                'order_number' => "",
-                'product_adjustment_id' => 0,
-                'final_amount' => $value[2],
-            ];
-        }
-        if(empty($sub)) return [false, '暂无需要写入的产品调整单数据'];
-
-        try{
-            $order_number = (new OrderNoService())->createOrderNumber(ProductAdjustment::prefix);
-
-            DB::beginTransaction();
-
-            $inventory_model = new ProductAdjustment();
-            $inventory_model->order_number = $order_number;
-            $inventory_model->storehouse_id = $storehouse_id;
-            $inventory_model->counted_id = $user['id'];
-            $inventory_model->counted_time = $time;
-            $inventory_model->depart_id = $top_depart_id;
-            $inventory_model->top_depart_id = $top_depart_id;
-            $inventory_model->crt_id = $user['id'];
-            $inventory_model->save();
-
-            foreach ($sub as $key => $value){
-                $sub[$key]['product_adjustment_id'] = $inventory_model->id;
-                $sub[$key]['order_number'] = $order_number;
-            }
-
-            //写入数据
-            ProductAdjustmentSub::insert($sub);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
-                return [false, '网络波动,请重新操作!'];
-            }
-            return [false, $exception->getMessage() . $exception->getLine() . $exception->getCode()];
-        }
-
-        return [true, ''];
-    }
-
-    public function customerPerformanceImport($array, $user, $other_param){
-        if(empty($other_param["ym"])) return [false,'请选择导入客资业绩年月'];
-
-        // 去除表头
-        unset($array[0]);
-        if(empty($array)) return [false, '导入数据不能为空'];
-
-        $insert = [];
-        foreach ($array as $key => $value){
-            $rowData = array_filter($value);
-            if (empty($rowData)) {
-                unset($array[$key]);
-            } elseif(empty($value[0]) || empty($value[1])) {
-                return [false, '带*号的字段项必填'];
-            }else{
-                foreach ($value as $k => $v){
-                    $value[$k] = trim($v);
-                }
-
-                if(! empty($value[2]) && ! is_numeric($value[2])) return [false, '当月打款金额请填写正确的数值'];
-            }
-
-            $insert[] = [
-                'area' => $value['0'],
-                'title' => $value['1'],
-                'current_month_payment' => $value['2'] ?? 0,
-                'crt_time' => $other_param['ym']
-            ];
-        }
-
-        $start_time = strtotime(date("Y-m-01 00:00:00", $other_param['ym']));
-        $end_time = strtotime(date("Y-m-t 23:59:59", $other_param['ym']));
-        CustomerPerFormance::where('del_time',0)
-            ->where('crt_time','>=', $start_time)
-            ->where('crt_time','<=', $end_time)
-            ->update(['del_time' => time()]);
-
-        if(! empty($insert)) CustomerPerFormance::insert($insert);
-
-        return [true, ''];
+        return [true, $config_array];
     }
 }
 

+ 35 - 1401
app/Service/ProductService.php

@@ -28,19 +28,6 @@ use Illuminate\Support\Facades\DB;
  */
 class ProductService extends Service
 {
-    public function setIsEditUnitPrice($data,$user){
-        if($this->isEmpty($data,'id')) return [false,'请选择分类!'];
-        if(! isset($data['is_edit_unit_price'])) return [false,'请选择受否允许修改采购单价!'];
-        $is_edit_unit_price = $data['is_edit_unit_price'] > 0 ? 1 : 0;
-        $all_id = $this->getProductCateGory($data['id']);
-
-        ProductCategory::whereIn('id',$all_id)->update([
-            'is_edit_unit_price' => $is_edit_unit_price
-        ]);
-
-        return [true, ''];
-    }
-
     /**
      * 产品分类编辑
      * @param $data
@@ -110,8 +97,7 @@ class ProductService extends Service
      * @return array
      */
     public function productCategoryList($data,$user){
-        $model = ProductCategory::TopClear($user,$data);
-        $model = $model->leftJoin('product_category_orderby as a', function ($join) {
+        $model = ProductCategory::leftJoin('product_category_orderby as a', function ($join) {
                 $join->on('product_category.id', '=', 'a.category_id')
                     ->where('a.del_time',0);
             })
@@ -136,46 +122,6 @@ class ProductService extends Service
         return [200, ['data' => $list,'tree' => $list_tree]];
     }
 
-    public function productCategoryList2($data,$user){
-        $head_top_depart_id = $user['head']['id'] ?? 0;
-        $now_top_depart_id = $this->getDepart($user);
-
-        //总社分类
-        $head = ProductCategory::leftJoin('product_category_orderby as a', function ($join) {
-                $join->on('product_category.id', '=', 'a.category_id')
-                    ->where('a.del_time',0);
-            })
-            ->where('product_category.del_time',0)
-            ->where('product_category.top_depart_id', $head_top_depart_id)
-            ->when($head_top_depart_id != $now_top_depart_id, function ($query){
-                return $query->where('product_category.is_show',0);
-            })
-            ->select('product_category.title','product_category.id','product_category.parent_id')
-            ->orderByRaw('IF(a.sort IS NULL, product_category.id, a.sort) ASC') // 排序逻辑:优先按 a.sort 排序,没有关联时按主表 id 排序
-            ->get()->toArray();
-        $head_tree = [];
-        if(! empty($head)) {
-            $head_tree = $this->makeTree(0,$head);
-            $head_tree = $this->set_sort_circle($head_tree);
-        }
-
-        //我的
-        $my_tree = [];
-        if($head_top_depart_id != $now_top_depart_id){
-            $model = ProductCategory::TopClear($user,$data);
-            $model = $model->where('del_time',0)
-                ->select('title','id','parent_id')
-                ->orderby('id','asc');
-            $list = $model->get()->toArray();
-            if(! empty($list)) {
-                $my_tree = $this->makeTree(0,$list);
-                $my_tree = $this->set_sort_circle($my_tree);
-            }
-        }
-
-        return [200, ['head_tree' => $head_tree, 'my_tree' => $my_tree]];
-    }
-
     /**
      * 产品分类参数规则
      * @param $data
@@ -185,10 +131,6 @@ class ProductService extends Service
     public function productCategoryRule($data,$user, $is_add = true){
         if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
 
-        //所属部门 以及  顶级部门
-        if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
-        $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
-
         $title = array_column($data['data'],'title');
         $title = array_map(function($val) {
             return $val !== null ? $val : 0;
@@ -228,7 +170,6 @@ class ProductService extends Service
                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
                 $top_depart_id = ProductCategory::where('id',$data['id'])->value('top_depart_id');
                 $bool = ProductCategory::where('title',$value['title'])
-                    ->where('top_depart_id',$top_depart_id)
                     ->where('id','<>',$data['id'])
                     ->where('del_time',0)
                     ->exists();
@@ -253,112 +194,26 @@ class ProductService extends Service
             DB::beginTransaction();
 
             $model = Product::where('id',$data['id'])->first();
-            $model->product_category_id = $data['product_category_id'] ?? 0;
-            $model->product_category = $data['product_category'] ?? '';
+            $model->category = $data['category'] ?? '';
             $model->title = $data['title'];
             $model->code = $data['code'] ?? '';
-            $model->warranty_time = $data['warranty_time'] ?? 0;
-            $model->install_time = $data['install_time'] ?? 0;
             $model->size = $data['size'] ?? '';
             $model->unit = $data['unit'] ?? 0;
-            $model->bar_code = $data['bar_code'] ?? '';
+            $model->business_cost = $data['business_cost'] ?? 0;
             $model->cost = $data['cost'] ?? 0;
-            $model->retail_price = $data['retail_price'] ?? 0;
-            $model->build_fee = $data['build_fee'] ?? 0;
-            $model->item_code = $data['item_code'] ?? "";
+            $model->write_off_price = $data['write_off_price'] ?? 0;
+            $model->major_client_settlement_price = $data['major_client_settlement_price'] ?? 0;
+            $model->return_change_price = $data['return_change_price'] ?? "";
             $model->mark = $data['mark'] ?? '';
-            $model->state = $data['state'] ?? 0;
-            $model->product_attribute = $data['product_attribute'] ?? 0;
-            $model->is_use = $data['is_use'] ?? Product::is_use_one;
             $model->save();
 
-            $time = time();
-
-            ProductIntroduction::where('product_id',$data['id'])
-                ->where('del_time',0)
-                ->update(['del_time' => $time]);
-            if(! empty($data['introduction'])){
-                $models = new ProductIntroduction();
-                $models->product_id = $model->id;
-                $models->introduction = $data['introduction'];
-                $models->save();
-            }
-
-            $old = ProductInfo::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->select('file')
-                ->get()->toArray();
-            $old = array_column($old,'file');
-            ProductInfo::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            $new = [];
-            if(! empty($data['img'])){
-                $insert = [];
-                foreach ($data['img'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'file' => $value['url'],
-                        'type' => ProductInfo::type_one,
-                        'name' => $value['name'],
-                        'crt_time' => $time,
-                    ];
-                    if(in_array($value['url'], $old)) {
-                        foreach ($old as $o_k => $o_v){
-                            if($o_v == $value['url']) unset($old[$o_k]);
-                        }
-                    }else{
-                        $new[] = $value['url'];
-                    }
-                }
-                ProductInfo::insert($insert);
-            }
-            if(! empty($data['file'])){
-                $insert = [];
-                foreach ($data['file'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'file' => $value['url'],
-                        'type' => ProductInfo::type_two,
-                        'name' => $value['name'],
-                        'crt_time' => $time,
-                    ];
-                    if(in_array($value['url'], $old)) {
-                        foreach ($old as $o_k => $o_v){
-                            if($o_v == $value['url']) unset($old[$o_k]);
-                        }
-                    }else{
-                        $new[] = $value['url'];
-                    }
-                }
-                ProductInfo::insert($insert);
-            }
-
-            ProductPriceDetail::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            if(! empty($data['product_price'])){
-                $insert = [];
-                foreach ($data['product_price'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'basic_type_id' => $value['basic_type_id'],
-                        'price' => $value['price'] ?? 0,
-                        'crt_time' => $time,
-                    ];
-                }
-                ProductPriceDetail::insert($insert);
-            }
-
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
             return [false,$exception->getMessage()];
         }
 
-        return [true, ['file' => ['new' => $new, 'old' => $old]]];
+        return [true, ''];
     }
 
     /**
@@ -375,88 +230,27 @@ class ProductService extends Service
             DB::beginTransaction();
 
             $model = new Product();
-            $model->product_category_id = $data['product_category_id'] ?? 0;
-            $model->product_category = $data['product_category'] ?? '';
+            $model->category = $data['category'] ?? '';
             $model->title = $data['title'];
             $model->code = $data['code'] ?? '';
-            $model->warranty_time = $data['warranty_time'] ?? 0;
-            $model->install_time = $data['install_time'] ?? 0;
             $model->size = $data['size'] ?? '';
             $model->unit = $data['unit'] ?? 0;
-            $model->bar_code = $data['bar_code'] ?? '';
+            $model->business_cost = $data['business_cost'] ?? 0;
             $model->cost = $data['cost'] ?? 0;
-            $model->retail_price = $data['retail_price'] ?? 0;
-            $model->build_fee = $data['build_fee'] ?? 0;
-            $model->item_code = $data['item_code'] ?? "";
+            $model->write_off_price = $data['write_off_price'] ?? 0;
+            $model->major_client_settlement_price = $data['major_client_settlement_price'] ?? 0;
+            $model->return_change_price = $data['return_change_price'] ?? "";
             $model->mark = $data['mark'] ?? '';
-            $model->state = $data['state'] ?? 0;
-            $model->product_attribute = $data['product_attribute'] ?? 0;
             $model->crt_id = $user['id'];
-            $model->depart_id = $data['depart_id'] ?? 0;
-            $model->top_depart_id = $data['top_depart_id'] ?? 0;
-            $model->is_use = $data['is_use'] ?? Product::is_use_one;
             $model->save();
 
-            $time = time();
-
-            if(! empty($data['introduction'])){
-                $models = new ProductIntroduction();
-                $models->product_id = $model->id;
-                $models->introduction = $data['introduction'];
-                $models->save();
-            }
-
-            $new = [];
-            if(! empty($data['img'])){
-                $insert = [];
-                foreach ($data['img'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'file' => $value['url'],
-                        'type' => ProductInfo::type_one,
-                        'name' => $value['name'],
-                        'crt_time' => $time,
-                    ];
-                    if(! empty($value['url'])) $new[] = $value['url'];
-                }
-                ProductInfo::insert($insert);
-            }
-
-            if(! empty($data['file'])){
-                $insert = [];
-                foreach ($data['file'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'file' => $value['url'],
-                        'type' => ProductInfo::type_two,
-                        'name' => $value['name'],
-                        'crt_time' => $time,
-                    ];
-                    if(! empty($value['url'])) $new[] = $value['url'];
-                }
-                ProductInfo::insert($insert);
-            }
-
-            if(! empty($data['product_price'])){
-                $insert = [];
-                foreach ($data['product_price'] as $value){
-                    $insert[] = [
-                        'product_id' => $model->id,
-                        'basic_type_id' => $value['basic_type_id'],
-                        'price' => $value['price'] ?? 0,
-                        'crt_time' => $time,
-                    ];
-                }
-                ProductPriceDetail::insert($insert);
-            }
-
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
             return [false,$exception->getMessage()];
         }
 
-        return [true, ['file' => ['new' => $new]]];
+        return [true, ''];
     }
 
     /**
@@ -473,26 +267,6 @@ class ProductService extends Service
 
             Product::where('del_time',0)->where('id',$data['id'])->update(['del_time' => $time]);
 
-            ProductIntroduction::where('product_id',$data['id'])
-                ->where('del_time',0)
-                ->update(['del_time' => $time]);
-
-            $old = ProductInfo::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->select('file')
-                ->get()->toArray();
-            $old = array_column($old,'file');
-
-            ProductInfo::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            ProductPriceDetail::where('del_time',0)
-                ->where('product_id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            (new RangeService())->RangeDelete($data['id'],SeeRange::type_four);
-
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
@@ -515,95 +289,9 @@ class ProductService extends Service
             ->first();
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         $customer = $customer->toArray();
-        $customer['product_attribute_title'] = Product::$product_attribute[$customer['product_attribute']] ?? "";
-        $customer['is_use_title'] = Product::$is_use[$customer['is_use']] ?? "";
-        $customer['product_category'] = ! empty($customer['product_category']) ? json_decode($customer['product_category'],true): [];
-        $category = ProductCategory::where('id',$customer['product_category_id'])
-            ->value('title');
-        $customer['product_category_title'] = $category;
-        $customer['introduction'] = "";
-        $in = ProductIntroduction::where('del_time',0)
-            ->where('product_id',$data['id'])
-            ->first();
-        if(! empty($in)) $customer['introduction'] = $in->introduction;
-
-        $data['top_depart_id'] = $user['head']['id'] ?? 0;
-        $model = BasicType::TopClear($user,$data);
-        $basic = $model->where('del_time',0)
-            ->where('type',22)
-            ->select('title','id','type')
-            ->orderby('id', 'asc')->get()->toArray();
-
-        $detail = ProductPriceDetail::where('del_time',0)
-            ->where('product_id',$data['id'])
-            ->select('product_id','basic_type_id','price')
-            ->get()->toArray();
-        $title_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($detail,'basic_type_id'),array_column($basic,'id'))))
-            ->pluck('title','id')
-            ->toArray();
-        $top_depart = $user['depart_top'][0] ?? [];
-        $customer['is_edit'] = $customer['top_depart_id'] == $top_depart['depart_id'] ? 1 : 0;
-        $customer['product_price'] = [];
-
-        //特殊功能按钮
-        $special_button = $user['special_button'] ?? [];
-
-        //成本
-        $is_show_cost = 0;
-        if(in_array(RoleMenuButton::special_two,$special_button)) $is_show_cost = 1;
-        $customer['cost_show'] = $is_show_cost;
-
-        //所有金额
-        foreach ($basic as $value){
-            $show = 0;
-            if(in_array(RoleMenuButton::special_one,$special_button)){
-                $show = 1;
-            }else{
-                if($top_depart['basic_type_id'] == $value['id']) $show = 1;
-            }
-            $customer['product_price'][$value['id']] = [
-                'basic_type_id' => $value['id'],
-                'basic_type_title' => $title_map[$value['id']] ?? '',
-                'price' => 0,
-                'is_show' => $show,
-            ];
-        }
-        //展示金额
-        foreach ($detail as $value){
-            if(isset($customer['product_price'][$value['basic_type_id']])) $customer['product_price'][$value['basic_type_id']]['price'] = $value['price'];
-        }
-
-        $customer['product_price'] = array_values($customer['product_price']);
-
-        //单位
-        $title = BasicType::where('id',$customer['unit'])->value('title');
-        $customer['unit_name'] = $title;
-
-        $customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
-        $customer_info = ProductInfo::where('del_time',0)
-            ->where('product_id',$customer['id'])
-            ->select('id','product_id','file','type','name')
-            ->get()->toArray();
-        $fileUploadService = new FileUploadService();
-        foreach ($customer_info as $value){
-            $tmp = [
-                'url' => $value['file'],
-                'name' => $value['name'],
-                'show_url' => $fileUploadService->getFileShow($value['file']),
-            ];
-            if($value['type'] == ProductInfo::type_one){
-                $customer['img'][] = $tmp;
-            }elseif ($value['type'] == ProductInfo::type_two){
-                $customer['file'][] = $tmp;
-            }
-        }
 
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
-        //可见范围
-        $return = (new RangeService())->RangeDetail($data['id'],SeeRange::type_four);
-        $customer['depart'] = $return[0] ?? [];
-        $customer['employee'] = $return[1] ?? [];
 
         return [true, $customer];
     }
@@ -611,62 +299,26 @@ class ProductService extends Service
     public function productCommon($data,$user, $field = []){
         if(empty($field)) $field = Product::$field;
 
-        $model = Product::ProductClear($user,$data);
-        $model = $model->where('del_time',0)
+        $model = Product::where('del_time',0)
             ->select($field)
-            ->orderby('product_attribute', 'desc')
-            ->orderby('id', 'desc');
+            ->orderby('code', 'asc');
+
 
-        if(! empty($data['title_t'])) {
-            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
-            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
-            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->where(function ($query) use ($cleanTitle, $data) {
-                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
-                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
-            });
-        }
         if(! empty($data['title'])) {
             // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
             $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
             // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
             $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
-
-//            $model->where('title', 'LIKE', '%'.$data['title'].'%');
-        }
-        if(! empty($data['product_item_code_title'])){
-            $item_code = ProductItemCodeMessage::where('del_time',0)
-                ->where('title', 'LIKE', '%'.$data['product_item_code_title'].'%')
-                ->select('item_code')
-                ->get()->toArray();
-            $model->whereIn('item_code', array_column($item_code,'item_code'));
         }
-        if(isset($data['state'])) $model->where('state', $data['state']);
-        if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
-        if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
+
         if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
-        if(! empty($data['category'])){
-            $id = $this->getProductCateGory($data['category']);
-            $model->whereIn('product_category_id', $id);
-        }
-        if(! empty($data['product_category'])) {
-            $product_category = ProductCategory::where('del_time',0)
-                ->where('title', 'LIKE', '%'.$data['product_category'].'%')
-                ->select('id')
-                ->get()->toArray();
-            $model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
-        }
-        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        if(! empty($data['item_code'])) $model->where('item_code', 'LIKE', '%'.$data['item_code'].'%');
-        if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
+        if(! empty($data['category'])) $model->where('code', 'LIKE', '%'.$data['category'].'%');
         if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
             $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
             $model->where('crt_time','>=',$return[0]);
             $model->where('crt_time','<=',$return[1]);
         }
-        if(! empty($data['product_id'])) $model->whereIn('id',$data['product_id']);
 
         return $model;
     }
@@ -677,108 +329,14 @@ class ProductService extends Service
      * @param $user
      * @return array
      */
-    public function productListIndex($data,$user){
-        $model = $this->productCommon($data, $user);
-        $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list,$user,$data);
-
-        return [true, $list];
-    }
-
     public function productList($data,$user){
-        $field = Product::$field;
-        $model = Product::ProductClear($user,$data);
-        $model = $model->where('del_time',0)
-            ->select($field)
-            ->where('is_use', Product::is_use_one)
-            ->orderby('product_attribute', 'desc')
-            ->orderby('id', 'desc');
-
-        if(! empty($data['title_t'])) {
-            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
-            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
-            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->where(function ($query) use ($cleanTitle, $data) {
-                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
-                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
-            });
-        }
-        if(! empty($data['title'])){
-            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
-            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
-            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
-//            $model->where('title', 'LIKE', '%'.$data['title'].'%');
-        }
-        if(isset($data['state'])) $model->where('state', $data['state']);
-        if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
-        if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
-        if(! empty($data['category'])){
-            $id = $this->getProductCateGory($data['category']);
-            $model->whereIn('product_category_id', $id);
-        }
-        if(! empty($data['product_category'])) {
-            $product_category = ProductCategory::where('del_time',0)
-                ->where('title', 'LIKE', '%'.$data['product_category'].'%')
-                ->select('id')
-                ->get()->toArray();
-            $model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
-        }
-        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
-        if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
-        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
-            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
-            $model->where('crt_time','>=',$return[0]);
-            $model->where('crt_time','<=',$return[1]);
-        }
-        if(! empty($data['product_id'])) $model->whereIn('id',$data['product_id']);
-        if(isset($data['is_head'])){
-            if($data['is_head'] == 1){
-                $head = $user['head']['id'] ?? 0;
-                $model->where('top_depart_id', $head);
-            }else{
-                $top_depart_id = $user['depart_top'][0] ?? [];
-                $top_depart_id = $top_depart_id['depart_id'] ?? 0;
-                $model->where('top_depart_id', $top_depart_id);
-            }
-        }
-
+        $model = $this->productCommon($data, $user);
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list,$user,$data);
 
         return [true, $list];
     }
 
-    public function productList2($data,$user){
-        $model = ProductCategory::ProductClear($user,$data);
-        $model = $model->where('del_time',0)
-            ->select('title','id','parent_id')
-            ->orderby('id','desc');
-        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
-
-        $list = $model->get()->toArray();
-        if(! empty($list)) {
-            $productList = Product::where('del_time',0)
-                ->whereIn('product_category_id',array_column($list,'id'))
-                ->select('id','product_category_id','title','code')
-                ->get()->toArray();
-            $productMap = [];
-            foreach ($productList as $value){
-                $productMap[$value['product_category_id']][] = $value;
-            }
-            foreach ($list as $key => $value){
-                if(isset($productMap[$value['id']])) $list[$key]['product'] = $productMap[$value['id']];
-            }
-
-            $list = $this->makeTree(0,$list);
-            $list = $this->set_sort_circle($list);
-        }
-
-        return [200, $list];
-    }
-
     /**
      * 产品参数规则
      * @param $data
@@ -786,46 +344,34 @@ class ProductService extends Service
      * @return array
      */
     public function productRule(&$data, $user, $is_add = true){
-        if(empty($data['title'])) return [false,'产品名称不能为空'];
-        if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
-        if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
-        $data['product_category'] = json_encode($data['product_category']);
         if(empty($data['code'])) return [false,'产品编码不能为空'];
+        if(empty($data['title'])) return [false,'产品名称不能为空'];
         if(! isset($data['cost'])) return [false, '请填写成本'];
-        if(! isset($data['retail_price'])) return [false, '请填写零售价'];
+        if(! isset($data['business_cost'])) return [false, '请填写业务成本'];
         $res = $this->checkNumber($data['cost']);
         if(! $res) return [false,'成本请输入不超过两位小数并且大于等于0的数值'];
-        $res = $this->checkNumber($data['retail_price']);
-        if(! $res) return [false,'零售价格请输入不超过两位小数并且大于等于0的数值'];
-        if(! empty($data['product_price'])){
-            $map = BasicType::whereIn('id',array_column($data['product_price'],'basic_type_id'))
-                ->pluck('title','id')
-                ->toArray();
-            foreach ($data['product_price'] as $value){
-                if(! empty($value['price'])) {
-                    $tmp = $map[$value['basic_type_id']] ?? '';
-                    $res = $this->checkNumber($value['price']);
-                    if(! $res) return [false, $tmp . '请输入不超过两位小数并且大于0的数值'];
-                }
-            }
+        $res = $this->checkNumber($data['business_cost']);
+        if(! $res) return [false,'业务成本请输入不超过两位小数并且大于等于0的数值'];
+        if(! empty($data['write_off_price'])){
+            $res = $this->checkNumber($data['write_off_price']);
+            if(! $res) return [false,'核销单价请输入不超过两位小数并且大于等于0的数值'];
         }
-
-        //所属部门 以及 顶级部门
-        if(empty($data['depart_id'])) {
-            $data['depart_id'] = $this->getDepart($user);
-            $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
+        if(! empty($data['major_client_settlement_price'])){
+            $res = $this->checkNumber($data['major_client_settlement_price']);
+            if(! $res) return [false,'大客户结算单价请输入不超过两位小数并且大于等于0的数值'];
+        }
+        if(! empty($data['return_change_price'])){
+            $res = $this->checkNumber($data['return_change_price']);
+            if(! $res) return [false,'退货损耗单价请输入不超过两位小数并且大于等于0的数值'];
         }
 
-        //总社id
-        $top_depart_id = $user['head'] ?? [];
-        $top_depart_id = $top_depart_id['id'] ?? 0;
         if($is_add){
-            $bool = Product::whereRaw("(binary code = '{$data['code']}') AND (top_depart_id = {$data['top_depart_id']} OR top_depart_id = {$top_depart_id})")
+            $bool = Product::where('code', $data['code'])
                 ->where('del_time',0)
                 ->exists();
         }else{
             if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = Product::whereRaw("(binary code = '{$data['code']}') AND (top_depart_id = {$data['top_depart_id']} OR top_depart_id = {$top_depart_id})")
+            $bool = Product::where('code', $data['code'])
                 ->where('id','<>',$data['id'])
                 ->where('del_time',0)
                 ->exists();
@@ -843,923 +389,11 @@ class ProductService extends Service
     public function fillData($data, $user, $search){
         if(empty($data['data'])) return $data;
 
-        $type = $search['type'] ?? 0;
-        $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
-            ->pluck('emp_name','id')
-            ->toArray();
-        $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
-            ->select('title','id','is_edit_unit_price')
-            ->get()
-            ->toArray();
-        $category = array_column($category,null,'id');
-        $array = array_unique(array_merge_recursive(array_column($data['data'],'unit'),array_column($data['data'],'unit_2')));
-        $basic_map = BasicType::whereIn('id',$array)
-            ->orWhere('type',BasicType::type_22)
-            ->pluck('title','id')
-            ->toArray();
-
-        $depart_map = Depart::whereIn('id',array_unique(array_column($data['data'],'top_depart_id')))->pluck('title','id')->toArray();
-
-        //产品使用价格
-        $product_id = array_column($data['data'],'id');
-        $detail_map = $this->getProductPrice($product_id, $type);
-
-        //获取产品图片
-        $img = $this->getProductImg($product_id);
-
-        //当前门店
-        $top_depart = $user['depart_top'][0] ?? [];
-        //特殊功能按钮
-        $special_button = $user['special_button'] ?? [];
-
-        //库存
-        $stock_map = [];
-        if(! empty($search['storehouse_id'])){
-            $stock = ProductInventoryService::getRealStock($product_id, $search['storehouse_id']);
-            foreach ($stock as $value){
-                $stock_map[$value['product_id']] = $value;
-            }unset($stock);
-        }
-
-        //分社价格
-        $product_fs = [];
-        if(! empty($search['fs_price_get'])) $product_fs = $this->getProductPriceDetail(['id' => $product_id], $user);
-
-        //商品编码关联信息
-        $item_code_map = ProductItemCodeMessage::where('del_time',0)
-            ->whereIn('item_code', array_column($data['data'],'item_code'))
-            ->pluck('title','item_code')
-            ->toArray();
         foreach ($data['data'] as $key => $value){
-            $tmp = [];
-            if(isset($detail_map[$value['id']])){
-                $d = $detail_map[$value['id']];
-                foreach ($d as $v){
-                    $is_show = 0;
-                    if(in_array(RoleMenuButton::special_one,$special_button)) $is_show = 1;
-                    $is_use = 0;
-                    if($top_depart['basic_type_id'] == $v['basic_type_id']) $is_use = 1;
-                    $tmp[] = [
-                        'basic_type_id' => $v['basic_type_id'],
-                        'basic_type_title' => $basic_map[$v['basic_type_id']] ?? '',
-                        'price' => $v['price'],
-                        'is_show' => $is_show,
-                        'is_use' => $is_use
-                    ];
-                }
-            }
-            $data['data'][$key]['product_price'] = $tmp;
-            $price_tmp = $product_fs[$value['id']] ?? [];
-            foreach ($price_tmp as $t_k => $t){
-                $data['data'][$key][$t_k] = $t;
-            }
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
-            $data['data'][$key]['is_use_title'] = Product::$is_use[$value['is_use']] ?? "";
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
-            $category_tmp = $category[$value['product_category_id']] ?? [];
-            $data['data'][$key]['product_category_name'] = $category_tmp['title'] ?? '';
-            $data['data'][$key]['is_edit_unit_price'] = $category_tmp['is_edit_unit_price'] ?? 0;
-            $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
-            $data['data'][$key]['unit_title'] = $basic_map[$value['unit']] ?? '';
-            $data['data'][$key]['unit_2_title'] = $basic_map[$value['unit_2']] ?? '';
-            $str = "";
-            if(! empty(floatval($value['main_number']))) $str = $value['main_number'] . " : " . $value['second_number'];
-            $data['data'][$key]['change_number'] = $str;
-            $data['data'][$key]['belong_to'] = $depart_map[$value['top_depart_id']] ?? '';
-            $data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
-            $data['data'][$key]['color'] = Product::$product_attribute_color[$value['product_attribute']] ?? [];
-            $data['data'][$key]['img'] = $img[$value['id']] ?? "";
-            //库存
-            $data['data'][$key]['stock'] = $stock_map[$value['id']] ?? (object)[];
-            //成本
-            $data['data'][$key]['cost_show'] = $value['cost'];
-            $data['data'][$key]['product_item_code_title'] = $item_code_map[$value['item_code']] ?? "";
         }
 
         return $data;
     }
-
-    public function getProductCateGory($category){
-        $product_category = ProductCategory::where('del_time',0)
-            ->select('id','parent_id')
-            ->get()->toArray();
-        $result = array_merge($this->getAllDescendants($product_category,$category),[$category]);
-        return $result;
-    }
-
-    public function getProductImg($product_id = []){
-        if(empty($product_id)) return [];
-
-        $img = [];
-        $customer_info = ProductInfo::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->where('type',ProductInfo::type_one)
-            ->select('product_id','file','type','name')
-            ->get()->toArray();
-        $fileUploadService = new FileUploadService();
-        foreach ($customer_info as $value){
-            if(isset($img[$value['product_id']])) continue;
-            $url = "";
-            if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
-            $img[$value['product_id']] = $url;
-        }
-
-        return $img;
-    }
-
-    public function getProductImgGroup($product_id = [],$search){
-        if(empty($product_id)) return [];
-
-        $img = [];
-        $customer_info = ProductInfo::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->where('type',ProductInfo::type_one)
-            ->select('product_id','file','type','name')
-            ->get()->toArray();
-        $fileUploadService = new FileUploadService();
-        foreach ($customer_info as $value){
-            if(empty($search['from_wechat_program'])){
-                if(isset($img[$value['product_id']])) continue;
-                $url = "";
-                if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
-                $img[$value['product_id']][] = $url;
-            }else{
-                $url = "";
-                if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
-                $img[$value['product_id']][] = $url;
-            }
-        }
-
-        return $img;
-    }
-
-    public function batchUploadImg($data){
-        if(empty($data['product_id'])) return [false, '请选择产品'];
-
-        $time = time();
-        try {
-            DB::beginTransaction();
-
-            $old = ProductInfo::where('del_time',0)
-                ->where('type',ProductInfo::type_one)
-                ->whereIn('product_id',$data['product_id'])
-                ->select('file')
-                ->get()->toArray();
-            $old = array_column($old,'file');
-            ProductInfo::where('del_time',0)
-                ->where('type',ProductInfo::type_one)
-                ->whereIn('product_id',$data['product_id'])
-                ->update(['del_time' => $time]);
-
-            $new['origin'] = $data['img_url'] ?? "";
-            $new['img_list'] = [];
-            $img = str_replace(FileUploadService::string . FileUploadService::string2, '', $data['img_url']);
-            $img = explode('.', $img);
-
-            $insert = [];
-            if(! empty($data['img_url'])){
-                foreach ($data['product_id'] as $key => $value){
-                    $copy = $img[0] . 'C' . $key . '.' . $img[1];
-                    $copy = FileUploadService::string . FileUploadService::string2 . $copy;
-                    $insert[] = [
-                        'product_id' => $value,
-                        'file' => $copy,
-                        'type' => ProductInfo::type_one,
-                        'name' => $data['img_name'] ?? "",
-                        'crt_time' => $time,
-                    ];
-                    $new['img_list'][] = $copy;
-                }
-                if(! empty($insert)) ProductInfo::insert($insert);
-            }
-
-            DB::commit();
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ['is_batch' => true, 'file' => ['new' => $new, 'old' => $old]]];
-    }
-
-    public function batchBuildFee($data){
-        if(empty($data['product_id'])) return [false, '请选择产品'];
-        if(! isset($data['build_fee'])) return [false, '请填写安装费'];
-        $res = $this->checkNumber($data['build_fee']);
-        if(! $res) return [false,'安装费请输入不超过两位小数并且大于等于0的数值'];
-
-        try {
-            DB::beginTransaction();
-
-            Product::where('del_time',0)
-                ->whereIn('id', $data['product_id'])
-                ->update([
-                    'build_fee' => $data['build_fee']
-                ]);
-
-            DB::commit();
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function batchUnitInfo($data){
-        if(empty($data['product_id'])) return [false, '请选择产品'];
-        if(! isset($data['main_number'])) return [false, '请填写主单位转换数字'];
-        $res = $this->checkNumber($data['main_number'],1);
-        if(! $res) return [false,'主单位转换数字请输入不超过一位小数并且大于等于0的数值'];
-
-        $unit_2 = $data['unit_2'] ?? 0;
-        if(! isset($data['second_number'])) return [false, '请填写副单位转换数字'];
-        $res = $this->checkNumber($data['second_number'],1);
-        if(! $res) return [false,'副单位转换数字请输入不超过一位小数并且大于等于0的数值'];
-
-        try {
-            DB::beginTransaction();
-
-            Product::where('del_time',0)
-                ->whereIn('id', $data['product_id'])
-                ->update([
-                    'unit_2' => $unit_2,
-                    'main_number' => $data['main_number'],
-                    'second_number' => $data['second_number'],
-                ]);
-
-            DB::commit();
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    //获取产品字典
-    public function getProductDetail($product_id = []){
-        if(empty($product_id)) return [];
-        $pro = Product::whereIn('id', $product_id)->get()->toArray();
-        $category = ProductCategory::whereIn('id',array_unique(array_column($pro,'product_category_id')))
-            ->pluck('is_edit_unit_price','id')
-            ->toArray();
-        foreach ($pro as $key => $value){
-            $pro[$key]['is_edit_unit_price'] = $category[$value['product_category_id']] ?? 0;
-        }
-        return array_column($pro,null,'id');
-    }
-
-    //获取产品使用价格
-    public function getProductPrice($product_id = [], $type = 1, $basic_type_id_for = 0){
-        if(! is_array($product_id)) $product_id = [$product_id];
-        //type 1 采购    2 合同 和 活动包
-
-        $detail_map = [];
-        $time = time();
-        if($type == 1) {
-            //供应商活动价格
-            $activity = ProductActivityPrice::from('product_activity_price as a')
-                ->join('product_activity as b','b.id','a.product_activity_id')
-                ->where('a.del_time',0)
-                ->whereIn('a.product_id',$product_id)
-                ->where('a.start_time','<=',$time)
-                ->where('a.end_time','>=',$time)
-                ->where('b.type',ProductActivity::type_two)
-                ->when(! empty($basic_type_id_for), function ($query) use ($basic_type_id_for) {
-                    return $query->where('a.basic_type_id',$basic_type_id_for);
-                })
-                ->select('a.product_id','a.basic_type_id','a.price')
-                ->get()->toArray();
-            foreach ($activity as $value){
-                $detail_map[$value['product_id']][] = $value;
-            }
-            //分社价 没有供应商活动价格使用分社价格
-            $detail = ProductPriceDetail::where('del_time',0)
-                ->whereIn('product_id',$product_id)
-                ->when(! empty($basic_type_id_for), function ($query) use ($basic_type_id_for) {
-                    return $query->where('basic_type_id',$basic_type_id_for);
-                })
-                ->select('product_id','basic_type_id','price')
-                ->get()->toArray();
-            foreach ($detail as $value){
-                if(! isset($detail_map[$value['product_id']][$value['basic_type_id']])){
-                    $detail_map[$value['product_id']][$value['basic_type_id']] = $value;
-                }
-            }
-        }else{
-            //零售活动价格
-            $activity = ProductActivityPrice::from('product_activity_price as a')
-                ->join('product_activity as b','b.id','a.product_activity_id')
-                ->where('a.del_time',0)
-                ->whereIn('a.product_id',$product_id)
-                ->where('a.start_time','<=',$time)
-                ->where('a.end_time','>=',$time)
-                ->where('b.type',ProductActivity::type_one)
-                ->select('a.product_id','a.basic_type_id','a.price')
-                ->get()->toArray();
-            foreach ($activity as $value){
-                $detail_map[$value['product_id']][] = $value;
-            }
-        }
-
-        return $detail_map;
-    }
-
-    public function getProductPriceTmp($product_id = []){
-        //type 0 采购  1 合同
-
-        //分社价
-        $detail = ProductPriceDetail::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->select('product_id','basic_type_id','price')
-            ->get()->toArray();
-        $detail_map = [];
-        foreach ($detail as $value){
-            $detail_map[$value['product_id']][] = $value;
-        }
-        $return = $detail_map;
-
-        //活动价格
-        $time = time();
-        $activity = ProductActivityPrice::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->where('start_time','<=',$time)
-            ->where('end_time','>=',$time)
-            ->select('product_id','basic_type_id','price')
-            ->get()->toArray();
-        if(! empty($activity)){
-            foreach ($activity as $value){
-                if(! isset($detail_map[$value['product_id']])) {
-                    $return[$value['product_id']][] = $value;
-                }else{
-                    $basic_type = array_column($detail_map[$value['product_id']],'basic_type_id');
-                    if(! in_array($value['basic_type_id'], $basic_type)){
-                        $return[$value['product_id']][] = $value;
-                        continue;
-                    }
-                    foreach ($detail_map[$value['product_id']] as $key => $val){
-                        if($value['basic_type_id'] == $val['basic_type_id']) {
-                            //活动价格替换
-                            $return[$value['product_id']][$key]['price'] = $value['price'];
-                        }
-                    }
-                }
-            }
-        }unset($detail_map);
-
-        return $return;
-    }
-
-    //获取产品分社价格
-    public function getProductPriceDetail($data, $user){
-        $data['top_depart_id'] = $user['head']['id'] ?? 0;
-        $model = BasicType::TopClear($user,$data);
-        $basic = $model->where('del_time',0)
-            ->where('type',22)
-            ->select('title','id','type')
-            ->orderby('id', 'asc')->get()->toArray();
-
-        $detail = ProductPriceDetail::where('del_time',0)
-            ->whereIn('product_id',$data['id'])
-            ->select('product_id','basic_type_id','price')
-            ->get()->toArray();
-        $product_price = [];
-
-        //所有金额
-        foreach ($basic as $value){
-            $product_price[$value['id']] = "0";
-        }
-
-        $return = [];
-        foreach ($data['id'] as $value){
-            $return[$value] = $product_price;
-        }
-
-        //展示金额
-        foreach ($detail as $value){
-            if(isset($return[$value['product_id']][$value['basic_type_id']])) $return[$value['product_id']][$value['basic_type_id']] = $value['price'];
-        }
-
-        return $return;
-    }
-
-    public function productGroupByList($data,$user){
-        $head_top_depart_id = $user['head']['id'] ?? 0;
-        $now_top_depart_id = $this->getDepart($user);
-        $p = ProductCategory::Special_for_p;
-
-        $model = Product::ProductClear($user,$data);
-        $model = $model->where('del_time',0)
-            ->where('item_code','<>',"")
-            ->where('is_use', Product::is_use_one)
-            ->when($head_top_depart_id != $now_top_depart_id, function ($query) use($p){
-                return $query->where('product_category','NOT LIKE', '%'.$p.'%');
-            })
-            ->select('title','id','product_category_id','product_category','retail_price','product_attribute','item_code','unit','size','code','bar_code')
-            ->groupBy('item_code')
-            ->orderByDesc('product_attribute')
-            ->orderByDesc('item_code');
-
-//        if(isset($data['from_wechat_program'])){
-//            //先根据大类分类排序 然后再根据子类分类排序 然后再根据产品属性排序
-//            $model = $model->orderByRaw("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(product_category, ',', 1), '[', -1) AS UNSIGNED)")
-//                ->orderByRaw("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(product_category, ',', 2), ',', -1) AS UNSIGNED)")
-//                ->orderByDesc('product_attribute')
-//                ->orderByDesc('item_code');
-//        }else{
-//            $model = $model->orderByDesc('product_attribute')
-//                ->orderByDesc('item_code');
-//        }
-
-        if(! empty($data['title_t'])) {
-            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
-            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
-            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->where(function ($query) use ($cleanTitle, $data) {
-                $query->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
-                    ->orWhere('code', 'LIKE', '%' . $data['title_t'] . '%')
-                    ->orWhere('size', 'LIKE', '%' . $data['title_t'] . '%');
-            });
-        }
-        if(! empty($data['title'])){
-            // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
-            $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title']));
-            // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
-            $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%']);
-//            $model->where('title', 'LIKE', '%'.$data['title'].'%');
-        }
-        if(isset($data['state'])) $model->where('state', $data['state']);
-        if(isset($data['product_attribute'])) $model->where('product_attribute', $data['product_attribute']);
-        if(! empty($data['product_category_id'])) $model->where('product_category_id', $data['product_category_id']);
-        if(! empty($data['product_category_array_id'])) $model->whereIn('product_category_id', $data['product_category_array_id']);
-        if(! empty($data['category'])){
-            $id = $this->getProductCateGory($data['category']);
-            $model->whereIn('product_category_id', $id);
-        }
-        if(! empty($data['product_category'])) {
-            $product_category = ProductCategory::where('del_time',0)
-                ->where('title', 'LIKE', '%'.$data['product_category'].'%')
-                ->select('id')
-                ->get()->toArray();
-            $model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
-        }
-        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
-        if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
-        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
-            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
-            $model->where('crt_time','>=',$return[0]);
-            $model->where('crt_time','<=',$return[1]);
-        }
-        if(! empty($data['product_id'])) $model->whereIn('id',$data['product_id']);
-
-        $list = $this->limit($model,'',$data);
-        $list = $this->productGroupByListData($list,$user,$data);
-
-        return [true, $list];
-    }
-
-    public function productGroupByListData($data, $user, $search){
-        if(empty($data['data'])) return $data;
-
-        $type = $search['type'] ?? 1;
-        $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
-            ->select('title','id')
-            ->get()
-            ->toArray();
-        $category = array_column($category,null,'id');
-        $basic_map = BasicType::whereIn('id',array_unique(array_column($data['data'], 'unit')))
-            ->OrWhere('type',BasicType::type_22)
-            ->pluck('title','id')
-            ->toArray();
-
-        //产品使用价格
-        $product_id = array_column($data['data'],'id');
-        $detail_map = $this->getProductPrice($product_id, $type);
-
-        //获取产品图片
-        $img = $this->getProductImgGroup($product_id,$search);
-
-        //当前门店
-        $top_depart = $user['depart_top'][0] ?? [];
-
-        //库存
-        $stock = ProductInventoryOfTop::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->pluck('number','product_id')
-            ->toArray();
-
-        //商品编码关联信息
-        $item_code_map = ProductItemCodeMessage::where('del_time',0)
-            ->whereIn('item_code', array_column($data['data'],'item_code'))
-            ->pluck('title','item_code')
-            ->toArray();
-        foreach ($data['data'] as $key => $value){
-            $arr = json_decode($value['product_category'], true);
-            $arr = array_flip($arr);
-            if (isset($arr[ProductCategory::Special_for_roll1]) || isset($arr[ProductCategory::Special_for_roll2])) {
-                $data['data'][$key]['is_roll'] = true;
-                $is_roll = true;
-            }else{
-                $data['data'][$key]['is_roll'] = false;
-                $is_roll = false;
-            }
-
-            $tmp = $img[$value['id']] ?? [];
-            $data['data'][$key]['img'] = $tmp[0] ?? "";
-            if(isset($tmp[0])) unset($tmp[0]);
-            $data['data'][$key]['img_detail'] = array_values($tmp);
-            $tmp = $this->fillProductPrice($detail_map, $value, $top_depart,$basic_map);
-            $data['data'][$key]['product_price'] = $tmp;
-            $category_tmp = $category[$value['product_category_id']] ?? [];
-            $data['data'][$key]['product_category_name'] = $category_tmp['title'] ?? '';
-            $data['data'][$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
-            $data['data'][$key]['stock'] = $this->returnStock($stock, $value);
-            $data['data'][$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
-            $title = $value['title'];
-            if(! empty($item_code_map[$value['item_code']])) $title = $item_code_map[$value['item_code']];
-            $data['data'][$key]['title'] = $title;
-
-            //通用名称
-            $common_title = $item_code_map[$value['item_code']] ?? "";
-            //is_roll false 展示title  true product_category_name
-            if($is_roll){
-                $category_tmp = $category[$value['product_category_id']] ?? [];
-                $category_title = $category_tmp['title'] ?? '';
-                if(! empty($common_title)) $category_title = $common_title;
-                $data['data'][$key]['product_category_name'] = $category_title;
-            }else{
-                $title = $value['title'];
-                if(! empty($common_title)) $title = $common_title;
-                $data['data'][$key]['title'] = $title;
-            }
-        }
-
-        return $data;
-    }
-
-    public function productGroupByListDetail($data, $user){
-        if(empty($data['item_code'])) return [false, '商品编码不能为空'];
-        $type = $data['type'] ?? 1;
-
-        //获取相同itemCode的产品
-        $product = $this->getProductByItemCode([$data['item_code']], $user);
-
-        $category = ProductCategory::whereIn('id',array_unique(array_column($product,'product_category_id')))
-            ->pluck('title','id')
-            ->toArray();
-
-        $basic_map = BasicType::whereIn('id',array_unique(array_column($product, 'unit')))
-            ->OrWhere('type',BasicType::type_22)
-            ->pluck('title','id')
-            ->toArray();
-
-        //产品使用价格
-        $product_id = array_column($product,'id');
-        $detail_map = $this->getProductPrice($product_id, $type);
-
-        //获取产品图片
-        $img = $this->getProductImg($product_id);
-
-        //当前门店
-        $top_depart = $user['depart_top'][0] ?? [];
-
-        $stock = ProductInventoryOfTop::where('del_time',0)
-            ->whereIn('product_id',$product_id)
-            ->pluck('number','product_id')
-            ->toArray();
-        foreach ($product as $key => $value){
-            $tmp = $this->fillProductPrice($detail_map, $value, $top_depart,$basic_map);
-            $product[$key]['product_price'] = $tmp;
-            $product[$key]['img'] = $img[$value['id']] ?? "";
-            $product[$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
-            $product[$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
-            $product[$key]['stock'] = $this->returnStock($stock, $value);
-            $product[$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
-            $arr = json_decode($value['product_category'], true);
-            $arr = array_flip($arr);
-            if (isset($arr[ProductCategory::Special_for_roll1]) || isset($arr[ProductCategory::Special_for_roll2])) {
-                $product[$key]['is_roll'] = true;
-            }else{
-                $product[$key]['is_roll'] = false;
-            }
-        }
-
-        return [true, $product];
-    }
-
-    public function productUpdateProductBasicInfo($data){
-        $time = time();
-        list($status, $msg) = $this->productUpdateProductBasicInfoRule($data,$time);
-        if(! $status) return [false, $msg];
-
-        //产品id 主表更新信息 子表插入信息 子表是否参与更新
-        list($product_id,$update,$insert_detail,$update_detail_bool) = $msg;
-//        dd($product_id,$update,$insert_detail,$update_detail_bool);
-
-        try {
-            DB::beginTransaction();
-
-            if(! empty($update)){
-                foreach ($product_id as $p_id){
-                    Product::where('id',$p_id)
-                        ->update($update);
-                }
-            }
-
-            if($update_detail_bool){
-                ProductPriceDetail::where('del_time',0)
-                    ->whereIn('product_id',$product_id)
-                    ->update(['del_time' => $time]);
-
-                if(! empty($insert_detail)) ProductPriceDetail::insert($insert_detail);
-            }
-
-            DB::commit();
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function productUpdateProductBasicInfoRule($data,$time){
-        if(empty($data['product_id'])) return [false, '产品ID不能为空'];
-        $product = Product::where('del_time',0)
-            ->whereIn('id',$data['product_id'])
-            ->select('id')
-            ->get()->toArray();
-        if(empty($product)) return [false, '产品不存在或已被删除'];
-        $product = array_column($product,'id');
-
-        // 产品分类   单位   成本   各分社价   商品编码   产品属性
-        $update = $update_detail = [];
-        if(! empty($data['product_category_id'])){
-            $update['product_category_id'] = $data['product_category_id'];
-            if(empty($data['product_category'])) return [false,'产品分类树结构不能为空'];
-            $product_category = json_encode($data['product_category']);
-            $update['product_category'] = $product_category;
-        }
-        if(Arr::has($data,'unit')) $update['unit'] = $data['unit'] ?? 0;
-        if(Arr::has($data,'cost')){
-            $cost = $data['cost'] ?? 0;
-            $res = $this->checkNumber($cost);
-            if(! $res) return [false,'成本请输入不超过两位小数并且大于等于0的数值'];
-            $update['cost'] = $cost;
-        }
-        if(Arr::has($data,'item_code')) $update['item_code'] = $data['item_code'] ?? "";
-        if(Arr::has($data,'product_attribute')) $update['product_attribute'] = $data['product_attribute'] ?? 0;
-        if(! empty($data['product_price'])){
-            $map = BasicType::whereIn('id',array_column($data['product_price'],'basic_type_id'))
-                ->pluck('title','id')
-                ->toArray();
-            foreach ($data['product_price'] as $value){
-                $price = $value['price'] ?? 0;
-                $tmp = $map[$value['basic_type_id']] ?? '';
-                if(! $tmp) return [false, '分社价格错误'];
-                $res = $this->checkNumber($price);
-                if(! $res) return [false, $tmp . '请输入不超过两位小数并且大于0的数值'];
-                $update_detail[] = [
-                    'product_id' => 0,
-                    'basic_type_id' => $value['basic_type_id'],
-                    'price' => $price,
-                    'crt_time' => $time,
-                ];
-            }
-        }
-        if(empty($update) && empty($update_detail)) return [false, '暂无更新'];
-        $update_detail_bool = false;
-
-        //详情信息
-        $insert_detail = [];
-        if(! empty($update_detail)){
-            $update_detail_bool = true;
-            foreach ($product as $p_id){
-                foreach ($update_detail as $detail){
-                    $detail['product_id'] = $p_id;
-                    $insert_detail[] = $detail;
-                }
-            }
-        }
-
-        return [true, [$product, $update, $insert_detail, $update_detail_bool]];
-    }
-
-    public function productUpdateByItemCode($data){
-        if(empty($data['item_code'])) return [false, "商品编码不能为空"];
-
-        $title = $data['title'] ?? '';
-        try {
-            DB::beginTransaction();
-
-            $time = time();
-
-            ProductItemCodeMessage::where('del_time',0)
-                ->where('item_code', $data['item_code'])
-                ->update(['del_time' => $time]);
-
-            ProductItemCodeMessage::insert([
-                'item_code' => $data['item_code'],
-                'title' => $title,
-            ]);
-
-            DB::commit();
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function getProductByItemCode($item_code,$user){
-        if(empty($item_code)) return [];
-
-        $model = Product::ProductClear($user,[]);
-        $product = $model->where('del_time',0)
-            ->whereIn('item_code', $item_code)
-            ->where('is_use', Product::is_use_one)
-            ->select('title','id','product_category_id','retail_price','product_attribute','item_code','size','unit','code','bar_code','product_category')
-            ->orderby('product_attribute', 'desc')
-            ->get()->toArray();
-
-        return $product;
-    }
-
-    public function fillProductPrice($detail_map, $value, $top_depart,$basic_map = []){
-        $tmp = [];
-        if(isset($detail_map[$value['id']])){
-            $d = $detail_map[$value['id']];
-            foreach ($d as $v){
-                if($top_depart['basic_type_id'] != $v['basic_type_id']) continue;
-                $tmp = [
-                    'basic_type_id' => $v['basic_type_id'],
-                    'basic_type_title' => $basic_map[$v['basic_type_id']] ?? '',
-                    'price' => $v['price']
-                ];
-            }
-        }
-        if(empty($tmp)) $tmp = (object)$tmp;
-
-        return $tmp;
-    }
-
-    public function updateTopStock($data, $user){
-        $limit_key = "updateTopStockFromYy";
-//        list($status, $msg) = $this->limitingSendRequestBackg($limit_key);
-//        if(! $status) return [false, '正在获取T9杭州总仓库存货库存,请勿重复操作'];
-
-        //总店
-        $head = $user['head']['id'] ?? 0;
-        $storehouse_id = Storehouse::where('top_depart_id', $head)->where('del_time',0)->value('id') ?? 0;
-
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
-        $time = time();
-        DB::table('product')
-            ->where('del_time', 0)
-            ->where('top_depart_id', $head)
-            ->select('id','code')
-            ->orderBy('id')
-            ->chunk(200, function ($data) use($head,$storehouse_id,$time,$service){
-                $data = Collect($data)->map(function ($object) {
-                    return (array)$object;
-                })->toArray();
-
-                $map = array_column($data,'id','code');
-                $id = array_unique(array_column($data,'id'));
-                $code = array_unique(array_column($data,'code'));
-                list($status, $msg) = $service->getStock($code, "001");
-                if(! $status) return [false, $msg];
-//                $post = [
-//                    'urlFromT9' => 'getStock',
-//                    'code' => $code,
-//                    'warehouse' => '001',
-//                ];
-//                $post = json_encode($post);
-//                $header = ['Content-Type:application/json'];
-//                list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
-//                if($msg['code'] != 200) return [false, $msg['msg']];
-//                $msg = $msg['data'] ?? [];
-
-                $insert = [];
-                foreach ($msg as $value){
-                    $insert[] = [
-                        'product_id' => $map[$value['product_no']] ?? 0,
-                        'storehouse_id' => $storehouse_id,
-                        'top_depart_id' => $head,
-                        'number' => $value['number'],
-                        'crt_time' => $time,
-                    ];
-                }
-
-                ProductInventoryOfTop::where('del_time',0)
-                    ->whereIn('product_id',$id)
-                    ->update(['del_time' => $time]);
-
-                if(! empty($insert)) ProductInventoryOfTop::insert($insert);
-            });
-
-        return [true, ''];
-
-        try{
-            $job = ProcessDataJob::dispatch(['head' => $head, 'storehouse_id' => $storehouse_id, 'type' => U8Job::three,'limit_key' => $limit_key])->onQueue(U8Job::job3);
-            if(! $job) {
-                $this->dellimitingSendRequestBackg($limit_key);
-                return [false,'T9杭州总仓库存货库存任务没有进入队列!'];
-            }
-        }catch (\Throwable $e){
-            $this->dellimitingSendRequestBackg($limit_key);
-            return [false,$e->getMessage()];
-        }
-
-        return [true, 'T9杭州总仓库存货库存任务正在后台执行,请等待'];
-    }
-
-    private function returnStock($stock, $value){
-        if(isset($stock[$value['id']])){
-            $number = $stock[$value['id']];
-            if($number <= 0){
-                $stock = "售罄";
-            } elseif($number <= 15){
-                $stock = " 库存紧张";
-            }else{
-                $stock = " 库存充足";
-            }
-        }else{
-            $stock = "联系客服";
-        }
-
-        return $stock;
-    }
-
-    public function writeStock($data){
-        try {
-            $head = $data['head'];
-            $storehouse_id = $data['storehouse_id'];
-            $limit_key = $data['limit_key'];
-
-            DB::enableQueryLog();
-
-            $service = new U8ServerService(true);
-            if(! empty($service->error)) return [false, $service->error];
-
-            $time = time();
-            DB::table('product')
-                ->where('del_time', 0)
-                ->where('top_depart_id', $head)
-                ->select('id','code')
-                ->orderBy('id')
-                ->chunk(200, function ($data) use($head,$storehouse_id,$time,$service){
-                    $data = Collect($data)->map(function ($object) {
-                        return (array)$object;
-                    })->toArray();
-
-                    $map = array_column($data,'id','code');
-                    $id = array_unique(array_column($data,'id'));
-                    $code = array_unique(array_column($data,'code'));
-                    list($status, $msg) = $service->getStock($code, "001");
-                    if(! $status) return [false, $msg];
-//                    $post = [
-//                        'urlFromT9' => 'getStock',
-//                        'code' => $code,
-//                        'warehouse' => '001',
-//                    ];
-//                    $post = json_encode($post);
-//                    $header = ['Content-Type:application/json'];
-//                    list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/updateTopStock",$post, $header);
-//                    if($msg['code'] != 200) return [false, $msg['msg']];
-//                    $msg = $msg['data'] ?? [];
-
-                    $insert = [];
-                    foreach ($msg as $value){
-                        $insert[] = [
-                            'product_id' => $map[$value['product_no']] ?? 0,
-                            'storehouse_id' => $storehouse_id,
-                            'top_depart_id' => $head,
-                            'number' => $value['number'],
-                            'crt_time' => $time,
-                        ];
-                    }
-
-                    ProductInventoryOfTop::where('del_time',0)
-                        ->whereIn('product_id',$id)
-                        ->update(['del_time' => $time]);
-
-                    if(! empty($insert)) ProductInventoryOfTop::insert($insert);
-                });
-
-            DB::commit();
-            $this->dellimitingSendRequestBackg($limit_key);
-        }catch (\Throwable $exception){
-            DB::rollBack();
-            $this->dellimitingSendRequestBackg($limit_key);
-            return [false, $exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
 }

+ 10 - 0
config/excel/productTable.php

@@ -4,6 +4,7 @@ return [
         'key' =>'code',
         'value' => '存货编码',
         'required' => true,
+        'unique' => true,
     ],
     [
         'key' =>'title',
@@ -14,45 +15,54 @@ return [
         'key' =>'size',
         'value' => '规格型号',
         'required' => false,
+        'default' => "",
     ],
     [
         'key' =>'category',
         'value' => '所属类别',
         'required' => false,
+        'default' => "",
     ],
     [
         'key' =>'unit',
         'value' => '计量单位',
         'required' => false,
+        'default' => "",
     ],
     [
         'key' =>'cost',
         'value' => '成本单价',
         'required' => false,
+        'default' => 0,
     ],
     [
         'key' =>'business_cost',
         'value' => '业务成本单价',
         'required' => false,
+        'default' => 0,
     ],
     [
         'key' =>'major_client_settlement_price',
         'value' => '大客户结算单价',
         'required' => false,
+        'default' => 0,
     ],
     [
         'key' =>'write_off_price',
         'value' => '核销单价',
         'required' => false,
+        'default' => 0,
     ],
     [
         'key' => 'return_change_price',
         'value' => '退货损耗单价',
         'required' => false,
+        'default' => 0,
     ],
     [
         'key' => 'mark',
         'value' => '备注',
         'required' => false,
+        'default' => "",
     ],
 ];

+ 3 - 3
routes/api.php

@@ -94,9 +94,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //产品名称
     $route->any('productList', 'Api\ProductController@productList');//选择列表页
-    $route->any('productEdit', 'Api\ProductController@productEdit')->middleware('OssFileDeal');
-    $route->any('productAdd', 'Api\ProductController@productAdd')->middleware('OssFileDeal');
-    $route->any('productDel', 'Api\ProductController@productDel')->middleware('OssFileDeal');
+    $route->any('productEdit', 'Api\ProductController@productEdit');
+    $route->any('productAdd', 'Api\ProductController@productAdd');
+    $route->any('productDel', 'Api\ProductController@productDel');
     $route->any('productDetail', 'Api\ProductController@productDetail');
 
     //获取默认表头