Explorar o código

Merge remote-tracking branch 'origin/master'

gogs hai 1 ano
pai
achega
f96acfe4da

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

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\ImportService;
+use Illuminate\Http\Request;
+
+class ImportController extends BaseController
+{
+    public function import(Request $request)
+    {
+        $service = new ImportService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->import($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 13 - 0
app/Http/Controllers/Api/WxController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers\Api;
 
+use App\Service\PurchaseOrderService;
 use App\Service\SalesOrderService;
 use App\Service\Wx\WxEmployeeService;
 use Illuminate\Http\Request;
@@ -55,4 +56,16 @@ class WxController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function purchaseOrderList(Request $request){
+        $service = new PurchaseOrderService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->getList($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 43 - 30
app/Http/Middleware/CheckWx.php

@@ -25,36 +25,49 @@ class CheckWx
         $openid = $data['openid'];
         //校验openid是否绑定
         $employee = new WxEmployee();
-        $employee_id = $employee->where('openid',$openid)->value('mobile');
-        if ($employee_id <= 0) return response()->json(['code'=> 202,'msg'=>'用户手机号信息不存在!','data'=>null]);
-
-        //校验用户
-//        $service = new WxEmployeeService();
-//        $checkResult = $service->checkWxUser($employee_id);
-//        list($state, $data) = $checkResult;
-//        if(! $state) return response()->json(['code'=> 202,'msg'=>$data,'data'=>null]);
-
-        //人员角色
-//        $data['role'] = EmployeeService::getPersonRole($employee_id);
-//        $return = EmployeeService::getLoginDepart($employee_id);
-//        //所属部门
-//        $data['rule_depart'] = $return[0] ?? [];
-//        //顶级公司
-//        $data['depart_top'] = $return[1] ?? [];
-//        //部门对应的顶级公司
-//        $data['depart_map'] = $return[2] ?? [];
-//        //权限范围内的部门以及公司
-//        $data['depart_range'] = $return[3] ?? [];
-//        //是否有所有的部门权限
-//        $data['is_all_depart'] = $return[4] ?? 0;
-//        //总公司
-//        $data['head'] = $return[5] ?? [];
-//        //是否是总公司下的人
-//        $data['is_behind_main'] = $return[6] ?? 0;
-//        //是否库存校验
-//        $data['is_check_stock'] = true;
-
-        $request->userData = new Employee();
+        $employee = $employee->where('openid',$openid)->first();
+        if (empty($employee)) return response()->json(['code'=> 202,'msg'=>'用户信息不存在!','data'=>null]);
+        $employee = $employee->toArray();
+        if (empty($employee['mobile'])) return response()->json(['code'=> 202,'msg'=>'用户手机信息不存在!','data'=>null]);
+
+        //当前请求接口
+        $uri = $request->path();
+        //不需要校验是否绑定账号的接口
+        $url = config('nocheck');
+
+        if(in_array($uri,$url)){
+            $request->userData = new Employee();
+        }else{
+            $employee_id = $employee['employee_id'];
+            if(empty($employee_id)) return response()->json(['code'=> 202,'msg'=>'用户未绑定账号!','data'=>null]);
+            //校验用户
+            $service = new WxEmployeeService();
+            $checkResult = $service->checkWxUser($employee_id);
+            list($state, $data) = $checkResult;
+            if(! $state) return response()->json(['code'=> 202,'msg'=>$data,'data'=>null]);
+
+            //人员角色
+            $data['role'] = EmployeeService::getPersonRole($employee_id);
+            $return = EmployeeService::getLoginDepart($employee_id);
+            //所属部门
+            $data['rule_depart'] = $return[0] ?? [];
+            //顶级公司
+            $data['depart_top'] = $return[1] ?? [];
+            //部门对应的顶级公司
+            $data['depart_map'] = $return[2] ?? [];
+            //权限范围内的部门以及公司
+            $data['depart_range'] = $return[3] ?? [];
+            //是否有所有的部门权限
+            $data['is_all_depart'] = $return[4] ?? 0;
+            //总公司
+            $data['head'] = $return[5] ?? [];
+            //是否是总公司下的人
+            $data['is_behind_main'] = $return[6] ?? 0;
+            //是否库存校验
+            $data['is_check_stock'] = true;
+
+            $request->userData = $data;
+        }
 
         return $next($request);
     }

+ 331 - 0
app/Import/Import.php

@@ -0,0 +1,331 @@
+<?php
+
+
+namespace  App\Import;
+
+use App\Service\ImportService;
+use Illuminate\Support\Facades\DB;
+use Maatwebsite\Excel\Concerns\ToArray;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use Maatwebsite\Excel\Facades\Excel;
+
+
+class Import implements WithMultipleSheets,ToArray {
+    private $msg = '';
+    public $crt_id = 0;
+    public $config = [];
+    public $mergedCells = [];
+    public $data = [];
+
+    public function sheets(): array
+    {
+        return [
+            0 => $this, // 指定要导入的 sheet 索引,这里假设是第一个 sheet
+        ];
+    }
+
+    public function array (array $array){
+        $this->handleData($array);
+    }
+
+    public function setConfig($config,$mergedCells,$data){
+        $this->config = $config;
+        $this->mergedCells = $mergedCells;
+        $this->data = $data;
+    }
+
+    public function getMsg(){
+        return $this->msg;
+    }
+
+    public function setMsg($msg){
+        $this->msg = $msg;
+    }
+
+    public function handleData (array $array) {
+        //表头处理
+        list($status,$msg) = $this->clearHead($array);
+        if(! $status) {
+            $this->setMsg($msg);
+            return ;
+        }
+
+        //表头
+        $table_head = $msg;
+
+        // 去除表头
+        unset($array[0]);
+        if(empty($array)) {
+            $this->setMsg('导入数据不能为空!');
+            return ;
+        }
+
+        //数据处理
+        list($status,$msg) = $this->checkRule($table_head,$array);
+        if(! $status) {
+            $this->setMsg($msg);
+            return ;
+        }
+
+        //写入数据
+        $time = time();
+        list($status,$msg) = $this->insertAllData($msg, $time);
+        if(! $status) {
+            $this->setMsg($msg);
+            return ;
+        }
+
+        //(特殊 需要额外写入的数据) 做对写入数据的更新
+        if(! empty($this->config['other_field_func'])){
+            $func = $this->config['other_field_func'] ?? "";
+            if(empty($func)) return;
+            (new ImportService)->$func($time);
+        }
+    }
+
+    public function clearHead($array){
+        $table_head = array_filter($array[0]);
+        if(empty($table_head)) return [false, '表头不能为空!'];
+
+        foreach ($table_head as $key => $value){
+            $head_tmp = trim($value);
+            if(empty($head_tmp)) {
+                unset($table_head[$key]);
+            }else{
+                $table_head[$key] = $head_tmp;
+            }
+        }
+        if(empty($table_head)) return [false, '表头不能为空!'];
+
+        return [true, $table_head];
+    }
+
+    public function insertAllData($data, $time){
+        $model_array = $this->config['table'];
+
+        //执行写入
+        try{
+            DB::beginTransaction();
+
+            foreach ($model_array as $model_name => $model_field){
+                if(! empty($model_field['need_param'])) {
+                    $model = "\App\Model\\" . $model_field['db_name'];
+                    $last_insert_id = $model::where('crt_time',$time)
+                        ->select($model_field['db_key'])
+                        ->get()->toArray();
+                    $last_insert_id = array_column($last_insert_id,$model_field['db_key']);
+                }
+                $tmp = [];$insert = [];
+                if(! empty($model_field['field'])){
+                    foreach ($model_field['field'] as $m){
+                        $tmp[$m] = "";
+                        if(strstr($m,'time')) $tmp[$m] = $time;
+                        if($m == "depart_id") $tmp[$m] = $this->data['depart_id'] ?? 0;
+                        if($m == "top_depart_id") $tmp[$m] = $this->data['top_depart_id'] ?? 0;
+                        if($m == "crt_id") $tmp[$m] = $this->data['user_id'] ?? 0;
+                    }
+                    foreach ($data as $value){
+                        $insert[] = array_intersect_key(array_merge($tmp, $value),$tmp);
+                    }
+                }elseif (! empty($model_field['field_array'])){
+                    foreach ($model_field['field_array'] as $km => $m){
+                        foreach ($m as $v){
+                            $tmp[$v] = "";
+                            if(strstr($v,'time')) $tmp[$v] = $time;
+                        }
+                        foreach ($data as $key => $value){
+                            foreach ($value[$km] as $vv){
+                                $vv[$model_field['need_param']] = $last_insert_id[$key];
+                                $insert[] = array_intersect_key(array_merge($tmp, $vv),$tmp);
+                            }
+                        }
+                    }
+                }
+
+                $model = "\App\Model\\" . $model_name;
+                $model::insert($insert);
+            }
+
+            DB::commit();
+        }catch (\Exception $e){
+            DB::rollBack();
+            return [false, $e->getMessage().$e->getLine()];
+        }
+
+        return [true, ''];
+    }
+
+    public function checkRule($head, $data){
+        //模板里的表头
+        foreach ($this->config['field'] as $key => $value){
+            if(! in_array($key, $head)) return [false, "缺少表头:" . $key];
+        }
+
+        //处理 =》 存在合并单元格数据
+        if(! empty($this->mergedCells)) $data = $this->clearMergeData($data);
+
+        //数据校验
+        list($status,$msg) = $this->checkData($head,$data);
+        return [$status,$msg];
+    }
+
+    function checkData($head,$data){
+        $return_data = [];
+
+        //数据处理
+        foreach ($this->config['field'] as $key => $value){
+            //找到表头在xlsx中的下标位置
+            $key2 = array_search($key, $head);
+            if ($key2 === false) return [false, '未找到表头在xlsx中的位置!'];
+            //获取表头对应列数据
+            $tmp_data = array_column($data,$key2);
+            //去除数据中两侧的空白字符或其他预定义字符
+            foreach ($tmp_data as $v_key => $v_data){
+                $tmp_data[$v_key] = trim($v_data);
+            }
+
+            //------ 根据规则 查找数据 =>做 替换和校验--------------//
+            //校验数据唯一
+            if (strpos($value['other_rule'], 'unique') !== false) {
+                $uniqueIndex = strpos($value['other_rule'], 'unique:');
+                $start = $uniqueIndex + strlen('unique:');
+                $end = strpos($value['other_rule'], '|', $start);
+                if ($end !== false) {
+                    $uniqueValue = substr($value['other_rule'], $start, $end - $start);
+                } else {
+                    $uniqueValue = substr($value['other_rule'], $start);
+                }
+                $model = "\App\Model\\" . $uniqueValue;
+                $bool = $model::whereIn($value['key'], array_unique($tmp_data))
+                    ->where('del_time',0)
+                    ->exists();
+                if($bool) return [false, $key . "在数据库中已存在"];
+            }
+
+            //替换数据
+            if(! empty($value['db_search'])){
+                $db = $value['db_search'];
+                $model = "\App\Model\\" . $db['db_name'];
+                $map = $model::whereIn($db['key'], array_unique($tmp_data))
+                    ->pluck($db['value'], $db['key'])
+                    ->toArray();
+            }
+            //------ 根据规则 查找数据 =>做 替换和校验--------------//
+
+
+            //校验&&组织
+            $tmp_clean = [];
+            foreach ($tmp_data as $v_key => $v_data){
+                if (strpos($value['other_rule'], 'require') !== false) {
+                    if(empty($v_data)) return [false, $key . '不能为空!'];
+                }
+                if (strpos($value['other_rule'], 'unique') !== false) {
+                    if(in_array($v_data,$tmp_clean)) return [false, $key . '不能重复!'];
+                    $tmp_clean[] = $v_data;
+                }
+                if (strpos($value['other_rule'], 'is_numeric') !== false && ! empty($v_data)) {
+                    if(! is_numeric($v_data))  return [false, $key . '请输入数字!'];
+                    $formattedNumber = number_format($v_data, 2, '.', '');
+                    if($formattedNumber != $v_data) return [false, $key . '请输入数字(请输入不超过两位小数)!'];
+                }
+                if(! empty($value['db_search'])) {
+                    if(empty($map[$v_data])) return [false, $key . '下所输入的内容在系统中不存在!'];
+                    $v_data = $map[$v_data];
+                }
+
+                if(! empty($value['multiple'])) {
+                    $field = $value['map'][$key] ?? "";
+                    $value['key_array'][$field] = $v_data;
+
+                    //子表数据 一对多
+                    $return_data[$v_key][$value['key']][] = $value['key_array'];
+                }else{
+                    //数据
+                    $return_data[$v_key][$value['key']] = $v_data;
+                }
+            }
+        }
+        unset($tmp_clean);
+
+        return [true, $return_data];
+    }
+
+    // 处理合并单元格数据
+    function clearMergeData($data){
+        //获取行列
+        $rows = count($data);
+        $cols = count($data[1]);
+
+        //非合并单元格并且为null的数据 替换成空字符串
+        for ($row = 1; $row < $rows; $row++) {
+            // 遍历每一列
+            for ($col = 0; $col < $cols; $col++) {
+                // 如果当前值为 null,并且不是合并单元格
+                if ($data[$row][$col] === null && ! $this->isMergedCell($this->mergedCells, $row, $col)) {
+                    $data[$row][$col] = '';
+                } else {
+                    $data[$row][$col] = $data[$row][$col];
+                }
+            }
+        }
+
+        //合并单元格数据替换为原来的数据
+        for ($row = 1; $row <= $rows; $row++) {
+            // 遍历每一列
+            for ($col = 0; $col < $cols; $col++) {
+                // 如果当前值为 null
+                if ($data[$row][$col] === null) {
+                    // 查找左方第一个非 null 值
+                    for ($i = $col - 1; $i >= 0; $i--) {
+                        if ($data[$row][$i] !== null) {
+                            $data[$row][$col] = $data[$row][$i];
+                            break;
+                        }
+                    }
+                    // 如果左方没有非 null 值,则查找上方第一个非 null 值
+                    if (!isset($newArray[$row][$col])) {
+                        for ($i = $row - 1; $i >= 1; $i--) {
+                            if ($data[$i][$col] !== null) {
+                                $data[$row][$col] = $data[$i][$col];
+                                break;
+                            }
+                        }
+                    }
+                } else {
+                    $data[$row][$col] = $data[$row][$col];
+                }
+            }
+        }
+
+        return $data;
+    }
+
+    // 判断一个单元格是否是合并单元格
+    function isMergedCell($mergeCells, $row, $col) {
+        foreach ($mergeCells as $mergeCell) {
+            [$start, $end] = explode(':', $mergeCell);
+            [$startCol, $startRow] = $this->coordinateToIndex($start);
+            [$endCol, $endRow] = $this->coordinateToIndex($end);
+
+            if ($col >= $startCol && $col <= $endCol && $row >= $startRow && $row <= $endRow) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    // 将 Excel 单元格坐标转换为索引
+    function coordinateToIndex($coordinate) {
+        preg_match('/([A-Z]+)(\d+)/', $coordinate, $matches);
+        [, $col, $row] = $matches;
+
+        $colIndex = 0;
+        $length = strlen($col);
+        for ($i = 0; $i < $length; $i++) {
+            $colIndex += (ord($col[$i]) - 65 + 1) * pow(26, $length - $i - 1);
+        }
+
+        return [$colIndex - 1, $row - 1];
+    }
+}

+ 2 - 1
app/Service/ConstructionService.php

@@ -291,7 +291,7 @@ class ConstructionService extends Service
         $sales = SalesOrder::where('id',$construction['sales_order_id'])->value('order_number');
         $construction['sales_order_number'] = $sales;
         $customer_title = Customer::where('id',$construction['customer_id'])->value('title');
-        $construction['customer_title'] = $customer_title;
+        $construction['customer_title'] = $customer_title ?? "";
         $construction['storehouse_title'] = Storehouse::where('id',$construction['storehouse_id'])->value('title');
         $emp_title = Employee::where('id',$construction['customer_contact_id'])->value('emp_name');
         $construction['customer_contact_title'] = $emp_title;
@@ -433,6 +433,7 @@ class ConstructionService extends Service
         if(! empty($data['service_price'])){
             $res = $this->checkNumber($data['service_price']);
             if(! $res) return [false,'服务价格请输入不超过两位小数并且大于0的数值'];
+            if(! $res) return [false,'服务价格请输入不超过两位小数并且大于0的数值'];
         }
         if(! empty($data['construction_time'])) $data['construction_time'] = $this->changeDateToDateMin($data['construction_time']);
         if(! empty($data['handover_time'])) $data['handover_time'] = $this->changeDateToDateMin($data['handover_time']);

+ 7 - 7
app/Service/CustomerService.php

@@ -498,14 +498,14 @@ class CustomerService extends Service
             $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
         }
         if($data['model_type'] == Customer::Model_type_one){
-            if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
-            if(empty($data['customer_type'])) return [false,'客户类别不能为空'];
-            if(empty($data['consulting_product'])) return [false,'咨询产品不能为空'];
-            if(empty($data['progress_stage'])) return [false,'进展阶段不能为空'];
-            if(empty($data['employee_one'])) return [false,'销售SA不能为空'];
+//            if(empty($data['customer_from'])) return [false,'客户来源不能为空'];
+//            if(empty($data['customer_type'])) return [false,'客户类别不能为空'];
+//            if(empty($data['consulting_product'])) return [false,'咨询产品不能为空'];
+//            if(empty($data['progress_stage'])) return [false,'进展阶段不能为空'];
+//            if(empty($data['employee_one'])) return [false,'销售SA不能为空'];
         }else{
-            if(empty($data['car_type'])) return [false,'车型不能为空'];
-            if(empty($data['customer_contact'])) return [false,'客户联系方式不能为空'];
+//            if(empty($data['car_type'])) return [false,'车型不能为空'];
+//            if(empty($data['customer_contact'])) return [false,'客户联系方式不能为空'];
         }
 
         if($is_add){

+ 118 - 0
app/Service/ImportService.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace App\Service;
+
+use App\Import\Import;
+use App\Model\BasicType;
+use App\Model\Product;
+use App\Model\ProductCategory;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+
+class ImportService extends Service
+{
+    public static $type = [
+        '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)
+            ]);
+        }
+    }
+}

+ 26 - 2
app/Service/ProductService.php

@@ -415,11 +415,17 @@ class ProductService extends Service
             ->first();
         if(! empty($in)) $customer['introduction'] = $in->introduction;
 
+        $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_column($detail,'basic_type_id'))
+        $title_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($detail,'basic_type_id'),array_column($basic,'id'))))
             ->pluck('title','id')
             ->toArray();
         //是否总公司
