相关记录表admin_id关联当前管理员id

This commit is contained in:
2026-03-10 12:30:56 +08:00
parent b1efeb8b31
commit fdd8f6dffa
18 changed files with 290 additions and 26 deletions

View File

@@ -137,9 +137,16 @@ class GameController extends BaseController
]);
$timeoutRecord = null;
$timeout_message = '';
$adminId = null;
try {
$timeoutPlayer = DicePlayer::find($userId);
$adminId = ($timeoutPlayer && ($timeoutPlayer->admin_id ?? null)) ? (int) $timeoutPlayer->admin_id : null;
} catch (\Throwable $_) {
}
try {
$timeoutRecord = DicePlayRecord::create([
'player_id' => $userId,
'admin_id' => $adminId,
'lottery_config_id' => 0,
'lottery_type' => 0,
'is_win' => 0,

View File

@@ -6,6 +6,7 @@ namespace app\api\controller\v1;
use app\api\logic\UserLogic;
use app\api\util\ReturnCode;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -40,9 +41,18 @@ class GameController extends BaseController
$time = (string) time();
}
$adminId = null;
$agentId = trim((string) ($request->agent_id ?? ''));
if ($agentId !== '') {
$systemUser = SystemUser::where('agent_id', $agentId)->find();
if ($systemUser) {
$adminId = (int) $systemUser->id;
}
}
try {
$logic = new UserLogic();
$result = $logic->loginByUsername($username, $password, 'chs', 0.0, $time);
$result = $logic->loginByUsername($username, $password, 'chs', 0.0, $time, $adminId);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
}
@@ -264,8 +274,10 @@ class GameController extends BaseController
$player->coin = $walletAfter;
$player->save();
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$record = DicePlayerWalletRecord::create([
'player_id' => (int) $player->id,
'admin_id' => $adminId,
'coin' => $coinVal,
'type' => $type,
'wallet_before' => $walletBefore,

View File

@@ -69,10 +69,12 @@ class GameLogic
UserCache::setUser($playerId, $updatedUserArr);
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
try {
Db::transaction(function () use (
$player,
$playerId,
$adminId,
$cost,
$coinBefore,
$coinAfter,
@@ -91,6 +93,7 @@ class GameLogic
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'coin' => -$cost,
'type' => self::WALLET_TYPE_BUY_DRAW,
'wallet_before' => $coinBefore,
@@ -103,6 +106,7 @@ class GameLogic
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'use_coins' => $cost,
'total_ticket_count' => $addTotal,
'paid_ticket_count' => $addPaid,

View File

@@ -160,9 +160,11 @@ class PlayStartLogic
$rewardId = $chosenId;
$configName = (string) ($config->name ?? '');
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
try {
Db::transaction(function () use (
$playerId,
$adminId,
$configId,
$rewardId,
$configName,
@@ -181,6 +183,7 @@ class PlayStartLogic
) {
$record = DicePlayRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'lottery_config_id' => $configId,
'lottery_type' => $ticketType,
'is_win' => $isWin,
@@ -218,9 +221,10 @@ class PlayStartLogic
$p->total_ticket_count = (int) $p->total_ticket_count + 1;
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'player_id' => $playerId,
'admin_id' => $adminId,
'free_ticket_count' => 1,
'remark' => '中奖结果为T5',
'remark' => '中奖结果为T5',
]);
}
@@ -236,6 +240,7 @@ class PlayStartLogic
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'coin' => $winCoin,
'type' => self::WALLET_TYPE_DRAW,
'wallet_before' => $coinBefore,
@@ -248,6 +253,7 @@ class PlayStartLogic
try {
$record = DicePlayRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId ?? null,
'lottery_config_id' => $configId ?? 0,
'lottery_type' => $ticketType,
'is_win' => 0,

View File

@@ -45,8 +45,10 @@ class UserLogic
* 登录JSONusername, password, lang, coin, time
* 存在则校验密码并更新 coin累加不存在则创建用户并写入 coin。
* 将会话写入 Redis返回 token 与前端连接地址。
*
* @param int|null $adminId 创建新用户时关联的后台管理员IDsa_system_user.id可选
*/
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time): array
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null): array
{
$username = trim($username);
if ($username === '') {
@@ -72,6 +74,9 @@ class UserLogic
$player->password = $this->hashPassword($password);
$player->status = self::STATUS_NORMAL;
$player->coin = $coin;
if ($adminId !== null && $adminId > 0) {
$player->admin_id = $adminId;
}
$player->save();
}