cqp il y a 1 mois
Parent
commit
595958bd65
4 fichiers modifiés avec 62 ajouts et 289 suppressions
  1. 2 210
      app/Service/EmployeeService.php
  2. 0 79
      config/excel/product.php
  3. 58 0
      config/excel/productTable.php
  4. 2 0
      routes/api.php

+ 2 - 210
app/Service/EmployeeService.php

@@ -494,8 +494,6 @@ class EmployeeService extends Service
 
         $model = new Role();
         $model->title = $data['title'] ;
-        $model->depart_id = $data['depart_id'] ?? 0;
-        $model->top_depart_id = $data['top_depart_id'] ?? 0;
         $model->save();
 
         return [true,''];
@@ -535,8 +533,7 @@ class EmployeeService extends Service
      * @return array
      */
     public function roleList($data,$user){
-        $model = Role::TopClear($user,$data);
-        $model = $model->where('del_time',0)
+        $model = Role::where('del_time',0)
             ->select('title','crt_time','id','upd_time')
             ->orderBy('id','desc');
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%' . $data['title'] . '%');
@@ -555,21 +552,14 @@ class EmployeeService extends Service
     public function roleRule(&$data,$user, $is_check = true){
         if($this->isEmpty($data,'title')) return [false,'名称不能为空!'];
 
-        //所属部门 以及  顶级部门
-        if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
-        $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
-
         if($is_check){
             $bool = Role::where('title',$data['title'])
-                ->where('top_depart_id',$data['top_depart_id'])
                 ->where('del_time',0)
                 ->exists();
             if($bool) return [false,'角色名称已存在!'];
         }else{
             if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
-            $top_depart_id = Role::where('id',$data['id'])->value('top_depart_id');
             $bool = Role::where('title',$data['title'])
-                ->where('top_depart_id',$top_depart_id)
                 ->where('id','<>',$data['id'])
                 ->where('del_time',0)
                 ->exists();
@@ -652,34 +642,6 @@ class EmployeeService extends Service
         return [true, $role];
     }
 
-    public function departSetIndex($data,$user){
-        if(empty($data['data'])) return [false, '指标数据不能为空'];
-
-        $time = time();
-        $insert = [];
-        foreach ($data['data'] as $value){
-            if(empty($value['top_depart_id'])) return [false, '请选择门店'];
-            if(! isset($value['param_one'])) return [false, '请填写销售额'];
-            if(floatval($value['param_one']) == 0.0) return [false,'销售额不能为空'];
-            $insert[] = [
-                'top_depart_id' => $value['top_depart_id'],
-                'param_one' => $value['param_one'],
-                'crt_time' => $time,
-            ];
-        }
-
-        if(empty($insert)) return [true, ''];
-
-        //删除指标
-        DepartIndex::where('del_time',0)
-            ->update(['del_time' => $time]);
-
-        //写入指标
-        DepartIndex::insert($insert);
-
-        return [true, ''];
-    }
-
     /**
      * 部门编辑
      * @param $data
@@ -690,14 +652,9 @@ class EmployeeService extends Service
         if(!$status) return [$status,$msg];
 
         $update = $msg['data'][0];
-
         $model = new Depart();
         $model->where('id',$data['id'])->update($update);
 
-        Storehouse::where('del_time',0)
-            ->where('top_depart_id',$data['id'])
-            ->update(['title' => $update['title']]);
-
         return [true, ''];
     }
 
@@ -714,83 +671,18 @@ class EmployeeService extends Service
         try {
             DB::beginTransaction();
 
-            $time = time();
-
             foreach ($msg['data'] as $value){
                 $model = new Depart();
                 $model->parent_id = $value['parent_id'];
                 $model->title = $value['title'];
                 $model->code = $value['code'];
                 $model->is_main = $value['is_main'];
-                $model->basic_type_id = $value['basic_type_id'] ?? 0;
-                $model->rate = $value['rate'] ?? 0;
-                $model->notify_id = $value['notify_id'] ?? 0;
-                $model->area = $value['area'] ?? 0;
-                $model->province = $value['province'] ?? "";
                 $model->save();
                 $depart_id = $model->id;
                 if(empty($depart_id)) {
                     DB::rollBack();
                     return [false,'部门新建失败'];
                 }
-
-                if(empty($value['parent_id'])){
-                    $m = new Storehouse();
-                    $m->title = $value['title'];
-                    $m->depart_id = $depart_id;
-                    $m->top_depart_id = $depart_id;
-                    $m->crt_id = $user['id'];
-                    $m->save();
-                    if(empty($m->id)) {
-                        DB::rollBack();
-                        return [false,'仓库生成失败'];
-                    }
-
-                    $employee = new Employee();
-                    $number = "admin" . $value['code'];
-                    $employee->number = $number;
-                    $employee->emp_name = $value['title'] . "管理员账号";
-                    $employee->entry_time = date('Y-m-d');
-                    $employee->state = 1;
-                    $employee->crt_id = $user['id'];
-                    $employee->is_admin = 1;
-                    $employee->account = $number;
-                    $employee->password = Hash::make("password");
-                    $employee->is_manager = 1;
-                    $employee->save();
-                    if(empty($employee->id)) {
-                        DB::rollBack();
-                        return [false,'管理员账号生成失败'];
-                    }
-
-                    $depart = new EmployeeDepartPermission();
-                    $depart->employee_id = $employee->id;
-                    $depart->depart_id = $depart_id;
-                    $depart->save();
-
-                    if(empty($depart->id)) {
-                        DB::rollBack();
-                        return [false,'管理员账号部门关联生成失败'];
-                    }
-
-                    //公司系统设置
-                    ProductInventorySet::insert(['top_depart_id' => $depart_id, 'param_one' => 1, 'crt_time' => $time]);
-
-                    //基础设置 产品分类 默认
-                    $this->createBasicType($depart_id);
-
-//                    if(! empty($value['is_main'])){
-//                        //总供应商 所有分社可见
-//                        Supplier::insert([
-//                            'title' => $value['title'],
-//                            'crt_id' => $user['id'],
-//                            'crt_time' => $time,
-//                            'depart_id' => $depart_id,
-//                            'top_depart_id' => $depart_id,
-//                            'is_main' => Supplier::is_main,
-//                        ]);
-//                    }
-                }
             }
 
             DB::commit();
@@ -802,30 +694,6 @@ class EmployeeService extends Service
         return [true,'保存成功!'];
     }
 
-    private function createBasicType($depart_id = 0){
-        $insert = [];
-        $time = time();
-        foreach (BasicType::$type as $key => $value){
-            $insert[] = [
-                'title' => '默认',
-                'type' => $key,
-                'depart_id' => $depart_id,
-                'top_depart_id' => $depart_id,
-                'crt_time' => $time
-            ];
-        }
-
-        BasicType::insert($insert);
-
-        ProductCategory::insert([
-            'title' => '默认',
-            'parent_id' => 0,
-            'crt_time' => $time,
-            'depart_id' => $depart_id,
-            'top_depart_id' => $depart_id,
-        ]);
-    }
-
     /**
      * 部门删除
      * @param $data
@@ -855,9 +723,6 @@ class EmployeeService extends Service
 
         if($this->checkDepartHasPerson($data['id'])) return [false,'部门下有人员档案!'];
 
-        $bool = ProductInventory::whereIn('top_depart_id',$data['id'])->where('del_time',0)->exists();
-        if($bool) return [false,'部门下的仓库有产品信息!'];
-
         return [true, ''];
     }
 
@@ -869,20 +734,9 @@ class EmployeeService extends Service
      */
     public function departList($data,$user){
         $model = Depart::where('del_time',0)
-            ->select('title','id','code','parent_id','is_main','basic_type_id','rate','notify_id','channel_id','area','province')
+            ->select('title','id','code','parent_id')
             ->orderby('id', 'asc');
 
-        if(! empty($data['get_top']) && $data['get_top'] == 1){
-            //指派销售
-            $depart_id = $this->getDepartIdListOfMySales($user);
-            $model->whereIn('id', $depart_id);
-        }else{
-            if(! $user['is_all_depart'] && empty($data['is_top_qx'])){
-                $depart_id = $this->getDepartIdList($user);
-                $model->whereIn('id',$depart_id);
-            }
-        }
-
         if(isset($data['parent_id'])) $model->where('parent_id', $data['parent_id']);
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
@@ -901,26 +755,6 @@ class EmployeeService extends Service
     public function fillDepartList($list,$user){
         if(empty($list)) return $list;
 
-        $basic = BasicType::where('del_time',0)
-            ->whereIn('id', array_unique(array_column($list,'basic_type_id')))
-            ->pluck('title','id')->toArray();
-        $emp_id = array_unique(array_merge_recursive(array_column($list,'notify_id'),array_column($list,'channel_id')));
-        $emp_map = Employee::whereIn('id',$emp_id)
-            ->pluck('emp_name','id')
-            ->toArray();
-
-        //省
-        $address_map = config('address');
-        $address_map = array_column($address_map,'label','value');
-        foreach ($list as $key => $value){
-            $list[$key]['basic_type_title'] = $basic[$value['basic_type_id']] ?? '';
-            $list[$key]['is_show_basic_type'] = $user['is_all_depart'];
-            $list[$key]['notify_name'] = $emp_map[$value['notify_id']] ?? '';
-            $list[$key]['channel_name'] = $emp_map[$value['channel_id']] ?? '';
-            $list[$key]['area_name'] = Depart::$area[$value['area']] ?? '';
-            $list[$key]['province_name'] = $address_map[$value['province']] ?? '';
-        }
-
         return $list;
     }
 
@@ -941,18 +775,6 @@ class EmployeeService extends Service
         return array_unique($result);
     }
 
-    //获取指派销售时的部门
-    public function getDepartIdListOfMySales($user){
-        $top = $user['depart_top'][0] ?? [];
-        $top = $top['depart_id'] ?? 0;
-        $list = Depart::where('del_time',0)->select('id','parent_id')->get()->toArray();
-        // 查找所有子级id
-        $childIds = $this->findChildIds($top, $list);
-        $result = array_merge($childIds, [$top]);
-
-        return $result;
-    }
-
     /**
      * 部门参数规则
      * @param $data
@@ -981,48 +803,18 @@ class EmployeeService extends Service
             if($title_count[$value] > 1) return [false,'名称不能重复'];
         }
 
-        $count = 0;
-        foreach ($data['data'] as $value){
-            if(empty($value['parent_id']) && ! empty($value['is_main'])) $count ++;
-        }
-        if($count > 1) return [false,'总社已存在!'];
-        if($count == 1){
-            $id = $data['id'] ?? 0;
-            $bool = Depart::where('del_time',0)
-                ->where('parent_id',0)
-                ->where('is_main',1)
-                ->when(! empty($id), function ($query) use ($id) {
-                    return $query->where('id', '<>',$id);
-                })
-                ->exists();
-            if($bool) return [false,'总社已存在!'];
-        }
-
-        //省
-        $address_map = config('address');
-        $address_map = array_column($address_map,'label','value');
-
         foreach ($data['data'] as $key => $value){
-            if(! empty($value['area'])){
-                $area = array_keys(Depart::$area);
-                if(! in_array($value['area'], $area)) return [false, '门店所属大区不存在'];
-            }
-            if(! empty($value['province']) && ! isset($address_map[$value['province']])) return [false, '门店所属省份不存在'];
-
             if(empty($value['parent_id'])) $data['data'][$key]['parent_id'] = 0;
 
             $data['data'][$key]['upd_time'] = time();
 
-            //Depart::whereRaw("(binary code = '{$value['code']}' OR title = '{$value['title']}')")
             if($is_check){
-                if(empty($user['is_all_depart']) && empty($value['parent_id'])) return [false,'上级部门必须选择'];
                 $data['data'][$key]['crt_time'] = time();
                 $bool = Depart::whereRaw("binary code = '{$value['code']}'")
                     ->where('del_time',0)
                     ->exists();
             }else{
                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
-                if($data['id'] == $user['head']['id'] && empty($value['is_main'])) return [false,'总社不支持变更!'];
                 $bool = Depart::whereRaw("binary code = '{$value['code']}'")
                     ->where('id','<>',$data['id'])
                     ->where('del_time',0)

+ 0 - 79
config/excel/product.php

@@ -1,79 +0,0 @@
-<?php
-return [
-    "field" => [
-        '产品名称' => [
-            'key' =>'title',
-            'rule' =>'',
-            'other_rule' => 'require|unique:Product',
-            'search_raw' => 'top_depart_id = ? AND (top_depart_id = ? OR top_depart_id = ?)',
-            'search_field' => ['top_depart_id']
-        ],
-        '产品编码' => [
-            'key' =>'code',
-            'rule' => '',
-            'other_rule' => 'require|unique:Product',
-            'search_raw' => 'top_depart_id = ? AND (top_depart_id = ? OR top_depart_id = ?)',
-            'search_field' => ['top_depart_id']
-        ],
-        '产品分类' => [
-            'key' =>'product_category_id',
-            'db_search' => [
-                'db_name' => 'ProductCategory',
-                'key' => 'title',
-                'value' => 'id',
-            ],
-            'other_rule' => 'require',
-        ],
-        '规格' => [
-            '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","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",
-        ],
-    ],
-];

+ 58 - 0
config/excel/productTable.php

@@ -0,0 +1,58 @@
+<?php
+return [
+    [
+        'key' =>'code',
+        'value' => '存货编码',
+        'required' => true,
+    ],
+    [
+        'key' =>'title',
+        'value' => '存货名称',
+        'required' => true,
+    ],
+    [
+        'key' =>'size',
+        'value' => '规格型号',
+        'required' => false,
+    ],
+    [
+        'key' =>'category',
+        'value' => '所属类别',
+        'required' => false,
+    ],
+    [
+        'key' =>'unit',
+        'value' => '计量单位',
+        'required' => false,
+    ],
+    [
+        'key' =>'cost',
+        'value' => '成本单价',
+        'required' => false,
+    ],
+    [
+        'key' =>'business_cost',
+        'value' => '业务成本单价',
+        'required' => false,
+    ],
+    [
+        'key' =>'major_client_settlement_price',
+        'value' => '大客户结算单价',
+        'required' => false,
+    ],
+    [
+        'key' =>'write_off_price',
+        'value' => '核销单价',
+        'required' => false,
+    ],
+    [
+        'key' => 'return_change_price',
+        'value' => '退货损耗单价',
+        'required' => false,
+    ],
+    [
+        'key' => 'mark',
+        'value' => '备注',
+        'required' => false,
+    ],
+];

+ 2 - 0
routes/api.php

@@ -114,6 +114,8 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //设置默认打开筛选
     $route->any('setFilter','Api\TableHeadController@filterAdd');
 
+    //获取下载模板
+    $route->any('getTableTitleXls','Api\ImportController@getTableTitleXls');
     //导入统一方法
     $route->any('importAll','Api\ImportController@importAll');