Ver código fonte

代码优化

PC-202304251453\Administrator 5 meses atrás
pai
commit
3b9b893f35

+ 22 - 0
app/functions.php

@@ -42,4 +42,26 @@ function getMonthsBetweenDates($startDate, $endDate) {
     }
 
     return $months;
+}
+
+// 获取IP地址
+function getIpLocation($ip): string
+{
+    $ip2region = new \Ip2Region();
+    try {
+        $region = $ip2region->memorySearch($ip);
+    } catch (\Exception $e) {
+        return '未知';
+    }
+    list($country, $number, $province, $city, $network) = explode('|', $region['region']);
+    if ($network === '内网IP') {
+        return $network;
+    }
+    if ($country == '中国') {
+        return $province.'-'.$city.':'.$network;
+    } else if ($country == '0') {
+        return '未知';
+    } else {
+        return $country;
+    }
 }

+ 2 - 1
app/process/CreateTables.php

@@ -360,7 +360,7 @@ class CreateTables
   `role_id` varchar(32) DEFAULT '',
   `role_name` varchar(32) DEFAULT '',
   `reg_date`  datetime DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间',
-  `pay_date`  datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `pay_date`  datetime DEFAULT CURRENT_TIMESTAMP COMMENT '下单时间',
   `sync_date` datetime DEFAULT NULL COMMENT '支付通知时间',
   `sync_data` text COMMENT '支付回调信息',
   `sync_result` text COMMENT '第三方支付返回值',
@@ -376,6 +376,7 @@ class CreateTables
   `product_id` varchar(64) DEFAULT NULL COMMENT '充值商品ID',
   `product_name` varchar(64) DEFAULT NULL COMMENT '充值商品名',
   `package_name` varchar(64) DEFAULT NULL COMMENT '包名',
+  `pay_time` int(10) unsigned NOT NULL COMMENT '下单时间',
   `reg_time` int(10) unsigned NOT NULL COMMENT '注册时间',
   `login_time` int(10) unsigned NOT NULL COMMENT '登录时间',
   PRIMARY KEY (`id`),

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

@@ -23,30 +23,6 @@ class AccountLogic extends BaseLogic
     {
         $this->model = new Account();
     }
