Selaa lähdekoodia

添加充值排行

ith5 6 kuukautta sitten
vanhempi
commit
8204926887

+ 51 - 0
app/v1/controller/gameLog/RoleDataController.php

@@ -0,0 +1,51 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\controller\gameLog;
+
+use plugin\saiadmin\basic\BaseController;
+use app\v1\logic\gameLog\RoleDataLogic;
+use app\v1\validate\gameLog\RoleDataValidate;
+use support\Request;
+use support\Response;
+
+/**
+ * 角色数据控制器
+ */
+class RoleDataController extends BaseController
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->logic = new RoleDataLogic();
+        $this->validate = new RoleDataValidate;
+        parent::__construct();
+    }
+
+    /**
+     * 数据列表
+     * @param Request $request
+     * @return Response
+     */
+    public function index(Request $request): Response
+    {
+        $where = $request->more([
+            ['game_id', ''],
+            ['media_id', ''],
+            ['site_id', ''],
+            ['auth_id', ''],
+            ['user_name', ''],
+            ['reg_time', ''],
+        ]);
+        $query = $this->logic->search($where);
+        $data = $this->logic->getList($query);
+        // $data['data'] = $this->logic->trandformListColumn($data['data'], ['game', 'ip', 'auth', 'agent']);
+        return $this->success($data);
+    }
+
+}

+ 4 - 1
app/v1/controller/gameLog/SdkLoginLogController.php

@@ -44,7 +44,10 @@ class SdkLoginLogController extends BaseController
             ['login_time', ''],
             ['reg_time', ''],
         ]);
-        $query = $this->logic->search($where);
+        // 传入的是多选game_id, 转换成字符串
+        $where['game_id'] = is_array($where['game_id']) ? implode(',', $where['game_id']) : $where['game_id'];
+        
+        $query = $this->logic->searchByAuth($where);
         $data = $this->logic->getList($query);
         $data['data'] = $this->logic->trandformListColumn($data['data'], ['game', 'ip', 'agent']);
         return $this->success($data);

+ 4 - 3
app/v1/controller/gameLog/SdkOrderRankController.php

@@ -46,10 +46,11 @@ class SdkOrderRankController extends BaseController
             ['reg_date', ''],
             ['pay_date', ''],
         ]);
-        $query = $this->logic->search($where);
+        // 传入的是多选game_id, 转换成字符串
+        //$where['game_id'] = is_array($where['game_id']) ? implode(',', $where['game_id']) : $where['game_id'];
 
-        $data = $this->logic->getList($query);
-        // $data['data'] = $this->logic->trandformListColumn($data['data'] , ['game', 'ip', 'auth', 'pay_channel']);
+
+        $data = $this->logic->getList($where);
         return $this->success($data);
        
     }

+ 3 - 1
app/v1/controller/gameLog/SdkOrderSuccessController.php

@@ -46,7 +46,9 @@ class SdkOrderSuccessController extends BaseController
             ['reg_date', ''],
             ['pay_date', ''],
         ]);
-        $query = $this->logic->search($where);
+        // 传入的是多选game_id, 转换成字符串
+        $where['game_id'] = is_array($where['game_id']) ? implode(',', $where['game_id']) : $where['game_id'];
+        $query = $this->logic->searchByAuth($where);
         $data = $this->logic->getList($query);
         $data['data'] = $this->logic->trandformListColumn($data['data'], ['game', 'ip', 'agent','auth', 'pay_channel']);
         return $this->success($data);

+ 3 - 1
app/v1/controller/gameLog/SdkRegLogController.php

@@ -44,7 +44,9 @@ class SdkRegLogController extends BaseController
             ['vt', ''],
         ]);
 
-        $query = $this->logic->search($where);
+        // 传入的是多选game_id, 转换成字符串
+        $where['game_id'] = is_array($where['game_id']) ? implode(',', $where['game_id']) : $where['game_id'];
+        $query = $this->logic->searchByAuth($where);
         $data = $this->logic->getList($query);
         $data['data'] = $this->logic->trandformListColumn($data['data'], ['game', 'ip', 'agent']);
         return $this->success($data);

+ 129 - 0
app/v1/logic/gameLog/RoleDataLogic.php