@@ -434,7 +440,7 @@ class ProductService extends Service
             }else{
                 $is_show = 1;
             }
-            $customer['product_price'][] = [
+            $customer['product_price'][$value['basic_type_id']] = [
                 'basic_type_id' => $value['basic_type_id'],
                 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
                 'price' => $value['price'],
@@ -442,6 +448,24 @@ class ProductService extends Service
             ];
         }
 
+        foreach ($basic as $value){
+            if(! $is_main && ($top_depart['basic_type_id'] != $value['id'])) {
+                $is_show = 0;
+            }else{
+                $is_show = 1;
+            }
+            if(! isset($customer['product_price'][$value['id']])){
+                $customer['product_price'][$value['id']] = [
+                    'basic_type_id' => $value['id'],
+                    'basic_type_title' => $title_map[$value['id']] ?? '',
+                    'price' => 0,
+                    'is_show' => $is_show,
+                ];
+            }
+        }
+
+        $customer['product_price'] = array_values($customer['product_price']);
+
         //单位
         $title = BasicType::where('id',$customer['unit'])->value('title');
         $customer['unit_name'] = $title;

+ 1 - 1
app/Service/ReturnExchangeOrderService.php

@@ -322,7 +322,7 @@ class ReturnExchangeOrderService extends Service
         }elseif ($data['type'] == ReturnExchangeOrder::Order_type2){
             $purchase = PurchaseOrder::where('del_time',0)->where('id',$data['data_id'])->first();
             if(empty($purchase)) return [false,'采购单不存在或已被删除'];
-            if($purchase['state'] < PurchaseOrder::STATE_ONE) return [false,'采购单未确认,不能进行退换货操作'];
+            if($purchase['state'] < PurchaseOrder::STATE_Four) return [false,'采购单未入库,不能进行退换货操作'];
         }
 
         //所属部门 以及  顶级部门

