Browse Source

Merge branch 'dev' of http://git.range8.cn/youyou/dms-api into dev

PC-202304251453\Administrator 5 months ago
parent
commit
5524378c02

+ 8 - 0
app/v1/logic/center/GameLogic.php

@@ -118,6 +118,14 @@ class GameLogic extends BaseLogic
                 'name' => $group['name'],
                 'children' => $groupGames
             ];
+
+
+        }
+
+        foreach($result as $key => $value){
+            if(empty($value['children'])){
+                unset($result[$key]);
+            }
         }
 
         return $result;

+ 2 - 0
app/v1/logic/customer/AccountLogic.php

@@ -60,6 +60,8 @@ class AccountLogic extends BaseLogic
             $data = Db::connect('db_origin')->table('user_'.$query['val']%10)->where('uid', $query['val'])->select()->toArray();
         }
 
+
+
         $data = array_map(function($item){
             $item['login_ip'] = $item['login_ip'].$this->getIpLocation($item['login_ip']);
             $item['reg_ip'] = $item['reg_ip'].$this->getIpLocation($item['reg_ip']);

+ 1 - 0
app/v1/logic/customer/RoleDataLogic.php

@@ -38,6 +38,7 @@ class RoleDataLogic extends BaseLogic
         $game_ids = array_unique(array_column($data, 'game_id'));
         $main_id_arr = Db::connect('db_center')->table('pf_game')->whereIn('id', $game_ids)->column('main_id', 'id');
 
+        
         $data = array_map(function ($item) use ($main_id_arr) {
             // 最后登录时间
             $item['login_time'] = Db::connect('db_origin')->table('agent_reg_' . $item['uid'] % 10)->where('main_id', $main_id_arr[$item['game_id']])->where('uid', $item['uid'])->value('login_time');

+ 25 - 85
app/v1/logic/dataReport/AnalyseLogic.php

@@ -76,62 +76,6 @@ class AnalyseLogic extends BaseLogic
         return $result;
     }
 
-    // 注册按时
-    public function generateWhereSql($params)
-    {
-
-        $whereSql = "";
-
-        // 游戏id
-        if (!empty($params['game_id'])) {
-            if (is_array($params['game_id'])) {
-                $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
-            } else {
-                $whereSql .= " AND game_id = {$params['game_id']}";
-            }
-        }
-        // 媒体id
-        if (!empty($params['media_id'])) {
-            $whereSql .= " AND media_id = {$params['media_id']}";
-        }
-        // 渠道id
-        if (!empty($params['agent_id'])) {
-            $whereSql .= " AND agent_id = {$params['agent_id']}";
-        }
-        // 广告位id
-        if (!empty($params['site_id'])) {
-            if (is_array($params['site_id'])) {
-                $whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
-            } else {
-                $whereSql .= " AND site_id = {$params['site_id']}";
-            }
-        }
-        // 负责人
-        if (!empty($params['auth_id'])) {
-            if (is_array($params['auth_id'])) {
-                $whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
-            } else {
-                $whereSql .= " AND auth_id = {$params['auth_id']}";
-            }
-        }
-        // 注册日期
-        if (!empty($params['reg_date']) && is_array($params['reg_date'])) {
-            $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
-        }
-        // 注册日期,不是数组,则认为是单个日期
-        if (!empty($params['reg_date']) && !is_array($params['reg_date'])) {
-            $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;
-    }
 
     // 留存按日
 
@@ -321,6 +265,7 @@ class AnalyseLogic extends BaseLogic
         return $result;
     }
 
+    // 数据总览
     public function getDataOverview($where)
     {
         $params = $this->searchByAuth($where);
@@ -400,6 +345,7 @@ class AnalyseLogic extends BaseLogic
         ];
     }
 
+    // 数据总览(按月)
     public function getDataOverviewByMonth($where)
     {
         $params = $this->searchByAuth($where);
@@ -482,7 +428,6 @@ class AnalyseLogic extends BaseLogic
         ];
     }
 
-    // 图表数据
 
     /**
      * 收入分析
@@ -577,8 +522,7 @@ class AnalyseLogic extends BaseLogic
         ];
     }
 
-    // 生成基础日统计表的联合查询列表
-
+   
     /**
      * 付费留存
      * 1. 登录日志表:sdk_login_log_, 查找符合注册时间的用户, 获取用户id
@@ -591,36 +535,35 @@ class AnalyseLogic extends BaseLogic
     public function getPayRetention($where)
     {
         $params = $this->searchByAuth($where);
-        // $whereSql = $this->generateWhereSql($params);
+       
         // 判断不能超过90天查询
         $days = ToolLogic::getDays($where['reg_date'][0], $where['reg_date'][1]);
         if ($days > 90) {
             throw new ApiException('时间查询范围请勿超过90天');
         }
-        $whereRaw = '1=1';
-        if (!empty($params['game_id'])) {
-            $whereRaw .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
-        }
-        if (!empty($params['media_id'])) {
-            $whereRaw .= " AND media_id = ({$params['media_id']})";
-        }
-        if (!empty($params['agent_id'])) {
-            $whereRaw .= " AND agent_id IN(" . implode(',', $params['agent_id']) . ")";
-        }
+        $whereParams = $params;
+        unset($whereParams['reg_date']);
+        $whereSql = $this->generateWhereSql($whereParams);
+
+     
+        $whereSql = str_replace('tdate', 'reg_date', $whereSql);
+
 
 
         // 1. 根据注册时间,获取注册付费人数
         $payData = Db::connect('db_game_log')->query("
-        SELECT 
-          SUBSTRING(reg_date,1,10) as dimension, 
-          COUNT(DISTINCT uid) as pay_num 
-        FROM sdk_order_success
-          WHERE {$whereRaw} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
-            GROUP BY 
-              dimension
-      ");
+            SELECT 
+            SUBSTRING(reg_date,1,10) as dimension, 
+            COUNT(DISTINCT uid) as pay_num 
+            FROM sdk_order_success
+            WHERE 1=1 {$whereSql} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
+                GROUP BY 
+                dimension
+        ");
         $payDataMap = array_column($payData, null, 'dimension');
 
+
+     
         // 2. 计算留存付费的人数
         $sqlArr = [];
         $medate = date("Y-m-d", strtotime("+ 60 day", strtotime($params['reg_date'][1])));
@@ -637,11 +580,11 @@ class AnalyseLogic extends BaseLogic
               SELECT 
                 DISTINCT user_name
               FROM sdk_order_success
-               WHERE 
-                {$whereRaw} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
+               WHERE 1=1
+                {$whereSql} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
             )  AS b ON a.user_name = b.user_name
-           WHERE
-              {$whereRaw} AND reg_time BETWEEN " . strtotime($params['reg_date'][0] . " 00:00:00") . " AND " . strtotime($params['reg_date'][1] . " 23:59:59") . "
+           WHERE 1=1
+              {$whereSql} AND reg_time BETWEEN " . strtotime($params['reg_date'][0] . " 00:00:00") . " AND " . strtotime($params['reg_date'][1] . " 23:59:59") . "
           GROUP BY dimension
         ";
         }
@@ -923,9 +866,6 @@ class AnalyseLogic extends BaseLogic
         }
     }
 
-
-    // 生成wheresql
-
     public function generateMonthUnionList($namePrefix, $regDate, $whereSql = '', $field = '*', $group = null)
     {
         $tableNames = ToolLogic::getMonthlyTableNames($namePrefix, $regDate[0], $regDate[1]);

+ 2 - 43
app/v1/logic/dataReport/ChannelAnalysisLogic.php

@@ -27,7 +27,7 @@ class ChannelAnalysisLogic extends BaseLogic
             SUM(reg_pay_total_rg) as reg_pay_total_rg";
         $group = 'agent_id,thour';
         $whereSql = $this->generateWhereSql($params);
-
+    
         // 根据日期,连表查询
         $tableNames = ToolLogic::getMonthlyTableNames('base_total_hour_', $where['reg_date'][0], $where['reg_date'][1]);
         $sqlParts = [];
@@ -106,50 +106,9 @@ class ChannelAnalysisLogic extends BaseLogic
     }
 
 
-    // 留存按日
-    public function generateWhereSql($params): string
-    {
-        $whereSql = "";
-        // 游戏id
-        if (!empty($params['game_id'])) {
-            if (is_array($params['game_id'])) {
-                $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
-            } else {
-                $whereSql .= " AND game_id = {$params['game_id']}";
-            }
-        }
-        // 媒体id
-        if (!empty($params['media_id'])) {
-            $whereSql .= " AND media_id = {$params['media_id']}";
-        }
-        // 渠道id
-        if (!empty($params['agent_id'])) {
-            $whereSql .= " AND agent_id = {$params['agent_id']}";
-        }
-        // 广告位id
-        if (!empty($params['site_id'])) {
-            if (is_array($params['site_id'])) {
-                $whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
-            } else {
-                $whereSql .= " AND site_id = {$params['site_id']}";
-            }
-        }
-        // 负责人
-        if (!empty($params['auth_id'])) {
-            if (is_array($params['auth_id'])) {
-                $whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
-            } else {
-                $whereSql .= " AND auth_id = {$params['auth_id']}";
-            }
-        }
-        // 注册日期
-        if (!empty($params['reg_date']) ?? null) {
-            $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
-        }
 
-        return $whereSql;
-    }
 
+    // 留存按日
     public function getActiveDataList($where): array
     {
         $params = $this->searchByAuth($where);

+ 12 - 50
app/v1/logic/dataReport/MaterialLogic.php

@@ -33,6 +33,8 @@ class MaterialLogic extends BaseLogic
 
         // 基础筛选
         $whereSql = $this->generateWhereSql($params);
+
+
         //  作者筛选
         if (!empty($params['author_id'])) {
             $whereSql .= " AND author_id = {$params['author_id']}";
@@ -73,6 +75,13 @@ class MaterialLogic extends BaseLogic
         $sql = " SELECT $field FROM $tableName WHERE 1=1 $whereSql GROUP BY $group";
         $data = Db::connect('db_advert')->query($sql);
 
+        if(empty($data)){
+            return [
+                'data' => [],
+                'totalRow' => []
+            ];
+        }
+
         $totalData = [];
         foreach ($data as &$row) {
 
@@ -98,9 +107,9 @@ class MaterialLogic extends BaseLogic
 
         }
 
-        $totalData['ad_click_rate'] = ToolLogic::getPercent($totalData['click'], $totalData['ad_show'], 2);
-        $totalData['reg_cost'] = ToolLogic::getRound($totalData['cost'], $totalData['register'], 2);
-        $totalData['pay_cost'] = ToolLogic::getRound($totalData['cost'], (int)$totalData['pay_count'], 2);
+        $totalData['ad_click_rate'] = ToolLogic::getPercent($totalData['click']??0, $totalData['ad_show']??0, 2);
+        $totalData['reg_cost'] = ToolLogic::getRound($totalData['cost']??0, $totalData['register']??0, 2);
+        $totalData['pay_cost'] = ToolLogic::getRound($totalData['cost']??0, (int)$totalData['pay_count']??0, 2);
 
         return [
             'data' => $data,
@@ -108,51 +117,4 @@ class MaterialLogic extends BaseLogic
         ];
     }
 
-    // 生成wheresql
-    public function generateWhereSql($params)
-    {
-        $whereSql = "";
-        // 游戏id
-        if (!empty($params['game_id'])) {
-            if (is_array($params['game_id'])) {
-                $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
-            } else {
-                $whereSql .= " AND game_id = {$params['game_id']}";
-            }
-        }
-        // 媒体id
-        if (!empty($params['media_id'])) {
-            $whereSql .= " AND media_id = {$params['media_id']}";
-        }
-        // 渠道id
-        if (!empty($params['agent_id'])) {
-            $whereSql .= " AND agent_id = {$params['agent_id']}";
-        }
-        // 广告位id
-        if (!empty($params['site_id'])) {
-            if (is_array($params['site_id'])) {
-                $whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
-            } else {
-                $whereSql .= " AND site_id = {$params['site_id']}";
-            }
-        }
-        // 负责人
-        if (!empty($params['auth_id'])) {
-            if (is_array($params['auth_id'])) {
-                $whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
-            } else {
-                $whereSql .= " AND auth_id = {$params['auth_id']}";
-            }
-        }
-        // 注册日期
-        if (!empty($params['reg_date']) && is_array($params['reg_date'])) {
-            $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
-        }
-        // 注册日期,不是数组,则认为是单个日期
-        if (!empty($params['reg_date']) && !is_array($params['reg_date'])) {
-            $whereSql .= " AND tdate = '{$params['reg_date']}'";
-        }
-
-        return $whereSql;
-    }
 }

+ 62 - 28
app/v1/logic/dataReport/UserLogLogic.php

@@ -44,15 +44,28 @@ class UserLogLogic extends BaseLogic
         if (!empty($params['site_id'])) {
             $regLogQuery = $regLogQuery->where('site_id', $params['site_id']);
         }
+        
         if (!empty($params['agent_id'])) {
             $regLogQuery = $regLogQuery->where('agent_id', $params['agent_id']);
         }
+        if (!empty($params['auth_id'])){
+            $regLogQuery = $regLogQuery->where('auth_id', 'in', is_array($params['auth_id']) ? implode(',', $params['auth_id']) : $params['auth_id']);
+        }
         if (!empty($params['vt'])) {
             $regLogQuery = $regLogQuery->where('vt', $params['vt']);
         }
 
-        // 执行查询并排序
-        // $data = $regLogQuery->order($orderBy, $orderType)->select()->toArray();
+        // 自然量ID, auth_id=0为自然量
+        $whereRaw = [];
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereRaw[] = "(game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
+            }
+        }
+        $whereRaw = implode(' OR ', $whereRaw);
+        $regLogQuery = $regLogQuery->whereRaw($whereRaw);
+
+        echo $regLogQuery->buildSql();
 
         // 分页
         $data = $regLogQuery->paginate($limit)->toArray();
@@ -91,7 +104,7 @@ class UserLogLogic extends BaseLogic
             $loginLogQuery = $loginLogQuery->where('site_id', $params['site_id']);
         }
         if (!empty($params['auth_id'])) {
-            $loginLogQuery = $loginLogQuery->where('auth_id', $params['auth_id']);
+            $loginLogQuery = $loginLogQuery->where('auth_id', 'in', is_array($params['auth_id']) ? implode(',', $params['auth_id']) : $params['auth_id']);
         }
         if (!empty($params['agent_id'])) {
             $loginLogQuery = $loginLogQuery->where('agent_id', $params['agent_id']);
@@ -107,9 +120,21 @@ class UserLogLogic extends BaseLogic
                 ->where('login_time', '<=', strtotime($params['login_time'] . ' 23:59:59'));
         }
 
+        // 自然量ID, auth_id=0为自然量
+        $whereRaw = [];
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereRaw[] = "(game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
+            }
+        }
+        $whereRaw = implode(' OR ', $whereRaw);
+        $loginLogQuery = $loginLogQuery->whereRaw($whereRaw);
+
         // 执行查询并排序
         $loginLogQuery->order($orderBy, $orderType);
 
+
+
         $data = $loginLogQuery->paginate($limit)->toArray();
         return $data;
     }
@@ -187,7 +212,7 @@ class UserLogLogic extends BaseLogic
             $rechargeDetailQuery = $rechargeDetailQuery->where('media_id', $params['media_id']);
         }
         if (!empty($params['auth_id'])) {
-            $rechargeDetailQuery = $rechargeDetailQuery->where('auth_id', $params['auth_id']);
+            $rechargeDetailQuery = $rechargeDetailQuery->where('auth_id', 'in', is_array($params['auth_id']) ? implode(',', $params['auth_id']) : $params['auth_id']);
         }
         if (!empty($params['agent_id'])) {
             $rechargeDetailQuery = $rechargeDetailQuery->where('agent_id', $params['agent_id']);
@@ -206,6 +231,15 @@ class UserLogLogic extends BaseLogic
                 ->where('reg_date', '>=', $params['reg_date'][0] . ' 00:00:00')
                 ->where('reg_date', '<=', $params['reg_date'][1] . ' 23:59:59');
         }
+        // 自然量ID, auth_id=0为自然量
+        $whereRaw = [];
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereRaw[] = "(game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
+            }
+        }
+        $whereRaw = implode(' OR ', $whereRaw);
+        $rechargeDetailQuery = $rechargeDetailQuery->whereRaw($whereRaw);
 
         $rechargeDetailQuery->order($orderBy, $orderType);
 
@@ -219,7 +253,6 @@ class UserLogLogic extends BaseLogic
     }
 
     // 充值排行
-
     public function getRechargeRankList($where): mixed
     {
         $orderBy = request()->input('orderBy', 'searchTotalMoney');
@@ -246,7 +279,7 @@ class UserLogLogic extends BaseLogic
             $rechargeRankQuery = $rechargeRankQuery->where('media_id', $params['media_id']);
         }
         if (!empty($params['auth_id'])) {
-            $rechargeRankQuery = $rechargeRankQuery->where('auth_id', $params['auth_id']);
+            $rechargeRankQuery = $rechargeRankQuery->where('auth_id', 'in', is_array($params['auth_id']) ? implode(',', $params['auth_id']) : $params['auth_id']);
         }
         if (!empty($params['agent_id'])) {
             $rechargeRankQuery = $rechargeRankQuery->where('agent_id', $params['agent_id']);
@@ -265,6 +298,15 @@ class UserLogLogic extends BaseLogic
                 ->where('reg_date', '>=', $params['reg_date'][0] . ' 00:00:00')
                 ->where('reg_date', '<=', $params['reg_date'][1] . ' 23:59:59');
         }
+        // 自然量ID, auth_id=0为自然量
+        $whereRaw = [];
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereRaw[] = "(game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
+            }
+        }
+        $whereRaw = implode(' OR ', $whereRaw);
+        $rechargeRankQuery = $rechargeRankQuery->whereRaw($whereRaw);
 
         // 先选择字段,包括计算字段
         $rechargeRankQuery->field('user_name,sum(money) as searchTotalMoney,
@@ -344,9 +386,20 @@ class UserLogLogic extends BaseLogic
         if (!empty($where['reg_date'])) {
             $totalWhere['reg_date'] = $params['reg_date'];
         }
+        // 自然量ID, auth_id=0为自然量
+        $whereRaw = [];
+        if(!empty($params['nomal_game_id'])){
+            for($i=0;$i<count($params['nomal_game_id']);$i++){
+                $whereRaw[] = "(game_id = {$params['nomal_game_id'][$i]} AND auth_id=0)";
+            }
+        }
+        $whereRaw = implode(' OR ', $whereRaw);
+     
+
 
         $totalList = Db::connect('db_game_log')->table('sdk_order_success')
             ->where($totalWhere)
+            ->whereRaw($whereRaw)
             ->field('game_id,uid,sum(money) as totalMoney')
             ->group('uid,game_id,site_id,server_id,media_id,auth_id,agent_id,server_id,auth_id,role_id')
             ->select()->toArray();
@@ -372,7 +425,6 @@ class UserLogLogic extends BaseLogic
 
     // 角色数据
 
-
     public function getRoleDataList($where): mixed
     {
         $orderBy = request()->input('orderBy', 'reg_time');
@@ -389,31 +441,12 @@ class UserLogLogic extends BaseLogic
 
         $userData = Db::connect('db_game_log')->table($egTableName)->where('reg_time', '>=', strtotime($regTime . ' 00:00:00'))->where('reg_time', '<=', strtotime($regTime . ' 23:59:59'))->select()->toArray();
 
-        $where_sql = "";
-        if (!empty($params['game_id'])) {
-            $where_sql .= is_array($params['game_id']) ? " AND game_id in (" . implode(',', $params['game_id']) . ")" : " AND game_id = {$params['game_id']}";
-        }
-
-        if (!empty($params['media_id'])) {
-            $where_sql .= " AND media_id = {$params['media_id']}";
-        }
-
-        if (!empty($params['site_id'])) {
-            $where_sql .= " AND site_id = {$params['site_id']}";
-        }
-
-        if (!empty($params['auth_id'])) {
-            $where_sql .= " AND auth_id = {$params['auth_id']}";
-        }
-
-        if (!empty($params['user_name'])) {
-            $where_sql .= " AND user_name = {$params['user_name']}";
-        }
+        $where_sql = $this->generateWhereSql($params);
+        
 
 
         $uids = array_column($userData, 'uid');
 
-
         if (empty($userData)) {
             return [];
         }
@@ -421,6 +454,7 @@ class UserLogLogic extends BaseLogic
         $where_sql = " AND uid in (" . implode(',', $uids) . ") {$where_sql}";
 
 
+      
         $sql_parts = [];
         $sql_parts[] = "SELECT * FROM role_data_and WHERE 1=1 {$where_sql}";
         $sql_parts[] = "SELECT * FROM role_data_ios WHERE 1=1 {$where_sql}";

+ 12 - 3
app/v1/middleware/FilterPermission.php

@@ -27,14 +27,23 @@ class FilterPermission implements MiddlewareInterface
         if(in_array(1,$currentUserRoleList)){
             $authGameList = '';
         }else{
-            $authGameList = $user_info['game_list'] ?? '';
+            // 根据部门的游戏权限
+            $result = Db::connect('db_system')->table('sa_system_user')->field('dept_id')->where('id', $user_info['id'])->find();
+            $departmentId = $result['dept_id'] ?? 0;
+            $departmentInfo = Db::connect('db_system')->table('sa_system_dept')->where('id',$departmentId)->find();
+            $departmentGameList = $departmentInfo['game_list'] ?? '';
+            $authGameList = $departmentGameList;
+            if($departmentGameList=='*'){
+                $authGameList = '';
+            }
+            
         }
 
         // 获取游戏自然量数据权限
         if(in_array(1,$currentUserRoleList)){
-            $auth_normal_game_list = '';
+            $auth_normal_game_list = '*';
         }else{
-            $auth_normal_game_list = $user_info['normal_game_list'] ?? '';
+            $auth_normal_game_list = $user_info['normal_game_list'] ?? '-1';
         }
 
         // 获取广告投放数据权限

+ 3 - 2
plugin/saiadmin/app/controller/system/SystemUserController.php

@@ -200,15 +200,16 @@ class SystemUserController extends BaseController
         $game_list = $request->post('game_list');
         $normal_game_list = $request->post('normal_game_list');
         $ad_permission = $request->post('ad_permission');
+        $data = [];
         if ($game_list) {
             $data['game_list'] = $game_list;
         }
         if ($normal_game_list) {
             $data['normal_game_list'] = $normal_game_list;
         }
-        if($ad_permission){
+        if($ad_permission!==null){
             $data['ad_permission'] = $ad_permission;
-        }
+        }      
         
         $this->logic->authEdit($id, $data);
         $userInfoCache = new UserInfoCache($id);

+ 86 - 28
plugin/saiadmin/basic/BaseLogic.php

@@ -186,36 +186,20 @@ class BaseLogic
         }
         
         // 游戏权限
+        
         if(!empty($authGameList)){
             if(!empty($data['game_id'])){
+                // 如果传入了game_id,则取权限交集
                 $inputGameIds = is_array($data['game_id']) ? $data['game_id'] : explode(',', $data['game_id']);
                 $authGameIds = explode(',', $authGameList);
                 $data['game_id'] = array_values(array_intersect($inputGameIds, $authGameIds));
             }else{
+                // 如果没传入game_id,则取权限
                 $data['game_id'] = $authGameList ? explode(',', $authGameList) : '';
             }
         }
-           
-        // 自然量游戏权限
-        if(!empty($authNormalGameList)){
-            // 如果传入了game_id,则取auth_normal_game_list交集
-            if(!empty($data['game_id'])){
-                $data['nomal_game_id'] = array_values(array_intersect($authNormalGameList, $data['game_id']));
-            }else{
-                $data['nomal_game_id'] = $authNormalGameList ? explode(',', $authNormalGameList) : '';
-            }
-        }
-
         /**广告数据权限-开始***************************************** */
-        // 广告数据权限-全公司数据
-        if($authAdPermission==1){
-            // 如果传入了auth_id,则取交集
-            if(!empty($data['auth_id'])){
-                $data['auth_id'] = array_values(array_intersect(explode(',', $data['auth_id']), explode(',', $authAdPermission)));
-            }else{
-                $data['auth_id'] =  '';
-            }
-        }
+    
 
         // 广告数据权限-自己以及下面组员
         if($authAdPermission==2){
@@ -228,7 +212,7 @@ class BaseLogic
 
             if(!empty($data['auth_id'])){
                // 如果传入了负责人ID,则取交集
-               $data['auth_id'] = array_values(array_intersect(explode(',', $data['auth_id']), array_values($under_user_ids)));
+               $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($under_user_ids)));
             }else{
                 // 如果没有传入负责人ID, 则取当前用户以及下面组员
                 $data['auth_id'] =  array_values($under_user_ids);
@@ -240,13 +224,36 @@ class BaseLogic
             $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)));
