From 282d73a203774383350128ccc26d158cff813b8e Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Sat, 7 Mar 2026 11:51:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=8E=A9=E5=AE=B6DicePlayer?= =?UTF-8?q?=E6=9D=83=E9=87=8D=E8=BE=93=E5=85=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/dice/api/lottery_config/index.ts | 11 +- .../src/views/plugin/dice/api/player/index.ts | 12 + .../dice/player/index/modules/edit-dialog.vue | 215 +++++++++++++++--- .../player/index/modules/table-search.vue | 6 +- .../DiceLotteryConfigController.php | 16 ++ .../player/DicePlayerController.php | 16 ++ 6 files changed, 241 insertions(+), 35 deletions(-) diff --git a/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts b/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts index 7a67a6b..cfb4d82 100644 --- a/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts +++ b/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts @@ -17,17 +17,16 @@ export default { }, /** - * 获取彩金池配置下拉选项(来自 DiceLotteryConfig,用于 lottery_config_id 选择) - * @returns { id, name }[] + * 获取 DiceLotteryConfig 列表数据,仅含 id、name,用于 lottery_config_id 下拉 + * @returns DiceLotteryConfig['id','name'] 列表 */ async getOptions(): Promise> { const res = await request.get({ - url: '/dice/lottery_config/DiceLotteryConfig/index', - params: { limit: 500, page: 1 } + url: '/dice/lottery_config/DiceLotteryConfig/getOptions' }) - const rows = (res?.data?.data ?? res?.data?.rows ?? []) as Array<{ id: number; name: string }> + const rows = (res?.data ?? []) as Array<{ id: number; name: string }> return Array.isArray(rows) - ? rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id) })) + ? rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') })) : [] }, diff --git a/saiadmin-artd/src/views/plugin/dice/api/player/index.ts b/saiadmin-artd/src/views/plugin/dice/api/player/index.ts index 12a0717..1833540 100644 --- a/saiadmin-artd/src/views/plugin/dice/api/player/index.ts +++ b/saiadmin-artd/src/views/plugin/dice/api/player/index.ts @@ -71,5 +71,17 @@ export default { url: '/dice/player/DicePlayer/updateStatus', data: params }) + }, + + /** + * 获取彩金池配置选项(DiceLotteryConfig.id、name),供 lottery_config_id 下拉使用 + * @returns [ { id, name } ] + */ + async getLotteryConfigOptions(): Promise> { + const res = await request.get({ + url: '/dice/player/DicePlayer/getLotteryConfigOptions' + }) + const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }> + return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') })) } } 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 f2a85dd..5b12ca8 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 @@ -44,39 +44,98 @@ style="width: 100%" /> + - - - + + +
+
+ 名称: + {{ currentLotteryConfig.name ?? '-' }} +
+
+ 类型: + {{ lotteryConfigTypeText(currentLotteryConfig.type) }} +
+
+ T1~T5 权重: + {{ currentLotteryConfigWeightsText }} +
+
+ 备注: + {{ currentLotteryConfig.remark }} +
+
- - + + + - - + + - - + + - - + + - + + + +
五个池权重总和:{{ weightsSum @@ -130,6 +189,18 @@ return WEIGHT_FIELDS.reduce((sum, key) => sum + Number(formData[key] ?? 0), 0) }) + /** 当前彩金池配置的 T1~T5 权重展示文案 */ + const currentLotteryConfigWeightsText = computed(() => { + const c = currentLotteryConfig.value + if (!c) return '-' + const t1 = c.t1_weight ?? 0 + const t2 = c.t2_weight ?? 0 + const t3 = c.t3_weight ?? 0 + const t4 = c.t4_weight ?? 0 + const t5 = c.t5_weight ?? 0 + return `${t1}% / ${t2}% / ${t3}% / ${t4}% / ${t5}%` + }) + /** 新增时密码必填,编辑时选填 */ const passwordRules = computed(() => props.dialogType === 'add' ? [{ required: true, message: '密码必需填写', trigger: 'blur' }] : [] @@ -151,6 +222,7 @@ password: '', status: 1 as number, coin: 0 as number, + /** 彩金池配置 ID:空 = 自定义权重,否则 = DiceLotteryConfig.id */ lottery_config_id: null as number | null, t1_weight: 0 as number, t2_weight: 0 as number, @@ -161,8 +233,48 @@ const formData = reactive({ ...initialFormData }) - /** 彩金池配置下拉选项 */ + /** 彩金池配置下拉选项(DiceLotteryConfig id、name) */ const lotteryConfigOptions = ref>([]) + /** 彩金池选项加载中 */ + const lotteryConfigLoading = ref(false) + /** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */ + const currentLotteryConfig = ref | null>(null) + + function lotteryConfigTypeText(type: unknown): string { + const t = Number(type) + if (t === 0) return '付费' + if (t === 1) return '赠送' + return t ? `类型${t}` : '-' + } + + /** 是否为空/自定义权重(未选彩金池或选 0) */ + function isLotteryConfigEmpty(): boolean { + const v = formData.lottery_config_id + return v == null || v === 0 + } + + /** 根据当前 lottery_config_id 加载 DiceLotteryConfig,并将五个权重写入当前 player.*_weight */ + async function loadCurrentLotteryConfig() { + const id = formData.lottery_config_id + if (id == null || id === 0) { + currentLotteryConfig.value = null + return + } + try { + const res = await lotteryConfigApi.read(id) + const row = (res as any)?.data ?? (res as any) + if (row && typeof row === 'object') { + currentLotteryConfig.value = row + WEIGHT_FIELDS.forEach((key) => { + ;(formData as any)[key] = Number(row[key] ?? 0) + }) + } else { + currentLotteryConfig.value = null + } + } catch { + currentLotteryConfig.value = null + } + } watch( () => props.modelValue, @@ -171,37 +283,51 @@ } ) - /** 选择彩金池配置时,拉取该配置的权重填入表单(仅展示/备份;lottery_config_id 非空时后端以配置为准) */ - async function onLotteryConfigChange(lotteryConfigId: number | null) { - if (!lotteryConfigId) return + /** 选择彩金池后,拉取该配置的五个权重并写入当前 player.*_weight,并更新当前配置展示 */ + async function onLotteryConfigChange(lotteryConfigId: number | null | undefined) { + if (lotteryConfigId == null || lotteryConfigId === 0) { + currentLotteryConfig.value = null + return + } try { const res = await lotteryConfigApi.read(lotteryConfigId) - const row = (res as any)?.data - if (row) { + const row = (res as any)?.data ?? (res as any) + if (row && typeof row === 'object') { WEIGHT_FIELDS.forEach((key) => { ;(formData as any)[key] = Number(row[key] ?? 0) }) + currentLotteryConfig.value = row + } else { + currentLotteryConfig.value = null } } catch (err) { - console.warn('拉取彩金池配置权重失败', err) + console.warn('拉取彩金池配置失败', err) + currentLotteryConfig.value = null } } const initPage = async () => { + currentLotteryConfig.value = null Object.assign(formData, initialFormData) await loadLotteryConfigOptions() if (props.data) { await nextTick() initForm() + if (!isLotteryConfigEmpty()) { + await loadCurrentLotteryConfig() + } } } - /** 从 DiceLotteryConfig 拉取彩金池配置下拉选项 */ + /** 从玩家控制器获取 DiceLotteryConfig id/name 列表,供 lottery_config_id 下拉使用 */ async function loadLotteryConfigOptions() { + lotteryConfigLoading.value = true try { - lotteryConfigOptions.value = await lotteryConfigApi.getOptions() + lotteryConfigOptions.value = await api.getLotteryConfigOptions() } catch { lotteryConfigOptions.value = [] + } finally { + lotteryConfigLoading.value = false } } @@ -227,8 +353,14 @@ } const val = props.data[key] if (numKeys.includes(key)) { - ;(formData as any)[key] = - key === 'id' ? (val != null ? Number(val) || null : null) : Number(val) || 0 + if (key === 'id') { + ;(formData as any)[key] = val != null ? Number(val) || null : null + } else if (key === 'lottery_config_id') { + const num = Number(val) + ;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null + } else { + ;(formData as any)[key] = Number(val) || 0 + } } else { ;(formData as any)[key] = val ?? '' } @@ -244,12 +376,15 @@ if (!formRef.value) return try { await formRef.value.validate() - const useCustomWeights = !formData.lottery_config_id + const useCustomWeights = isLotteryConfigEmpty() if (useCustomWeights && Math.abs(weightsSum.value - 100) > 0.01) { ElMessage.warning('五个池权重总和必须为100%') return } const payload = { ...formData } + if (isLotteryConfigEmpty()) { + ;(payload as any).lottery_config_id = null + } if (props.dialogType === 'edit' && !payload.password) { delete (payload as any).password } @@ -267,3 +402,31 @@ } } + + diff --git a/saiadmin-artd/src/views/plugin/dice/player/index/modules/table-search.vue b/saiadmin-artd/src/views/plugin/dice/player/index/modules/table-search.vue index 2390245..636abcc 100644 --- a/saiadmin-artd/src/views/plugin/dice/player/index/modules/table-search.vue +++ b/saiadmin-artd/src/views/plugin/dice/player/index/modules/table-search.vue @@ -64,7 +64,7 @@