1.新增游戏管理接口和菜单
2.创建对接第三方文档
This commit is contained in:
@@ -5,6 +5,7 @@ namespace app\api\controller\v1;
|
||||
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use app\dice\model\game\DiceGame;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use app\dice\model\play_record\DicePlayRecord;
|
||||
@@ -22,6 +23,53 @@ use app\api\cache\UserCache;
|
||||
*/
|
||||
class GameController extends BaseController
|
||||
{
|
||||
private const GAME_PUBLIC_FIELDS = [
|
||||
'provider',
|
||||
'provider_code',
|
||||
'game_code',
|
||||
'game_key',
|
||||
'game_type',
|
||||
'logo',
|
||||
'game_url',
|
||||
'hall_url',
|
||||
'status',
|
||||
'sort',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取游戏列表
|
||||
* POST 参数:lang(可选,zh/en,默认 zh)
|
||||
* 当前返回启用中的游戏列表
|
||||
*/
|
||||
public function getGameList(Request $request): Response
|
||||
{
|
||||
$lang = $this->resolveLang($request->post('lang', 'zh'));
|
||||
$games = $this->buildPublicGameList($lang);
|
||||
return $this->success([
|
||||
'game_list' => $games,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取游戏大厅信息(脱敏)
|
||||
* POST 参数:lang(可选,zh/en,默认 zh)
|
||||
*/
|
||||
public function getGameHall(Request $request): Response
|
||||
{
|
||||
$lang = $this->resolveLang($request->post('lang', 'zh'));
|
||||
$games = $this->buildPublicGameList($lang);
|
||||
$hallUrl = '';
|
||||
if (!empty($games)) {
|
||||
$hallUrl = $games[0]['hall_url'] ?? '';
|
||||
}
|
||||
return $this->success([
|
||||
'provider' => 'Dicey Fun',
|
||||
'provider_code' => 'DF',
|
||||
'hall_url' => $hallUrl,
|
||||
'game_list' => $games,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取游戏地址
|
||||
* 根据 username 创建登录 token(JWT),拼接游戏地址返回
|
||||
@@ -310,4 +358,41 @@ class GameController extends BaseController
|
||||
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
|
||||
return $this->success($recordArr);
|
||||
}
|
||||
|
||||
private function resolveLang($lang): string
|
||||
{
|
||||
if (!is_string($lang)) {
|
||||
return 'zh';
|
||||
}
|
||||
$langValue = strtolower(trim($lang));
|
||||
if (!in_array($langValue, ['zh', 'en'], true)) {
|
||||
return 'zh';
|
||||
}
|
||||
return $langValue;
|
||||
}
|
||||
|
||||
private function buildPublicGameList(string $lang): array
|
||||
{
|
||||
$rows = DiceGame::where('status', 1)
|
||||
->orderBy('sort', 'asc')
|
||||
->orderBy('id', 'asc')
|
||||
->select(array_merge(self::GAME_PUBLIC_FIELDS, ['game_name', 'game_name_en']))
|
||||
->get()
|
||||
->toArray();
|
||||
if (empty($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$games = [];
|
||||
foreach ($rows as $row) {
|
||||
$game = [];
|
||||
foreach (self::GAME_PUBLIC_FIELDS as $fieldName) {
|
||||
$game[$fieldName] = $row[$fieldName] ?? '';
|
||||
}
|
||||
$gameNameEn = $row['game_name_en'] ?? '';
|
||||
$game['game_name'] = $lang === 'en' && $gameNameEn !== '' ? $gameNameEn : ($row['game_name'] ?? '');
|
||||
$games[] = $game;
|
||||
}
|
||||
return $games;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user