cqpCow 1 năm trước cách đây
mục cha
commit
6d4cba51fa

+ 0 - 1
app/Model/Supplier.php

@@ -25,7 +25,6 @@ class Supplier extends Model
         if(! empty($attributes['userData'])) {
             self::$user = $attributes['userData'];
             self::$user['range_function'] = self::range_function;
-            self::$user['is_search_main'] = 1;
             self::$search = $attributes['search'] ?? [];
             self::$is_search = true;
         }

+ 7 - 6
app/Scopes/DepartmentScope.php

@@ -53,29 +53,30 @@ class DepartmentScope implements Scope
                     //全部
                     $builder->whereIn('depart_id', $depart_range);
                 }else{
+                    //可见
                     $builder->whereIn('id', $id);
                 }
             }else{
                 if(! $is_see){
-                    //某个分社
-                    $builder->where('top_depart_id', $top_depart_id)
-                        ->whereIn('depart_id', $depart_range);
+                    //查看某个分社
+                    $builder->where('top_depart_id', $top_depart_id);
                 }else{
+                    //查看某个分社可见
                     $builder->whereIn('id', $id);
                 }
             }
         }else{
+            //分社
             if(! $is_see){
-                //某个分社
+                //某个分社全部
                 $builder->where('top_depart_id', $top_depart_id)
                     ->whereIn('depart_id', $depart_range)
                     ->orWhereIn('id', $id);
             }else{
+                //某个分社可见
                 $builder->whereIn('id', $id);
             }
         }
-
-        if(! empty($this->user['is_search_main'])) $builder->orWhere('is_main', '>',0);
     }
 
     function hasMethod($class, $methodName)

+ 25 - 5
app/Scopes/TopDepartmentScope.php

@@ -19,14 +19,34 @@ class TopDepartmentScope implements Scope
 
     public function apply(Builder $builder, Model $model)
     {
-        if(empty($this->search['top_depart_id'])){
-            //默认进来 只显示自己公司下的 自己权限范围下的部门数据
+        //是否所有部门
+        $is_all_depart = $this->user['is_all_depart'] ?? 0;
+        //权限范围内的部门
+        $depart_range = $this->user['depart_range'] ?? [];
+
+        //顶级部门
+        $search_depart_id = $this->search['top_depart_id'] ?? 0;
+        if(empty($search_depart_id)){
+            //默认进来 自身顶级公司
             $top_depart_id = $this->user['depart_top'][0] ?? [];
             $top_depart_id = $top_depart_id['depart_id'] ?? 0;
         }else{
-            //查询给的公司下的 自己权限范围下的部门数据
-            $top_depart_id = $this->search['top_depart_id'];
+            //查询 顶级公司
+            $top_depart_id = $search_depart_id;
+        }
+
+        if($is_all_depart){
+            //所有部门
+            if(empty($search_depart_id)){
+                //全部
+                $builder->whereIn('top_depart_id', $depart_range);
+            }else{
+                //查看某个分社
+                $builder->where('top_depart_id', $top_depart_id);
+            }
+        }else{
+            //某个分社全部
+            $builder->where('top_depart_id', $top_depart_id);
         }
-        $builder->where('top_depart_id', $top_depart_id);
     }
 }

+ 0 - 2
app/Service/BasicTypeService.php

@@ -3,8 +3,6 @@
 namespace App\Service;
 
 use App\Model\BasicType;
-use App\Model\Supplier;
-
 /**
  * 基础分类设置相关
  */

+ 6 - 2
app/Service/CheckService.php

