Pārlūkot izejas kodu

36、角色权限中需要添加 产品价格权限

cqpCow 11 mēneši atpakaļ
vecāks
revīzija
2a99f59e32

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

@@ -42,6 +42,8 @@ class CheckLogin
         $data['role'] = EmployeeService::getPersonRole($result);
         //角色里所有菜单权限
         $data['role_authority'] = EmployeeService::getPersonRoleQx($data['role']);
+        //角色里特殊的按钮
+        $data['special_button'] = EmployeeService::getSpecialButton($data['role'],$result);
 
         //当前门店
         $userSetTopDepartId = $request->header('userSetTopDepartId');

+ 2 - 0
app/Http/Middleware/CheckWx.php

@@ -63,6 +63,8 @@ class CheckWx
             $data['role'] = EmployeeService::getPersonRole($employee_id);
             //角色里所有菜单权限
             $data['role_authority'] = EmployeeService::getPersonRoleQx($data['role']);
+            //角色里特殊的按钮
+            $data['special_button'] = EmployeeService::getSpecialButton($data['role'],$employee_id);
 
             //当前门店
             $userSetTopDepartId = $request->input('userSetTopDepartId');

+ 2 - 0
app/Model/RoleMenuButton.php

@@ -11,4 +11,6 @@ class RoleMenuButton extends Model
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
 
+    const special_one = -1;
+    const special_two = -2;
 }

+ 24 - 1
app/Service/EmployeeService.php

@@ -1149,7 +1149,7 @@ class EmployeeService extends Service
         return $role_id;
     }
 
-    public static function getPersonRoleQx($role_id){
+    public static function getPersonRoleQx($role_id = []){
         if(empty($role_id)) return [];
         $role = RoleMenu::where('del_time',0)
             ->whereIn('role_id',$role_id)
@@ -1174,6 +1174,29 @@ class EmployeeService extends Service
         return $return;
     }
 
+    public static function getSpecialButton($role_id,$user){
+        $return = [];
+        $special_button = config('specialButton');
+        if($user == Employee::SPECIAL_ADMIN) {
+            foreach ($special_button as $value){
+                $return[] = $value['id'];
+            }
+            return $return;
+        }
+
+        $role_button = RoleMenuButton::where('del_time',0)
+            ->where('button_id','<',0)
+            ->whereIn('role_id',$role_id)
+            ->select('menu_id','button_id')
+            ->get()->toArray();
+
+        foreach ($role_button as $value){
+            $return[] = $value['button_id'];
+        }
+
+        return $return;
+    }
+
     //通过角色获取菜单
     public function getMenuByRoleInList($user){
         $role_id = $user['role'] ?? [];

+ 37 - 41
app/Service/ProductService.php

@@ -11,6 +11,8 @@ use App\Model\ProductCategory;
 use App\Model\ProductInfo;
 use App\Model\ProductIntroduction;
 use App\Model\ProductPriceDetail;
+use App\Model\Role;
+use App\Model\RoleMenuButton;
 use App\Model\SeeRange;
 use Illuminate\Support\Facades\DB;
 
@@ -423,9 +425,6 @@ class ProductService extends Service
             ->first();
         if(empty($customer)) return [false,'产品不存在或已被删除'];
         $customer = $customer->toArray();
-        //成本隐藏
-        $customer['cost_show'] = "*";
-
         $customer['product_category'] = ! empty($customer['product_category']) ? json_decode($customer['product_category'],true): [];
         $category = ProductCategory::where('id',$customer['product_category_id'])
             ->value('title');
@@ -436,6 +435,7 @@ class ProductService extends Service
             ->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)
@@ -454,35 +454,33 @@ class ProductService extends Service
         $top_depart = $user['depart_top'][0] ?? [];
         $customer['is_edit'] = $customer['top_depart_id'] == $top_depart['depart_id'] ? 1 : 0;
         $customer['product_price'] = [];
-        //展示金额
-        foreach ($detail as $value){
-            if(! $is_main && ($top_depart['basic_type_id'] != $value['basic_type_id'])) {
-                $is_show = 0;
-            }else{
-                $is_show = 1;
-            }
-            $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'],
-                'is_show' => $is_show,
-            ];
-        }
 
+        //特殊功能按钮
+        $special_button = $user['special_button'] ?? [];
+
+        //成本隐藏
+        $price = "******";
+        if(in_array(RoleMenuButton::special_two,$special_button)) $price = $customer['cost'];
+        $customer['cost_show'] = $price;
+
+        //所有金额
         foreach ($basic as $value){
-            if(! $is_main && ($top_depart['basic_type_id'] != $value['id'])) {
-                $is_show = 0;
+            $show = 0;
+            if(in_array(RoleMenuButton::special_one,$special_button)){
+                $show = 1;
             }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,
-                ];
+                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']);
@@ -661,24 +659,19 @@ class ProductService extends Service
         //产品使用价格
         $detail_map = $this->getProductPrice(array_column($data['data'],'id'), $type);
 
-        //是否总公司
-        $is_main = $user['is_all_depart'];
+        //当前门店
         $top_depart = $user['depart_top'][0] ?? [];
+        //特殊功能按钮
+        $special_button = $user['special_button'] ?? [];
         foreach ($data['data'] as $key => $value){
             $tmp = [];
             if(isset($detail_map[$value['id']])){
                 $d = $detail_map[$value['id']];
                 foreach ($d as $v){
-                    if(! $is_main && ($top_depart['basic_type_id'] != $v['basic_type_id'])) {
-                        $is_show = 0;
-                    }else{
-                        $is_show = 1;
-                    }
-                    if($top_depart['basic_type_id'] != $v['basic_type_id']) {
-                        $is_use = 0;
-                    }else{
-                        $is_use = 1;
-                    }
+                    $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']] ?? '',
@@ -696,7 +689,9 @@ class ProductService extends Service
             $data['data'][$key]['unit_name'] = $basic_map[$value['unit']] ?? '';
 
             //成本隐藏
-            $data['data'][$key]['cost_show'] = "*";
+            $price = "******";
+            if(in_array(RoleMenuButton::special_two,$special_button)) $price = $value['cost'];
+            $data['data'][$key]['cost_show'] = $price;
         }
 
         return $data;
@@ -711,6 +706,7 @@ class ProductService extends Service
 
     //获取产品使用价格
     public function getProductPrice($product_id = [], $type = 1){
+        if(! is_array($product_id)) $product_id = [$product_id];
         //type 1 采购    2 合同 和 活动包
 
         $detail_map = [];

+ 4 - 0
app/Service/SysMenuService.php

@@ -255,6 +255,10 @@ class SysMenuService extends Service
             ->select('id','title','sort','func','menu_id')
             ->get()->toArray();
         $button_map = [];
+        $special_button = config('specialButton');
+        foreach ($special_button as $value){
+            $button[] = $value;
+        }
         foreach ($button as $value){
             $button_map[$value['menu_id']][] = $value;
         }

+ 19 - 0
config/specialButton.php

@@ -0,0 +1,19 @@
+<?php
+
+return [
+    [
+        "id" => \App\Model\RoleMenuButton::special_one,
+        "title" => "分社价格",
+        "sort" => -1,
+        "func" => "special_show_branch_price",
+        "menu_id" => 17,
+    ],
+    [
+        "id" => \App\Model\RoleMenuButton::special_two,
+        "title" => "成本",
+        "sort" => -2,
+        "func" => "special_show_cost",
+        "menu_id" => 17,
+    ],
+];
+