소스 검색

update:玩家列表增加数据字段

aiden 2 달 전
부모
커밋
171d64d631
5개의 변경된 파일143개의 추가작업 그리고 198개의 파일을 삭제
  1. 45 2
      app/model/GameBetGameModel.php
  2. 1 1
      app/model/MerchantsUserBalanceModel.php
  3. 20 4
      app/model/MerchantsUserModel.php
  4. 77 0
      app/model/PlayerLoginLogModel.php
  5. 0 191
      app/model/PlayerModel.php

+ 45 - 2
app/model/GameBetGameModel.php

@@ -313,12 +313,12 @@ class GameBetGameModel extends Model
         // 时间筛选
         if (!empty($filters['start_time'])) {
             $startTime = strtotime($filters['start_time']);
-            $where[] = ['create_time', '>=', $startTime . ' 00:00:00'];
+            $where[] = ['create_time', '>=', $startTime];
         }
         
         if (!empty($filters['end_time'])) {
             $endTime = strtotime($filters['end_time']);
-            $where[] = ['create_time', '<=', $endTime . ' 23:59:59'];
+            $where[] = ['create_time', '<=', $endTime];
         }
 
         if (!empty($filters['game_id'])) {
@@ -342,7 +342,50 @@ class GameBetGameModel extends Model
         return $list;
     }
 