+               $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($under_user_ids)));
             }else{
                 // 如果没有传入负责人ID, 则取当前用户
                 $data['auth_id'] =  $current_user_id;
             }
         }
         /**广告数据权限-结束***************************************** */
+
+
+        /**自然量权限-开始***************************************** */
+        // 全部游戏的自然量
+        if($authNormalGameList=='*'){
+            if(!empty($data['auth_id'])){
+                $data['auth_id'][] = 0;
+            }else{
+                $data['auth_id'] =  [0];
+            }
+        }
+
+        // 看指定游戏的自然量
+        if(!empty($authNormalGameList)&&$authNormalGameList!='*'&&$authNormalGameList!='-1'){
+            // 如果传入了game_id,则取auth_normal_game_list交集
+            if(!empty($data['game_id'])){
+                $authNormalGameList = explode(',', $authNormalGameList);
+                $data['nomal_game_id'] = array_values(array_intersect($authNormalGameList, $data['game_id']));
+            }else{
+                $data['nomal_game_id'] = $authNormalGameList ? explode(',', $authNormalGameList) : '';
+            }
+        }
+        /**自然量权限-结束***************************************** */
         return $data;
     }
 
@@ -272,12 +279,6 @@ class BaseLogic
             return $query->select()->toArray();
         }
 
