|
|
@@ -0,0 +1,349 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\controller;
|
|
|
+
|
|
|
+use app\BaseController;
|
|
|
+use think\facade\Request;
|
|
|
+use app\model\GameRecordModel;
|
|
|
+use app\model\GameModel;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 游戏记录控制器
|
|
|
+ */
|
|
|
+class GameRecord extends BaseController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 获取游戏记录列表
|
|
|
+ */
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ // 获取查询参数
|
|
|
+ $page = Request::get('page', 1, 'intval');
|
|
|
+ $limit = Request::get('limit', 20, 'intval');
|
|
|
+
|
|
|
+ // 筛选条件
|
|
|
+ $filters = [
|
|
|
+ // 时间筛选
|
|
|
+ 'start_time' => Request::get('start_time', '', 'trim'),
|
|
|
+ 'end_time' => Request::get('end_time', '', 'trim'),
|
|
|
+ // 游戏品牌筛选(这里使用user_id作为平台ID)
|
|
|
+ 'platform_id' => Request::get('platform_id', '', 'trim'),
|
|
|
+ // 游戏筛选
|
|
|
+ 'game_id' => Request::get('game_id', '', 'trim'),
|
|
|
+ // 玩家状态筛选
|
|
|
+ 'play_status' => Request::get('play_status', ''),
|
|
|
+ // 玩法筛选
|
|
|
+ 'play_method' => Request::get('play_method', '', 'trim'),
|
|
|
+ // 触发方式筛选
|
|
|
+ 'trigger_method' => Request::get('trigger_method', '', 'trim'),
|
|
|
+ // 牌局编号筛选
|
|
|
+ 'round_number' => Request::get('round_number', '', 'trim'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = GameRecordModel::getGameRecords($userInfo['merchant_id'], $page, $limit, $filters);
|
|
|
+
|
|
|
+ // 获取游戏信息映射
|
|
|
+ $gameIds = array_unique(array_column($result['list'], 'game_id'));
|
|
|
+ $gameInfoMap = $this->getGameInfoMap($gameIds, $userInfo['merchant_id']);
|
|
|
+
|
|
|
+ // 添加游戏名称和图标到结果中
|
|
|
+ foreach ($result['list'] as &$item) {
|
|
|
+ $gameInfo = $gameInfoMap[$item['game_id']] ?? null;
|
|
|
+ $item['game_name'] = $gameInfo ? $gameInfo['title'] : $item['game_id'];
|
|
|
+ $item['game_name_en'] = $gameInfo ? $gameInfo['title_en'] : '';
|
|
|
+ $item['game_icon'] = $gameInfo ? $gameInfo['image'] : '';
|
|
|
+ $item['game_icon_en'] = $gameInfo ? $gameInfo['image_en'] : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success($result, '获取成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '获取游戏记录失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏记录详情
|
|
|
+ */
|
|
|
+ public function detail()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ $id = Request::get('id', 0, 'intval');
|
|
|
+ if (!$id) {
|
|
|
+ return json_error([], '记录ID不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $record = GameRecordModel::getGameRecordDetail($id, $userInfo['merchant_id']);
|
|
|
+
|
|
|
+ if (!$record) {
|
|
|
+ return json_error([], '记录不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取游戏信息
|
|
|
+ $gameInfo = GameModel::where('game_id', $record['game_id'])
|
|
|
+ ->where('merchant_id', $userInfo['merchant_id'])
|
|
|
+ ->field(['title', 'title_en', 'image', 'image_en'])
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ if ($gameInfo) {
|
|
|
+ $record['game_name'] = $gameInfo['title'];
|
|
|
+ $record['game_name_en'] = $gameInfo['title_en'];
|
|
|
+ $record['game_icon'] = $gameInfo['image'];
|
|
|
+ $record['game_icon_en'] = $gameInfo['image_en'];
|
|
|
+ } else {
|
|
|
+ $record['game_name'] = $record['game_id'];
|
|
|
+ $record['game_name_en'] = '';
|
|
|
+ $record['game_icon'] = '';
|
|
|
+ $record['game_icon_en'] = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success($record, '获取成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '获取记录详情失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏统计信息
|
|
|
+ */
|
|
|
+ public function statistics()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ // 筛选条件
|
|
|
+ $filters = [
|
|
|
+ 'start_time' => Request::get('start_time', '', 'trim'),
|
|
|
+ 'end_time' => Request::get('end_time', '', 'trim'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 如果没有指定时间范围,默认获取今天
|
|
|
+ if (empty($filters['start_time']) && empty($filters['end_time'])) {
|
|
|
+ $filters['start_time'] = date('Y-m-d');
|
|
|
+ $filters['end_time'] = date('Y-m-d');
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $statistics = GameRecordModel::getGameStatistics($userInfo['merchant_id'], $filters);
|
|
|
+
|
|
|
+ return json_success([
|
|
|
+ 'statistics' => $statistics,
|
|
|
+ 'date_range' => [
|
|
|
+ 'start_time' => $filters['start_time'],
|
|
|
+ 'end_time' => $filters['end_time']
|
|
|
+ ]
|
|
|
+ ], '获取成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '获取统计信息失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏列表(用于筛选下拉框)
|
|
|
+ */
|
|
|
+ public function getGames()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ try {
|
|
|
+ $gameIds = GameRecordModel::getAllGameIds($userInfo['merchant_id']);
|
|
|
+
|
|
|
+ // 从GameModel获取游戏详细信息
|
|
|
+ $gameInfos = GameModel::whereIn('game_id', $gameIds)
|
|
|
+ ->where('merchant_id', $userInfo['merchant_id'])
|
|
|
+ ->field(['game_id', 'title', 'title_en', 'image', 'image_en'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // 创建游戏ID到游戏信息的映射
|
|
|
+ $gameMap = [];
|
|
|
+ foreach ($gameInfos as $gameInfo) {
|
|
|
+ $gameMap[$gameInfo['game_id']] = $gameInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建游戏列表
|
|
|
+ $games = [];
|
|
|
+ foreach ($gameIds as $gameId) {
|
|
|
+ if (isset($gameMap[$gameId])) {
|
|
|
+ $games[] = [
|
|
|
+ 'game_id' => $gameId,
|
|
|
+ 'game_name' => $gameMap[$gameId]['title'],
|
|
|
+ 'game_name_en' => $gameMap[$gameId]['title_en'],
|
|
|
+ 'game_icon' => $gameMap[$gameId]['image'],
|
|
|
+ 'game_icon_en' => $gameMap[$gameId]['image_en']
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $games[] = [
|
|
|
+ 'game_id' => $gameId,
|
|
|
+ 'game_name' => $this->getGameName($gameId),
|
|
|
+ 'game_name_en' => '',
|
|
|
+ 'game_icon' => '',
|
|
|
+ 'game_icon_en' => ''
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success($games, '获取成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '获取游戏列表失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取玩法列表(用于筛选下拉框)
|
|
|
+ */
|
|
|
+ public function getPlayMethods()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ try {
|
|
|
+ $playMethods = GameRecordModel::getAllPlayMethods($userInfo['merchant_id']);
|
|
|
+
|
|
|
+ // 构建玩法列表
|
|
|
+ $methods = [];
|
|
|
+ foreach ($playMethods as $method) {
|
|
|
+ $methods[] = [
|
|
|
+ 'method_id' => $method,
|
|
|
+ 'method_name' => $this->getPlayMethodName($method)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success($methods, '获取成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '获取玩法列表失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出游戏记录
|
|
|
+ */
|
|
|
+ public function export()
|
|
|
+ {
|
|
|
+ $userInfo = $this->request->userInfo;
|
|
|
+
|
|
|
+ // 筛选条件
|
|
|
+ $filters = [
|
|
|
+ 'start_time' => Request::get('start_time', '', 'trim'),
|
|
|
+ 'end_time' => Request::get('end_time', '', 'trim'),
|
|
|
+ 'platform_id' => Request::get('platform_id', '', 'trim'),
|
|
|
+ 'game_id' => Request::get('game_id', '', 'trim'),
|
|
|
+ 'play_status' => Request::get('play_status', ''),
|
|
|
+ 'play_method' => Request::get('play_method', '', 'trim'),
|
|
|
+ 'trigger_method' => Request::get('trigger_method', '', 'trim'),
|
|
|
+ 'round_number' => Request::get('round_number', '', 'trim'),
|
|
|
+ ];
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取所有符合条件的数据(不分页)
|
|
|
+ $result = GameRecordModel::getGameRecords($userInfo['merchant_id'], 1, 100000, $filters);
|
|
|
+
|
|
|
+ // 获取游戏信息映射
|
|
|
+ $gameIds = array_unique(array_column($result['list'], 'game_id'));
|
|
|
+ $gameInfoMap = $this->getGameInfoMap($gameIds, $userInfo['merchant_id']);
|
|
|
+
|
|
|
+ // 生成CSV数据
|
|
|
+ $csvData = "序号,父局号,牌局ID,创建时间,牌局编号,平台昵称,玩家ID,所属商户," .
|
|
|
+ "平台ID,游戏名称,游戏玩法,调控状态,免费触发,RTP,下注金额," .
|
|
|
+ "应下注,应返奖,玩家输赢,下注前,结算后,总输赢,最后结算金额,操作\n";
|
|
|
+
|
|
|
+ foreach ($result['list'] as $index => $record) {
|
|
|
+ $gameInfo = $gameInfoMap[$record['game_id']] ?? null;
|
|
|
+ $gameName = $gameInfo ? $gameInfo['title'] : $this->getGameName($record['game_id']);
|
|
|
+
|
|
|
+ $csvData .= sprintf(
|
|
|
+ "%d,%s,%s,%s,%s,%s,%d,%s,%d,%s,%s,%s,%s,%s,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%s\n",
|
|
|
+ $index + 1, // 序号
|
|
|
+ $record['third_gid'], // 父局号
|
|
|
+ $record['id'], // 牌局ID
|
|
|
+ $record['create_time_text'], // 创建时间
|
|
|
+ $record['third_round_id'], // 牌局编号
|
|
|
+ $record['nickname'], // 平台昵称
|
|
|
+ $record['uname'], // 玩家ID
|
|
|
+ $userInfo['merchant_id'], // 所属商户
|
|
|
+ $record['user_id'], // 平台ID
|
|
|
+ $gameName, // 游戏名称
|
|
|
+ $this->getPlayMethodName($record['bet_game_play_type']), // 游戏玩法
|
|
|
+ $record['status_text'], // 调控状态
|
|
|
+ '', // 免费触发(暂时为空)
|
|
|
+ '', // RTP(暂时为空)
|
|
|
+ $record['bet_amount_yuan'], // 下注金额
|
|
|
+ 0.00, // 应下注
|
|
|
+ 0.00, // 应返奖
|
|
|
+ $record['amount_yuan'], // 玩家输赢
|
|
|
+ $record['prev_amount_yuan'], // 下注前
|
|
|
+ $record['next_amount_yuan'], // 结算后
|
|
|
+ $record['amount_yuan'], // 总输赢
|
|
|
+ $record['balance_amount_yuan'], // 最后结算金额
|
|
|
+ $record['action_type_text'] // 操作
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回CSV数据
|
|
|
+ return response($csvData)
|
|
|
+ ->header(['Content-Type' => 'text/csv; charset=utf-8'])
|
|
|
+ ->header(['Content-Disposition' => 'attachment; filename="game_records_' . date('YmdHis') . '.csv"'])
|
|
|
+ ->header(['Cache-Control' => 'no-cache, must-revalidate']);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_error([], '导出游戏记录失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏名称
|
|
|
+ */
|
|
|
+ private function getGameName($gameId)
|
|
|
+ {
|
|
|
+ // 这里可以根据实际情况配置游戏ID对应的名称
|
|
|
+ $gameNames = [
|
|
|
+ 'tiger' => '老虎机',
|
|
|
+ 'fortune_tiger' => '财富老虎',
|
|
|
+ // 可以继续添加其他游戏
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $gameNames[$gameId] ?? $gameId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取玩法名称
|
|
|
+ */
|
|
|
+ private function getPlayMethodName($methodId)
|
|
|
+ {
|
|
|
+ // 这里可以根据实际情况配置玩法ID对应的名称
|
|
|
+ $methodNames = [
|
|
|
+ 1 => '普通模式',
|
|
|
+ 2 => '免费模式',
|
|
|
+ 3 => '特殊模式',
|
|
|
+ // 可以继续添加其他玩法
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $methodNames[$methodId] ?? '未知玩法';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取游戏信息映射
|
|
|
+ */
|
|
|
+ private function getGameInfoMap($gameIds, $merchantId)
|
|
|
+ {
|
|
|
+ if (empty($gameIds)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $gameInfos = GameModel::whereIn('game_id', $gameIds)
|
|
|
+ ->where('merchant_id', $merchantId)
|
|
|
+ ->field(['game_id', 'title', 'title_en', 'image', 'image_en'])
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $map = [];
|
|
|
+ foreach ($gameInfos as $gameInfo) {
|
|
|
+ $map[$gameInfo['game_id']] = $gameInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $map;
|
|
|
+ }
|
|
|
+}
|