-
-     /**
-     * 获取IP地理位置
-     */
-    public function getIpLocation($ip): string
-    {
-        $ip2region = new \Ip2Region();
-        try {
-            $region = $ip2region->memorySearch($ip);
-        } catch (\Exception $e) {
-            return '未知';
-        }
-        list($country, $number, $province, $city, $network) = explode('|', $region['region']);
-        if ($network === '内网IP') {
-            return $network;
-        }
-        if ($country == '中国') {
-            return $province.'-'.$city.':'.$network;
-        } else if ($country == '0') {
-            return '未知';
-        } else {
-            return $country;
-        }
-    }
     
     /**
      * 列表
@@ -60,11 +36,9 @@ 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']);
+            $item['login_ip'] = $item['login_ip'].getIpLocation($item['login_ip']);
+            $item['reg_ip'] = $item['reg_ip'].getIpLocation($item['reg_ip']);
             $item['reg_time'] = date('Y-m-d H:i:s', $item['reg_time']);
             $item['login_time'] = date('Y-m-d H:i:s', $item['login_time']);
             unset($item['user_pwd']);

+ 1 - 2
app/v1/logic/dataReport/AnalyseLogic.php

@@ -1,6 +1,6 @@
 <?php
 
-// 玩家日志逻
+// 运营分析
 
 namespace app\v1\logic\dataReport;
 
@@ -78,7 +78,6 @@ class AnalyseLogic extends BaseLogic
 
 
     // 留存按日
-
     public function generateYearUnionList($namePrefix, $regDate, $whereSql = '', $field = '*', $group = null)
     {
 

+ 11 - 18
app/v1/logic/dataReport/MaterialLogic.php

@@ -11,10 +11,10 @@ use support\think\Db;
 class MaterialLogic extends BaseLogic
 {
 
-    public function getMaterialList($where)
+    public function getMaterialList($params)
     {
-        $params = $this->searchByAuth($where);
-        $tableName = 'media_cost_material';
+        $params = $this->searchByAuth($params);
+
         $field = "
           material_name,
           material_id,
@@ -32,34 +32,33 @@ class MaterialLogic extends BaseLogic
         ";
 
         // 基础筛选
-        $whereSql = $this->generateWhereSql($params);
-
+        $whereRaw = $this->getCommonWhereRaw($params);
 
         //  作者筛选
         if (!empty($params['author_id'])) {
-            $whereSql .= " AND author_id = {$params['author_id']}";
+            $whereRaw .= " AND author_id = {$params['author_id']}";
         }
         // 消耗筛选
         if (!empty($params['cost_type'])) {
             switch ($params['cost_type']) {
                 case '1':
-                    $whereSql .= " AND ori_money >= 2000";
+                    $whereRaw .= " AND ori_money >= 2000";
                     break;
                 case '2':
-                    $whereSql .= " AND ori_money < 2000";
+                    $whereRaw .= " AND ori_money < 2000";
                     break;
             }
         }
         // 素材名称筛选
         if (!empty($params['material_name'])) {
-            $whereSql .= " AND material_name LIKE '%{$params['material_name']}%'";
+            $whereRaw .= " AND material_name LIKE '%{$params['material_name']}%'";
         }
         // 素材id筛选
         if (!empty($params['material_id'])) {
-            $whereSql .= " AND material_id = {$params['material_id']}";
+            $whereRaw .= " AND material_id = {$params['material_id']}";
         }
         // 分组筛选
-        $group = 'material_id';
+        // $group = 'material_id';
         switch ($params['group']) {
             case 1:
                 $group = 'material_id';
@@ -72,8 +71,7 @@ class MaterialLogic extends BaseLogic
                 break;
         }
 
-        $sql = " SELECT $field FROM $tableName WHERE 1=1 $whereSql GROUP BY $group";
-        $data = Db::connect('db_advert')->query($sql);
+        $data = Db::connect('db_advert')->table("media_cost_material")->field($field)->whereRaw($whereRaw)->group($group)->select();
 
         if(empty($data)){
             return [
@@ -89,14 +87,10 @@ class MaterialLogic extends BaseLogic
                 $row['material_name'] = '';
                 $row['material_id'] = '';
             }
-
-
             $row['cost'] = round($row['cost'], 2);
             $row['ad_click_rate'] = ToolLogic::getPercent($row['click'], $row['ad_show'], 2);
             $row['reg_cost'] = ToolLogic::getRound($row['cost'], $row['register'], 2);
             $row['pay_cost'] = ToolLogic::getRound($row['cost'], (int)$row['pay_count'], 2);
-
-
             $totalData['cost'] = !empty($totalData['cost']) ? round($totalData['cost'] + $row['cost'], 2) : $row['cost'];
             $totalData['ad_show'] = !empty($totalData['ad_show']) ? $totalData['ad_show'] + $row['ad_show'] : $row['ad_show'];
             $totalData['click'] = !empty($totalData['click']) ? $totalData['click'] + $row['click'] : $row['click'];
@@ -104,7 +98,6 @@ class MaterialLogic extends BaseLogic
             $totalData['register'] = !empty($totalData['register']) ? $totalData['register'] + $row['register'] : $row['register'];
             $totalData['pay_count'] = !empty($totalData['pay_count']) ? $totalData['pay_count'] + $row['pay_count'] : $row['pay_count'];
             $totalData['pay_amount'] = !empty($totalData['pay_amount']) ? $totalData['pay_amount'] + $row['pay_amount'] : $row['pay_amount'];
-
         }
 
         $totalData['ad_click_rate'] = ToolLogic::getPercent($totalData['click']??0, $totalData['ad_show']??0, 2);

+ 32 - 41
app/v1/logic/dataReport/UserLogLogic.php

@@ -13,11 +13,11 @@ class UserLogLogic extends BaseLogic
 {
 
     // 注册日志
-    public function getRegLogList($where): mixed
+    public function getRegLogList($params): mixed
     {
         $orderBy = request()->input('orderBy', 'reg_time');
         $orderType = request()->input('orderType', 'desc');
-        $params = $this->searchByAuth($where);
+        $params = $this->searchByAuth($params);
         $limit = request()->input('limit', 10);
 
         // 检查注册时间只能查询3个月内
@@ -37,14 +37,14 @@ class UserLogLogic extends BaseLogic
 
 
         // 公共处理完的where, 自然量ID, auth_id=0为自然量
-        [$where, $whereRaw] = $this->getUlogCommonWhere($params);
+        $whereRaw = $this->getCommonWhereRaw($params);
         $monthRange = getMonthsBetweenDates($params['reg_time'][0], $params['reg_time'][1]);
 
         $db = Db::connect('db_game_log');
         $unionQuery = [];
         foreach ($monthRange as $month){
             $tableName = 'sdk_reg_log_' . $month;
-            $unionQuery[] = $db->table($tableName)->where($where)->whereRaw(where: $whereRaw)->buildSql();
+            $unionQuery[] = $db->table($tableName)->whereRaw(where: $whereRaw)->buildSql();
         }
         $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
 
@@ -52,14 +52,14 @@ class UserLogLogic extends BaseLogic
     }
 
     // 登录日志
-    public function getLoginLogList($where): mixed
+    public function getLoginLogList($params): mixed
     {
         $orderBy = request()->input('orderBy', 'login_time');
         $orderType = request()->input('orderType', 'desc');
         $page = request()->input('page', 1);
         $limit = request()->input('limit', 10);
 
-        $params = $this->searchByAuth($where);
+        $params = $this->searchByAuth($params);
 
 
          // 检查注册时间只能查询3个月内
@@ -92,14 +92,14 @@ class UserLogLogic extends BaseLogic
         }
 
          // 公共处理完的where, 自然量ID, auth_id=0为自然量
-        [$where, $whereRaw] = $this->getUlogCommonWhere($params);
+        $whereRaw = $this->getCommonWhereRaw($params);
         $monthRange = getMonthsBetweenDates($params['login_time'][0], $params['login_time'][1]);
 
         $db = Db::connect('db_game_log');
         $unionQuery = [];
         foreach ($monthRange as $month){
             $tableName = 'sdk_login_log_' . $month;
-            $unionQuery[] = $db->table($tableName)->where($where)->whereRaw(where: $whereRaw)->buildSql();
+            $unionQuery[] = $db->table($tableName)->whereRaw(where: $whereRaw)->buildSql();
         }
         $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
 
@@ -121,13 +121,9 @@ class UserLogLogic extends BaseLogic
         $rechargeDetailQuery = Db::connect('db_game_log')->table($tableName);
 
         // 公共处理完的where, 自然量ID, auth_id=0为自然量
-        [$where, $whereRaw] = $this->getUlogCommonWhere($params);
-        if($where){
-            $rechargeDetailQuery = $rechargeDetailQuery->where($where);
-        }
-        if($whereRaw){
-            $rechargeDetailQuery = $rechargeDetailQuery->whereRaw($whereRaw);
-        }
+        $whereRaw = $this->getCommonWhereRaw($params);
+echo $whereRaw . "\n";
+        $rechargeDetailQuery = $rechargeDetailQuery->whereRaw($whereRaw);
 
         $rechargeDetailQuery->order($orderBy, $orderType);
 
@@ -184,27 +180,23 @@ class UserLogLogic extends BaseLogic
     }
 
     // 充值排行
-    public function getRechargeRankList($where): mixed
+    public function getRechargeRankList($params): mixed
     {
         $orderBy = request()->input('orderBy', 'searchTotalMoney');
         $orderType = request()->input('orderType', 'desc');
         $page = request()->input('page', 1);
         $limit = request()->input('limit', 10);
 
-        $params = $this->searchByAuth($where);
+        $params = $this->searchByAuth($params);
 
         $tableName = 'sdk_order_success';
 
         $rechargeRankQuery = Db::connect('db_game_log')->table($tableName);
 
         // 公共处理完的where, 自然量ID, auth_id=0为自然量
-        [$where, $whereRaw] = $this->getUlogCommonWhere($params);
-        if($where){
-            $rechargeRankQuery = $rechargeRankQuery->where($where);
-        }
-        if($whereRaw){
-            $rechargeRankQuery = $rechargeRankQuery->whereRaw($whereRaw);
-        }
+        $whereRaw = $this->getCommonWhereRaw($params);
+
+        $rechargeRankQuery = $rechargeRankQuery->whereRaw($whereRaw);
 
         // 先选择字段,包括计算字段
         $rechargeRankQuery->field('user_name,sum(money) as searchTotalMoney,
@@ -255,7 +247,6 @@ class UserLogLogic extends BaseLogic
         }
 
         $totalList = Db::connect('db_game_log')->table('sdk_order_success')
-            ->where($where)
             ->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')
@@ -281,26 +272,26 @@ class UserLogLogic extends BaseLogic
 
     // 角色数据
 
-    public function getRoleDataList($where): mixed
+    public function getRoleDataList($params): mixed
     {
         $page = request()->input('page', 1);
         $limit = request()->input('limit', 10);
+        $orderBy = request()->input('orderBy', 'create_time');
+        $orderType = request()->input('orderType', 'desc');
 
-        $params = $this->searchByAuth($where);
-       
-        $where_sql = $this->generateWhereSql($params);
-       
-        $where_sql = str_replace('AND reg_time', 'AND create_time', $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}";
-        $unionSql = implode(" UNION ALL ", $sql_parts);
-
-        // 分页
-        $offset = ($page - 1) * $limit;
-        $unionSql .= " LIMIT {$offset}, {$limit}";
-        $roleData = Db::connect('db_game_log')->query($unionSql);
+        $params = $this->searchByAuth($params);
+
+        // 公共处理完的where, 自然量ID, auth_id=0为自然量
+        $whereRaw = $this->getCommonWhereRaw($params);
+        $tables = ['role_data_and', 'role_data_ios'];
+
+        $db = Db::connect('db_game_log');
+        $unionQuery = [];
+        foreach ($tables as $tableName){
+            $unionQuery[] = $db->table($tableName)->whereRaw(where: $whereRaw)->buildSql();
+        }
+        $fullSql = "(" . implode(' UNION ALL ', $unionQuery) . ") as unTable";
+        $roleData = $db->table($fullSql)->order($orderBy, $orderType)->paginate($limit)->toArray();
 
         // 合并相同uid的数据,将角色信息放到数组中
         $mergedData = [];

+ 0 - 69
app/v1/middleware/FilterPermission.php

@@ -1,69 +0,0 @@
-<?php
-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;
-
-/**
- * 权限检查中间件
- */
-class FilterPermission implements MiddlewareInterface
-{
-    public function process(Request $request, callable $handler) : Response
-    {
-        // 根据用户id获取用户权限
-        $token = getCurrentInfo();
-        // 用户权限缓存
-        $userAuthCache = new UserInfoCache($token['id']);
-        $user_info = $userAuthCache->getUserInfo();
-        $currentUserRoleList = array_column($user_info['roleList'], 'id');
-
-        // $user_info = $this->systemUserLogic->read($token['id']);
-
-        // 获取游戏数据权限
-        if(in_array(1,$currentUserRoleList)){
-            $authGameList = '';
-        }else{
-            // 根据部门的游戏权限
-            $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 = '*';
-        }else{
-            $auth_normal_game_list = $user_info['normal_game_list'] ?? '-1';
-        }
-
-        // 获取广告投放数据权限
-        if(in_array(1,$currentUserRoleList)){
-            $auth_ad_permission = 1;
-        }else{
-            $auth_ad_permission = $user_info['ad_permission'];
-        }
-
-        // 追加参数逻辑
-        $extraParams = [
-            'auth_normal_game_list' => $auth_normal_game_list,
-            'auth_game_list' => $authGameList,
-            'auth_ad_permission' =>$auth_ad_permission,
-        ];
-       
-        // 合并并设置回 request
-        $origin_header = $request->header();
-        $request->setHeader(array_merge($origin_header, $extraParams));
-
-        return $handler($request);
-    }
-}

