1.优化查询用户信息接口/api/v1/getPlayerInfo,如果没有用户则创建

This commit is contained in:
2026-05-19 17:18:51 +08:00
parent 37c0035bfc
commit 9a43e1d8f2
3 changed files with 80 additions and 3 deletions

View File

@@ -91,19 +91,37 @@ class DicePlayer extends DiceModel
$lotteryConfigId = null;
}
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
$config = DiceLotteryPoolConfig::where('name', 'default')->find();
$config = self::findDefaultLotteryConfigForPlayer($model);
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
}
// 彩金池权重默认取 name=default 的奖池配置
self::setDefaultWeightsFromLotteryConfig($model);
}
/**
* 按玩家所属渠道查找 default 彩金池配置
*/
protected static function findDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
{
$query = DiceLotteryPoolConfig::where('name', 'default');
try {
$deptId = $model->getAttr('dept_id');
if ($deptId !== null && $deptId !== '' && $deptId > 0) {
$query->where('dept_id', $deptId);
}
} catch (\Throwable $e) {
// ignore
}
return $query->find();
}
/**
* 从 DiceLotteryPoolConfig name=default 取 t1_weightt5_weight 作为玩家未设置时的默认值
*/
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
{
$config = DiceLotteryPoolConfig::where('name', 'default')->find();
$config = self::findDefaultLotteryConfigForPlayer($model);
if (!$config) {
return;
}