优化玩家DicePlayer保存的lottery_config_id

This commit is contained in:
2026-03-07 11:58:47 +08:00
parent 282d73a203
commit 316506b597
2 changed files with 13 additions and 0 deletions

View File

@@ -55,6 +55,9 @@ class UserLogic
$player = DicePlayer::where('username', $username)->find();
if ($player) {
if ((int) ($player->status ?? 1) === 0) {
throw new ApiException('账号已被禁用,无法登录');
}
$hashed = $this->hashPassword($password);
if ($player->password !== $hashed) {
throw new ApiException('密码错误');

View File

@@ -77,6 +77,16 @@ class DicePlayer extends BaseModel
if ($name === null || $name === '') {
$model->setAttr('name', $uid);
}
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryConfig type=0 的 id没有则为 0
try {
$lotteryConfigId = $model->getAttr('lottery_config_id');
} catch (\Throwable $e) {
$lotteryConfigId = null;
}
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
$config = DiceLotteryConfig::where('type', 0)->find();
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
}
// 彩金池权重默认取 type=0 的奖池配置
self::setDefaultWeightsFromLotteryConfig($model);
}