@@ -0,0 +1,129 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\logic\gameLog;
+
+use plugin\saiadmin\basic\BaseLogic;
+use plugin\saiadmin\exception\ApiException;
+use plugin\saiadmin\utils\Helper;
+use app\v1\model\gameLog\RoleData;
+use support\think\Db;
+
+/**
+ * 角色数据逻辑层
+ */
+class RoleDataLogic extends BaseLogic
+{
+    /**
+     * 构造函数
+     */
+    public function __construct()
+    {
+        $this->model = new RoleData();
+    }
+
+     public function getList($query): mixed
+    {
+        $saiType = request()->input('saiType', 'list');
+        $page = request()->input('page', 1);
+        $limit = request()->input('limit', 10);
+        $orderBy = request()->input('orderBy', '');
+        $orderType = request()->input('orderType', $this->orderType);
+        $regTime = request()->input('reg_time', '');
+        $gameId = request()->input('game_id', '');
+        $mediaId = request()->input('media_id', '');
+        $siteId = request()->input('site_id', '');
+        $authId = request()->input('auth_id', '');
+        $userName = request()->input('user_name', '');
+       
+       
+        $egTableName = 'sdk_reg_log_' . date('Ym', strtotime($regTime));
+
+
+
+        $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();
+
+
+        print_r('$userdata===>');
+        print_r($userData);
+
+        $where_sql = "";
+        if(!empty($gameId)){
+            $where_sql .= is_array($gameId) ? " AND game_id in (".implode(',', $gameId).")" : " AND game_id = {$gameId}";
+        }
+
+        if(!empty($mediaId)){
+            $where_sql .= " AND media_id = {$mediaId}";
+        }
+
+        if(!empty($siteId)){
+            $where_sql .= " AND site_id = {$siteId}";
+        }
+
+        if(!empty($authId)){
+            $where_sql .= " AND auth_id = {$authId}";
+        }
+
+        if(!empty($userName)){
+            $where_sql .= " AND user_name = {$userName}";
+        }
+
+        $uids = array_column($userData, 'uid');
+
+      
+
+        if(empty($userData)){
+            return [];
+        }
+        
+        $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}";
+
+        $unionSql = implode(" UNION ALL ", $sql_parts);
+        // 分页
+        $page = request()->input('page', 1);
+        $limit = request()->input('limit', 10);
+        $offset = ($page - 1) * $limit;
+        $unionSql .= " LIMIT {$offset}, {$limit}";
+        $roleData = Db::connect('db_game_log')->query($unionSql);
+        $count = count($roleData);
+
+        // 合并相同uid的数据,将角色信息放到数组中
+        $mergedData = [];
+        foreach ($roleData as $item) {
+            $uid = $item['uid'];
+            
+            if (!isset($mergedData[$uid])) {
+                // 创建用户基础信息,排除角色相关字段
+                $baseInfo = array_diff_key($item, array_flip(['role_id', 'role_name', 'role_level']));
+                $mergedData[$uid] = $baseInfo + ['roles' => []];
+            }
+            
+            // 添加角色信息到数组
+            $mergedData[$uid]['roles'][] = [
+                'server_name' => $item['server_name'],
+                'role_name' => $item['role_name'],
+                'role_level' => $item['role_level'],
+            ];
+        }
+        
+        // 转换回数组格式
+        $roleData = array_values($mergedData);
+        return [
+            'data'          => $roleData,
+            'current_page'  => $page,
+            'per_page'      => $limit,
+            'last_page'     => ceil($count / $limit),
+            'has_more'      => $page < ceil($count / $limit),
+            'total'         => $count
+        ];
+    }
+
+}

+ 131 - 9
app/v1/logic/gameLog/SdkOrderRankLogic.php

@@ -10,6 +10,7 @@ use plugin\saiadmin\basic\BaseLogic;
 use plugin\saiadmin\exception\ApiException;
 use plugin\saiadmin\utils\Helper;
 use app\v1\model\gameLog\SdkOrderRank;
