|
|
@@ -14,6 +14,9 @@ class Game extends BaseController
|
|
|
*/
|
|
|
public function list()
|
|
|
{
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
// 获取查询参数
|
|
|
$page = Request::get('page', 1, 'intval');
|
|
|
$limit = Request::get('limit', 10, 'intval');
|
|
|
@@ -24,44 +27,18 @@ class Game extends BaseController
|
|
|
'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);
|
|
|
+ $result = GameModel::getGameList($userInfo['merchant_id'], $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, '获取成功');
|
|
|
@@ -75,107 +52,72 @@ class Game extends BaseController
|
|
|
*/
|
|
|
public function detail()
|
|
|
{
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
$id = Request::get('id', 0, 'intval');
|
|
|
if (!$id) {
|
|
|
return json_error([], '游戏ID不能为空');
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $game = GameModel::getGameDetail($id);
|
|
|
+ $game = GameModel::getGameDetail($id, $userInfo['merchant_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()
|
|
|
- {
|
|
|
- $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()
|
|
|
{
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
$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'
|
|
|
- ]);
|
|
|
+ // 定义允许更新的字段
|
|
|
+ $allowedFields = [
|
|
|
+ 'rtp', 'rtp_type', 'free_game_status', 'bet_max_level', 'terminal_spin',
|
|
|
+ 'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level', 'min_deposit',
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 获取请求参数
|
|
|
+ $params = Request::param();
|
|
|
+ $data = [];
|
|
|
|
|
|
- // 验证必填字段
|
|
|
- if (empty($data['title'])) {
|
|
|
- return json_error([], '游戏名称不能为空');
|
|
|
+ // 只获取实际传递的字段
|
|
|
+ foreach ($allowedFields as $field) {
|
|
|
+ if (isset($params[$field])) {
|
|
|
+ $data[$field] = $params[$field];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 检查游戏是否存在
|
|
|
- $game = GameModel::getGameDetail($id);
|
|
|
+ // 如果没有要更新的字段
|
|
|
+ if (empty($data)) {
|
|
|
+ return json_error([], '没有要更新的数据');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查游戏是否存在且属于当前商户
|
|
|
+ $game = GameModel::getGameDetail($id, $userInfo['merchant_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);
|
|
|
+ GameModel::updateGame($id, $data, $userInfo['merchant_id']);
|
|
|
return json_success([], '更新游戏成功');
|
|
|
} catch (\Exception $e) {
|
|
|
return json_error([], '更新游戏失败:' . $e->getMessage());
|
|
|
@@ -187,11 +129,14 @@ class Game extends BaseController
|
|
|
*/
|
|
|
public function updateStatus()
|
|
|
{
|
|
|
- $id = Request::post('id', 0, 'intval');
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
+ $ids = Request::post('ids', []);
|
|
|
$status = Request::post('status', 0, 'intval');
|
|
|
|
|
|
- if (!$id) {
|
|
|
- return json_error([], '游戏ID不能为空');
|
|
|
+ if (empty($ids) || !is_array($ids)) {
|
|
|
+ return json_error([], '请选择要更新的游戏');
|
|
|
}
|
|
|
|
|
|
if (!in_array($status, [
|
|
|
@@ -203,7 +148,7 @@ class Game extends BaseController
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- $result = GameModel::updateGameStatus($id, $status);
|
|
|
+ $result = GameModel::updateGameStatus($ids, $userInfo['merchant_id'], $status);
|
|
|
if ($result) {
|
|
|
return json_success([], '状态更新成功');
|
|
|
} else {
|
|
|
@@ -214,45 +159,17 @@ class Game extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 批量更新游戏状态
|
|
|
- */
|
|
|
- public function batchUpdateStatus()
|
|
|
- {
|
|
|
- $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()
|
|
|
{
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
try {
|
|
|
- $statistics = GameModel::getGameStatistics();
|
|
|
+ $statistics = GameModel::getGameStatistics($userInfo['merchant_id']);
|
|
|
return json_success($statistics, '获取成功');
|
|
|
} catch (\Exception $e) {
|
|
|
return json_error([], '获取游戏统计失败:' . $e->getMessage());
|
|
|
@@ -272,57 +189,28 @@ class Game extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除游戏
|
|
|
- */
|
|
|
- public function delete()
|
|
|
- {
|
|
|
- $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()
|
|
|
{
|
|
|
+ // 获取当前用户信息
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
+
|
|
|
// 获取所有过滤条件
|
|
|
$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'),
|
|
|
+ 'order' => Request::get('order', 'id', 'trim'),
|
|
|
+ 'sort' => Request::get('sort', 'desc', 'trim'),
|
|
|
];
|
|
|
|
|
|
try {
|
|
|
// 获取所有数据
|
|
|
- $result = GameModel::getGameList(1, 100000, $filters);
|
|
|
+ $result = GameModel::getGameList($userInfo['merchant_id'], 1, 100000, $filters);
|
|
|
|
|
|
// 生成CSV数据
|
|
|
$csvData = "ID,游戏ID,游戏平台,中文名称,英文名称,RTP,RTP类型,免费游戏,下注线数,最高倍数,默认押注,最低押注,止损止赢,状态,创建时间\n";
|
|
|
@@ -332,27 +220,27 @@ class Game extends BaseController
|
|
|
"%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['game_platform'],
|
|
|
$game['title'],
|
|
|
$game['title_en'],
|
|
|
$game['rtp'],
|
|
|
GameModel::getRtpTypeText($game['rtp_type']),
|
|
|
- $game['free_game_status'] ? '支持' : '不支持',
|
|
|
+ $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'])
|
|
|
+ $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');
|
|
|
+ ->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());
|