瀏覽代碼

菜单按钮

cqpCow 1 年之前
父節點
當前提交
0be1967518

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

@@ -113,4 +113,17 @@ class ProductController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function productDetail(Request $request)
+    {
+        $service = new ProductService();
+        $user = $request->userData->toArray();
+        list($status,$data) = $service->productDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 2 - 2
app/Http/Middleware/CheckLogin.php

@@ -35,8 +35,8 @@ class CheckLogin
 
         //人员角色
         $data['role'] = EmployeeService::getPersonRole($result);
-        //部门权限
-        $data['rule_depart'] = EmployeeService::getPersonDepart($result);
+        //部门
+        $data['rule_depart'] = EmployeeService::getLoginDepart($result);
         //写入user信息
         $request->userData = $data;
 

+ 16 - 1
app/Service/EmployeeService.php

@@ -678,7 +678,7 @@ class EmployeeService extends Service
         return $object;
     }
 
-    //获取登录账号的权限部门
+    //获取登录账号的权限部门 暂时不用了
     public static function getPersonDepart($employee_id){
         if(empty($employee_id)) return [];
 
@@ -728,6 +728,7 @@ class EmployeeService extends Service
         return [true,''];
     }
 
+    //填充角色下的按钮
     public function fillRoleButton($role_id){
         $button = RoleMenuButton::whereIn('role_id',$role_id)
             ->where('del_time',0)
@@ -740,4 +741,18 @@ class EmployeeService extends Service
 
         return $button_map;
     }
+
+    //获取登录账号的部门
+    public static function getLoginDepart($employee_id){
+        if(empty($employee_id)) return [];
+
+        //admin账号
+        if($employee_id == Employee::SPECIAL_ADMIN) return [Depart::RULE_DEPART];
+
+        $depart = EmployeeDepartPermission::where('employee_id',$employee_id)
+            ->select('depart_id')
+            ->get()->toArray();
+
+        return array_unique(array_column($depart,'depart_id'));
+    }
 }

+ 20 - 2
app/Service/ProductService.php

@@ -6,6 +6,7 @@ use App\Model\Employee;
 use App\Model\Product;
 use App\Model\ProductCategory;
 use App\Model\ProductInfo;
+use App\Model\ProductInventory;
 use App\Model\ProductRange;
 use Illuminate\Support\Facades\DB;
 
@@ -319,7 +320,7 @@ class ProductService extends Service
         return [true,''];
     }
 
-    public function productDetail($data){
+    public function productDetail($data,$user){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
         $customer = Product::where('del_time',0)
@@ -327,8 +328,11 @@ class ProductService extends Service
             ->first();
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         $customer = $customer->toArray();
-        $customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
+        $customer['product_inventory'] = [];
+        $inventory = $this->getProductInventory([$data['id']], $user['rule_depart']);
+        if(! empty($inventory)) $customer['product_inventory'] = $inventory;
 
+        $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')
@@ -423,4 +427,18 @@ class ProductService extends Service
 
         return $data;
     }
+
+    public function getProductInventory($product_id = [],$depart_id = []){
+        if(empty($product_id)) return [];
+
+        $result = ProductInventory::whereIn('product_id',$product_id)
+            ->when(! empty($depart_id), function ($query) use ($depart_id) {
+                return $query->whereIn('depart_id', $depart_id);
+            })
+            ->select('id','product_id','number','depart_id','lock_number')
+            ->get()
+            ->toArray();
+
+        return $result;
+    }
 }