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

This commit is contained in:
2026-06-04 14:24:22 +08:00
parent 16a59c28d4
commit 8a4a268526
3 changed files with 35 additions and 19 deletions

View File

@@ -261,18 +261,25 @@ export function getChannelDeptRequestParams(): { dept_id?: number } {
return {}
}
/** 保存/更新时附带 dept_id优先渠道栏选中值,其次表单/行数据中的 dept_id */
/** 保存/更新时附带 dept_id新增优先渠道栏;更新优先行内 dept_id避免默认模板 0 覆盖真实渠道 */
export function withChannelDeptParams<T extends Record<string, unknown>>(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) {

View File

@@ -338,9 +338,11 @@
/** 将彩金池配置的 T1T5 写入表单(绑定彩金池时展示与提交均以池为准) */
function applyPoolWeightsToForm(cfg: LotteryPoolConfigOption) {
WEIGHT_FIELDS.forEach((key) => {
;(formData as Record<string, number>)[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<string, number>)[key] = Number(
(formData as Record<string, number>)[key] ?? 0
)
})
payload.lottery_config_id = null
}
if (props.dialogType === 'edit' && !payload.password) {
delete (payload as any).password

View File

@@ -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'] ?? '');
}
/**