+ 0 - 4
config/middleware.php

@@ -1,6 +1,5 @@
 <?php
 
-use app\v1\middleware\FilterPermission;
 use plugin\saiadmin\app\middleware\SystemLog;
 use plugin\saiadmin\app\middleware\CheckLogin;
 use plugin\saiadmin\app\middleware\CheckAuth;
@@ -11,7 +10,4 @@ return [
         CheckAuth::class,
         SystemLog::class,
     ],
-    'v1' => [
-        FilterPermission::class,
-    ],
 ];

+ 65 - 128
plugin/saiadmin/basic/BaseLogic.php

@@ -171,143 +171,103 @@ class BaseLogic
     {
         $withSearch = array_keys($searchWhere);
         $data = $searchWhere;
-       
-        // 获取游戏权限
-        $authGameList = request()->header('auth_game_list');
-
-        $authNormalGameList = request()->header('auth_normal_game_list');
-        $authAdPermission = request()->header('auth_ad_permission');
-
-
         foreach ($withSearch as $k => $v) {
             if ($data[$v] === '') {
                 unset($data[$v]);
                 unset($withSearch[$k]);
             }
         }
-        
-        // 游戏权限
-        
-        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($authAdPermission==2){
-
-            // 根据用户id获取用户权限
-            $token = getCurrentInfo();
-            // 用户权限缓存
-            $userAuthCache = new UserInfoCache($token['id']);
-            $user_info = $userAuthCache->getUserInfo();
-            $current_user_id = $user_info['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');
-
-           
-
-            if(!empty($data['auth_id'])){
-               // 如果传入了负责人ID,则取交集
-               $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);
-            }
+        $userAuthCache = new UserInfoCache(getCurrentInfo()['id']);
+        $userInfo = $userAuthCache->getUserInfo();
+        // Todo 如果角色权限,超过跳过权限限制
+        $roleIds = array_column($userInfo['roleList'], 'id');
+        if(in_array(1, $roleIds)){
+            return $data;
         }
 
-        // 广告数据权限-如果auth_id为空,则取当前用户
-        if($authAdPermission==0){
-            // 根据用户id获取用户权限
-            $token = getCurrentInfo();
-            // 用户权限缓存
-            $userAuthCache = new UserInfoCache($token['id']);
-            $user_info = $userAuthCache->getUserInfo();
-            $current_user_id = $user_info['id'];
-            if(!empty($data['auth_id'])){
-               // 如果传入了负责人ID,则取交集
-               $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($under_user_ids)));
+        // Todo 1、游戏权限
+        $authGameList = $userInfo['deptList']['game_list'];
+        if($authGameList != '*'){
+            $authGameIds = explode(',', $authGameList);
+
+            if(!empty($data['game_id'])){
+                $inputGameIds = is_array($data['game_id']) ? $data['game_id'] : explode(',', $data['game_id']);
+                $data['game_id'] = array_values(array_intersect($inputGameIds, $authGameIds)); // 如果传入了game_id,则取权限交集
             }else{
-                // 如果没有传入负责人ID, 则取当前用户
-                $data['auth_id'] =  $current_user_id;
+                // 如果没传入game_id,则取权限
+                $data['game_id'] = $authGameIds;
             }
         }
-        /**广告数据权限-结束***************************************** */
-
 
-        /**自然量权限-开始***************************************** */
-        // 全部游戏的自然量
-        if($authNormalGameList=='*'){
-            if(!empty($data['auth_id'])){
-                $data['auth_id'][] = 0;
-            }else{
-                $data['auth_id'] =  [0];
+        // Todo 2、广告数据权限
+        $userId = $userInfo['id'];
+        $deptId = $userInfo['deptList']['id'];
+        // 广告权限,自己 or 全部
+        $authAdPermission = $userInfo['ad_permission'];
+        if($authAdPermission){
+            if($authAdPermission==1){ // Todo 1、仅自己
+                $data['auth_id'] = [$userId];
+            } elseif($authAdPermission==2) { // Todo 2、自己部门
+                $underUserIds = Db::connect('db_system')->table('sa_system_user')->where('dept_id', 'in', $deptId)->column('id');
+                if(!empty($data['auth_id'])) { // 如果传入了负责人ID,则取交集
+                    $data['auth_id'] = array_values(array_intersect( $data['auth_id'], array_values($underUserIds)));
+                }else{ // 如果没有传入负责人ID, 则取当前用户以及下面组员
+                    $data['auth_id'] =  array_values($underUserIds);
+                }
             }
         }
 
         // 看指定游戏的自然量
-        $data['nomal_game_id'] = "";
-        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) : '';
-            }
+        $authNormalGameList = $userInfo['normal_game_list']; // 可看自然量的游戏
+        if($authNormalGameList!='*' && $authNormalGameList!='-1' && !empty($data['game_id'])){
+            // 则取auth_normal_game_list交集
+            $data['normal_game_id'] = array_values(array_intersect(explode(',', $authNormalGameList), $data['game_id']));
         }
 
-        /**自然量权限-结束***************************************** */
         return $data;
     }
 
