PlayerModel.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model;
  4. use think\Model;
  5. /**
  6. * 商户玩家模型
  7. */
  8. class PlayerModel extends Model
  9. {
  10. // 设置表名
  11. protected $name = 'player';
  12. // 设置主键
  13. protected $pk = 'player_id';
  14. // 设置自动时间戳
  15. protected $autoWriteTimestamp = 'int';
  16. // 设置字段类型
  17. protected $type = [
  18. 'player_id' => 'int',
  19. 'nickname' => 'string',
  20. 'merchant_id' => 'int',
  21. 'reg_ip' => 'string',
  22. 'login_ip' => 'string',
  23. 'today_win_amount' => 'float',
  24. 'history_win_amount' => 'float',
  25. 'today_bet_amount' => 'float',
  26. 'balance' => 'float',
  27. 'today_login_count' => 'int',
  28. 'history_login_count' => 'int',
  29. 'adjust_status' => 'int',
  30. 'status' => 'int',
  31. 'login_time' => 'int',
  32. 'create_time' => 'int',
  33. 'update_time' => 'int',
  34. ];
  35. // 状态常量
  36. const STATUS_NORMAL = 0; // 正常
  37. const STATUS_FROZEN = 1; // 冻结
  38. const STATUS_DELETED = 2; // 删除
  39. // 调控状态常量
  40. const ADJUST_STATUS_NORMAL = 0; // 正常
  41. const ADJUST_STATUS_WIN = 1; // 放水(赢)
  42. const ADJUST_STATUS_LOSE = 2; // 收割(输)
  43. /**
  44. * 获取状态文本
  45. */
  46. public static function getStatusText($status): string
  47. {
  48. $statusMap = [
  49. self::STATUS_NORMAL => '正常',
  50. self::STATUS_FROZEN => '冻结',
  51. self::STATUS_DELETED => '删除',
  52. ];
  53. return $statusMap[$status] ?? '未知';
  54. }
  55. /**
  56. * 获取调控状态文本
  57. */
  58. public static function getAdjustStatusText($adjustStatus): string
  59. {
  60. $adjustStatusMap = [
  61. self::ADJUST_STATUS_NORMAL => '正常',
  62. self::ADJUST_STATUS_WIN => '放水',
  63. self::ADJUST_STATUS_LOSE => '收割',
  64. ];
  65. return $adjustStatusMap[$adjustStatus] ?? '未知';
  66. }
  67. /**
  68. * 根据商户ID获取玩家列表
  69. */
  70. public static function getPlayerListByMerchant($merchantId, $page = 1, $limit = 10, $filters = [])
  71. {
  72. $query = self::where('merchant_id', $merchantId);
  73. // 应用过滤条件
  74. if (!empty($filters['nickname'])) {
  75. $query->where('nickname', 'like', '%' . $filters['nickname'] . '%');
  76. }
  77. if (!empty($filters['player_id'])) {
  78. $query->where('player_id', $filters['player_id']);
  79. }
  80. if (isset($filters['status']) && $filters['status'] !== '') {
  81. $query->where('status', $filters['status']);
  82. }
  83. if (isset($filters['adjust_status']) && $filters['adjust_status'] !== '') {
  84. $query->where('adjust_status', $filters['adjust_status']);
  85. }
  86. if (!empty($filters['login_ip'])) {
  87. $query->where('login_ip', 'like', '%' . $filters['login_ip'] . '%');
  88. }
  89. if (!empty($filters['reg_ip'])) {
  90. $query->where('reg_ip', 'like', '%' . $filters['reg_ip'] . '%');
  91. }
  92. // 登录时间范围
  93. if (!empty($filters['login_time_start'])) {
  94. $query->where('login_time', '>=', strtotime($filters['login_time_start']));
  95. }
  96. if (!empty($filters['login_time_end'])) {
  97. $query->where('login_time', '<=', strtotime($filters['login_time_end']));
  98. }
  99. // 排序
  100. $order = $filters['order'] ?? 'player_id';
  101. $sort = $filters['sort'] ?? 'desc';
  102. $query->order($order, $sort);
  103. // 获取总数
  104. $total = $query->count();
  105. // 获取列表
  106. $list = $query->page($page, $limit)->select();
  107. return [
  108. 'list' => $list,
  109. 'total' => $total,
  110. 'page' => $page,
  111. 'limit' => $limit
  112. ];
  113. }
  114. /**
  115. * 获取玩家详情
  116. */
  117. public static function getPlayerDetail($playerId, $merchantId)
  118. {
  119. return self::where('player_id', $playerId)
  120. ->where('merchant_id', $merchantId)
  121. ->find();
  122. }
  123. /**
  124. * 更新玩家状态
  125. */
  126. public static function updatePlayerStatus($playerIds, $merchantId, $status)
  127. {
  128. return self::where('merchant_id', $merchantId)
  129. ->whereIn('player_id', $playerIds)
  130. ->update(['status' => $status]);
  131. }
  132. /**
  133. * 更新玩家调控状态
  134. */
  135. public static function updatePlayerAdjustStatus($playerIds, $merchantId, $adjustStatus)
  136. {
  137. return self::where('merchant_id', $merchantId)
  138. ->whereIn('player_id', $playerIds)
  139. ->update(['adjust_status' => $adjustStatus]);
  140. }
  141. /**
  142. * 获取玩家统计信息
  143. */
  144. public static function getPlayerStatistics($merchantId)
  145. {
  146. $today = strtotime(date('Y-m-d'));
  147. return [
  148. 'total_players' => self::where('merchant_id', $merchantId)->count(),
  149. 'active_players' => self::where('merchant_id', $merchantId)
  150. ->where('status', self::STATUS_NORMAL)
  151. ->count(),
  152. 'today_new_players' => self::where('merchant_id', $merchantId)
  153. ->where('create_time', '>=', $today)
  154. ->count(),
  155. 'today_login_players' => self::where('merchant_id', $merchantId)
  156. ->where('login_time', '>=', $today)
  157. ->count(),
  158. 'total_balance' => self::where('merchant_id', $merchantId)->sum('balance'),
  159. 'today_bet_amount' => self::where('merchant_id', $merchantId)->sum('today_bet_amount'),
  160. 'today_win_amount' => self::where('merchant_id', $merchantId)->sum('today_win_amount'),
  161. 'history_win_amount' => self::where('merchant_id', $merchantId)->sum('history_win_amount'),
  162. ];
  163. }
  164. }