Request::get('title', '', 'trim'), 'game_id' => Request::get('game_id', 0, 'intval'), 'game_platform' => Request::get('game_platform', ''), 'status' => Request::get('status', ''), 'rtp_type' => Request::get('rtp_type', ''), 'free_game_status' => Request::get('free_game_status', ''), 'terminal_spin' => Request::get('terminal_spin', ''), 'rtp_min' => Request::get('rtp_min', 0, 'floatval'), 'rtp_max' => Request::get('rtp_max', 0, 'floatval'), 'max_multiple_min' => Request::get('max_multiple_min', 0, 'intval'), 'max_multiple_max' => Request::get('max_multiple_max', 0, 'intval'), 'create_time_start' => Request::get('create_time_start', '', 'trim'), 'create_time_end' => Request::get('create_time_end', '', 'trim'), 'order' => Request::get('order', 'id', 'trim'), 'sort' => Request::get('sort', 'desc', 'trim'), ]; try { // 获取游戏列表 $result = GameModel::getGameList($page, $limit, $filters); // 处理列表数据 foreach ($result['list'] as &$game) { $game['platform_text'] = GameModel::getPlatformText($game['game_platform']); $game['status_text'] = GameModel::getStatusText($game['status']); $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']); $game['free_game_status_text'] = $game['free_game_status'] ? '支持' : '不支持'; $game['terminal_spin_text'] = $game['terminal_spin'] ? '开启' : '关闭'; $game['create_time_text'] = date('Y-m-d H:i:s', $game['create_time']); $game['update_time_text'] = date('Y-m-d H:i:s', $game['update_time']); // 处理押注配置显示 if (!empty($game['deposit_list'])) { $depositList = $game['deposit_list']; if (is_array($depositList)) { $game['deposit_list_text'] = implode(', ', $depositList); } else { $game['deposit_list_text'] = $depositList; } } else { $game['deposit_list_text'] = '未设置'; } } return json_success($result, '获取成功'); } catch (\Exception $e) { return json_error([], '获取游戏列表失败:' . $e->getMessage()); } } /** * 获取游戏详情 */ public function detail() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'detail')) { return json_error([], '没有查看游戏详情的权限'); } $id = Request::get('id', 0, 'intval'); if (!$id) { return json_error([], '游戏ID不能为空'); } try { $game = GameModel::getGameDetail($id); if (!$game) { return json_error([], '游戏不存在'); } // 添加文本字段 $game['platform_text'] = GameModel::getPlatformText($game['game_platform']); $game['status_text'] = GameModel::getStatusText($game['status']); $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']); $game['free_game_status_text'] = $game['free_game_status'] ? '支持' : '不支持'; $game['terminal_spin_text'] = $game['terminal_spin'] ? '开启' : '关闭'; $game['create_time_text'] = date('Y-m-d H:i:s', $game['create_time']); $game['update_time_text'] = date('Y-m-d H:i:s', $game['update_time']); return json_success($game, '获取成功'); } catch (\Exception $e) { return json_error([], '获取游戏详情失败:' . $e->getMessage()); } } /** * 创建游戏 */ public function create() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'create')) { return json_error([], '没有创建游戏的权限'); } $data = Request::only([ 'game_platform', 'game_id', 'title', 'title_en', 'image', 'image_en', 'rtp', 'rtp_type', 'free_game_status', 'bet_line_count', 'bet_max_level', 'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level', 'min_deposit', 'terminal_spin', 'status' ]); // 验证必填字段 if (empty($data['game_platform'])) { return json_error([], '游戏平台不能为空'); } if (empty($data['game_id'])) { return json_error([], '游戏ID不能为空'); } if (empty($data['title'])) { return json_error([], '游戏名称不能为空'); } // 检查游戏ID是否已存在 if (GameModel::checkGameIdExists($data['game_id'])) { return json_error([], '游戏ID已存在'); } try { $game = GameModel::createGame($data); return json_success(['id' => $game->id], '创建游戏成功'); } catch (\Exception $e) { return json_error([], '创建游戏失败:' . $e->getMessage()); } } /** * 更新游戏 */ public function update() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'update')) { return json_error([], '没有更新游戏的权限'); } $id = Request::post('id', 0, 'intval'); if (!$id) { return json_error([], '游戏ID不能为空'); } $data = Request::only([ 'game_platform', 'game_id', 'title', 'title_en', 'image', 'image_en', 'rtp', 'rtp_type', 'free_game_status', 'bet_line_count', 'bet_max_level', 'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level', 'min_deposit', 'terminal_spin', 'status' ]); // 验证必填字段 if (empty($data['title'])) { return json_error([], '游戏名称不能为空'); } // 检查游戏是否存在 $game = GameModel::getGameDetail($id); if (!$game) { return json_error([], '游戏不存在'); } // 如果修改了游戏ID,检查是否与其他游戏冲突 if (isset($data['game_id']) && $data['game_id'] != $game['game_id']) { if (GameModel::checkGameIdExists($data['game_id'], $id)) { return json_error([], '游戏ID已存在'); } } try { GameModel::updateGame($id, $data); return json_success([], '更新游戏成功'); } catch (\Exception $e) { return json_error([], '更新游戏失败:' . $e->getMessage()); } } /** * 更新游戏状态 */ public function updateStatus() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'updateStatus')) { return json_error([], '没有更新游戏状态的权限'); } $id = Request::post('id', 0, 'intval'); $status = Request::post('status', 0, 'intval'); if (!$id) { return json_error([], '游戏ID不能为空'); } if (!in_array($status, [ GameModel::STATUS_NORMAL, GameModel::STATUS_MAINTAIN, GameModel::STATUS_DISABLED ])) { return json_error([], '状态值无效'); } try { $result = GameModel::updateGameStatus($id, $status); if ($result) { return json_success([], '状态更新成功'); } else { return json_error([], '状态更新失败'); } } catch (\Exception $e) { return json_error([], '更新游戏状态失败:' . $e->getMessage()); } } /** * 批量更新游戏状态 */ public function batchUpdateStatus() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'batchUpdate')) { return json_error([], '没有批量更新游戏状态的权限'); } $ids = Request::post('ids', []); $status = Request::post('status', 0, 'intval'); if (empty($ids) || !is_array($ids)) { return json_error([], '请选择要更新的游戏'); } if (!in_array($status, [ GameModel::STATUS_NORMAL, GameModel::STATUS_MAINTAIN, GameModel::STATUS_DISABLED ])) { return json_error([], '状态值无效'); } try { $result = GameModel::batchUpdateStatus($ids, $status); if ($result > 0) { return json_success(['updated' => $result], '批量更新成功'); } else { return json_error([], '批量更新失败'); } } catch (\Exception $e) { return json_error([], '批量更新游戏状态失败:' . $e->getMessage()); } } /** * 获取游戏统计信息 */ public function statistics() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'statistics')) { return json_error([], '没有查看游戏统计的权限'); } try { $statistics = GameModel::getGameStatistics(); return json_success($statistics, '获取成功'); } catch (\Exception $e) { return json_error([], '获取游戏统计失败:' . $e->getMessage()); } } /** * 获取游戏平台列表 */ public function getPlatforms() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } try { $platforms = GameModel::getAllPlatforms(); return json_success($platforms, '获取成功'); } catch (\Exception $e) { return json_error([], '获取游戏平台失败:' . $e->getMessage()); } } /** * 删除游戏 */ public function delete() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'delete')) { return json_error([], '没有删除游戏的权限'); } $id = Request::post('id', 0, 'intval'); if (!$id) { return json_error([], '游戏ID不能为空'); } try { // 检查游戏是否存在 $game = GameModel::getGameDetail($id); if (!$game) { return json_error([], '游戏不存在'); } // 删除游戏 GameModel::where('id', $id)->delete(); return json_success([], '删除成功'); } catch (\Exception $e) { return json_error([], '删除游戏失败:' . $e->getMessage()); } } /** * 导出游戏列表 */ public function export() { $loginInfo = checkUserLogin(); if (!$loginInfo) { return json_error([], '请先登录'); } if (!checkPermission($loginInfo, 'Game', 'export')) { return json_error([], '没有导出游戏列表的权限'); } // 获取所有过滤条件 $filters = [ 'title' => Request::get('title', '', 'trim'), 'game_id' => Request::get('game_id', 0, 'intval'), 'game_platform' => Request::get('game_platform', ''), 'status' => Request::get('status', ''), 'rtp_type' => Request::get('rtp_type', ''), 'free_game_status' => Request::get('free_game_status', ''), 'terminal_spin' => Request::get('terminal_spin', ''), 'rtp_min' => Request::get('rtp_min', 0, 'floatval'), 'rtp_max' => Request::get('rtp_max', 0, 'floatval'), 'max_multiple_min' => Request::get('max_multiple_min', 0, 'intval'), 'max_multiple_max' => Request::get('max_multiple_max', 0, 'intval'), 'create_time_start' => Request::get('create_time_start', '', 'trim'), 'create_time_end' => Request::get('create_time_end', '', 'trim'), ]; try { // 获取所有数据 $result = GameModel::getGameList(1, 100000, $filters); // 生成CSV数据 $csvData = "ID,游戏ID,游戏平台,中文名称,英文名称,RTP,RTP类型,免费游戏,下注线数,最高倍数,默认押注,最低押注,止损止赢,状态,创建时间\n"; foreach ($result['list'] as $game) { $csvData .= sprintf( "%d,%d,%s,%s,%s,%.2f,%s,%s,%d,%d,%.2f,%.2f,%s,%s,%s\n", $game['id'], $game['game_id'], GameModel::getPlatformText($game['game_platform']), $game['title'], $game['title_en'], $game['rtp'], GameModel::getRtpTypeText($game['rtp_type']), $game['free_game_status'] ? '支持' : '不支持', $game['bet_line_count'], $game['max_multiple_count'], $game['default_deposit'], $game['min_deposit'], $game['terminal_spin'] ? '开启' : '关闭', GameModel::getStatusText($game['status']), date('Y-m-d H:i:s', $game['create_time']) ); } // 返回CSV数据 return response($csvData) ->header('Content-Type', 'text/csv; charset=utf-8') ->header('Content-Disposition', 'attachment; filename="games_' . date('YmdHis') . '.csv"') ->header('Cache-Control', 'no-cache, must-revalidate'); } catch (\Exception $e) { return json_error([], '导出游戏列表失败:' . $e->getMessage()); } } }