-    // Todo 玩家日志的公共 where 子句
-    protected function getUlogCommonWhere($params): array
+    // Todo 公共 where 子句
+    protected function getCommonWhereRaw($params): string
     {
         $eqParams = ["user_name", "media_id", "site_id", "agent_id", "vt", "server_id", "server_name"];
         $inParams = ["game_id", "auth_id"];
-        $betweenParams = ["pay_date", "reg_date"];
-        $betweenTimeParams = ["reg_time", "login_time"];
+        $betweenParams  = ["tdate"];
+        $timeParams     = ["reg_time", "pay_time", "login_time"];
+        $DateTimeParams = ["create_time"];
 
-        $where = [];
+        // Todo And条件
+        $whereRaw = " 1=1 ";
         foreach ($params as $key => $value){
             if (in_array($key, $eqParams)) {
-                $where[$key] = $value;
-            } elseif (in_array($key, $inParams)) {
-                $where[$key] = is_string($value) ? explode(',', $value) : $value;
-            } elseif (in_array($key, $betweenParams)) {
-                if (!empty($value)) {
-                    $where[] = [$key, 'between', [$value[0] .' 00:00:00', $value[1] .' 23:59:59']];
-                }
+                $whereRaw .= " AND `{$key}`='{$value}'";
+            } elseif (in_array($key, $inParams) && !empty($value)) {
+                $value = is_string($value) ? explode(',', $value) : $value;
+                $whereRaw .= " AND `{$key}` IN ('".implode("','", $value)."')";
+            } elseif (in_array($key, $betweenParams) && !empty($value)) {
+                $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
+            } elseif (in_array($key, $DateTimeParams) && !empty($value)) {
+                $value[0] = $value[0] .' 00:00:00';
+                $value[1] = $value[1] .' 23:59:59';
+                $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
+            } elseif (in_array($key, $timeParams) && !empty($value)) {
+                $value[0] = strtotime($value[0] .' 00:00:00');
+                $value[1] = strtotime($value[1] .' 23:59:59');
+                $whereRaw .= " AND `{$key}` BETWEEN '{$value[0]}' AND '{$value[1]}'";
             }
-            elseif (in_array($key, $betweenTimeParams)) {
-                if (!empty($value)) {
-                    $where[] = [$key, 'between', [strtotime($value[0] .' 00:00:00'), strtotime($value[1] .' 23:59:59')]];
-                }
-            }
-
         }
 
+        // Todo 自然量走 Or 条件
         $whereOr = [];
-        if(!empty($params['nomal_game_id'])){
-            foreach ($params['nomal_game_id'] as $gameId){
+        if(!empty($params['normal_game_id'])){
+            foreach ($params['normal_game_id'] as $gameId){
                 $whereOr[] = "(game_id = {$gameId} AND auth_id=0)";
             }
         }
-        $whereRaw = $whereOr ? implode(' OR ', $whereOr) : "1=1";
+        $whereOr = $whereOr ? implode(' OR ', $whereOr) : "";
 
-        return [$where, $whereRaw];
+        return $whereRaw . ($whereOr ? " OR {$whereOr}" : "");
     }
     /**
      * 分页查询数据
@@ -347,29 +307,6 @@ class BaseLogic
         $query->order($orderBy, $orderType);
         return $query->select()->toArray();
     }
-    /**
-     * 获取IP地理位置
-     */
-    public function getIpLocation($ip): string
-    {
-        $ip2region = new \Ip2Region();
-        try {
-            $region = $ip2region->memorySearch($ip);
-        } catch (\Exception $e) {
-            return '未知';
-        }
-        list($country, $number, $province, $city, $network) = explode('|', $region['region']);
-        if ($network === '内网IP') {
-            return $ip.' '.$network;
-        }
-        if ($country == '中国') {
-            return $ip.' '.$province.'-'.$city.':'.$network;
-        } else if ($country == '0') {
-            return $ip.' 未知';
-        } else {
-            return $ip.' '.$country;
-        }
-    }
 
     /**
      * 转换列表列
@@ -460,7 +397,7 @@ class BaseLogic
             }
 
             if(in_array('ip', $fields)){
-                $data[$key]['ip'] = $this->getIpLocation($value['ip']) ?? '';
+                $data[$key]['ip'] = getIpLocation($value['ip']) ?? '';
             }
         }
         return $data;
@@ -538,9 +475,9 @@ class BaseLogic
         }
 
         // 自然量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['normal_game_id'])){
+            for($i=0;$i<count($params['normal_game_id']);$i++){
+                $whereSql .= " OR (game_id = {$params['normal_game_id'][$i]} AND auth_id=0)";
             }
         }