diff --git a/saiadmin-artd/src/composables/useChannelDeptScope.ts b/saiadmin-artd/src/composables/useChannelDeptScope.ts index 97aae02..9f1fcd1 100644 --- a/saiadmin-artd/src/composables/useChannelDeptScope.ts +++ b/saiadmin-artd/src/composables/useChannelDeptScope.ts @@ -261,18 +261,25 @@ export function getChannelDeptRequestParams(): { dept_id?: number } { return {} } -/** 保存/更新时附带 dept_id(优先渠道栏选中值,其次表单/行数据中的 dept_id) */ +/** 保存/更新时附带 dept_id(新增优先渠道栏;更新优先行内 dept_id,避免默认模板 0 覆盖真实渠道) */ export function withChannelDeptParams>(payload: T): T { + const rowDeptRaw = payload.dept_id + const hasRowDept = + rowDeptRaw !== undefined && rowDeptRaw !== null && rowDeptRaw !== '' + const rowDeptNum = hasRowDept ? Number(rowDeptRaw) : NaN + const isUpdate = + payload.id !== undefined && payload.id !== null && payload.id !== '' + + if (isUpdate && hasRowDept && Number.isFinite(rowDeptNum) && rowDeptNum >= 0) { + return { ...payload, dept_id: rowDeptNum } + } + const extra = getChannelDeptRequestParams() if ('dept_id' in extra) { return { ...payload, ...extra } } - const rowDeptId = payload.dept_id - if (rowDeptId !== undefined && rowDeptId !== null && rowDeptId !== '') { - const num = Number(rowDeptId) - if (num > 0) { - return { ...payload, dept_id: num } - } + if (hasRowDept && Number.isFinite(rowDeptNum) && rowDeptNum > 0) { + return { ...payload, dept_id: rowDeptNum } } const channel = useInjectedChannelDept() if (channel && channel.selectedDeptId.value > 0) { diff --git a/saiadmin-artd/src/views/plugin/dice/player/index/modules/edit-dialog.vue b/saiadmin-artd/src/views/plugin/dice/player/index/modules/edit-dialog.vue index 8448d06..9ecb701 100644 --- a/saiadmin-artd/src/views/plugin/dice/player/index/modules/edit-dialog.vue +++ b/saiadmin-artd/src/views/plugin/dice/player/index/modules/edit-dialog.vue @@ -338,9 +338,11 @@ /** 将彩金池配置的 T1–T5 写入表单(绑定彩金池时展示与提交均以池为准) */ function applyPoolWeightsToForm(cfg: LotteryPoolConfigOption) { - WEIGHT_FIELDS.forEach((key) => { - ;(formData as Record)[key] = Number(cfg[key] ?? 0) - }) + formData.t1_weight = Number(cfg.t1_weight ?? 0) + formData.t2_weight = Number(cfg.t2_weight ?? 0) + formData.t3_weight = Number(cfg.t3_weight ?? 0) + formData.t4_weight = Number(cfg.t4_weight ?? 0) + formData.t5_weight = Number(cfg.t5_weight ?? 0) } /** 根据当前 lottery_config_id 加载 DiceLotteryConfig,并将五个权重写入当前 player.*_weight */ @@ -522,16 +524,12 @@ ElMessage.warning(t('page.form.ruleWeightsSumMustBe100')) return } + if (!isLotteryConfigEmpty() && currentLotteryConfig.value) { + applyPoolWeightsToForm(currentLotteryConfig.value) + } const payload = { ...formData } if (isLotteryConfigEmpty()) { - ;(payload as any).lottery_config_id = null - } else if (currentLotteryConfig.value) { - applyPoolWeightsToForm(currentLotteryConfig.value) - WEIGHT_FIELDS.forEach((key) => { - ;(payload as Record)[key] = Number( - (formData as Record)[key] ?? 0 - ) - }) + payload.lottery_config_id = null } if (props.dialogType === 'edit' && !payload.password) { delete (payload as any).password diff --git a/server/app/dice/model/lottery_pool_config/DiceLotteryPoolConfig.php b/server/app/dice/model/lottery_pool_config/DiceLotteryPoolConfig.php index 29b5d5c..2fb1687 100644 --- a/server/app/dice/model/lottery_pool_config/DiceLotteryPoolConfig.php +++ b/server/app/dice/model/lottery_pool_config/DiceLotteryPoolConfig.php @@ -60,12 +60,23 @@ class DiceLotteryPoolConfig extends DiceModel return $query->find(); } + /** + * 是否玩家默认模板池(name=playerDefault) + * 须用 getData()['name']:方法内 $this->name 会命中 ThinkORM 内部属性而非表字段,导致恒为 false + */ + public static function isPlayerDefaultPoolName($name): bool + { + return (string) $name === self::NAME_PLAYER_DEFAULT; + } + /** * 是否玩家默认模板池(运行时按该池权重抽档,改池配置即对所有关联玩家生效) */ public function isPlayerDefaultTemplate(): bool { - return (string) ($this->name ?? '') === self::NAME_PLAYER_DEFAULT; + $data = $this->getData(); + + return self::isPlayerDefaultPoolName($data['name'] ?? ''); } /**