ith5 5 mēneši atpakaļ
vecāks
revīzija
54488c3e37

+ 1 - 1
app/v1/controller/CommonController.php

@@ -125,7 +125,7 @@ class CommonController extends BaseController
         $user_info = $userAuthCache->getUserInfo();
         $currentUserRoleList = $user_info['roleList'];
         $currentUserRoleList = array_column($currentUserRoleList, 'id');
-        print_r($currentUserRoleList);
+
 
         // 管理员角色ID:1, 则不限制权限
         if(in_array(1,$currentUserRoleList)){

+ 10 - 0
app/v1/logic/dataReport/AnalyseLogic.php

@@ -82,6 +82,9 @@ class AnalyseLogic extends BaseLogic
     {
 
         $whereSql = "";
+
+       
+
         // 游戏id
         if (!empty($params['game_id'])) {
             if (is_array($params['game_id'])) {
@@ -123,6 +126,13 @@ class AnalyseLogic extends BaseLogic
             $whereSql .= " AND tdate = '{$params['reg_date']}'";
         }
 
+        // 自然量ID, agent_id=1000为自然量
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereSql .= " OR (game_id = {$params['nomal_game_id'][$i]} AND agent_id=1000)";
+            }
+        }
+        
         return $whereSql;
     }
 

+ 23 - 5
app/v1/middleware/FilterPermission.php

@@ -2,6 +2,7 @@
 namespace app\v1\middleware;
 
 use plugin\saiadmin\app\cache\UserInfoCache;
+use support\think\Db;
 use Webman\Http\Request;
 use Webman\Http\Response;
 use Webman\MiddlewareInterface;
@@ -18,23 +19,40 @@ class FilterPermission implements MiddlewareInterface
         // 用户权限缓存
         $userAuthCache = new UserInfoCache($token['id']);
         $user_info = $userAuthCache->getUserInfo();
+        $currentUserRoleList = array_column($user_info['roleList'], 'id');
 
         // $user_info = $this->systemUserLogic->read($token['id']);
 
         // 获取游戏数据权限
-        $authGameList = $user_info['game_list'] ?? '';
+        if(in_array(1,$currentUserRoleList)){
+            $authGameList = '*';
+        }else{
+            $authGameList = $user_info['game_list'] ?? '';
+        }
 
         // 获取游戏自然量数据权限
-        $auth_normal_game_list = $user_info['normal_game_list'] ?? '';
+        if(in_array(1,$currentUserRoleList)){
+            // 如果是管理员,则不限制自然量数据权限
+            // 需要请求所有游戏ID
+            $gameData = Db::connect('db_center')->table('pf_game')->where('status',1)->select()->toArray();
+            $game_list = array_column($gameData, 'id');
+            $auth_normal_game_list = array_values($game_list);
+        }else{
+            $auth_normal_game_list = $user_info['normal_game_list'] ?? '';
+        }
 
         // 获取广告投放数据权限
-        $auth_ad_permission = $user_info['ad_permission'] ?? '';
+        if(in_array(1,$currentUserRoleList)){
+            $auth_ad_permission = '*';
+        }else{
+            $auth_ad_permission = $user_info['ad_permission'] ?? '';
+        }
 
         // 追加参数逻辑
         $extraParams = [
             'auth_normal_game_list' => $auth_normal_game_list === '*' ? '' : $auth_normal_game_list,
-            'auth_game_list' => $authGameList === '*' ? '' : $authGameList,
-            'auth_ad_permission' => $auth_ad_permission === '*' ? '' : $auth_ad_permission,
+            'auth_game_list' => $authGameList === '' ? '' : $authGameList,
+            'auth_ad_permission' => $auth_ad_permission === '*' ? 1 : $auth_ad_permission,
         ];
        
         // 合并并设置回 request

+ 37 - 31
plugin/saiadmin/basic/BaseLogic.php

@@ -170,7 +170,6 @@ class BaseLogic
     {
         $withSearch = array_keys($searchWhere);
         $data = $searchWhere;
-
        
         // 获取游戏权限
         $auth_game_list = request()->header('auth_game_list');
@@ -187,17 +186,7 @@ class BaseLogic
         }
         
         // 游戏权限
