1.新增默认彩金池配置
2.优化关联彩金池配置的名称显示 3.优化一键测试权重 4.优化底注配置
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\DiceModel;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
|
||||
@@ -84,44 +85,61 @@ class DicePlayer extends DiceModel
|
||||
if ($name === null || $name === '') {
|
||||
$model->setAttr('name', $uid);
|
||||
}
|
||||
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig name=default 的 id,没有则为 0
|
||||
// 创建玩家时:未指定则关联 name=playerDefault(玩家默认彩金池),没有则为 0
|
||||
try {
|
||||
$lotteryConfigId = $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = null;
|
||||
}
|
||||
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
|
||||
$config = self::findDefaultLotteryConfigForPlayer($model);
|
||||
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
|
||||
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
|
||||
}
|
||||
// 彩金池权重默认取 name=default 的奖池配置
|
||||
// 展示用权重:从玩家关联的彩金池复制(playerDefault 在抽奖时仍实时读池配置)
|
||||
self::setDefaultWeightsFromLotteryConfig($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按玩家所属渠道查找 default 彩金池配置
|
||||
* 按玩家所属渠道查找玩家默认彩金池(name=playerDefault)
|
||||
*/
|
||||
protected static function findDefaultLotteryConfigForPlayer(DicePlayer $model): ?DiceLotteryPoolConfig
|
||||
protected static function findPlayerDefaultLotteryConfigForPlayer(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
|
||||
$deptId = null;
|
||||
}
|
||||
|
||||
return $query->find();
|
||||
$normalizedDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($model);
|
||||
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
|
||||
$normalizedDeptId = (int) $deptId;
|
||||
}
|
||||
$config = DiceLotteryPoolConfig::findByNameForDept(
|
||||
DiceLotteryPoolConfig::NAME_PLAYER_DEFAULT,
|
||||
$normalizedDeptId
|
||||
);
|
||||
if ($config) {
|
||||
return $config;
|
||||
}
|
||||
return DiceLotteryPoolConfig::findByNameForDept('default', $normalizedDeptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 DiceLotteryPoolConfig name=default 取 t1_weight~t5_weight 作为玩家未设置时的默认值
|
||||
* 从玩家关联彩金池(或 playerDefault / default)取 t1_weight~t5_weight 作为未设置时的默认值
|
||||
*/
|
||||
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
|
||||
{
|
||||
$config = self::findDefaultLotteryConfigForPlayer($model);
|
||||
$config = null;
|
||||
try {
|
||||
$lotteryConfigId = (int) $model->getAttr('lottery_config_id');
|
||||
} catch (\Throwable $e) {
|
||||
$lotteryConfigId = 0;
|
||||
}
|
||||
if ($lotteryConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
|
||||
}
|
||||
if (!$config) {
|
||||
$config = self::findPlayerDefaultLotteryConfigForPlayer($model);
|
||||
}
|
||||
if (!$config) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user