+use support\think\Db;
 
 /**
  * 充值排行逻辑层
@@ -24,26 +25,147 @@ class SdkOrderRankLogic extends BaseLogic
         $this->model = new SdkOrderRank();
     }
 
-    public function getList($query): mixed
+    public function getList($where): mixed
     {
         $saiType = request()->input('saiType', 'list');
         $page = request()->input('page', 1);
         $limit = request()->input('limit', 10);
         $orderBy = request()->input('orderBy', '');
         $orderType = request()->input('orderType', $this->orderType);
+        
         if(empty($orderBy)) {
-            $orderBy = $this->orderField !== '' ? $this->orderField : $this->model->getPk();
+            $orderBy = 'searchTotalMoney';
         }
-        $query->order($orderBy, $orderType);
-        // 历史累计充值,就是,所有的充值金额。
-        $query->group('user_name,game_id,media_id,agent_id,site_id,uid');
-        $query->field('user_name,sum(money) as searchTotalMoney,game_id,media_id,agent_id,site_id,uid');
+
+        $params = $this->searchByAuth($where);
+
+        
+        $where = [];
+       if(!empty($params['game_id'])){
+            $where[] = ['game_id', 'in', $params['game_id']];
+       }
+       if(!empty($params['auth_id'])){
+            $where[] = ['auth_id', 'in', $params['auth_id']];
+       }
+       if(!empty($params['agent_id'])){
+            $where['agent_id'] = $params['agent_id'];
+       }
+       if(!empty($params['site_id'])){
+            $where['site_id'] = $params['site_id'];
+       }
+       if(!empty($params['server_id'])){
+            $where['server_id'] = $params['server_id'];
+       }
+       if(!empty($params['user_name'])){
+            $where['user_name'] = $params['user_name'];
+       }
+       if(!empty($params['server_name'])){
+            $where['server_name'] = $params['server_name'];
+       }
+       if(!empty($params['reg_date'])){
+            $where['reg_date'] = $params['reg_date'];
+       }
+       if(!empty($params['pay_date'])){
+            $sTime = $params['pay_date'][0] . " 00:00:00";
+            $eTime = $params['pay_date'][1] . " 23:59:59";    
+            $where[] = ['pay_date', 'between', [$sTime, $eTime]];
+       }
+
+
        
+        $rankQuery = Db::connect('db_game_log')->table('sdk_order_success')->where($where);
+
+        $rankQuery->order($orderBy, $orderType);
+        
+        // 显示指定日期范围内的所有充值记录,不按uid和game_id分组
+        $rankQuery->field('user_name,sum(money) as searchTotalMoney,
+            orderid,
+            game_id,
+            media_id,
+            agent_id,
+            site_id,
+            uid,
+            pay_channel_id,
+            auth_id,
+            server_id,
+            server_name,
+            pay_date,
+            reg_date,
+            role_name,
+            role_id');
+
+
         if ($saiType === 'all') {
-            return $query->select()->toArray();
+            return $rankQuery->select()->toArray();
         }
-        return $query->paginate($limit, false, ['page' => $page])->toArray();
         
-    }
+        // 先分组,再分页
+        $rankQuery->group('uid, game_id,site_id,server_id,media_id,auth_id,agent_id,server_id,auth_id,role_id');
+
+        $data = $rankQuery->paginate($limit, false, ['page' => $page])->toArray();
+
+
+
+        print_r($data);
+
+
+        $data['data'] = $this->trandformListColumn($data['data'], ['game','auth', 'agent', 'pay_channel']);
 
+
+        // 告警提示,查询最近登录时间,查询最近充值时间,和现在时间对比,如果超过3天,则告警,并提示
+
+        foreach($data['data'] as &$item){
+            // 最后登录时间
+           $item['login_time'] = Db::connect('db_origin')->table('user_'.$item['uid']%10)->where('uid', $item['uid'])->value('login_time');
+           // 最近注册时间
+           $item['pay_time'] = Db::connect('db_origin')->table('user_'.$item['uid']%10)->where('uid', $item['uid'])->value('pay_time');
+           // 现在时间
+           $item['now_time'] = time();
+
+           // 最近登录时间与现在时间对比,如果超过3天,则告警,并提示
+           if($item['login_time'] < $item['now_time'] - 3 * 24 * 60 * 60){
+            $item['login_alert'] = 1;
+           }else{
+            $item['login_alert'] = 0;
+           }
+           // 最近充值时间与现在时间对比,如果超过3天,则告警,并提示
+           if($item['pay_time'] < $item['now_time'] - 3 * 24 * 60 * 60){
+            $item['pay_alert'] = 1;
+           }else{
+            $item['pay_alert'] = 0;
+           }
+        }
+
+      
+
+
+       
+        $totalWhere = array_filter($where, function($item) {
+            return $item[0] !== 'pay_date';
+        });
+
+        $totalList = Db::connect('db_game_log')->table('sdk_order_success')
+                    ->where($totalWhere)
+                    ->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();
+
+        
+        // 查询累计充值金额(对每一行数据单独查询历史充值金额)
+        $totalMoneyMap = [];
+        if (!empty($data['data']) && !empty($totalList)) {
+            foreach ($totalList as $totalItem) {
+                $key = $totalItem['uid'] . '_' . $totalItem['game_id'];
+                $totalMoneyMap[$key] = $totalItem['totalMoney'] ?? 0;
+            }
+        }
+        
+        // 为搜索结果添加累计充值金额
+        foreach($data['data'] as &$item){
+            $key = $item['uid'] . '_' . $item['game_id'];
+            $item['totalMoney'] = $totalMoneyMap[$key] ?? 0;
+        }
+
+        return $data;
+    }
 }

+ 3 - 1
app/v1/logic/gameLog/SdkOrderSuccessLogic.php

@@ -30,7 +30,9 @@ class SdkOrderSuccessLogic extends BaseLogic
      */
     public function export($where = [])
     {
-        $query = $this->search($where);
+        // 传入的是多选game_id, 转换成字符串
+        $where['game_id'] = is_array($where['game_id']) ? implode(',', $where['game_id']) : $where['game_id'];
+        $query = $this->searchByAuth($where);
         $data = $this->getAll($query);
        
         $data = $this->trandformListColumn($data, ['game', 'ip', 'agent','auth', 'pay_channel']);

+ 49 - 0
app/v1/model/gameLog/RoleData.php

@@ -0,0 +1,49 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\model\gameLog;
+
+use plugin\saiadmin\basic\BaseNormalModel;
+
+/**
+ * 角色数据模型
+ */
+class RoleData extends BaseNormalModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 数据库表名称
+     * @var string
+     */
+    protected $table = 'role_data_and';
+
+    /**
+     * 数据库连接
+     * @var string
+     */
+    protected $connection = 'db_game_log';
+
+    /**
+     * 用户名 搜索
+     */
+    public function searchUserNameAttr($query, $value)
+    {
+        $query->where('user_name', 'like', '%'.$value.'%');
+    }
+
+    /**
+     * 注册时间 搜索
+     */
+    public function searchCreateTimeAttr($query, $value)
+    {
+        $query->where('create_time', '>=', $value . ' 00:00:00')->where('create_time', '<=', $value . ' 23:59:59');
+    }
+}