@@ -167,8 +167,12 @@ class CheckService extends Service
 
     //todo
     public function createPurchaseOrderSales($data, $order, $user){
-        //没有供应商||是总公司的采购单 不创建合同
-        if(empty($order['supplier']) || ! empty($user['is_all_depart'])) return [true, ''];
+        //没有供应商 不创建合同
+        if(empty($order['supplier'])) return [true, ''];
+        //总公司的采购单 不创建合同
+        $top_depart_id = Depart::where('parent_id',0)->where('is_main',1)->value('id');
+        if($top_depart_id == $order['top_depart_id']) return [true, ''];
+        //分社公司的采购单 不向总供应商采购 不创建合同
         $is_create = Supplier::where('id',$order['supplier'])->value('is_main');
         if(empty($is_create)) return [true, ''];
 

+ 21 - 2
app/Service/EmployeeService.php

@@ -10,11 +10,13 @@ use App\Model\EmployeeManagerDepart;
 use App\Model\EmployeeMenuPermission;
 use App\Model\EmployeeRole;
 use App\Model\EmployeeTeamPermission;
+use App\Model\ProductInventory;
 use App\Model\ProductInventorySet;
 use App\Model\Role;
 use App\Model\RoleMenu;
 use App\Model\RoleMenuButton;
 use App\Model\Storehouse;
+use App\Model\Supplier;
 use App\Model\SysMenu;
 use App\Model\SysMenuButton;
 use App\Model\Team;
@@ -525,6 +527,8 @@ class EmployeeService extends Service
         try {
             DB::beginTransaction();
 
+            $time = time();
+
             foreach ($msg['data'] as $value){
                 $model = new Depart();
                 $model->parent_id = $value['parent_id'];
@@ -578,8 +582,20 @@ class EmployeeService extends Service
                         return [false,'管理员账号部门关联生成失败'];
                     }
 
-                    //公司是否校验锁定库存
-                    ProductInventorySet::insert(['top_depart_id' => $depart_id, 'param_one' => 1, 'crt_time' => time()]);
+                    //公司系统设置
+                    ProductInventorySet::insert(['top_depart_id' => $depart_id, 'param_one' => 1, 'crt_time' => $time]);
+
+//                    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,
+//                        ]);
+//                    }
                 }
             }
 
@@ -621,6 +637,9 @@ class EmployeeService extends Service
 
         if($this->checkDepartHasPerson($data['id'])) return [false,'部门下有人员档案!'];
 
+        $bool = ProductInventory::where('top_depart_id',$data['id'])->where('del_time',0)->exists();
+        if($bool) return [false,'部门下的仓库有产品信息!'];
+
         return [true, ''];
     }
 

+ 7 - 7
app/Service/RangeService.php

@@ -30,7 +30,7 @@ class RangeService extends Service
             })->select('customer_id')->get()->toArray();
 
         $return_id = array_unique(array_column($customer_id,'customer_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('customer')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -60,7 +60,7 @@ class RangeService extends Service
             })->select('supplier_id')->get()->toArray();
 
         $return_id = array_unique(array_column($supplier_id,'supplier_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('supplier')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -86,7 +86,7 @@ class RangeService extends Service
             ->toArray();
 
         $return_id = array_unique(array_column($product_id,'product_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('product')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -119,7 +119,7 @@ class RangeService extends Service
             })->select('sales_order_id')->get()
             ->toArray();
         $return_id = array_unique(array_merge_recursive($sales_order_id,array_column($sales_order_id2,'sales_order_id')));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('sales_order')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -141,7 +141,7 @@ class RangeService extends Service
             ->select('construction_id')
             ->get()->toArray();
         $return_id = array_unique(array_column($construction_id,'construction_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('construction')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -167,7 +167,7 @@ class RangeService extends Service
             ->toArray();
 
         $return_id = array_unique(array_column($return_exchange_id,'return_exchange_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('return_exchange_order')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])
@@ -193,7 +193,7 @@ class RangeService extends Service
             ->toArray();
 
         $return_id = array_unique(array_column($return_exchange_id,'sports_bag_id'));
-        if(! empty($search['top_depart_id'])){
+        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
             $id = DB::table('sports_bag')
                 ->where('del_time',0)
                 ->where('top_depart_id',$search['top_depart_id'])

+ 1 - 1
app/Service/SupplierService.php

@@ -236,7 +236,7 @@ class SupplierService extends Service
             ->orderby('id', 'asc');
 
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
-
+        if(! empty($data['get_all'])) $model->orWhere('is_main',Supplier::is_main);
         $list = $this->limit($model,'',$data);
         $list = $this->fillData($list);