-
-
-
-
-        
-
         return $query->paginate($limit, false, ['page' => $page])->toArray();
     }
 
@@ -443,4 +444,61 @@ class BaseLogic
         // TODO: Implement __call() method.
         return call_user_func_array([$this->model, $name], $arguments);
     }
+
+    // 渠道分析、运营分析生成的whereSql
+    public function generateWhereSql($params): string
+    {
+        $whereSql = "";
+        // 游戏id
+        if (!empty($params['game_id'])) {
+            if (is_array($params['game_id'])) {
+                $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
+            } else {
+                $whereSql .= " AND game_id = {$params['game_id']}";
+            }
+        }
+        // 媒体id
+        if (!empty($params['media_id'])) {
+            $whereSql .= " AND media_id = {$params['media_id']}";
+        }
+        // 渠道id
+        if (!empty($params['agent_id'])) {
+            $whereSql .= " AND agent_id = {$params['agent_id']}";
+        }
+        // 广告位id
+        if (!empty($params['site_id'])) {
+            if (is_array($params['site_id'])) {
+                $whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
+            } else {
+                $whereSql .= " AND site_id = {$params['site_id']}";
+            }
+        }
+        // 负责人
+        if (!empty($params['auth_id'])) {
+            if (is_array($params['auth_id'])) {
+                $whereSql .= " AND auth_id IN(" . implode(',', $params['auth_id']) . ")";
+            } else {
+                $whereSql .= " AND auth_id = {$params['auth_id']}";
+            }
+        }
+        // 注册日期
+        if (!empty($params['reg_date']) ?? null) {
+            $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
+        }
+
+        // 自然量ID, auth_id=0为自然量
+        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 auth_id=0)";
+            }
+        }
+
+        // 用户名
+        if (!empty($params['user_name'])) {
+            $whereSql .= " AND user_name = {$params['user_name']}";
+        }
+
+        return $whereSql;
+    }
+
 }