+ 8 - 7
app/v1/model/gameLog/SdkOrderRank.php

@@ -39,19 +39,20 @@ class SdkOrderRank extends BaseNormalModel
         return json_encode($value, JSON_UNESCAPED_UNICODE);
     }
 
-    /**
-     * 游戏名 读取数组转换
-     */
-    public function getGameIdAttr($value)
-    {
-        return json_decode($value ?? '', true);
-    }
+    // /**
+    //  * 游戏名 读取数组转换
+    //  */
+    // public function getGameIdAttr($value)
+    // {
+    //     return json_decode($value ?? '', true);
+    // }
 
     /**
      * 注册日期 搜索
      */
     public function searchRegDateAttr($query, $value)
     {
+        // $query->whereTime('reg_date', 'between', $value);
          $sTime = strtotime($value[0] . " 00:00:00");
         $eTime = strtotime($value[1] . " 23:59:59");    
         $query->whereTime('reg_date', 'between', [$sTime, $eTime]);

+ 38 - 0
app/v1/validate/gameLog/RoleDataValidate.php

@@ -0,0 +1,38 @@
+<?php
+// +----------------------------------------------------------------------
+// | saiadmin [ saiadmin快速开发框架 ]
+// +----------------------------------------------------------------------
+// | Author: your name
+// +----------------------------------------------------------------------
+namespace app\v1\validate\gameLog;
+
+use think\Validate;
+
+/**
+ * 角色数据验证器
+ */
+class RoleDataValidate extends Validate
+{
+    /**
+     * 定义验证规则
+     */
+    protected $rule =   [
+    ];
+
+    /**
+     * 定义错误信息
+     */
+    protected $message  =   [
+    ];
+
+    /**
+     * 定义场景
+     */
+    protected $scene = [
+        'save' => [
+        ],
+        'update' => [
+        ],
+    ];
+
+}

+ 14 - 13
plugin/saiadmin/basic/BaseLogic.php

@@ -171,6 +171,7 @@ class BaseLogic
         $withSearch = array_keys($searchWhere);
         $data = $searchWhere;
        
+        // 获取游戏权限
         $auth_game_list = request()->header('auth_game_list');
         $auth_normal_game_list = request()->header('auth_normal_game_list');
         $auth_ad_permission = request()->header('auth_ad_permission');
@@ -194,21 +195,21 @@ 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)){
+        //     // 如果传入的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($auth_ad_permission==1){
-            $data['auth_id'] = '';
+            $data['auth_id'] = [];
         }
         // 自己以及下面组员
         if($auth_ad_permission==2){
@@ -219,8 +220,8 @@ class BaseLogic
             $under_user_ids = array_column($under_user_ids, 'id');
             $data['auth_id'] =  $under_user_ids;
         }
-        
-        return $this->model->withSearch($withSearch, $data);
+  
+        return $data;
     }
 
 

BIN
plugin/saiadmin/public/export/充值明细_20250710102759.xlsx