| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?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
- ];
- }
- }
|