1.修改彩金池配置中的playerDefault时自动修改绑定该配置的用户

This commit is contained in:
2026-06-04 13:47:35 +08:00
parent 8c6c122dc2
commit eb9ade6d16
2 changed files with 96 additions and 1 deletions

View File

@@ -6,9 +6,11 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\lottery_pool_config;
use app\api\service\LotteryService;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
@@ -39,7 +41,7 @@ class DiceLotteryPoolConfigLogic extends DiceBaseLogic
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$result = ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
@@ -48,6 +50,58 @@ class DiceLotteryPoolConfigLogic extends DiceBaseLogic
$adminInfo,
$pickedDeptId
);
if ($result) {
$pool = DiceLotteryPoolConfig::find($id);
if ($pool && $pool->isPlayerDefaultTemplate()) {
$this->syncPlayersBoundToPlayerDefaultPool($pool);
}
}
return $result;
}
/**
* 修改 playerDefault 后:同步同渠道所有 lottery_config_id 指向该池的玩家 T1T5 权重,并刷新 Redis 彩金池快照
*
* @return int 已同步玩家数量
*/
public function syncPlayersBoundToPlayerDefaultPool(DiceLotteryPoolConfig $pool): int
{
$poolId = (int) ($pool->id ?? 0);
if ($poolId <= 0) {
return 0;
}
$weights = [
't1_weight' => (int) ($pool->t1_weight ?? 0),
't2_weight' => (int) ($pool->t2_weight ?? 0),
't3_weight' => (int) ($pool->t3_weight ?? 0),
't4_weight' => (int) ($pool->t4_weight ?? 0),
't5_weight' => (int) ($pool->t5_weight ?? 0),
];
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
$query = DicePlayer::where('lottery_config_id', $poolId);
if (AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $poolDeptId);
}
$playerIds = $query->column('id');
if ($playerIds === [] || $playerIds === null) {
return 0;
}
$ids = array_map('intval', is_array($playerIds) ? $playerIds : [$playerIds]);
DicePlayer::whereIn('id', $ids)->update($weights);
foreach ($ids as $playerId) {
LotteryService::patchPlayerWeightsCache($playerId, $weights);
}
return count($ids);
}
/**