+ 25 - 13
app/Service/SalesOrderService.php

@@ -136,17 +136,17 @@ class SalesOrderService extends Service
                 $insert = [];
                 foreach ($data['product'] as $value){
                     $sports_bag_product_info_id = 0;
-                    if(! empty($value['sports_bag_id'])) $sports_bag_product_info_id = $value['id'];
+                    if(! empty($value['sports_bag_id'])) $sports_bag_product_info_id = empty($value['id']) ? 0 : $value['id'];
                     $insert[] = [
                         'sales_order_id' => $model->id,
-                        'product_id' => $value['product_id'],
-                        'number' => $value['number'],
+                        'product_id' => $value['product_id'] ?? 0,
+                        'number' => $value['number'] ?? 0,
                         'cost' => $value['cost'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,
                         'basic_type_id' => $value['basic_type_id'],
-                        'price' => $value['price'],
+                        'price' => $value['price'] ?? 0,
                         'final_amount' => $value['final_amount'] ?? 0,
                         'sports_bag_id' => $value['sports_bag_id'] ?? 0,
                         'sports_bag_product_info_id' => $sports_bag_product_info_id,
@@ -275,17 +275,17 @@ class SalesOrderService extends Service
                 $insert = [];
                 foreach ($data['product'] as $value){
                     $sports_bag_product_info_id = 0;
-                    if(! empty($value['sports_bag_id'])) $sports_bag_product_info_id = $value['id'];
+                    if(! empty($value['sports_bag_id'])) $sports_bag_product_info_id = empty($value['id']) ? 0 : $value['id'];;
                     $insert[] = [
                         'sales_order_id' => $model->id,
-                        'product_id' => $value['product_id'],
-                        'number' => $value['number'],
+                        'product_id' => $value['product_id'] ?? 0,
+                        'number' => $value['number'] ?? 0,
                         'cost' => $value['cost'] ?? 0,
                         'retail_price' => $value['retail_price'] ?? 0,
                         'mark' => $value['mark'] ?? '',
                         'crt_time' => $time,
-                        'basic_type_id' => $value['basic_type_id'],
-                        'price' => $value['price'],
+                        'basic_type_id' => $value['basic_type_id'] ?? 0,
+                        'price' => $value['price'] ?? 0,
                         'final_amount' => $value['final_amount'] ?? 0,
                         'sports_bag_id' => $value['sports_bag_id'] ?? 0,
                         'sports_bag_product_info_id' => $sports_bag_product_info_id,
@@ -437,19 +437,25 @@ class SalesOrderService extends Service
 
         $basic_price = BasicType::whereIn('id',array_unique(array_column($sales_p_info,'basic_type_id')))->pluck('title','id')->toArray();
         $map = (new ProductService())->getProductDetail(array_column($sales_p_info,'product_id'));
+        $sports_bag_arr = [];
+        $sports_bag_pro = [];
         foreach ($sales_p_info as $value){
             $tmp = $map[$value['product_id']] ?? [];
-            if(!empty($value['sports_bag_id'])){
+            if(! empty($value['sports_bag_id'])){
                 $bag_tmp = $bag_map[$value['sports_bag_id']] ?? [];
+                if(! isset($sports_bag_arr[$value['sports_bag_id']])) $sports_bag_arr[$value['sports_bag_id']] = $bag_tmp;
                 $bag_pro_tmp = $bag_pro_map[$value['sports_bag_id']] ?? [];
                 foreach ($bag_pro_tmp as $k => $v){
+                    if($v['product_id'] != $value['product_id']) continue;
                     $is_choose = false;
                     $final_amount = 0;
                     $number = $v['number'];
+                    $mark = "";
                     if($v['id'] == $value['sports_bag_product_info_id']){
                         $is_choose = true;
                         $final_amount = $value['final_amount'];
                         $number = $value['number'];
+                        $mark = $value['mark'];
                     }
                     $bag_pro_tmp[$k]['is_choose'] = $is_choose;
                     $bag_pro_tmp[$k]['final_amount'] = $final_amount;
@@ -459,9 +465,9 @@ class SalesOrderService extends Service
                     $bag_pro_tmp[$k]['size'] = $tmp['size'] ?? "";
                     $bag_pro_tmp[$k]['unit'] = $tmp['unit'] ?? "";
                     $bag_pro_tmp[$k]['bar_code'] = $tmp['bar_code'] ?? "";
+                    $bag_pro_tmp[$k]['mark'] = $mark ?? "";
+                    $sports_bag_pro[$value['sports_bag_id']][] = $bag_pro_tmp[$k];
                 }
-                $bag_tmp['product'] = $bag_pro_tmp;
-                $sales['activity_product'][] = $bag_tmp;
             }else{
                 $value['title'] = $tmp['title'] ?? "";
                 $value['code'] = $tmp['code'] ?? "";
@@ -472,6 +478,10 @@ class SalesOrderService extends Service
                 $sales['product'][] = $value;
             }
         }
+        foreach ($sports_bag_arr as $key => $value){
+            $value['product'] = $sports_bag_pro[$key] ?? [];
+            $sales['activity_product'][] = $value;
+        }
         $sales['crt_name'] = $emp_map[$sales['crt_id']] ?? '';
         $sales['crt_time'] = $sales['crt_time'] ? date("Y-m-d H:i:s",$sales['crt_time']): '';
         $sales['dispatch_time_first'] = $sales['dispatch_time_first'] ? date("Y-m-d H:i:s",$sales['dispatch_time_first']): '';
@@ -501,6 +511,7 @@ class SalesOrderService extends Service
             ->select('title','id','sales_order_type','model_type','order_number','selling_price','vin_no','car_type','order_type','deal_type','customer_id','sign_time','contract_state','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','expire_time','other_fee','discount_fee','contract_fee','contract_type','pay_way','send_state','logistics_company','logistics_number','car_type','year','mileage','color','original_set','processing','state')
             ->orderby('id', 'desc');
 
+        if(! empty($data['order_number'])) $model->where('order_number','LIKE', '%'.$data['order_number'].'%');
         if(! empty($data['sales_order_type'])) $model->where('sales_order_type',$data['sales_order_type']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
@@ -807,7 +818,7 @@ class SalesOrderService extends Service
         if(empty($sale)) return [false,'合同不存在或已被删除'];
         $sale = $sale->toArray();
         if($sale['sales_order_type'] != SalesOrder::Order_type_one) return [false,'非安装件合同,操作失败'];
-        if($sale['state'] != SalesOrder::State_two) return [false,'合同未确认,操作失败'];
+        if($sale['state'] < SalesOrder::State_two) return [false,'合同还未确认,操作失败'];
         if($sale['state'] > SalesOrder::State_three) return [false,'请确认合同状态,操作失败'];
         $bool = SalesOrderProductInfo::where('del_time',0)
             ->where('sales_order_id',$data['id'])
@@ -886,6 +897,7 @@ class SalesOrderService extends Service
         if(empty($sale)) return [false,'合同不存在或已被删除'];
         $sale = $sale->toArray();
         if($sale['sales_order_type'] != SalesOrder::Order_type_one) return [false,'非安装件合同,操作失败'];
+        if($sale['state'] != SalesOrder::State_three) return [false,'合同还未指派销售,操作失败'];
         if($sale['state'] > SalesOrder::State_four) return [false,'请确认合同状态,操作失败'];
         $product = SalesOrderProductInfo::where('del_time',0)
             ->where('sales_order_id',$data['id'])

+ 1 - 1
app/Service/Wx/WxEmployeeService.php

@@ -111,7 +111,7 @@ class WxEmployeeService extends Service
 
     public function checkWxUser($userId){
         $res = Employee::where('id', $userId)
-            ->where('del_time',0)
+//            ->where('del_time',0)
             ->where('state',Employee::USE)->get()->first();
         if(empty($res)) return [false, '该账号无法登录,请联系管理员!'];
 

+ 80 - 0
config/excel/product.php

@@ -0,0 +1,80 @@
+<?php
+return [
+    "field" => [
+        '产品名称' => [
+            'key' =>'title',
+            'rule' =>'',
+            'other_rule' => 'require|unique:Product',
+        ],
+        '产品分类' => [
+            'key' =>'product_category_id',
+            'db_search' => [
+                'db_name' => 'ProductCategory',
+                'key' => 'title',
+                'value' => 'id',
+            ],
+            'other_rule' => 'require',
+        ],
+        '产品编码' => [
+            'key' =>'code',
+            'rule' => '',
+            'other_rule' => 'require|unique:Product',
+        ],
+        '产品SN编码' => [
+            'key' =>'sn_code',
+            'rule' => '',
+            'other_rule' => 'require|unique:Product',
+        ],
+        '规格' => [
+            'key' =>'size',
+            'rule' =>'',
+            'other_rule' => '',
+        ],
+        '单位' => [
+            'key' =>'unit',
+            'rule' =>'',
+            'other_rule' => '',
+            'db_search' => [
+                'db_name' => 'BasicType',
+                'key' => 'title',
+                'value' => 'id',
+            ],
+        ],
+        '条码' => [
+            'key' =>'bar_code',
+            'rule' =>'',
+            'other_rule' => '',
+        ],
+        '成本' => [
+            'key' =>'cost',
+            'rule' =>'',
+            'other_rule' => 'require|is_numeric',
+        ],
+        '零售价' => [
+            'key' =>'retail_price',
+            'rule' =>'',
+            'other_rule' => 'is_numeric',
+        ],
+    ],
+    //(特殊) 额外表头字段数组名 因为一般这个数据理论上是无限的  所以放在子表里 结构是数组
+    "dynamics_field" => [
+        "name" => "basic_type_22",
+        "func" => "productTitle",
+    ],
+    "other_field_func" => "fillInsertProductData",// (特殊)需要填充的其它字段 这里是为了前端组件渲染的数据
+    "table" => [
+        "Product" => [
+            "field" => ["title","product_category_id","code","size","unit","bar_code","cost","retail_price","crt_id","mark","sn_code","crt_time","depart_id","top_depart_id"],
+        ],
+        "ProductPriceDetail" => [
+            "field_array" => [
+                "basic_type_22" => [
+                    "product_id","basic_type_id","price","crt_time"
+                ],
+            ],
+            "need_param" => "product_id",
+            "db_name" => "Product",
+            "db_key" => "id",
+        ],
+    ],
+];

+ 8 - 0
config/nocheck.php

@@ -0,0 +1,8 @@
+<?php
+
+return [
+    "wx/saleOrderList",
+    "wx/uploadFile",
+    "wx/checkAll"
+];
+

+ 2 - 0
routes/api.php

@@ -236,4 +236,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //移交 分配
     $route->any('fpMan','Api\DeleteController@fp');
     $route->any('yjMan','Api\DeleteController@yj');
+    //导入
+    $route->any('import','Api\ImportController@import');
 });

+ 43 - 0
routes/wx.php

@@ -17,8 +17,51 @@ Route::any('wxSetMobile', 'Api\WxController@setMobile');
 Route::any('wxLogin', 'Api\WxController@login');
 
 Route::group(['middleware'=> ['checkWx']],function ($route){
+    //不需要账号登录的
     //文件上传统一方法
     $route->any('uploadFile', 'Api\FileUploadController@uploadFile');
     $route->any('saleOrderList', 'Api\WxController@saleOrderList');
     $route->any('checkAll', 'Api\CheckController@checkAll');
+
+    //需要账号登录的
+    //采购单
+    $route->any('purchaseOrderList', 'Api\WxController@purchaseOrderList');
+    $route->any('purchaseOrderEdit', 'Api\PurchaseOrderController@purchaseOrderEdit');
+    $route->any('purchaseOrderDetail', 'Api\PurchaseOrderController@purchaseOrderDetail');
+    $route->any('purchaseOrderAdd', 'Api\PurchaseOrderController@purchaseOrderAdd');
+    $route->any('purchaseOrderDel', 'Api\PurchaseOrderController@purchaseOrderDel');
+
+    //合同
+    $route->any('salesOrderGet', 'Api\SalesOrderController@salesOrderGet');
+    $route->any('salesOrderList', 'Api\SalesOrderController@salesOrderList');
+    $route->any('salesOrderEdit', 'Api\SalesOrderController@salesOrderEdit');
+    $route->any('salesOrderDetail', 'Api\SalesOrderController@salesOrderDetail');
+    $route->any('salesOrderAdd', 'Api\SalesOrderController@salesOrderAdd');
+    $route->any('salesOrderDel', 'Api\SalesOrderController@salesOrderDel');
+
+    $route->any('constructionGet', 'Api\ConstructionController@constructionGet');
+    $route->any('constructionList', 'Api\ConstructionController@constructionList');
+    $route->any('constructionEdit', 'Api\ConstructionController@constructionEdit');
+    $route->any('constructionDetail', 'Api\ConstructionController@constructionDetail');
+    $route->any('constructionAdd', 'Api\ConstructionController@constructionAdd');
+    $route->any('constructionDel', 'Api\ConstructionController@constructionDel');
+
+    $route->any('employeeList', 'Api\EmployeeController@employeeList');
+    $route->any('departList', 'Api\EmployeeController@departList');
+    $route->any('storehouseList', 'Api\StorehouseController@storehouseList');
+    $route->any('basicTypeList', 'Api\BasicTypeController@basicTypeList');
+    $route->any('productList', 'Api\ProductController@productList');
+    $route->any('supplierList', 'Api\SupplierController@customerList');
+    $route->any('customerList', 'Api\CustomerController@customerList');
+    $route->any('sportsBagOrderList', 'Api\SportsBagController@orderList');
+    $route->any('productAdd', 'Api\ProductController@productAdd');
+    $route->any('productCategoryList', 'Api\ProductController@productCategoryList');
+
+    //退换货
+    $route->any('ReturnExchangeOrderList', 'Api\ReturnExchangeOrderController@ReturnExchangeOrderList');
+    $route->any('ReturnExchangeOrderEdit', 'Api\ReturnExchangeOrderController@ReturnExchangeOrderEdit');
+    $route->any('ReturnExchangeOrderDetail', 'Api\ReturnExchangeOrderController@ReturnExchangeOrderDetail');
+    $route->any('ReturnExchangeOrderAdd', 'Api\ReturnExchangeOrderController@ReturnExchangeOrderAdd');
+    $route->any('ReturnExchangeOrderDel', 'Api\ReturnExchangeOrderController@ReturnExchangeOrderDel');
+
 });