+    /**
+     * 获取用户汇总数据
+     */
+    public static function getGameUserSummary($merchantId, $filters = [])
+    {
+        $where = [
+            ['app_id', '=', $merchantId],
+            ['action_type', '=', 1],
+        ];
+        
+        // 时间筛选
+        if (!empty($filters['start_time'])) {
+            $where[] = ['create_time', '>=', $filters['start_time']];
+        }
+        
+        if (!empty($filters['end_time'])) {
+            $where[] = ['create_time', '<=', $filters['end_time']];
+        }
 
+        if (!empty($filters['game_id'])) {
+            $gameId = is_array($filters['game_id']) ? $filters['game_id'] : explode(',', $filters['game_id']);
+            $where[] = ['game_id', 'in', $gameId];
+        }
+
+        if (!empty($filters['user_ids'])) {
+            $userIds = is_array($filters['user_ids']) ? $filters['user_ids'] : explode(',', $filters['user_ids']);
+            $where[] = ['user_id', 'in', $userIds];
+        }        
+
+        $list = self::field([
+                "user_id", // 用户id
+                'COUNT(DISTINCT uname) as bet_users',  // 投注用户数
+                'COUNT(id) as bet_count',  // 注单数
+                'SUM(bet) as bet_amount',  // 注单金额(下注分数)
+                'SUM(total_win_amount) as game_profit',  // 游戏输赢(金额变化)
+                'SUM(is_buy_game) as buy_free_bet_count'
+        ])
+        ->where($where)
+        ->group('user_id')
+        ->select()
+        ->toArray();
+
+        return $list;
+    }    
 
     public static function getBuyBetGameList($appId, $filters = []) {
         $where = [

+ 1 - 1
app/model/MerchantsUserBalanceModel.php

@@ -26,7 +26,7 @@ class MerchantsUserBalanceModel extends Model {
         'user_id'     => 'int', // 用户ID
         'app_id'      => 'int', // 商家ID
         'uname'       => 'int', // 平台用户的id 必须唯一
-        'balance'     => 'decimal', // 分数 分 * 100
+        'balance'     => 'decimal', // 分数
         'hash'        => 'string', // 分数 校验
         'create_time' => 'int', // 创建时间
         'update_time' => 'int', // 更新时间

+ 20 - 4
app/model/MerchantsUserModel.php

@@ -4,6 +4,8 @@ declare (strict_types = 1);
 namespace app\model;
 
 use think\Model;
+use app\model\PlayerLoginLogModel;
+use app\model\GameBetGameModel;
 
 /**
  * 商户用户模型 - 连接到fortue_tiger数据库的tp_merchants_user表
@@ -165,19 +167,33 @@ class MerchantsUserModel extends Model
 
         $user_ids = array_column($list, 'user_id');
 
+        // 获取余额
         $userBalanceConfig = MerchantsUserBalanceModel::getUsersBalanceList($merchantId, $user_ids);
+        // 获取今日登录次数
+        $loginFilter = [
+            'start_time' => strtotime(date('Y-m-d')),
+            'end_time' => strtotime(date('Y-m-d') . " +1 day"),
+        ];
+        $loginCount = PlayerLoginLogModel::getLoginCount($merchantId, $user_ids, $loginFilter);
+        $betGameFilter = [
+            'start_time' => strtotime(date('Y-m-d')),
+            'end_time' => strtotime(date('Y-m-d') . " +1 day"),
+            'user_ids' => $user_ids,
+        ];        
+        // 获取今日输赢、今日下注
+        $betGameSummary = GameBetGameModel::getGameUserSummary($merchantId, $betGameFilter);
         
         // 转换字段名以保持与原有接口的兼容性
         foreach ($list as &$item) {
             $userBalanceInfo = $userBalanceConfig[$item['user_id']] ?? [];
             $item['merchant_id'] = $item['app_id'];
-            $item['today_login_count'] = $item['today_count'];
+            $item['today_login_count'] = $loginCount[$item['user_id']]['count'] ?? 0;
             $item['history_login_count'] = $item['history_day_count'];
             // 添加原系统中可能需要但新表中没有的字段
             $item['balance'] =  $userBalanceInfo['balance'] ?? 0;
-            $item['today_win_amount'] = 0;
-            $item['history_win_amount'] = 0;
-            $item['today_bet_amount'] = 0;
+            $item['today_win_amount'] = $betGameSummary['game_profit'] ?? 0;
+            $item['history_win_amount'] = (float)$item['total_win_amount'];
+            $item['today_bet_amount'] = $betGameSummary['bet_amount'] ?? 0;;
 
             // 移除字段
             unset($item['app_id']);

+ 77 - 0
app/model/PlayerLoginLogModel.php

@@ -0,0 +1,77 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+use think\Model;
+
+/**
+ * 玩家登录日志模型
+ */
+class PlayerLoginLogModel extends Model
+{
+    // 设置数据库连接
+    protected $connection = 'fortue_tiger';    
+    // 设置表名
+    protected $name = 'player_login_log';
+
+    // 设置主键
+    protected $pk = 'id';
+
+    // 设置自动时间戳
+    protected $autoWriteTimestamp = 'int';
+
+    // 设置字段类型
+    protected $type = [
+        'merchant_id' => 'int',
+        'player_id' => 'int',
+        'game_id' => 'int',
+        'game_platform' => 'string',
+        'login_ip' => 'string',
+        'login_time' => 'int',
+        'login_status' => 'int',
+    ];
+
+    /**
+     * 获取玩家登录次数
+     */
+    public static function getLoginCount($merchant_id, $player_ids, $filter = []) {
+        // 支持单个或多个player_id
+        $player_ids = is_array($player_ids) ? $player_ids : [$player_ids];
+        
+        $query = self::where('merchant_id', $merchant_id)
+                     ->whereIn('player_id', $player_ids);
+        
+        // 处理可选过滤条件
+        if (!empty($filter['game_id'])) {
+            $query->where('game_id', $filter['game_id']);
+        }
+        
+        if (!empty($filter['game_platform'])) {
+            $query->where('game_platform', $filter['game_platform']);
+        }
+        
+        if (!empty($filter['login_status'])) {
+            $query->where('login_status', $filter['login_status']);
+        }
+        
+        if (!empty($filter['start_time'])) {
+            $query->where('login_time', '>=', $filter['start_time']);
+        }
+        
+        if (!empty($filter['end_time'])) {
+            $query->where('login_time', '<=', $filter['end_time']);
+        }
+        
+        if (!empty($filter['login_ip'])) {
+            $query->where('login_ip', $filter['login_ip']);
+        }
+        
+        // 按player_id分组统计
+        $result = $query->field('player_id, COUNT(*) as count')
+                       ->group('player_id')
+                       ->select()
+                       ->toArray();
+        return array_column($result, null, 'player_id');
+    }
+}

+ 0 - 191
app/model/PlayerModel.php

@@ -1,191 +0,0 @@
-<?php
-declare (strict_types = 1);
-
-namespace app\model;
-
-use think\Model;
-
-/**
- * 商户玩家模型
- */
-class PlayerModel extends Model
-{
-    // 设置表名
-    protected $name = 'player';
-
-    // 设置主键
-    protected $pk = 'player_id';
-
-    // 设置自动时间戳
-    protected $autoWriteTimestamp = 'int';
-
-    // 设置字段类型
-    protected $type = [
-        'player_id' => 'int',
-        'nickname' => 'string',
-        'merchant_id' => 'int',
-        'reg_ip' => 'string',
-        'login_ip' => 'string',
-        'today_win_amount' => 'float',
-        'history_win_amount' => 'float',
-        'today_bet_amount' => 'float',
-        'balance' => 'float',
-        'today_login_count' => 'int',
-        'history_login_count' => 'int',
-        'adjust_status' => 'int',
-        'status' => 'int',
-        'login_time' => 'int',
-        'create_time' => 'int',
-        'update_time' => 'int',
-    ];
-
-    // 状态常量
-    const STATUS_NORMAL = 0;    // 正常
-    const STATUS_FROZEN = 1;    // 冻结
-    const STATUS_DELETED = 2;   // 删除
-
-    // 调控状态常量
-    const ADJUST_STATUS_NORMAL = 0;     // 正常
-    const ADJUST_STATUS_WIN = 1;        // 放水(赢)
-    const ADJUST_STATUS_LOSE = 2;       // 收割(输)
-
-    /**
-     * 获取状态文本
-     */
-    public static function getStatusText($status): string
-    {
-        $statusMap = [
-            self::STATUS_NORMAL => '正常',
-            self::STATUS_FROZEN => '冻结',
-            self::STATUS_DELETED => '删除',
-        ];
-        return $statusMap[$status] ?? '未知';
-    }
-
-    /**
-     * 获取调控状态文本
-     */
-    public static function getAdjustStatusText($adjustStatus): string
-    {
-        $adjustStatusMap = [
-            self::ADJUST_STATUS_NORMAL => '正常',
-            self::ADJUST_STATUS_WIN => '放水',
-            self::ADJUST_STATUS_LOSE => '收割',
-        ];
-        return $adjustStatusMap[$adjustStatus] ?? '未知';
-    }
-
-    /**
-     * 根据商户ID获取玩家列表
-     */
-    public static function getPlayerListByMerchant($merchantId, $page = 1, $limit = 10, $filters = [])
-    {
-        $query = self::where('merchant_id', $merchantId);
-
-        // 应用过滤条件
-        if (!empty($filters['nickname'])) {
-            $query->where('nickname', 'like', '%' . $filters['nickname'] . '%');
-        }
-
-        if (!empty($filters['player_id'])) {
-            $query->where('player_id', $filters['player_id']);
-        }
-
-        if (isset($filters['status']) && $filters['status'] !== '') {
-            $query->where('status', $filters['status']);
-        }
-
-        if (isset($filters['adjust_status']) && $filters['adjust_status'] !== '') {
-            $query->where('adjust_status', $filters['adjust_status']);
-        }
-
-        if (!empty($filters['login_ip'])) {
-            $query->where('login_ip', 'like', '%' . $filters['login_ip'] . '%');
-        }
-
-        if (!empty($filters['reg_ip'])) {
-            $query->where('reg_ip', 'like', '%' . $filters['reg_ip'] . '%');
-        }
-
-        // 登录时间范围
-        if (!empty($filters['login_time_start'])) {
-            $query->where('login_time', '>=', strtotime($filters['login_time_start']));
-        }
-        if (!empty($filters['login_time_end'])) {
-            $query->where('login_time', '<=', strtotime($filters['login_time_end']));
-        }
-
-        // 排序
-        $order = $filters['order'] ?? 'player_id';
-        $sort = $filters['sort'] ?? 'desc';
-        $query->order($order, $sort);
-
-        // 获取总数
-        $total = $query->count();
-
-        // 获取列表
-        $list = $query->page($page, $limit)->select();
-
-        return [
-            'list' => $list,
-            'total' => $total,
-            'page' => $page,
-            'limit' => $limit
-        ];
-    }
-
-    /**
-     * 获取玩家详情
-     */
-    public static function getPlayerDetail($playerId, $merchantId)
-    {
-        return self::where('player_id', $playerId)
-            ->where('merchant_id', $merchantId)
-            ->find();
-    }
-
-    /**
-     * 更新玩家状态
-     */
-    public static function updatePlayerStatus($playerIds, $merchantId, $status)
-    {
-        return self::where('merchant_id', $merchantId)
-            ->whereIn('player_id', $playerIds)
-            ->update(['status' => $status]);
-    }
-
-    /**
-     * 更新玩家调控状态
-     */
-    public static function updatePlayerAdjustStatus($playerIds, $merchantId, $adjustStatus)
-    {
-        return self::where('merchant_id', $merchantId)
-            ->whereIn('player_id', $playerIds)
-            ->update(['adjust_status' => $adjustStatus]);
-    }
-
-    /**
-     * 获取玩家统计信息
-     */
-    public static function getPlayerStatistics($merchantId)
-    {
-        $today = strtotime(date('Y-m-d'));
-
-        return [
-            'total_players' => self::where('merchant_id', $merchantId)->count(),
-            'active_players' => self::where('merchant_id', $merchantId)
-                ->where('status', self::STATUS_NORMAL)
-                ->count(),
-            'today_new_players' => self::where('merchant_id', $merchantId)
-                ->where('create_time', '>=', $today)
-                ->count(),
-            'today_login_players' => self::where('merchant_id', $merchantId)
-                ->where('login_time', '>=', $today)
-                ->count(),
-            'total_balance' => self::where('merchant_id', $merchantId)->sum('balance'),
-            'today_bet_amount' => self::where('merchant_id', $merchantId)->sum('today_bet_amount'),
-            'today_win_amount' => self::where('merchant_id', $merchantId)->sum('today_win_amount'),
-            'history_win_amount' => self::where('merchant_id', $merchantId)->sum('history_win_amount'),
-        ];
-    }
-}