-        // if(!empty($auth_game_list)){
-        //     // 如果传入的game_id存在,则取交集
-        //     if(!empty($data['game_id'])){
-        //         $data['game_id'] = array_values(array_intersect(explode(',', $data['game_id']), explode(',', $auth_game_list)));
-        //     }else{
-        //         // 如果传入的game_id不存在,则取权限中的game_id
-        //         $data['game_id'] =  $auth_game_list?explode(',', $auth_game_list) : '';
-        //     }
-        // }
         if(!empty($auth_game_list)){
-            echo '进入auth_game_list';
             if(!empty($data['game_id'])){
                 $inputGameIds = is_array($data['game_id']) ? $data['game_id'] : explode(',', $data['game_id']);
                 $authGameIds = explode(',', $auth_game_list);
@@ -207,35 +196,52 @@ class BaseLogic
             }
         }
            
-        // // 自然量游戏权限
-        // if(!empty($auth_normal_game_list)){
-        //     // 如果传入的game_id存在,则取交集
-        //     if(!empty($data['nomal_game_id'])){
-        //         $data['nomal_game_id'] = array_values(array_intersect(explode(',', $data['nomal_game_id']), explode(',', $auth_normal_game_list)));
-        //     }else{
-        //         // 如果传入的game_id不存在,则取权限中的game_id
-        //         $data['nomal_game_id'] =  $auth_normal_game_list?explode(',', $auth_normal_game_list) : '';
-        //     }
-        // }
-            
-        // 广告数据权限
-        // 全部
+        // 自然量游戏权限
+        if(!empty($auth_normal_game_list)){
+            $data['nomal_game_id'] = $auth_normal_game_list;
+        }
+
+        /**广告数据权限-开始***************************************** */
+        // 广告数据权限-全公司数据
         if($auth_ad_permission==1){
-            $data['auth_id'] = [];
+            // 如果传入了auth_id,则取交集
+            if(!empty($data['auth_id'])){
+                $data['auth_id'] = array_values(array_intersect(explode(',', $data['auth_id']), explode(',', $auth_ad_permission)));
+            }else{
+                $data['auth_id'] =  '';
+            }
         }
-        // 自己以及下面组员
+
+        // 广告数据权限-自己以及下面组员
         if($auth_ad_permission==2){
+            // 如果没有传入负责人ID, 则取当前用户以及下面组员
             $current_user_id = $this->adminInfo['id'];
             $result = Db::connect('db_system')->table('sa_system_user')->field('dept_id')->where('id', $current_user_id)->select()->toArray();
             $dept_ids = array_column($result, 'dept_id');
             $under_user_ids = Db::connect('db_system')->table('sa_system_user')->field('id')->where('dept_id', 'in', $dept_ids)->select()->toArray();
             $under_user_ids = array_column($under_user_ids, 'id');
-            $data['auth_id'] =  $under_user_ids;
+
+            if(!empty($data['auth_id'])){
+               // 如果传入了负责人ID,则取交集
+               $data['auth_id'] = array_values(array_intersect(explode(',', $data['auth_id']), array_values($under_user_ids)));
+            }else{
+                // 如果没有传入负责人ID, 则取当前用户以及下面组员
+                $data['auth_id'] =  array_values($under_user_ids);
+            }
+        }
+
+        // 广告数据权限-如果auth_id为空,则取当前用户
+        if($auth_ad_permission==''){
+            $current_user_id = $this->adminInfo['id'];
+            if(!empty($data['auth_id'])){
+               // 如果传入了负责人ID,则取交集
+               $data['auth_id'] = array_values(array_intersect(explode(',', $data['auth_id']), array_values($under_user_ids)));
+            }else{
+                // 如果没有传入负责人ID, 则取当前用户
+                $data['auth_id'] =  $current_user_id;
+            }
         }
-  
-        // return $data;
-        // print_r($data);
-        //  return $this->model->withSearch($withSearch, $data);
+        /**广告数据权限-结束***************************************** */
         return $data;
     }