1.优化开奖逻辑

2.优化后台开奖派彩
3.优化接口规范
This commit is contained in:
2026-04-17 13:56:13 +08:00
parent 3cf386756b
commit bf3d50a309
50 changed files with 1036 additions and 770 deletions

View File

@@ -45,6 +45,7 @@ class Account extends Frontend
'code' => 1,
'message' => __('ok'),
'data' => [
'uuid' => $user->uuid ?? '',
'username' => $user->username,
'head_image' => $user->avatar ?? '',
'coin' => $user->coin,

View File

@@ -34,6 +34,9 @@ class Auth extends MobileBase
if ($username === '' || $password === '') {
return $this->mobileError(1001, 'Missing parameters');
}
if ($inviteCode === '') {
return $this->mobileError(1001, 'Invite code required');
}
if (!preg_match('/^1[3-9]\d{9}$/', $username)) {
return $this->mobileError(1003, 'Please enter the correct mobile number');
}
@@ -41,19 +44,33 @@ class Auth extends MobileBase
$phone = $username;
$email = '';
$extend = [];
if ($inviteCode !== '') {
$inviterAdmin = Db::name('admin')->field(['id', 'channel_id'])->where('invite_code', $inviteCode)->find();
if (!$inviterAdmin) {
return $this->mobileError(2002, 'Invite code does not exist');
}
$extend['register_invite_code'] = $inviteCode;
$extend['admin_id'] = $inviterAdmin['id'];
$extend['channel_id'] = $inviterAdmin['channel_id'] ?? null;
if (User::where('username', $username)->find() || User::where('phone', $username)->find()) {
return $this->mobileError(2003, 'Account already registered', [
'already_registered' => true,
]);
}
$extend = [];
$inviterAdmin = Db::name('admin')->field(['id', 'channel_id'])->where('invite_code', $inviteCode)->find();
if (!$inviterAdmin) {
return $this->mobileError(2002, 'Invite code does not exist');
}
$extend['register_invite_code'] = $inviteCode;
$extend['admin_id'] = $inviterAdmin['id'];
$channelId = $inviterAdmin['channel_id'] ?? null;
if ($channelId === null || $channelId === '' || (int) $channelId <= 0) {
return $this->mobileError(2002, 'Invite code not bound to channel');
}
$extend['channel_id'] = (int) $channelId;
$registered = $this->auth->register($username, $password, $phone, $email, 1, $extend);
if (!$registered) {
$dup = $this->auth->getRegisterDuplicateKind();
if ($dup === 'username' || $dup === 'email' || $dup === 'phone') {
return $this->mobileError(2003, 'Account already registered', [
'already_registered' => true,
]);
}
return $this->mobileError(2000, (string) $this->auth->getError());
}
@@ -122,6 +139,7 @@ class Auth extends MobileBase
'expires_in' => config('buildadmin.user_token_keep_time', 259200),
'user' => [
'username' => $userInfo['username'] ?? '',
'uuid' => $userInfo['uuid'] ?? '',
'coin' => $userInfo['coin'] ?? '0.0000',
'channel_id' => $userInfo['channel_id'] ?? null,
'risk_flags' => $userInfo['risk_flags'] ?? 0,

View File

@@ -54,7 +54,7 @@ class Game extends MobileBase
'open_at' => $openAt,
],
'bet_config' => [
'max_select_count' => $this->intValue($this->getConfigValue('max_select_count', '5')),
'pick_max_number_count' => $this->getPickMaxNumberCount(),
'chips' => ['1.0000', '5.0000', '10.0000', '25.0000', '50.0000', '100.0000'],
'single_number_max_bet' => $this->getConfigValue('single_number_max_bet', '500.0000'),
],
@@ -140,13 +140,18 @@ class Game extends MobileBase
return $response;
}
$periodNo = trim((string) $request->post('period_no', ''));
$numbers = $request->post('numbers', []);
$numbersRaw = $request->post('numbers', '');
$betAmount = (string) $request->post('bet_amount', '');
$idempotencyKey = trim((string) $request->post('idempotency_key', ''));
if ($periodNo === '' || !is_array($numbers) || $betAmount === '' || $idempotencyKey === '') {
if ($periodNo === '' || $betAmount === '' || $idempotencyKey === '') {
return $this->mobileError(1001, 'Missing parameters');
}
if (count($numbers) < 1) {
$numbers = $this->parseBetNumbersFromRequest($numbersRaw);
if ($numbers === []) {
return $this->mobileError(1003, 'Invalid parameter value');
}
$maxSelect = $this->getPickMaxNumberCount();
if (count($numbers) > $maxSelect) {
return $this->mobileError(1003, 'Invalid parameter value');
}
@@ -285,6 +290,49 @@ class Game extends MobileBase
]);
}
/**
* 下注号码:`numbers` 为逗号分隔字符串(如 `1,8,16`);兼容旧版 JSON 数组。
*
* @return list<int>
*/
private function parseBetNumbersFromRequest($numbersRaw): array
{
if (is_array($numbersRaw)) {
$out = [];
foreach ($numbersRaw as $v) {
$n = filter_var($v, FILTER_VALIDATE_INT);
if ($n === false || $n < 1 || $n > 36) {
return [];
}
$out[] = $n;
}
$out = array_values(array_unique($out));
sort($out);
return $out;
}
$raw = trim((string) $numbersRaw);
if ($raw === '') {
return [];
}
$parts = preg_split('/\s*,\s*/', $raw);
$out = [];
foreach ($parts as $p) {
if ($p === '') {
continue;
}
$n = filter_var($p, FILTER_VALIDATE_INT);
if ($n === false || $n < 1 || $n > 36) {
return [];
}
$out[] = $n;
}
$out = array_values(array_unique($out));
sort($out);
return $out;
}
private function mapPeriodStatus($status): string
{
if ($this->intValue($status) === 0) {
@@ -299,6 +347,22 @@ class Game extends MobileBase
return 'finished';
}
/**
* 单注最多可选号码个数:`game_config.config_key = pick_max_number_count`
*/
private function getPickMaxNumberCount(): int
{
$v = $this->intValue($this->getConfigValue('pick_max_number_count', '10'));
if ($v < 1) {
return 1;
}
if ($v > 36) {
return 36;
}
return $v;
}
private function getConfigValue(string $key, string $default): string
{
$value = GameConfig::where('config_key', $key)->value('config_value');

View File

@@ -81,11 +81,15 @@ class User extends Frontend
->where('invite_code', $params['invite_code'])
->find();
if (!$inviterAdmin) {
return $this->error(__('Parameter error'));
return $this->error(__('Invite code does not exist'));
}
$ch = $inviterAdmin['channel_id'] ?? null;
if ($ch === null || $ch === '' || intval(trim((string) $ch)) <= 0) {
return $this->error(__('Invite code not bound to channel'));
}
$extend['register_invite_code'] = $params['invite_code'];
$extend['inviter_admin_id'] = $inviterAdmin['id'];
$extend['channel_id'] = $inviterAdmin['channel_id'] ?? null;
$extend['admin_id'] = $inviterAdmin['id'];
$extend['channel_id'] = intval(trim((string) $ch));
}
$res = $this->auth->register($params['username'], $params['password'], $params['mobile'], $params['email'], 1, $extend);
}
@@ -96,6 +100,10 @@ class User extends Frontend
'routePath' => '/user'
]);
}
$dup = $this->auth->getRegisterDuplicateKind();
if ($params['tab'] === 'register' && ($dup === 'username' || $dup === 'email' || $dup === 'phone')) {
return $this->error(__('Account already registered'));
}
$msg = $this->auth->getError();
return $this->error($msg ?: __('Check in failed, please try again or contact the website administrator~'));
}

View File

@@ -23,6 +23,9 @@ return [
'Invalid timestamp' => 'Invalid timestamp',
'Invite code does not exist' => 'Invite code does not exist',
'Register only supports phone' => 'Register only supports phone',
'Invite code required' => 'Invite code is required',
'Invite code not bound to channel' => 'This invite code is not bound to a valid channel',
'Account already registered' => 'This phone number is already registered. Please sign in.',
'Please enter the correct mobile number' => 'Please enter the correct mobile number',
'Registered successfully but login failed' => 'Registered successfully but login failed',
'Incorrect account or password' => 'Incorrect account or password',

View File

@@ -55,6 +55,9 @@ return [
'Invalid timestamp' => '时间戳无效',
'Invite code does not exist' => '邀请码不存在',
'Register only supports phone' => '注册仅支持手机号',
'Invite code required' => '请填写邀请码',
'Invite code not bound to channel' => '该邀请码未绑定有效渠道',
'Account already registered' => '该手机号已注册,请直接登录',
'Please enter the correct mobile number' => '请输入正确的手机号',
'Registered successfully but login failed' => '注册成功但登录失败',
'Incorrect account or password' => '账号或密码错误',