Compare commits

18 Commits

Author SHA1 Message Date
77ec0dcade 优化页面不显示小数 2026-03-26 14:31:32 +08:00
d72a8487a8 项目介绍-优化 2026-03-26 14:25:45 +08:00
7596007a5a 项目介绍 2026-03-26 14:19:35 +08:00
1b448833c6 优化【查看当前彩金池】翻译 2026-03-26 14:05:20 +08:00
748ee12a52 优化平台币显示样式不显示小数点,优化中大奖计算 2026-03-26 13:58:45 +08:00
d793a511ee [色子游戏]抽奖记录(测试权重)-优化
[API]记录抽奖券DicePlayerTicketRecord
2026-03-25 18:51:29 +08:00
f8cf85dd01 修改游戏地址为dice-v3-game.yuliao666.top 2026-03-25 17:53:34 +08:00
6c6971c4bf 修改plugin.webman.channel.server端口号为2207 2026-03-25 17:52:05 +08:00
60833aa6ff 修改plugin.webman.channel.server端口号为2207 2026-03-25 17:35:23 +08:00
d0d82399dc 优化前端VITE_API_URL 2026-03-25 16:10:57 +08:00
5b209da678 修复打包报错 2026-03-25 16:02:38 +08:00
d10dc81fc7 修改环境配置文件 2026-03-25 15:52:03 +08:00
6b9fb0c26e 优化游玩方式 2026-03-25 15:51:50 +08:00
9b4104fc0e [API]新增接口/api/game/anteConfig获取底注配置 2026-03-25 14:46:47 +08:00
ce9062e186 [色子游戏]奖励配置-新增按规则自动生成奖励配置 2026-03-25 14:34:04 +08:00
1027612cc0 [色子游戏]底注配置 2026-03-25 14:33:58 +08:00
5ef8ee8bc5 [色子游戏]奖励配置-新增按规则自动生成奖励配置 2026-03-25 13:42:46 +08:00
bd402aa97d v3分支环境配置 2026-03-25 09:42:27 +08:00
75 changed files with 2627 additions and 164 deletions

View File

@@ -7,7 +7,7 @@ VITE_BASE_URL = /
VITE_API_URL = /api
# 代理目标地址(开发环境通过 Vite 代理转发请求到此地址,解决跨域问题)
VITE_API_PROXY_URL = http://127.0.0.1:6688
VITE_API_PROXY_URL = http://127.0.0.1:8989
# Delete console
VITE_DROP_CONSOLE = false

View File

@@ -5,7 +5,7 @@
VITE_BASE_URL = ./
# API 根地址(后端路由为 /core、/tool、/dice 等,无 /prod 前缀,不要加 /prod
VITE_API_URL = https://dice-api.yuliao666.top
VITE_API_URL = https://dice-v3-api.yuliao666.top
# 登录页是否显示验证码,设为 false 可关闭(需与后端 LOGIN_CAPTCHA_ENABLE 一致)
VITE_LOGIN_CAPTCHA_ENABLED = false

View File

@@ -0,0 +1,53 @@
/**
* 命令行:按「当前盘面 grid_number 排布」与 T1/T2/T4/T5 约束生成 DiceRewardConfig 表 JSON不含保存
* 用法pnpm tsx scripts/generate-dice-reward-index.ts [t1Fixed] [t2Min] [t4Fixed] [t5Fixed]
* 默认3 5 1 1T4/T5 为顺、逆加权条数固定值)
*
* 生成逻辑见 src/views/plugin/dice/reward_config/utils/generateIndexByRules.ts
*/
import {
buildRowsFromTiers,
computeBoardFrequencies,
DEFAULT_TIER_REAL_EV_STANDARDS,
generateTiers,
summarizeCounts
} from '../src/views/plugin/dice/reward_config/utils/generateIndexByRules'
const grids = [
20, 27, 24, 10, 5, 15, 8, 22, 30, 23, 16, 12, 13, 7, 17, 9, 21, 26, 6, 29, 19, 11, 25, 14, 28, 18
]
const args = process.argv.slice(2).map((x) => parseInt(x, 10))
const t1 = Number.isFinite(args[0]) ? args[0] : 3
const t2 = Number.isFinite(args[1]) ? args[1] : 5
const x4 = Number.isFinite(args[2]) ? args[2] : 1
const x5 = Number.isFinite(args[3]) ? args[3] : 1
const constraints = {
t1FixedCw: t1,
t2MinCw: t2,
t4FixedCw: x4,
t5FixedCw: x5,
t1FixedCcw: t1,
t2MinCcw: t2,
t4FixedCcw: x4,
t5FixedCcw: x5
}
const gen = generateTiers({ grids, constraints })
if (gen.ok === false) {
console.error(gen.message)
process.exit(1)
}
const board = computeBoardFrequencies(grids)
if (board === null) {
console.error('computeBoardFrequencies failed')
process.exit(1)
}
const rows = buildRowsFromTiers(grids, gen.tiers, DEFAULT_TIER_REAL_EV_STANDARDS)
const sc = summarizeCounts(board, gen.tiers)
console.log(JSON.stringify({ weighted: { cw: sc.cw, ccw: sc.ccw }, rows }, null, 2))

View File

@@ -0,0 +1,37 @@
{
"search": {
"name": "Name",
"title": "Title",
"isDefault": "Default",
"placeholderName": "Please enter name",
"placeholderTitle": "Please enter title",
"placeholderIsDefault": "Please select default status"
},
"table": {
"id": "ID",
"name": "Name",
"title": "Title",
"mult": "Ante Multiplier",
"isDefault": "Default Ante",
"defaultYes": "Yes",
"defaultNo": "No",
"createTime": "Create Time",
"updateTime": "Update Time"
},
"form": {
"titleAdd": "Add Ante Config",
"titleEdit": "Edit Ante Config",
"labelName": "Name",
"labelTitle": "Title",
"labelMult": "Ante Multiplier",
"labelIsDefault": "Default Ante",
"placeholderName": "Please enter name",
"placeholderTitle": "Please enter title",
"ruleNameRequired": "Please enter name",
"ruleTitleRequired": "Please enter title",
"ruleMultRequired": "Please enter ante multiplier",
"ruleDefaultRequired": "Please select default status",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
}
}

View File

@@ -23,7 +23,7 @@
"poolName": "Pool Name",
"playerProfit": "Player Total Profit (profit_amount):",
"realtime": "Live",
"profitCalcHint": "Sum of (win amount including BIGWIN minus 100 ticket cost) per round; refreshes every 2s while open.",
"profitCalcHint": "Profit per round: paid = win_coin (incl. BIGWIN) - paid_amount (= ante×100); free = win_coin. Refreshes every 2s while open.",
"tierRuleTitle": "Tier Rule",
"tierRuleContent": "When player profit in this pool is below safety line, use player T*_weight; when above or equal, use pool T*_weight (kill).",
"killScoreWeights": "Kill weights",

View File

@@ -64,6 +64,8 @@
"player": "Player",
"lotteryPoolConfig": "Lottery Pool Config",
"drawType": "Draw Type",
"ante": "Ante",
"paidAmount": "Paid Amount",
"isBigWin": "Is Big Win",
"winCoin": "Win Coin",
"superWinCoin": "Super Win Coin",

View File

@@ -4,10 +4,13 @@
"platformTotalProfit": "Platform Total Profit"
},
"search": {
"rewardConfigRecordId": "Weight Test Record ID",
"drawType": "Draw Type",
"direction": "Direction",
"isBigWin": "Is Big Win",
"winCoin": "Win Coin",
"paidAmount": "Paid Amount",
"ante": "Ante",
"rewardTier": "Reward Tier",
"rollNumber": "Roll Number",
"paid": "Paid",
@@ -19,10 +22,13 @@
},
"table": {
"id": "ID",
"rewardConfigRecordId": "Weight Test Record ID",
"player": "Player",
"lotteryPoolConfig": "Lottery Pool Config",
"drawType": "Draw Type",
"isBigWin": "Is Big Win",
"paidAmount": "Paid Amount",
"ante": "Ante",
"winCoin": "Win Coin",
"superWinCoin": "Super Win Coin",
"rewardWinCoin": "Reward Win Coin",

View File

@@ -19,6 +19,7 @@
"search": {
"player": "Player",
"useCoins": "Use Coins",
"ante": "Ante",
"totalDrawCount": "Total Draw Count",
"paidDrawCount": "Paid Draw Count",
"freeDrawCount": "Free Draw Count",
@@ -29,6 +30,7 @@
"id": "ID",
"playerUsername": "Player Username",
"useCoins": "Use Coins",
"ante": "Ante",
"totalDrawCount": "Total Draw Count",
"paidDrawCount": "Paid Draw Count",
"freeDrawCount": "Free Draw Count",

View File

@@ -61,6 +61,7 @@
"stepFree": "Free ticket",
"labelLotteryTypePaid": "Test pool type",
"labelLotteryTypeFree": "Test pool type",
"labelAnte": "Ante",
"placeholderPaidPool": "Leave empty for custom tier odds below (default: default)",
"placeholderFreePool": "Leave empty for custom tier odds below (default: killScore)",
"tierProbHint": "Custom tier odds (T1T5), each 0100%, sum of five must not exceed 100%",
@@ -73,6 +74,7 @@
"btnNext": "Next",
"btnStart": "Start test",
"btnCancel": "Cancel",
"warnAnte": "Ante must be greater than 0",
"warnTotalSpins": "At least one of paid/free direction spin counts must be greater than 0",
"warnPaidTierSumPositive": "When no paid pool is selected, T1T5 odds sum must be greater than 0",
"warnPaidTierSumMax": "Paid T1T5 odds sum cannot exceed 100%",

View File

@@ -50,7 +50,50 @@
"warnDupGrid": "Duplicate dice points in this table: {list}",
"warnNoBigwinToSave": "No BIGWIN rows to save",
"warnBigwinDupGrid": "Duplicate big-win points in this table: {list}",
"infoNoBigwin": "No BIGWIN rows. Set tier to BIGWIN in the Reward Index tab first."
"infoNoBigwin": "No BIGWIN rows. Set tier to BIGWIN in the Reward Index tab first.",
"btnRuleGenerate": "Generate by rules",
"ruleGenerateTitle": "Generate reward index by rules",
"ruleGenerateRules": "[Generation logic (same as Create Reward Reference)]\n• 26 cells ordered by id ascending are positions 025; each rows grid_number is 530 and unique.\n• Roll D (530): start at the cell whose grid_number equals D (start_index); clockwise landing = (start position + D) mod 26; counter-clockwise = start D (if negative, +26).\n• Each reference rows “dice points” column is the roll D; tier / real_ev / display text come from the config at the landing id.\n\n[Leopard rolls]\nFor rolls 5, 10, 15, 20, 25, 30, clockwise and counter-clockwise landing tiers must NOT be T4 or T5 (avoid leopard roll + penalty / try again).\n\n[real_ev vs tier]\nreal < 100 → T4; 100 < real < 0 → T3; 0 < real < 100 → T2; 100 < real < 500 → T1; T5 “try again” real_ev=0. Set per-tier real_ev standards below; values are written into the config and can be edited later.\n\n[Inputs]\nT1/T4/T5: fixed weighted counts. T2: minimum weighted count — clockwise and counter-clockwise must satisfy the corresponding constraints (one value per tier, applied to both directions). real_ev standards: one value per tier. Generated T1T4 use ui_text / ui_text_en = 100 + real_ev (same EN); T5 uses “try again” / “Once again”. Remarks still distinguish break-even vs small win where applicable.",
"ruleGenT1Row": "T1 (big prize)",
"ruleGenT2Row": "T2 (small win / break-even)",
"ruleGenT3RealEvOnly": "T3 (rake)",
"ruleGenT4Row": "T4 (penalty)",
"ruleGenT5Row": "T5 (try again)",
"ruleGenMinCount": "Min count",
"ruleGenFixedCount": "Fixed count (CW & CCW)",
"ruleGenRealEvStd": "real_ev standard",
"ruleGenRealEvEditHint": "After saving, you can still edit display text, EN, real_ev and remarks per row in the table above.",
"ruleGenInvalidT1RealEv": "T1 real_ev must satisfy 100 < value < 500",
"ruleGenInvalidT2RealEv": "T2 real_ev must satisfy 0 < value < 100",
"ruleGenInvalidT3RealEv": "T3 real_ev must satisfy -100 < value < 0",
"ruleGenInvalidT4RealEv": "T4 real_ev must satisfy value < -100",
"ruleGenInvalidT5RealEv": "T5 “try again” real_ev must be 0",
"ruleGenT1Min": "T1 fixed count (CW & CCW)",
"ruleGenT2Min": "T2 min (CW & CCW)",
"ruleGenT4Max": "T4 fixed count (CW & CCW)",
"ruleGenT5Max": "T5 fixed count (CW & CCW)",
"ruleGenScopeHint": "T1/T4/T5 are exact; T2 is minimum: clockwise and counter-clockwise weighted counts must satisfy each constraint.",
"ruleGenApply": "Generate and save",
"ruleGenNeedFullGrid": "Missing id 025 rows or incomplete grid_number; cannot generate",
"ruleGenFreqFail": "Cannot compute board frequencies; check grid_number",
"ruleGenUnknownId": "Unknown reward index id: {id}",
"ruleGenSuccess": "Generated and saved. Clockwise weighted: T1={cwT1} T2={cwT2} T4={cwT4} T5={cwT5}; counter-clockwise: T1={ccT1} T2={ccT2} T4={ccT4} T5={ccT5}",
"btnJsonImport": "JSON import",
"jsonImportTitle": "Reward index JSON import",
"jsonImportHint": "Current Reward Index rows (excluding BIGWIN) are filled below. Edit and submit; id must be 025, grid_number must be 530. Submit applies to the table and saves.",
"jsonImportParseFail": "Invalid JSON",
"jsonImportNotArray": "Root must be a JSON array",
"jsonImportItemInvalid": "Item {n} is not a valid object",
"jsonImportMissingField": "Item {n} is missing field: {field}",
"jsonImportIdRange": "id must be 025; item {n} has {v}",
"jsonImportGridRange": "grid_number must be 530; item {n} has {v}",
"jsonImportDupId": "Duplicate id in JSON: {list}",
"jsonImportDupGrid": "Duplicate grid_number in JSON: {list}",
"jsonImportFullIdSet": "For 26 rows, id must be exactly 025 once each",
"jsonImportFullGridSet": "For 26 rows, grid_number must be exactly 530 once each",
"jsonImportUnknownId": "Unknown id: {id} (export from the current list first)",
"jsonImportTierInvalid": "Invalid tier at item {n}",
"jsonImportEmpty": "Nothing to submit"
},
"weightRatio": {
"title": "T1T5 Weight Ratio (Clockwise / Counter-clockwise)",

View File

@@ -12,6 +12,7 @@
"platformProfit": "Platform Profit",
"totalDrawCount": "Total Draw Count",
"createdBy": "Created By",
"remark": "Remark",
"createTime": "Create Time",
"statusFail": "Failed",
"statusDone": "Done",

View File

@@ -0,0 +1,37 @@
{
"search": {
"name": "名称",
"title": "标题",
"isDefault": "是否默认",
"placeholderName": "请输入名称",
"placeholderTitle": "请输入标题",
"placeholderIsDefault": "请选择是否默认"
},
"table": {
"id": "ID",
"name": "名称",
"title": "标题",
"mult": "底注倍率",
"isDefault": "默认底注",
"defaultYes": "是",
"defaultNo": "否",
"createTime": "创建时间",
"updateTime": "更新时间"
},
"form": {
"titleAdd": "新增底注配置",
"titleEdit": "编辑底注配置",
"labelName": "名称",
"labelTitle": "标题",
"labelMult": "底注倍率",
"labelIsDefault": "默认底注",
"placeholderName": "请输入名称",
"placeholderTitle": "请输入标题",
"ruleNameRequired": "请输入名称",
"ruleTitleRequired": "请输入标题",
"ruleMultRequired": "请输入底注倍率",
"ruleDefaultRequired": "请选择是否默认底注",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
}
}

View File

@@ -23,7 +23,7 @@
"poolName": "池子名称",
"playerProfit": "玩家累计盈利profit_amount",
"realtime": "实时",
"profitCalcHint": "计算方式:每局按“当前中奖金额(含超级大奖 BIGWIN减去抽奖券费用 100”累加弹窗打开期间每 2 秒自动刷新",
"profitCalcHint": "计算方式:付费每局按“赢取平台币 win_coin含 BIGWIN减去付费金额 压注金额paid_amount= 压注倍数ante×100”累加免费每局按“玩家赢得平台币win_coin”累加。弹窗打开期间每 2 秒自动刷新",
"tierRuleTitle": "抽奖档位规则",
"tierRuleContent": "当玩家在当前彩金池的累计盈利 低于安全线 时,按 玩家 的 T*_weight 权重抽取档位;当累计盈利 高于或等于安全线 时,按 当前彩金池 的 T*_weight 权重抽取档位(杀分)。",
"killScoreWeights": "杀分权重",

View File

@@ -8,7 +8,7 @@
"placeholderLotteryPool": "请选择彩金池配置",
"drawType": "抽奖类型",
"paid": "付费",
"free": "赠送",
"free": "免费",
"isBigWin": "是否中大奖",
"noBigWin": "无",
"bigWin": "中大奖",
@@ -53,7 +53,7 @@
"nameFuzzy": "名称模糊",
"uiTextFuzzy": "前端显示文本模糊",
"paid": "付费",
"free": "赠送",
"free": "免费",
"noBigWin": "无",
"bigWin": "中大奖",
"clockwise": "顺时针",
@@ -64,6 +64,8 @@
"player": "玩家",
"lotteryPoolConfig": "彩金池配置",
"drawType": "抽奖类型",
"ante": "注数",
"paidAmount": "付费金额",
"isBigWin": "是否中大奖",
"winCoin": "赢取平台币",
"superWinCoin": "中大奖平台币",

View File

@@ -4,14 +4,17 @@
"platformTotalProfit": "平台总盈利"
},
"search": {
"rewardConfigRecordId": "测试记录ID",
"drawType": "抽奖类型",
"direction": "方向",
"isBigWin": "是否中大奖",
"winCoin": "赢取平台币",
"paidAmount": "付费金额",
"ante": "底注",
"rewardTier": "奖励档位",
"rollNumber": "摇取点数和",
"paid": "付费",
"free": "赠送",
"free": "免费",
"clockwise": "顺时针",
"anticlockwise": "逆时针",
"noBigWin": "无",
@@ -19,10 +22,13 @@
},
"table": {
"id": "ID",
"rewardConfigRecordId": "测试记录ID",
"player": "玩家",
"lotteryPoolConfig": "彩金池配置",
"drawType": "抽奖类型",
"isBigWin": "是否中大奖",
"paidAmount": "付费金额",
"ante": "底注",
"winCoin": "赢取平台币",
"superWinCoin": "中大奖平台币",
"rewardWinCoin": "摇色子中奖平台币",

View File

@@ -19,6 +19,7 @@
"search": {
"player": "玩家",
"useCoins": "消耗硬币",
"ante": "底注",
"totalDrawCount": "总抽奖次数",
"paidDrawCount": "购买抽奖次数",
"freeDrawCount": "赠送抽奖次数",
@@ -29,6 +30,7 @@
"id": "ID",
"playerUsername": "玩家用户名",
"useCoins": "消耗硬币",
"ante": "底注",
"totalDrawCount": "总抽奖次数",
"paidDrawCount": "购买抽奖次数",
"freeDrawCount": "赠送抽奖次数",

View File

@@ -61,6 +61,7 @@
"stepFree": "免费抽奖券",
"labelLotteryTypePaid": "测试数据档位类型",
"labelLotteryTypeFree": "测试数据档位类型",
"labelAnte": "底注 ante",
"placeholderPaidPool": "不选则下方自定义档位概率(默认 default",
"placeholderFreePool": "不选则下方自定义档位概率(默认 killScore",
"tierProbHint": "自定义档位概率T1T5每档 0-100%,五档之和不能超过 100%",
@@ -73,6 +74,7 @@
"btnNext": "下一步",
"btnStart": "开始测试",
"btnCancel": "取消",
"warnAnte": "底注 ante 必须大于 0",
"warnTotalSpins": "付费或免费至少一种方向次数之和大于 0",
"warnPaidTierSumPositive": "付费未选奖池时T1T5 档位概率之和需大于 0",
"warnPaidTierSumMax": "付费档位概率 T1T5 之和不能超过 100%",

View File

@@ -50,7 +50,50 @@
"warnDupGrid": "色子点数在本表内不能重复,重复的点数为:{list}",
"warnNoBigwinToSave": "暂无 BIGWIN 档位配置可保存",
"warnBigwinDupGrid": "大奖权重本表内点数不能重复,重复的点数为:{list}",
"infoNoBigwin": "暂无 BIGWIN 档位配置,请先在「奖励索引」中设置 tier 为 BIGWIN"
"infoNoBigwin": "暂无 BIGWIN 档位配置,请先在「奖励索引」中设置 tier 为 BIGWIN",
"btnRuleGenerate": "按规则生成",
"ruleGenerateTitle": "按规则生成奖励索引",
"ruleGenerateRules": "【生成逻辑(与创建奖励对照一致)】\n• 盘面 26 格按 id 升序为位置 025每条配置的 grid_number 为 530 且不重复。\n• 摇取点数 D530起点为「grid_number=D」所在格位的 id即 start_index顺时针落点位置 = (起点位置 + D) mod 26逆时针落点 = 起点位置 D若小于 0 则 +26。\n• 对照表每条记录的「色子点数」列为摇取点数 D档位、真实结算、显示文案取自落点格位对应 id 的配置。\n\n【豹子摇取点数】\n摇取点数为 5、10、15、20、25、30 时,其顺/逆时针落点档位不能为 T4、T5避免对照表上出现豹子点数 + 惩罚/再来一次)。\n\n【real_ev 与 tier】\nreal < 100 → T4100 < real < 0 → T30 < real < 100 → T2100 < real < 500 → T1T5「再来一次」real_ev=0。下方可为各档位填写统一的 real_ev 标准,生成时写入配置;细则可稍后在表格中再改。\n\n【本弹窗输入】\n条数T1/T4/T5「固定」T2「不少于」——顺时针与逆时针的加权条数每条摇取结果计一次须分别满足所填数值T1、T4 与 T5 分开填写。\nreal_ev 标准:同档位各格使用同一数值。生成时 T1T4 的 ui_text / ui_text_en 均为「100+真实结算」T5 固定为「再来一次」/「Once again」。备注仍区分完美回本/小赚等。",
"ruleGenT1Row": "T1 大奖",
"ruleGenT2Row": "T2 小赚/回本",
"ruleGenT3RealEvOnly": "T3 抽水",
"ruleGenT4Row": "T4 惩罚",
"ruleGenT5Row": "T5 再来一次",
"ruleGenMinCount": "最少条数",
"ruleGenFixedCount": "固定条数(顺/逆)",
"ruleGenRealEvStd": "real_ev 标准",
"ruleGenRealEvEditHint": "生成并保存后,仍可在本页表格中逐条修改显示文案、英文、真实结算与备注。",
"ruleGenInvalidT1RealEv": "T1 的 real_ev 须满足100 < 值 < 500",
"ruleGenInvalidT2RealEv": "T2 的 real_ev 须满足0 < 值 < 100",
"ruleGenInvalidT3RealEv": "T3 的 real_ev 须满足:-100 < 值 < 0",
"ruleGenInvalidT4RealEv": "T4 的 real_ev 须满足:值 < -100",
"ruleGenInvalidT5RealEv": "T5「再来一次」的 real_ev 须为 0",
"ruleGenT1Min": "T1 固定条数(顺/逆)",
"ruleGenT2Min": "T2 最少条数(顺/逆)",
"ruleGenT4Max": "T4 固定条数(顺/逆)",
"ruleGenT5Max": "T5 固定条数(顺/逆)",
"ruleGenScopeHint": "T1/T4/T5 为「恰好」T2 为「不少于」:顺时针与逆时针加权条数须分别满足对应约束。",
"ruleGenApply": "生成并保存",
"ruleGenNeedFullGrid": "当前列表缺少 id 025 的奖励索引行或色子点数不完整,无法生成",
"ruleGenFreqFail": "无法计算盘面频率,请检查 grid_number",
"ruleGenUnknownId": "不存在奖励索引 id{id}",
"ruleGenSuccess": "已按规则生成并保存。顺时针加权T1={cwT1} T2={cwT2} T4={cwT4} T5={cwT5}逆时针加权T1={ccT1} T2={ccT2} T4={ccT4} T5={ccT5}",
"btnJsonImport": "JSON 导入",
"jsonImportTitle": "奖励索引 JSON 导入",
"jsonImportHint": "当前「奖励索引」表数据(不含 BIGWIN已填入下方可编辑后提交奖励索引 id 须为 025色子点数 grid_number 须为 530。提交后将写入表格并保存。",
"jsonImportParseFail": "JSON 解析失败,请检查格式",
"jsonImportNotArray": "JSON 根节点必须为数组",
"jsonImportItemInvalid": "第 {n} 项不是有效对象",
"jsonImportMissingField": "第 {n} 项缺少字段:{field}",
"jsonImportIdRange": "奖励索引 id 须为 025第 {n} 项为 {v}",
"jsonImportGridRange": "色子点数 grid_number 须为 530第 {n} 项为 {v}",
"jsonImportDupId": "JSON 内奖励索引 id 重复:{list}",
"jsonImportDupGrid": "JSON 内色子点数重复:{list}",
"jsonImportFullIdSet": "共 26 条时,奖励索引 id 必须且仅能各出现一次025",
"jsonImportFullGridSet": "共 26 条时色子点数必须且仅能各出现一次530",
"jsonImportUnknownId": "不存在奖励索引 id{id}(请从当前列表导出后编辑)",
"jsonImportTierInvalid": "第 {n} 项所属档位 tier 无效",
"jsonImportEmpty": "没有可提交的条目"
},
"weightRatio": {
"title": "T1-T5 权重配比(顺时针/逆时针)",

View File

@@ -12,6 +12,7 @@
"platformProfit": "平台赚取金额",
"totalDrawCount": "总抽奖次数",
"createdBy": "创建管理员",
"remark": "备注",
"createTime": "创建时间",
"statusFail": "失败",
"statusDone": "完成",

View File

@@ -0,0 +1,139 @@
<template>
<div class="art-full-height">
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never">
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<ElSpace wrap>
<ElButton v-permission="'dice:ante_config:index:save'" @click="showDialog('add')" v-ripple>
<template #icon>
<ArtSvgIcon icon="ri:add-fill" />
</template>
{{ $t('table.actions.add') }}
</ElButton>
<ElButton
v-permission="'dice:ante_config:index:destroy'"
:disabled="selectedRows.length === 0"
@click="deleteSelectedRows(api.delete, refreshData)"
v-ripple
>
<template #icon>
<ArtSvgIcon icon="ri:delete-bin-5-line" />
</template>
{{ $t('table.actions.delete') }}
</ElButton>
</ElSpace>
</template>
</ArtTableHeader>
<ArtTable
ref="tableRef"
rowKey="id"
:loading="loading"
:data="data"
:columns="columns"
:pagination="pagination"
@sort-change="handleSortChange"
@selection-change="handleSelectionChange"
@pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange"
>
<template #is_default="{ row }">
<ElTag :type="row.is_default === 1 ? 'success' : 'info'" size="small">
{{ row.is_default === 1 ? $t('page.table.defaultYes') : $t('page.table.defaultNo') }}
</ElTag>
</template>
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
v-permission="'dice:ante_config:index:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<SaButton
v-permission="'dice:ante_config:index:destroy'"
type="error"
@click="deleteRow(row, api.delete, refreshData)"
/>
</div>
</template>
</ArtTable>
</ElCard>
<EditDialog
v-model="dialogVisible"
:dialog-type="dialogType"
:data="dialogData"
@success="refreshData"
/>
</div>
</template>
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/ante_config/index'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
const searchForm = ref({
name: undefined,
title: undefined,
is_default: undefined
})
const handleSearch = (params: Record<string, unknown>) => {
Object.assign(searchParams, params)
getData()
}
const {
columns,
columnChecks,
data,
loading,
getData,
searchParams,
pagination,
resetSearchParams,
handleSortChange,
handleSizeChange,
handleCurrentChange,
refreshData
} = useTable({
core: {
apiFn: api.list,
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
{ prop: 'name', label: 'page.table.name', align: 'center' },
{ prop: 'title', label: 'page.table.title', align: 'center' },
{ prop: 'mult', label: 'page.table.mult', align: 'center' },
{ prop: 'is_default', label: 'page.table.isDefault', width: 110, align: 'center', useSlot: true },
{ prop: 'create_time', label: 'page.table.createTime', width: 170, align: 'center' },
{ prop: 'update_time', label: 'page.table.updateTime', width: 170, align: 'center' },
{
prop: 'operation',
label: 'table.actions.operation',
width: 100,
align: 'center',
fixed: 'right',
useSlot: true
}
]
}
})
const {
dialogType,
dialogVisible,
dialogData,
showDialog,
deleteRow,
deleteSelectedRows,
handleSelectionChange,
selectedRows
} = useSaiAdmin()
</script>

View File

@@ -0,0 +1,126 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
width="560px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form-item :label="$t('page.form.labelName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderName')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelTitle')" prop="title">
<el-input v-model="formData.title" :placeholder="$t('page.form.placeholderTitle')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelMult')" prop="mult">
<el-input-number v-model="formData.mult" :min="1" :step="1" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('page.form.labelIsDefault')" prop="is_default">
<el-radio-group v-model="formData.is_default">
<el-radio :value="1">{{ $t('page.table.defaultYes') }}</el-radio>
<el-radio :value="0">{{ $t('page.table.defaultNo') }}</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/ante_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
interface Props {
modelValue: boolean
dialogType: string
data?: Record<string, unknown>
}
interface Emits {
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
data: undefined
})
const emit = defineEmits<Emits>()
const formRef = ref<FormInstance>()
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
const rules = computed<FormRules>(() => ({
name: [{ required: true, message: t('page.form.ruleNameRequired'), trigger: 'blur' }],
title: [{ required: true, message: t('page.form.ruleTitleRequired'), trigger: 'blur' }],
mult: [{ required: true, message: t('page.form.ruleMultRequired'), trigger: 'blur' }],
is_default: [{ required: true, message: t('page.form.ruleDefaultRequired'), trigger: 'change' }]
}))
interface AnteFormData {
id: number | null
name: string
title: string
mult: number
is_default: number
}
const initialFormData: AnteFormData = {
id: null,
name: '',
title: '',
mult: 1,
is_default: 0
}
const formData = reactive({ ...initialFormData })
watch(
() => props.modelValue,
async (newVal) => {
if (!newVal) return
Object.assign(formData, initialFormData)
if (!props.data) return
await nextTick()
if (typeof props.data.id === 'number') formData.id = props.data.id
if (typeof props.data.name === 'string') formData.name = props.data.name
if (typeof props.data.title === 'string') formData.title = props.data.title
formData.mult = Number(props.data.mult ?? 1) || 1
formData.is_default = Number(props.data.is_default ?? 0) === 1 ? 1 : 0
}
)
function handleClose() {
visible.value = false
formRef.value?.resetFields()
}
async function handleSubmit() {
if (!formRef.value) return
try {
await formRef.value.validate()
if (props.dialogType === 'add') {
await api.save(formData)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(formData)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log(error)
}
}
</script>

View File

@@ -0,0 +1,76 @@
<template>
<sa-search-bar
ref="searchBarRef"
v-model="formData"
label-width="100px"
:showExpand="false"
@reset="handleReset"
@search="handleSearch"
>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.name')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.search.placeholderName')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.title')" prop="title">
<el-input v-model="formData.title" :placeholder="$t('page.search.placeholderTitle')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.isDefault')" prop="is_default">
<el-select v-model="formData.is_default" :placeholder="$t('page.search.placeholderIsDefault')" clearable>
<el-option :label="$t('page.table.defaultYes')" :value="1" />
<el-option :label="$t('page.table.defaultNo')" :value="0" />
</el-select>
</el-form-item>
</el-col>
</sa-search-bar>
</template>
<script setup lang="ts">
type AnteConfigSearchForm = {
name?: string
title?: string
/** 1=是 0=否 */
is_default?: 0 | 1 | null
[key: string]: unknown
}
interface Props {
modelValue: AnteConfigSearchForm
}
interface Emits {
(e: 'update:modelValue', value: AnteConfigSearchForm): void
(e: 'search', params: AnteConfigSearchForm): void
(e: 'reset'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const searchBarRef = ref()
const formData = computed<AnteConfigSearchForm>({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val)
})
function handleReset() {
searchBarRef.value?.ref.resetFields()
emit('reset')
}
function handleSearch() {
emit('search', formData.value)
}
const setSpan = (span: number) => {
return {
span,
xs: 24,
sm: span >= 12 ? span : 12,
md: span >= 8 ? span : 8,
lg: span,
xl: span
}
}
</script>

View File

@@ -0,0 +1,40 @@
import request from '@/utils/http'
/**
* 底注配置 API
*/
export default {
list(params: Record<string, unknown>) {
return request.get<Api.Common.ApiPage>({
url: '/core/dice/ante_config/DiceAnteConfig/index',
params
})
},
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/ante_config/DiceAnteConfig/read?id=' + id
})
},
save(params: Record<string, unknown>) {
return request.post({
url: '/core/dice/ante_config/DiceAnteConfig/save',
data: params
})
},
update(params: Record<string, unknown>) {
return request.put({
url: '/core/dice/ante_config/DiceAnteConfig/update',
data: params
})
},
delete(params: Record<string, unknown>) {
return request.del({
url: '/core/dice/ante_config/DiceAnteConfig/destroy',
data: params
})
}
}

View File

@@ -10,7 +10,7 @@ export default {
* @returns 数据列表
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
return request.get<Api.Common.ApiPage & { total_win_coin?: number }>({
url: '/core/dice/play_record_test/DicePlayRecordTest/index',
params
})

View File

@@ -61,6 +61,7 @@ export default {
* 可选 lottery_config_id不选则传 paid_tier_weights / free_tier_weightsT1-T5
*/
startWeightTest(params: {
ante?: number
lottery_config_id?: number
paid_lottery_config_id?: number
free_lottery_config_id?: number

View File

@@ -71,6 +71,16 @@
{{ row.direction === 0 ? t('page.search.clockwise') : row.direction === 1 ? t('page.search.anticlockwise') : '-' }}
</ElTag>
</template>
<!-- 平台币相关统一整数显示 -->
<template #win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.win_coin) }}</span>
</template>
<template #super_win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.super_win_coin) }}</span>
</template>
<template #reward_win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.reward_win_coin) }}</span>
</template>
<!-- 摇取点数 tag -->
<template #roll_array="{ row }">
<ElTag size="small">
@@ -166,6 +176,13 @@
return String(val)
}
function formatPlatformCoin(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
// 表格配置
const {
columns,
@@ -199,10 +216,12 @@
useSlot: true
},
{ prop: 'lottery_type', label: 'page.table.drawType', width: 100, useSlot: true },
{ prop: 'ante', label: 'page.table.ante', width: 80, align: 'center' },
{ prop: 'paid_amount', label: 'page.table.paidAmount', width: 110, align: 'center' },
{ prop: 'is_win', label: 'page.table.isBigWin', width: 100, useSlot: true },
{ prop: 'win_coin', label: 'page.table.winCoin', width: 110 },
{ prop: 'super_win_coin', label: 'page.table.superWinCoin', width: 120 },
{ prop: 'reward_win_coin', label: 'page.table.rewardWinCoin', width: 140 },
{ prop: 'win_coin', label: 'page.table.winCoin', width: 110, useSlot: true },
{ prop: 'super_win_coin', label: 'page.table.superWinCoin', width: 120, useSlot: true },
{ prop: 'reward_win_coin', label: 'page.table.rewardWinCoin', width: 140, useSlot: true },
{ prop: 'direction', label: 'page.table.direction', width: 90, useSlot: true },
{ prop: 'start_index', label: 'page.table.startIndex', width: 90 },
{ prop: 'target_index', label: 'page.table.targetIndex', width: 90 },

View File

@@ -70,7 +70,7 @@
<el-input-number
v-model="formData.win_coin"
:placeholder="$t('page.form.placeholderWinCoin')"
:precision="2"
:precision="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
/>
@@ -79,7 +79,7 @@
<el-input-number
v-model="formData.super_win_coin"
:placeholder="$t('page.form.placeholderSuperWinCoin')"
:precision="2"
:precision="0"
:min="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
@@ -89,7 +89,7 @@
<el-input-number
v-model="formData.reward_win_coin"
:placeholder="$t('page.form.placeholderRewardWinCoin')"
:precision="2"
:precision="0"
:min="0"
style="width: 100%"
:disabled="dialogType === 'edit'"

View File

@@ -48,7 +48,7 @@
<el-input-number
v-model="formData.win_coin_min"
:placeholder="$t('table.searchBar.min')"
:precision="2"
:precision="0"
controls-position="right"
class="range-input"
/>
@@ -56,7 +56,7 @@
<el-input-number
v-model="formData.win_coin_max"
:placeholder="$t('table.searchBar.max')"
:precision="2"
:precision="0"
controls-position="right"
class="range-input"
/>

View File

@@ -8,7 +8,7 @@
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<span v-if="totalWinCoin !== null" class="table-summary-inline">
{{ $t('page.toolbar.platformTotalProfit') }}<strong>{{ totalWinCoin }}</strong>
{{ $t('page.toolbar.platformTotalProfit') }}<strong>{{ formatPlatformCoin(totalWinCoin) }}</strong>
</span>
<ElSpace wrap class="table-toolbar-buttons">
<ElButton
@@ -58,19 +58,37 @@
<!-- 抽奖类型 -->
<template #lottery_type="{ row }">
<ElTag size="small" :type="row.lottery_type === 0 ? 'warning' : 'success'">
{{ row.lottery_type === 0 ? t('page.search.paid') : row.lottery_type === 1 ? t('page.search.free') : '-' }}
{{
row.lottery_type === 0
? t('page.search.paid')
: row.lottery_type === 1
? t('page.search.free')
: '-'
}}
</ElTag>
</template>
<!-- 是否中大奖 -->
<template #is_win="{ row }">
<ElTag size="small" :type="row.is_win === 1 ? 'success' : 'info'">
{{ row.is_win === 0 ? t('page.search.noBigWin') : row.is_win === 1 ? t('page.search.bigWin') : '-' }}
{{
row.is_win === 0
? t('page.search.noBigWin')
: row.is_win === 1
? t('page.search.bigWin')
: '-'
}}
</ElTag>
</template>
<!-- 方向 -->
<template #direction="{ row }">
<ElTag size="small" :type="row.direction === 0 ? 'primary' : 'warning'">
{{ row.direction === 0 ? t('page.search.clockwise') : row.direction === 1 ? t('page.search.anticlockwise') : '-' }}
{{
row.direction === 0
? t('page.search.clockwise')
: row.direction === 1
? t('page.search.anticlockwise')
: '-'
}}
</ElTag>
</template>
<!-- 摇取点数 -->
@@ -83,6 +101,16 @@
<template #reward_config_id="{ row }">
<ElTag size="small">{{ rewardTierFormatter(row) }}</ElTag>
</template>
<!-- 平台币相关统一整数显示 -->
<template #win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.win_coin) }}</span>
</template>
<template #super_win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.super_win_coin) }}</span>
</template>
<template #reward_win_coin="{ row }">
<span>{{ formatPlatformCoin(row?.reward_win_coin) }}</span>
</template>
<!-- 状态 -->
<template #status="{ row }">
<ElTag size="small" :type="row.status === 1 ? 'success' : 'info'">
@@ -129,9 +157,12 @@
// 搜索表单(与 play_record 对齐:方向、赢取平台币范围、是否中大奖、中奖档位、点数和)
const searchForm = ref<Record<string, unknown>>({
reward_config_record_id: undefined,
lottery_type: undefined,
direction: undefined,
is_win: undefined,
paid_amount: undefined,
ante: undefined,
win_coin_min: undefined,
win_coin_max: undefined,
reward_tier: undefined,
@@ -143,7 +174,7 @@
const listApi = async (params: Record<string, any>) => {
const res = await api.list(params)
totalWinCoin.value = (res as any)?.total_win_coin ?? null
totalWinCoin.value = res?.total_win_coin ?? null
return res
}
@@ -167,6 +198,13 @@
return String(val)
}
function formatPlatformCoin(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
const handleClearAll = async () => {
try {
await ElMessageBox.confirm('确定清空所有玩家抽奖测试数据?', '提示', {
@@ -208,12 +246,24 @@
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'id', label: 'page.table.id', width: 80 },
{ prop: 'lottery_config_id', label: 'page.table.lotteryPoolConfig', width: 120, useSlot: true },
{
prop: 'reward_config_record_id',
label: 'page.table.rewardConfigRecordId',
width: 120
},
{
prop: 'lottery_config_id',
label: 'page.table.lotteryPoolConfig',
width: 120,
useSlot: true
},
{ prop: 'lottery_type', label: 'page.table.drawType', width: 100, useSlot: true },
{ prop: 'is_win', label: 'page.table.isBigWin', width: 100, useSlot: true },
{ prop: 'win_coin', label: 'page.table.winCoin', width: 110 },
{ prop: 'super_win_coin', label: 'page.table.superWinCoin', width: 120 },
{ prop: 'reward_win_coin', label: 'page.table.rewardWinCoin', width: 140 },
{ prop: 'paid_amount', label: 'page.table.paidAmount', width: 130 },
{ prop: 'ante', label: 'page.table.ante', width: 90 },
{ prop: 'win_coin', label: 'page.table.winCoin', width: 110, useSlot: true },
{ prop: 'super_win_coin', label: 'page.table.superWinCoin', width: 120, useSlot: true },
{ prop: 'reward_win_coin', label: 'page.table.rewardWinCoin', width: 140, useSlot: true },
{ prop: 'direction', label: 'page.table.direction', width: 90, useSlot: true },
{ prop: 'start_index', label: 'page.table.startIndex', width: 90 },
{ prop: 'target_index', label: 'page.table.targetIndex', width: 90 },
@@ -222,7 +272,13 @@
{ prop: 'reward_config_id', label: 'page.table.rewardConfig', width: 100, useSlot: true },
{ prop: 'status', label: 'page.table.status', width: 80, useSlot: true },
{ prop: 'create_time', label: 'page.table.createTime', width: 170 },
{ prop: 'operation', label: 'table.actions.operation', width: 100, fixed: 'right', useSlot: true }
{
prop: 'operation',
label: 'table.actions.operation',
width: 100,
fixed: 'right',
useSlot: true
}
]
}
})

View File

@@ -28,6 +28,24 @@
<el-option :label="$t('page.search.anticlockwise')" :value="1" />
</el-select>
</el-form-item>
<el-form-item :label="$t('page.search.ante')" prop="ante">
<el-input-number
v-model="formData.ante"
:placeholder="$t('table.searchBar.all')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('page.search.paidAmount')" prop="paid_amount">
<el-input-number
v-model="formData.paid_amount"
:placeholder="$t('table.searchBar.all')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('page.search.isBigWin')" prop="is_win">
<el-select v-model="formData.is_win" :placeholder="$t('form.placeholderSelect')" clearable style="width: 100%">
<el-option :label="$t('page.search.noBigWin')" :value="0" />
@@ -38,7 +56,7 @@
<el-input-number
v-model="formData.win_coin"
:placeholder="$t('page.form.placeholderWinCoin')"
:precision="2"
:precision="0"
controls-position="right"
style="width: 100%"
/>
@@ -80,10 +98,22 @@
<sa-radio v-model="formData.status" dict="data_status" />
</el-form-item>
<el-form-item :label="$t('page.table.superWinCoin')" prop="super_win_coin">
<el-input v-model="formData.super_win_coin" :placeholder="$t('page.form.placeholderSuperWinCoin')" />
<el-input-number
v-model="formData.super_win_coin"
:placeholder="$t('page.form.placeholderSuperWinCoin')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('page.table.rewardWinCoin')" prop="reward_win_coin">
<el-input v-model="formData.reward_win_coin" :placeholder="$t('page.form.placeholderRewardWinCoin')" />
<el-input-number
v-model="formData.reward_win_coin"
:placeholder="$t('page.form.placeholderRewardWinCoin')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
<el-form-item :label="$t('page.form.labelAdminId')" prop="admin_id">
<el-input v-model="formData.admin_id" :placeholder="$t('page.form.placeholderAdminId')" />
@@ -153,6 +183,8 @@
lottery_config_id: null,
lottery_type: null,
is_win: null,
ante: 1,
paid_amount: 0,
win_coin: 0,
direction: null,
reward_tier: undefined as string | undefined,
@@ -162,8 +194,8 @@
roll_number: null,
roll_array: '',
status: 1,
super_win_coin: '0.00',
reward_win_coin: '0.00',
super_win_coin: 0,
reward_win_coin: 0,
admin_id: null
}
@@ -200,6 +232,13 @@
/**
* 初始化表单数据
*/
function normalizePlatformCoin(val: unknown): number {
if (val === '' || val === null || val === undefined) return 0
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return 0
return Math.trunc(n)
}
const initForm = () => {
if (props.data) {
for (const key in formData) {
@@ -208,9 +247,9 @@
;(formData as Record<string, unknown>)[key] = props.data[key]
}
}
if (typeof formData.win_coin === 'string') {
formData.win_coin = parseFloat(formData.win_coin) || 0
}
formData.win_coin = normalizePlatformCoin(formData.win_coin)
formData.super_win_coin = normalizePlatformCoin(formData.super_win_coin)
formData.reward_win_coin = normalizePlatformCoin(formData.reward_win_coin)
}
}
@@ -227,8 +266,8 @@
saiType: 'all',
tier: tier
})
const list = (res as any)?.data ?? (Array.isArray(res) ? res : [])
const first = Array.isArray(list) ? list[0] : (list?.data?.[0] ?? list?.[0])
const list = res?.data
const first = Array.isArray(list) && list.length > 0 ? list[0] : undefined
if (first && first.id != null) {
formData.reward_config_id = first.id
} else {

View File

@@ -8,6 +8,18 @@
@search="handleSearch"
@expand="handleExpand"
>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.rewardConfigRecordId')" prop="reward_config_record_id">
<el-input-number
v-model="formData.reward_config_record_id"
:placeholder="$t('table.searchBar.all')"
:precision="0"
:step="1"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.drawType')" prop="lottery_type">
<el-select v-model="formData.lottery_type" :placeholder="$t('table.searchBar.all')" clearable style="width: 100%">
@@ -32,13 +44,35 @@
</el-select>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.paidAmount')" prop="paid_amount">
<el-input-number
v-model="formData.paid_amount"
:placeholder="$t('table.searchBar.all')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.ante')" prop="ante">
<el-input-number
v-model="formData.ante"
:placeholder="$t('table.searchBar.all')"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.winCoin')" prop="win_coin_min">
<div class="range-wrap">
<el-input-number
v-model="formData.win_coin_min"
:placeholder="$t('table.searchBar.min')"
:precision="2"
:precision="0"
controls-position="right"
class="range-input"
/>
@@ -46,7 +80,7 @@
<el-input-number
v-model="formData.win_coin_max"
:placeholder="$t('table.searchBar.max')"
:precision="2"
:precision="0"
controls-position="right"
class="range-input"
/>

View File

@@ -82,6 +82,7 @@
username: undefined,
use_coins_min: undefined,
use_coins_max: undefined,
ante: undefined,
total_ticket_count_min: undefined,
total_ticket_count_max: undefined,
paid_ticket_count_min: undefined,
@@ -136,6 +137,7 @@
formatter: (row: Record<string, any>) => usernameFormatter(row)
},
{ prop: 'use_coins', label: 'page.table.useCoins', align: 'center' },
{ prop: 'ante', label: 'page.table.ante', align: 'center' },
{ prop: 'total_ticket_count', label: 'page.table.totalDrawCount', align: 'center' },
{ prop: 'paid_ticket_count', label: 'page.table.paidDrawCount', align: 'center' },
{ prop: 'free_ticket_count', label: 'page.table.freeDrawCount', align: 'center' },

View File

@@ -34,6 +34,18 @@
</div>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.ante')" prop="ante">
<el-input-number
v-model="formData.ante"
:placeholder="$t('table.searchBar.all')"
:min="1"
:precision="0"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.totalDrawCount')" prop="total_ticket_count_min">
<div class="range-wrap">

View File

@@ -146,6 +146,13 @@
return player?.username ?? row.player_id ?? '-'
}
function formatInteger(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
// 表格配置
const {
columns,
@@ -190,8 +197,20 @@
align: 'center',
formatter: operatorFormatter
},
{ prop: 'wallet_before', label: 'page.table.walletBefore', width: 110, align: 'center' },
{ prop: 'wallet_after', label: 'page.table.walletAfter', width: 110, align: 'center' },
{
prop: 'wallet_before',
label: 'page.table.walletBefore',
width: 110,
align: 'center',
formatter: (row: Record<string, any>) => formatInteger(row?.wallet_before)
},
{
prop: 'wallet_after',
label: 'page.table.walletAfter',
width: 110,
align: 'center',
formatter: (row: Record<string, any>) => formatInteger(row?.wallet_after)
},
{
prop: 'remark',
label: 'page.table.remark',

View File

@@ -45,7 +45,7 @@
<el-input-number
v-model="formData.coin"
:placeholder="$t('page.form.placeholderCoinChange')"
:precision="2"
:precision="0"
style="width: 100%"
@change="onCoinChange"
:disabled="dialogType === 'edit'"
@@ -55,7 +55,7 @@
<el-input-number
v-model="formData.wallet_before"
:placeholder="$t('page.form.placeholderWalletBefore')"
:precision="2"
:precision="0"
disabled
style="width: 100%"
/>
@@ -64,7 +64,7 @@
<el-input-number
v-model="formData.wallet_after"
:placeholder="$t('page.form.placeholderWalletAfter')"
:precision="2"
:precision="0"
disabled
style="width: 100%"
/>
@@ -131,14 +131,22 @@
type: [{ required: true, message: '请选择类型', trigger: 'change' }]
})
const initialFormData = {
id: null as number | null,
player_id: null as number | null,
coin: 0 as number,
type: null as number | null,
wallet_before: 0 as number,
wallet_after: 0 as number,
remark: '' as string
const initialFormData: {
id: number | null
player_id: number | null
coin: number
type: number | null
wallet_before: number
wallet_after: number
remark: string
} = {
id: null,
player_id: null,
coin: 0,
type: null,
wallet_before: 0,
wallet_after: 0,
remark: ''
}
const formData = reactive({ ...initialFormData })
@@ -170,7 +178,7 @@
function calcWalletAfter() {
const before = Number(formData.wallet_before) || 0
const coin = Number(formData.coin) || 0
formData.wallet_after = Math.round((before + coin) * 100) / 100
formData.wallet_after = Math.trunc(before + coin)
}
watch(
@@ -196,23 +204,24 @@
}
}
const numKeys = ['id', 'player_id', 'coin', 'type', 'wallet_before', 'wallet_after']
function normalizeInteger(val: unknown, fallback: number): number {
if (val === '' || val === null || val === undefined) return fallback
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return fallback
return Math.trunc(n)
}
const initForm = () => {
if (!props.data) return
for (const key of Object.keys(formData)) {
if (!(key in props.data)) continue
const val = props.data[key]
if (numKeys.includes(key)) {
if (key === 'id' || key === 'player_id' || key === 'type') {
;(formData as any)[key] = val != null && val !== '' ? Number(val) : null
} else {
;(formData as any)[key] = val != null && val !== '' ? Number(val) : 0
}
} else {
;(formData as any)[key] = val ?? ''
}
}
formData.id = props.data.id != null && props.data.id !== '' ? Number(props.data.id) : null
formData.player_id =
props.data.player_id != null && props.data.player_id !== '' ? Number(props.data.player_id) : null
formData.type = props.data.type != null && props.data.type !== '' ? Number(props.data.type) : null
formData.coin = normalizeInteger(props.data.coin, 0)
formData.wallet_before = normalizeInteger(props.data.wallet_before, 0)
formData.wallet_after = normalizeInteger(props.data.wallet_after, 0)
formData.remark = props.data.remark ?? ''
}
const handleClose = () => {

View File

@@ -70,6 +70,13 @@
return api.list({ ...params, direction: currentDirection.value })
}
function formatInteger(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
const handleSearch = (params: Record<string, any>) => {
Object.assign(searchParams, { ...params, direction: currentDirection.value })
getData()
@@ -117,7 +124,13 @@
align: 'center',
showOverflowTooltip: true
},
{ prop: 'real_ev', label: 'page.table.realEv', width: 110, align: 'center' },
{
prop: 'real_ev',
label: 'page.table.realEv',
width: 110,
align: 'center',
formatter: (row: Record<string, any>) => formatInteger(row?.real_ev)
},
{ prop: 'remark', label: 'page.table.remark', minWidth: 80, align: 'center', showOverflowTooltip: true },
{ prop: 'weight', label: 'page.table.weight', width: 110, align: 'center' }
]

View File

@@ -60,7 +60,11 @@
width="90"
align="center"
show-overflow-tooltip
/>
>
<template #default="{ row }">
<span>{{ formatInteger(row?.real_ev) }}</span>
</template>
</el-table-column>
<el-table-column
:label="$t('page.weightShared.colUiText')"
prop="ui_text"
@@ -250,6 +254,13 @@
import api from '../../../api/reward/index'
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus'
function formatInteger(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
import { useI18n } from 'vue-i18n'
const { t } = useI18n()

View File

@@ -54,7 +54,11 @@
width="90"
align="center"
show-overflow-tooltip
/>
>
<template #default="{ row }">
<span>{{ formatInteger(row?.real_ev) }}</span>
</template>
</el-table-column>
<el-table-column
:label="$t('page.weightShared.colUiText')"
prop="ui_text"
@@ -315,6 +319,13 @@
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
function formatInteger(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return String(Math.trunc(n))
}
const { t, locale } = useI18n()

View File

@@ -12,6 +12,9 @@
{{ $t('page.weightTest.alertBody') }}
</ElAlert>
<ElForm ref="formRef" :model="form" label-width="140px">
<ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante" required>
<ElInputNumber v-model="form.ante" :min="1" :step="1" style="width: 100%" />
</ElFormItem>
<ElSteps :active="currentStep" finish-status="success" simple class="steps-wrap">
<ElStep :title="$t('page.weightTest.stepPaid')" />
<ElStep :title="$t('page.weightTest.stepFree')" />
@@ -187,6 +190,7 @@
const formRef = ref()
const currentStep = ref(0)
const form = reactive({
ante: 1,
paid_lottery_config_id: undefined as number | undefined,
free_lottery_config_id: undefined as number | undefined,
paid_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
@@ -270,6 +274,7 @@
function buildPayload() {
const payload: Record<string, unknown> = {
ante: form.ante,
paid_s_count: form.paid_s_count,
paid_n_count: form.paid_n_count,
free_s_count: form.free_s_count,
@@ -289,6 +294,10 @@
}
function validateForm(): boolean {
if (form.ante == null || form.ante <= 0) {
ElMessage.warning(t('page.weightTest.warnAnte'))
return false
}
if (form.paid_s_count + form.paid_n_count + form.free_s_count + form.free_n_count <= 0) {
ElMessage.warning(t('page.weightTest.warnTotalSpins'))
return false

View File

@@ -21,6 +21,16 @@
<ElTabPane :label="$t('page.configPage.tabIndex')" name="index">
<div class="tab-panel">
<div class="panel-tip">{{ $t('page.configPage.tipIndex') }}</div>
<div class="index-toolbar">
<ElButton
v-permission="'dice:reward_config:index:batchUpdate'"
type="default"
@click="openRuleGenerateDialog"
v-ripple
>
{{ $t('page.configPage.btnRuleGenerate') }}
</ElButton>
</div>
<div class="table-scroll-wrap">
<ElTable
v-loading="loading"
@@ -212,16 +222,194 @@
</ElTabPane>
</ElTabs>
</ElCard>
<ElDialog
v-model="ruleGenerateDialogVisible"
:title="$t('page.configPage.ruleGenerateTitle')"
:width="ruleGenDialogWidth"
:fullscreen="ruleGenFullscreen"
align-center
destroy-on-close
:close-on-click-modal="false"
class="rule-generate-dialog"
>
<div class="rule-generate-rules">{{ $t('page.configPage.ruleGenerateRules') }}</div>
<ElForm
:label-position="ruleGenFormLabelPosition"
:label-width="ruleGenFormLabelWidth"
class="rule-generate-form"
@submit.prevent
>
<ElFormItem :label="$t('page.configPage.ruleGenT1Row')">
<div class="rule-gen-row">
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenFixedCount') }}</span>
<ElInputNumber
v-model="ruleGenT1Fixed"
class="rule-gen-input-num"
:min="0"
:max="26"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenRealEvStd') }}</span>
<ElInputNumber
v-model="ruleGenT1RealEv"
class="rule-gen-input-num"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
</div>
</ElFormItem>
<ElFormItem :label="$t('page.configPage.ruleGenT2Row')">
<div class="rule-gen-row">
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenMinCount') }}</span>
<ElInputNumber
v-model="ruleGenT2Min"
class="rule-gen-input-num"
:min="0"
:max="26"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenRealEvStd') }}</span>
<ElInputNumber
v-model="ruleGenT2RealEv"
class="rule-gen-input-num"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
</div>
</ElFormItem>
<ElFormItem :label="$t('page.configPage.ruleGenT3RealEvOnly')">
<div class="rule-gen-row">
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenRealEvStd') }}</span>
<ElInputNumber
v-model="ruleGenT3RealEv"
class="rule-gen-input-num"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
</div>
</ElFormItem>
<ElFormItem :label="$t('page.configPage.ruleGenT4Row')">
<div class="rule-gen-row">
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenFixedCount') }}</span>
<ElInputNumber
v-model="ruleGenT4Fixed"
class="rule-gen-input-num"
:min="0"
:max="26"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenRealEvStd') }}</span>
<ElInputNumber
v-model="ruleGenT4RealEv"
class="rule-gen-input-num"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
</div>
</ElFormItem>
<ElFormItem :label="$t('page.configPage.ruleGenT5Row')">
<div class="rule-gen-row">
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenFixedCount') }}</span>
<ElInputNumber
v-model="ruleGenT5Fixed"
class="rule-gen-input-num"
:min="0"
:max="26"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
<div class="rule-gen-cell">
<span class="rule-gen-hint">{{ $t('page.configPage.ruleGenRealEvStd') }}</span>
<ElInputNumber
v-model="ruleGenT5RealEv"
class="rule-gen-input-num"
:disabled="true"
:step="1"
:controls="ruleGenInputControls"
:size="ruleGenInputSize"
controls-position="right"
/>
</div>
</div>
</ElFormItem>
<p class="rule-generate-scope">{{ $t('page.configPage.ruleGenScopeHint') }}</p>
<p class="rule-generate-scope">{{ $t('page.configPage.ruleGenRealEvEditHint') }}</p>
</ElForm>
<template #footer>
<div class="rule-gen-footer-btns">
<ElButton @click="ruleGenerateDialogVisible = false">{{ $t('common.cancel') }}</ElButton>
<ElButton type="primary" :loading="ruleGenSubmitting" @click="handleRuleGenerateApply">
{{ $t('page.configPage.ruleGenApply') }}
</ElButton>
</div>
</template>
</ElDialog>
</div>
</template>
<script setup lang="ts">
import { useWindowSize } from '@vueuse/core'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useI18n } from 'vue-i18n'
import api from '../../api/reward_config/index'
import {
buildRowsFromTiers,
computeBoardFrequencies,
DEFAULT_TIER_REAL_EV_STANDARDS,
generateTiers,
summarizeCounts,
validateTierRealEvStandards
} from '../utils/generateIndexByRules'
const { t } = useI18n()
const { width: viewportWidth } = useWindowSize()
/** 窄屏:单列、标签置顶、全屏弹窗 */
const isRuleGenMobile = computed(() => viewportWidth.value < 640)
const ruleGenDialogWidth = computed(() => (isRuleGenMobile.value ? '100%' : 'min(880px, 92vw)'))
const ruleGenFullscreen = computed(() => isRuleGenMobile.value)
const ruleGenFormLabelPosition = computed(() => (isRuleGenMobile.value ? 'top' : 'right'))
const ruleGenFormLabelWidth = computed(() => (isRuleGenMobile.value ? undefined : '168px'))
/** 移动端隐藏步进按钮,避免误触;用系统数字键盘输入 */
const ruleGenInputControls = computed(() => !isRuleGenMobile.value)
const ruleGenInputSize = computed(() => (isRuleGenMobile.value ? 'large' : 'default'))
/** 第一页:奖励索引行(来自 DiceRewardConfig 表) */
interface IndexRow {
id: number
@@ -239,6 +427,31 @@
const savingIndex = ref(false)
const savingBigwin = ref(false)
const createRewardLoading = ref(false)
const ruleGenerateDialogVisible = ref(false)
const ruleGenSubmitting = ref(false)
const ruleGenT1Fixed = ref(3)
const ruleGenT2Min = ref(5)
const ruleGenT4Fixed = ref(1)
const ruleGenT5Fixed = ref(1)
const ruleGenT1RealEv = ref(DEFAULT_TIER_REAL_EV_STANDARDS.T1)
const ruleGenT2RealEv = ref(DEFAULT_TIER_REAL_EV_STANDARDS.T2)
const ruleGenT3RealEv = ref(DEFAULT_TIER_REAL_EV_STANDARDS.T3)
const ruleGenT4RealEv = ref(DEFAULT_TIER_REAL_EV_STANDARDS.T4)
const ruleGenT5RealEv = ref(DEFAULT_TIER_REAL_EV_STANDARDS.T5)
/** 奖励索引 id 与后端 DiceRewardConfigLogic 一致025 */
const REWARD_INDEX_MIN = 0
const REWARD_INDEX_MAX = 25
const ALLOWED_INDEX_TIERS = ['T1', 'T2', 'T3', 'T4', 'T5', 'BIGWIN'] as const
function isAllowedIndexTier(s: string): boolean {
for (let i = 0; i < ALLOWED_INDEX_TIERS.length; i++) {
if (ALLOWED_INDEX_TIERS[i] === s) {
return true
}
}
return false
}
/** 第一页数据(来自 api.list即 DiceRewardConfig 表) */
const indexRows = ref<IndexRow[]>([])
@@ -349,8 +562,8 @@
}
/** 奖励索引表单校验:仅对本表内的行(不含 BIGWIN校验点数 530 且本批内不重复 */
function validateIndexFormForSave(): string | null {
const toSave = indexRows.value.filter((r) => r.tier !== 'BIGWIN')
function validateIndexFormForSaveRows(rows: IndexRow[]): string | null {
const toSave = rows.filter((r) => r.tier !== 'BIGWIN')
if (toSave.length === 0) {
return t('page.configPage.warnNoIndexToSave')
}
@@ -370,6 +583,171 @@
return null
}
function validateIndexFormForSave(): string | null {
return validateIndexFormForSaveRows(indexRows.value)
}
/** 从当前表提取 id 025 的色子点数(不含 BIGWIN用于按规则生成 */
function extractGrids26(): number[] | null {
const map = new Map<number, number>()
for (const r of indexRows.value) {
if (r.tier === 'BIGWIN') {
continue
}
if (r.id >= REWARD_INDEX_MIN && r.id <= REWARD_INDEX_MAX) {
map.set(r.id, Number(r.grid_number))
}
}
const out: number[] = []
for (let id = REWARD_INDEX_MIN; id <= REWARD_INDEX_MAX; id++) {
if (!map.has(id)) {
return null
}
const gn = map.get(id)
if (gn === undefined || Number.isNaN(gn)) {
return null
}
out.push(gn)
}
return out
}
function openRuleGenerateDialog() {
ruleGenerateDialogVisible.value = true
}
function applyGeneratedRowsToIndex(
items: Array<{
id: number
grid_number: number
ui_text: string
ui_text_en: string
real_ev: number
tier: string
remark: string
}>
): string | null {
const next = indexRows.value.map((r) => ({ ...r }))
for (const item of items) {
const row = next.find((x) => x.id === item.id)
if (row === undefined) {
return t('page.configPage.ruleGenUnknownId', { id: item.id })
}
row.grid_number = item.grid_number
row.ui_text = item.ui_text
row.ui_text_en = item.ui_text_en
row.real_ev = item.real_ev
row.tier = item.tier
row.remark = item.remark
}
const err = validateIndexFormForSaveRows(next)
if (err) {
return err
}
indexRows.value = next
return null
}
async function handleRuleGenerateApply() {
const grids = extractGrids26()
if (grids === null) {
ElMessage.warning(t('page.configPage.ruleGenNeedFullGrid'))
return
}
const t1 = Math.max(0, Math.min(26, Math.floor(Number(ruleGenT1Fixed.value))))
const t2 = Math.max(0, Math.min(26, Math.floor(Number(ruleGenT2Min.value))))
const x4 = Math.max(0, Math.min(26, Math.floor(Number(ruleGenT4Fixed.value))))
const x5 = Math.max(0, Math.min(26, Math.floor(Number(ruleGenT5Fixed.value))))
const standards = {
T1: Number(ruleGenT1RealEv.value),
T2: Number(ruleGenT2RealEv.value),
T3: Number(ruleGenT3RealEv.value),
T4: Number(ruleGenT4RealEv.value),
T5: Number(ruleGenT5RealEv.value)
}
const invalidKey = validateTierRealEvStandards(standards)
if (invalidKey !== null) {
ElMessage.warning(t(`page.configPage.${invalidKey}`))
return
}
const constraints = {
t1FixedCw: t1,
t2MinCw: t2,
t4FixedCw: x4,
t5FixedCw: x5,
t1FixedCcw: t1,
t2MinCcw: t2,
t4FixedCcw: x4,
t5FixedCcw: x5
}
const gen = generateTiers({ grids, constraints })
if (!gen.ok) {
ElMessage.warning(gen.message)
return
}
const built = buildRowsFromTiers(grids, gen.tiers, standards)
const mergeErr = applyGeneratedRowsToIndex(built)
if (mergeErr) {
ElMessage.warning(mergeErr)
return
}
const board = computeBoardFrequencies(grids)
if (board === null) {
ElMessage.warning(t('page.configPage.ruleGenFreqFail'))
return
}
const sc = summarizeCounts(board, gen.tiers)
ruleGenSubmitting.value = true
try {
const indexPayload = built.map(
(r: {
id: number
grid_number: number
ui_text: string
ui_text_en: string
real_ev: number
tier: string
remark: string
}) => ({
id: r.id,
grid_number: r.grid_number,
ui_text: r.ui_text,
ui_text_en: r.ui_text_en,
real_ev: r.real_ev,
tier: r.tier,
remark: r.remark
})
)
await api.batchUpdate(indexPayload)
ElMessage.success(
t('page.configPage.ruleGenSuccess', {
cwT1: sc.cw.T1,
cwT2: sc.cw.T2,
cwT4: sc.cw.T4,
cwT5: sc.cw.T5,
ccT1: sc.ccw.T1,
ccT2: sc.ccw.T2,
ccT4: sc.ccw.T4,
ccT5: sc.ccw.T5
})
)
indexRowsSnapshot = indexRows.value.map((r) => ({ ...r }))
ruleGenerateDialogVisible.value = false
} catch (e: unknown) {
let msg = ''
if (e !== null && typeof e === 'object' && 'message' in e) {
const m = Reflect.get(e, 'message')
if (typeof m === 'string') {
msg = m
}
}
ElMessage.error(msg || t('page.configPage.saveFail'))
loadIndexList()
} finally {
ruleGenSubmitting.value = false
}
}
/** 奖励索引表单仅提交本表数据T1T5不包含大奖权重 */
async function handleSaveIndex() {
const err = validateIndexFormForSave()
@@ -551,6 +929,141 @@
margin-bottom: 12px;
line-height: 1.5;
}
.index-toolbar {
display: flex;
align-items: center;
justify-content: flex-end;
margin-bottom: 8px;
flex-shrink: 0;
}
.rule-generate-dialog {
:deep(.el-dialog__header) {
padding: 12px 16px;
margin-right: 0;
}
:deep(.el-dialog__body) {
padding: 12px 16px 8px;
}
:deep(.el-dialog__footer) {
padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.rule-generate-rules {
font-size: 12px;
color: var(--el-text-color-secondary);
line-height: 1.65;
white-space: pre-wrap;
margin: 0 0 12px;
padding: 12px;
background: var(--el-fill-color-light);
border-radius: 6px;
max-height: min(260px, 38vh);
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.rule-generate-form {
margin-top: 4px;
:deep(.el-form-item) {
margin-bottom: 14px;
}
:deep(.el-form-item__label) {
line-height: 1.4;
align-items: flex-start;
}
}
.rule-generate-scope {
font-size: 12px;
color: var(--el-text-color-secondary);
margin: 8px 0 0;
line-height: 1.5;
}
.rule-gen-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 12px 20px;
width: 100%;
}
.rule-gen-cell {
display: flex;
align-items: center;
gap: 8px;
flex: 1 1 200px;
min-width: 0;
}
.rule-gen-hint {
font-size: 12px;
color: var(--el-text-color-secondary);
white-space: nowrap;
flex-shrink: 0;
}
.rule-gen-input-num {
flex: 1;
min-width: 0;
width: 100%;
max-width: 100%;
}
.rule-gen-input-num :deep(.el-input__wrapper) {
min-height: 36px;
}
.rule-gen-footer-btns {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 10px;
width: 100%;
}
}
@media (max-width: 639px) {
.rule-generate-dialog {
:deep(.el-dialog) {
margin: 0;
max-height: 100%;
}
:deep(.el-dialog.is-fullscreen) {
display: flex;
flex-direction: column;
}
:deep(.el-dialog.is-fullscreen .el-dialog__body) {
flex: 1;
min-height: 0;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.rule-generate-rules {
max-height: min(200px, 32vh);
font-size: 11px;
}
.rule-gen-row {
flex-direction: column;
align-items: stretch;
gap: 12px;
}
.rule-gen-cell {
flex-direction: column;
align-items: stretch;
flex: none;
width: 100%;
}
.rule-gen-hint {
white-space: normal;
}
.rule-gen-input-num {
width: 100%;
}
.rule-gen-input-num :deep(.el-input__wrapper) {
min-height: 40px;
}
.rule-gen-footer-btns {
flex-direction: column-reverse;
align-items: stretch;
.el-button {
width: 100%;
margin: 0;
}
}
}
}
.config-table {
width: 100%;
.full-width {

View File

@@ -0,0 +1,413 @@
/**
* 按与后端 DiceRewardLogic 一致的环形规则,为盘面 26 格id 025求档位 tier
* 并生成 real_ev / ui 等字段。
*
* 摇取点数为 530起点为 grid_number==摇取点数 的格位下标,顺时针落点 (start+摇取)%26
* 逆时针落点 start-摇取(<0 则 +26
*/
export type IndexTier = 'T1' | 'T2' | 'T3' | 'T4' | 'T5'
/** 豹子摇取点数:这些摇取下落点不得为 T4/T5与 dice_reward 表中「点数」列一致) */
export const LEOPARD_ROLLS: readonly number[] = [5, 10, 15, 20, 25, 30]
const BOARD_SIZE = 26
const GRID_MIN = 5
const GRID_MAX = 30
const T_ALL: IndexTier[] = ['T1', 'T2', 'T3', 'T4', 'T5']
const T_NO_LEOPARD: IndexTier[] = ['T1', 'T2', 'T3']
export interface BoardFrequencies {
grids: number[]
freqCw: number[]
freqCcw: number[]
leopardLandCw: Set<number>
leopardLandCcw: Set<number>
leopardLandUnion: Set<number>
}
/**
* 条数约束T1/T4/T5 为「恰好」T2 为「不少于」(加权条数,与 dice_reward 中顺/逆各 26 条摇取结果一致)
*/
export interface TierCountConstraints {
t1FixedCw: number
t2MinCw: number
/** 顺时针方向 T4 加权条数固定为该值 */
t4FixedCw: number
/** 顺时针方向 T5 加权条数固定为该值 */
t5FixedCw: number
t1FixedCcw: number
t2MinCcw: number
/** 逆时针方向 T4 加权条数固定为该值 */
t4FixedCcw: number
/** 逆时针方向 T5 加权条数固定为该值 */
t5FixedCcw: number
}
/** 各档位统一 real_ev 标准(生成 DiceRewardConfig 时使用;细则可再到表格里改) */
export interface TierRealEvStandards {
T1: number
T2: number
T3: number
T4: number
T5: number
}
/** 默认标准与常见业务约定一致100&lt;T1&lt;500 */
export const DEFAULT_TIER_REAL_EV_STANDARDS: TierRealEvStandards = {
T1: 400,
T2: 50,
T3: -80,
T4: -140,
T5: 0
}
/**
* 校验档位与 real_ev 区间是否一致;通过返回 null否则返回 i18n 键名(不含 page.configPage. 前缀)
*/
export function validateTierRealEvStandards(s: TierRealEvStandards): string | null {
if (!Number.isFinite(s.T1) || !(s.T1 > 100 && s.T1 < 500)) {
return 'ruleGenInvalidT1RealEv'
}
if (!Number.isFinite(s.T2) || !(s.T2 > 0 && s.T2 < 100)) {
return 'ruleGenInvalidT2RealEv'
}
if (!Number.isFinite(s.T3) || !(-100 < s.T3 && s.T3 < 0)) {
return 'ruleGenInvalidT3RealEv'
}
if (!Number.isFinite(s.T4) || !(s.T4 < -100)) {
return 'ruleGenInvalidT4RealEv'
}
if (!Number.isFinite(s.T5) || s.T5 !== 0) {
return 'ruleGenInvalidT5RealEv'
}
return null
}
export interface GenerateTierInput {
grids: number[]
constraints: TierCountConstraints
}
export interface GenerateTierResultOk {
ok: true
tiers: IndexTier[]
}
export interface GenerateTierResultFail {
ok: false
message: string
}
export type GenerateTierResult = GenerateTierResultOk | GenerateTierResultFail
export function computeBoardFrequencies(grids: number[]): BoardFrequencies | null {
if (grids.length !== BOARD_SIZE) {
return null
}
const gridToPos: Record<number, number> = {}
for (let pos = 0; pos < BOARD_SIZE; pos++) {
const g = grids[pos]
if (g < GRID_MIN || g > GRID_MAX) {
return null
}
if (gridToPos[g] !== undefined) {
return null
}
gridToPos[g] = pos
}
const freqCw = new Array<number>(BOARD_SIZE).fill(0)
const freqCcw = new Array<number>(BOARD_SIZE).fill(0)
for (let roll = GRID_MIN; roll <= GRID_MAX; roll++) {
const startPos = gridToPos[roll]
const endCw = (startPos + roll) % BOARD_SIZE
const endCcw = startPos - roll >= 0 ? startPos - roll : BOARD_SIZE + startPos - roll
freqCw[endCw]++
freqCcw[endCcw]++
}
const leopardLandCw = new Set<number>()
const leopardLandCcw = new Set<number>()
for (let di = 0; di < LEOPARD_ROLLS.length; di++) {
const d = LEOPARD_ROLLS[di]
const sp = gridToPos[d]
leopardLandCw.add((sp + d) % BOARD_SIZE)
const eccw = sp - d >= 0 ? sp - d : BOARD_SIZE + sp - d
leopardLandCcw.add(eccw)
}
const leopardLandUnion = new Set<number>()
leopardLandCw.forEach((x) => leopardLandUnion.add(x))
leopardLandCcw.forEach((x) => leopardLandUnion.add(x))
return {
grids: [...grids],
freqCw,
freqCcw,
leopardLandCw,
leopardLandCcw,
leopardLandUnion
}
}
function sumWeighted(freq: number[], tiers: IndexTier[], tier: IndexTier): number {
let s = 0
for (let i = 0; i < BOARD_SIZE; i++) {
if (tiers[i] === tier) {
s += freq[i]
}
}
return s
}
function meetsConstraints(
tiers: IndexTier[],
freqCw: number[],
freqCcw: number[],
c: TierCountConstraints
): boolean {
const cw1 = sumWeighted(freqCw, tiers, 'T1')
const cw2 = sumWeighted(freqCw, tiers, 'T2')
const cw4 = sumWeighted(freqCw, tiers, 'T4')
const cw5 = sumWeighted(freqCw, tiers, 'T5')
const cc1 = sumWeighted(freqCcw, tiers, 'T1')
const cc2 = sumWeighted(freqCcw, tiers, 'T2')
const cc4 = sumWeighted(freqCcw, tiers, 'T4')
const cc5 = sumWeighted(freqCcw, tiers, 'T5')
return (
cw1 === c.t1FixedCw &&
cw2 >= c.t2MinCw &&
cw4 === c.t4FixedCw &&
cw5 === c.t5FixedCw &&
cc1 === c.t1FixedCcw &&
cc2 >= c.t2MinCcw &&
cc4 === c.t4FixedCcw &&
cc5 === c.t5FixedCcw
)
}
function nonLeopardTierChoices(c: TierCountConstraints): IndexTier[] {
const out: IndexTier[] = ['T1', 'T2', 'T3']
if (c.t4FixedCw > 0 || c.t4FixedCcw > 0) {
out.push('T4')
}
if (c.t5FixedCw > 0 || c.t5FixedCcw > 0) {
out.push('T5')
}
return out
}
function shuffleIndices(rand: () => number): number[] {
const a: number[] = []
for (let i = 0; i < BOARD_SIZE; i++) {
a.push(i)
}
for (let i = BOARD_SIZE - 1; i > 0; i--) {
const j = Math.floor(rand() * (i + 1))
const t = a[i]
a[i] = a[j]
a[j] = t
}
return a
}
function mulberry32(seed: number): () => number {
return () => {
let t = (seed += 0x6d2b79f5)
t = Math.imul(t ^ (t >>> 15), t | 1)
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
/**
* 随机搜索可行档位:豹子落点禁 T4/T5T4/T5 顺/逆加权条数分别等于约束中的固定值(可多条 T4/T5 格位)。
*/
export function generateTiers(input: GenerateTierInput): GenerateTierResult {
const board = computeBoardFrequencies(input.grids)
if (board === null) {
return { ok: false, message: 'grid_number 须为 530 各出现一次且共 26 条' }
}
const { freqCw, freqCcw, leopardLandUnion } = board
const c = input.constraints
let seed = 0
for (let i = 0; i < BOARD_SIZE; i++) {
seed = (seed + input.grids[i] * 31 + i) | 0
}
const rand = mulberry32(seed === 0 ? 0x9e3779b9 : seed)
const needT5Cell = c.t5FixedCw > 0 || c.t5FixedCcw > 0
if (needT5Cell) {
let hasNonLeopard = false
for (let i = 0; i < BOARD_SIZE; i++) {
if (!leopardLandUnion.has(i)) {
hasNonLeopard = true
break
}
}
if (!hasNonLeopard) {
return { ok: false, message: '无可用 T5 格位(豹子摇取落点占满全盘,请调整 grid_number 排布)' }
}
}
const nonLeopardChoices = nonLeopardTierChoices(c)
const maxAttempts = 400000
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const tiers: IndexTier[] = new Array(BOARD_SIZE).fill('T3')
const order = shuffleIndices(rand)
for (let oi = 0; oi < order.length; oi++) {
const pos = order[oi]
if (leopardLandUnion.has(pos)) {
tiers[pos] = T_NO_LEOPARD[Math.floor(rand() * T_NO_LEOPARD.length)]
} else {
tiers[pos] = nonLeopardChoices[Math.floor(rand() * nonLeopardChoices.length)]
}
}
if (meetsConstraints(tiers, freqCw, freqCcw, c)) {
return { ok: true, tiers }
}
}
return { ok: false, message: '在当前盘面与约束下未找到可行解,请调整 T1/T4/T5 固定条数或放宽 T2 下限后重试' }
}
/** 展示文案100 + 真实结算中英文相同T5 不使用 */
function uiTextFromRealEvPlus100(realEv: number): { ui_text: string; ui_text_en: string } {
const s = String(100 + realEv)
return { ui_text: s, ui_text_en: s }
}
/**
* 按 tier 生成展示字段。
* @param standards 若传入,则各档位统一使用对应 real_ev 标准;不传则使用内置随机占位(兼容脚本/旧逻辑)
*/
export function buildRowsFromTiers(
grids: number[],
tiers: IndexTier[],
standards?: TierRealEvStandards
): Array<{
id: number
grid_number: number
ui_text: string
ui_text_en: string
real_ev: number
tier: IndexTier
remark: string
}> {
const rows: Array<{
id: number
grid_number: number
ui_text: string
ui_text_en: string
real_ev: number
tier: IndexTier
remark: string
}> = []
let t4Seq = 0
for (let id = 0; id < BOARD_SIZE; id++) {
const tier = tiers[id]
const grid_number = grids[id]
let ui_text = ''
let ui_text_en = ''
let real_ev = 0
let remark = ''
if (standards !== undefined) {
if (tier === 'T1') {
real_ev = standards.T1
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '大奖格'
} else if (tier === 'T2') {
real_ev = standards.T2
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = standards.T2 <= 1 ? '完美回本' : '小赚'
} else if (tier === 'T3') {
real_ev = standards.T3
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '抽水'
} else if (tier === 'T4') {
real_ev = standards.T4
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '惩罚'
} else {
real_ev = standards.T5
ui_text = '再来一次'
ui_text_en = 'Once again'
remark = '前端需要在播放一次动画(特殊)'
}
} else if (tier === 'T1') {
real_ev = 101 + ((id * 17 + grid_number * 3) % 398)
if (real_ev >= 500) {
real_ev = 498
}
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '大奖格'
} else if (tier === 'T2') {
if (id % 3 === 0) {
real_ev = 1
remark = '完美回本'
} else {
real_ev = 20 + ((id * 11) % 75)
if (real_ev <= 0) {
real_ev = 50
}
remark = '小赚'
}
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
} else if (tier === 'T3') {
real_ev = -72 - (id % 15)
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '抽水'
} else if (tier === 'T4') {
t4Seq++
real_ev = -101 - t4Seq * 15
const f = uiTextFromRealEvPlus100(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '惩罚'
} else {
real_ev = 0
ui_text = '再来一次'
ui_text_en = 'Once again'
remark = '前端需要在播放一次动画(特殊)'
}
rows.push({
id,
grid_number,
ui_text,
ui_text_en,
real_ev,
tier,
remark
})
}
return rows
}
export function summarizeCounts(
board: BoardFrequencies,
tiers: IndexTier[]
): { cw: Record<IndexTier, number>; ccw: Record<IndexTier, number> } {
const cw: Record<IndexTier, number> = { T1: 0, T2: 0, T3: 0, T4: 0, T5: 0 }
const ccw: Record<IndexTier, number> = { T1: 0, T2: 0, T3: 0, T4: 0, T5: 0 }
for (let k = 0; k < T_ALL.length; k++) {
const t = T_ALL[k]
cw[t] = sumWeighted(board.freqCw, tiers, t)
ccw[t] = sumWeighted(board.freqCcw, tiers, t)
}
return { cw, ccw }
}

View File

@@ -214,6 +214,13 @@
align: 'center',
showOverflowTooltip: true
},
{
prop: 'remark',
label: 'page.table.remark',
width: 220,
align: 'center',
showOverflowTooltip: true
},
{ prop: 'create_time', label: 'page.table.createTime', width: 170, align: 'center' },
{
prop: 'operation',

View File

@@ -2,9 +2,9 @@
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=saiadmin
DB_USER=root
DB_PASSWORD=123456
DB_NAME=dafuweng-v3
DB_USER=dafuweng-v3
DB_PASSWORD=tA6rciKLKxpFNGAm
DB_PREFIX=
DB_POOL_MAX=32
DB_POOL_MIN=4
@@ -17,10 +17,15 @@ REDIS_POOL_MAX=32
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=''
REDIS_DB=0
REDIS_DB=1
# webman channel用于定时任务通信
WEBMAN_CHANNEL_HOST=127.0.0.1
WEBMAN_CHANNEL_PORT=2207
WEBMAN_CHANNEL_LISTEN_HOST=0.0.0.0
# 游戏地址,用于 /api/v1/getGameUrl 返回
GAME_URL=dice-game.yuliao666.top
GAME_URL=dice-v3-game.yuliao666.top
# API 鉴权与用户(可选,不填则用默认值)
# authToken 签名密钥(必填,与客户端约定,用于 signature 校验)

View File

@@ -11,6 +11,7 @@ use app\api\logic\GameLogic;
use app\api\logic\PlayStartLogic;
use app\api\util\ReturnCode;
use app\dice\model\config\DiceConfig;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\player\DicePlayer;
use app\dice\model\reward\DiceRewardConfig;
@@ -134,6 +135,20 @@ class GameController extends BaseController
return $this->success($list);
}
/**
* 获取底注配置(全部)
* GET/any /api/game/anteConfig
* header: tokenTokenMiddleware 注入)
* 返回dice_ante_config 列表(包含 mult/is_default 等字段)
*/
public function anteConfig(Request $request): Response
{
// 用于后续抽奖校验:在接口中实例化 model后续逻辑可复用相同的数据读取方式。
$anteConfigModel = new DiceAnteConfig();
$rows = $anteConfigModel->order('id', 'asc')->select()->toArray();
return $this->success($rows);
}
/**
* 开始游戏(抽奖一局)
* POST /api/game/playStart
@@ -147,21 +162,21 @@ class GameController extends BaseController
if ($direction !== null) {
$direction = (int) $direction;
}
$ante = $request->post('ante');
if ($ante !== null) {
$ante = (int) $ante;
}
if (!in_array($direction, [0, 1], true)) {
return $this->fail('direction must be 0 or 1', ReturnCode::PARAMS_ERROR);
}
if (!is_int($ante) || $ante <= 0) {
return $this->fail('ante must be a positive integer', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::find($userId);
if (!$player) {
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$minEv = DiceRewardConfig::getCachedMinRealEv();
$minCoin = abs($minEv + 100);
$coin = (float) $player->coin;
if ($coin < $minCoin) {
$msg = ApiLang::translateParams('Balance %s is less than %s, cannot continue', [$coin, $minCoin], $request);
return $this->success([], $msg);
}
$lockName = 'play_start_' . $userId;
$lockResult = Db::query('SELECT GET_LOCK(?, 30) as l', [$lockName]);
@@ -170,7 +185,7 @@ class GameController extends BaseController
}
try {
$logic = new PlayStartLogic();
$data = $logic->run($userId, (int)$direction);
$data = $logic->run($userId, (int) $direction, $ante);
$lang = $request->header('lang', 'zh');
if (!is_string($lang) || $lang === '') {

View File

@@ -108,6 +108,7 @@ class GameLogic
'player_id' => $playerId,
'admin_id' => $adminId,
'use_coins' => $cost,
'ante' => 1,
'total_ticket_count' => $addTotal,
'paid_ticket_count' => $addPaid,
'free_ticket_count' => $addFree,

View File

@@ -8,6 +8,7 @@ use app\api\util\ApiLang;
use app\api\service\LotteryService;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\player\DicePlayer;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
@@ -34,8 +35,12 @@ class PlayStartLogic
/** 对局状态:超时/失败 */
public const RECORD_STATUS_TIMEOUT = 0;
/** 开启对局最低余额 = |DiceRewardConfig 最小 real_ev + 100| */
private const MIN_COIN_EXTRA = 100;
/** 单注费用(对应原票价 100 */
private const UNIT_COST = 100;
/** 免费抽奖注数缓存 key 前缀(用于强制下一局注数一致) */
private const FREE_ANTE_KEY_PREFIX = 'api:game:free_ante:';
/** 免费抽奖注数缓存过期(秒) */
private const FREE_ANTE_TTL = 86400 * 7;
/** 豹子号中大奖额外平台币(无 BIGWIN 配置时兜底) */
private const SUPER_WIN_BONUS = 500;
/** 可触发超级大奖的 grid_number5=全1 10=全2 15=全3 20=全4 25=全5 30=全6 */
@@ -47,36 +52,60 @@ class PlayStartLogic
* 执行一局游戏
* @param int $playerId 玩家ID
* @param int $direction 方向 0=无/顺时针 1=中奖/逆时针(前端 direction
* @param int $ante 注数(必须在 DiceAnteConfig.mult 中存在)
* @return array 成功返回 DicePlayRecord 数据;余额不足时抛 ApiExceptionmessage 为约定文案
*/
public function run(int $playerId, int $direction): array
public function run(int $playerId, int $direction, int $ante): array
{
$player = DicePlayer::find($playerId);
if (!$player) {
throw new ApiException('User not found');
}
$minEv = DiceRewardConfig::getCachedMinRealEv();
$minCoin = abs($minEv + self::MIN_COIN_EXTRA);
$coin = (float) $player->coin;
if ($coin < $minCoin) {
throw new ApiException(ApiLang::translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin]));
if ($ante <= 0) {
throw new ApiException('ante must be a positive integer');
}
$paid = (int) ($player->paid_ticket_count ?? 0);
$free = (int) ($player->free_ticket_count ?? 0);
if ($paid + $free <= 0) {
throw new ApiException('Insufficient lottery tickets');
// 注数合规校验ante 必须存在于 dice_ante_config.mult
$anteConfigModel = new DiceAnteConfig();
$exists = $anteConfigModel->where('mult', $ante)->count();
if ($exists <= 0) {
throw new ApiException('当前注数不合规,请选择正确的注数');
}
// 免费抽奖:不再使用抽奖券作为开始条件,仅用 free_ticket_count 表示“免费抽奖次数”
$freeCount = (int) ($player->free_ticket_count ?? 0);
$isFree = $freeCount > 0;
$ticketType = $isFree ? self::LOTTERY_TYPE_FREE : self::LOTTERY_TYPE_PAID;
// 若为免费抽奖:注数必须与上一次触发免费抽奖时的注数一致
if ($isFree) {
$requiredAnte = Cache::get(self::FREE_ANTE_KEY_PREFIX . $playerId);
if ($requiredAnte !== null && $requiredAnte !== '' && (int) $requiredAnte !== $ante) {
throw new ApiException('免费抽奖注数必须与上一次一致,请修改注数后继续');
}
}
$lotteryService = LotteryService::getOrCreate($playerId);
$ticketType = LotteryService::drawTicketType($paid, $free);
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
if (!$configType0) {
throw new ApiException('Lottery pool config not found (name=default required)');
}
// 余额校验:统一校验 ante * min(real_ev)
$minEv = DiceRewardConfig::getCachedMinRealEv();
$needMinBalance = abs((float) $minEv) * $ante;
if ($coin < $needMinBalance) {
throw new ApiException('未达抽奖余额 ' . $needMinBalance . ',无法开始游戏');
}
// 付费抽奖:开始前扣除费用 ante * 100不足则提示余额不足
$paidAmount = $ticketType === self::LOTTERY_TYPE_PAID ? ($ante * self::UNIT_COST) : 0;
if ($ticketType === self::LOTTERY_TYPE_PAID && $coin < $paidAmount) {
throw new ApiException('余额不足');
}
// 彩金池累计盈利:用于判断是否触发杀分(不再依赖单个玩家累计盈利)
// 该值来自 dice_lottery_pool_config.profit_amount
$poolProfitTotal = $configType0->profit_amount ?? 0;
@@ -133,7 +162,8 @@ class PlayStartLogic
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
$realEv = (float) ($chosen['real_ev'] ?? 0);
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
// 摇色子中奖:按 dice_reward_config.real_ev 直接结算(已乘 ante不再叠加票价 100
$rewardWinCoin = $realEv * $ante;
// 豹子判定5/30 必豹子10/15/20/25 按 DiceRewardConfig 中 BIGWIN 该点数的 weight 判定0-1000010000=100%
// 杀分档位不触发豹子5/30 已在上方抽取时排除10/15/20/25 仅生成非豹子组合
@@ -166,7 +196,8 @@ class PlayStartLogic
if ($doSuperWin) {
$rollArray = $this->getSuperWinRollArray($rollNumber);
$isWin = 1;
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$bigWinEv = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$superWinCoin = $bigWinEv * $ante;
// 中 BIGWIN 豹子:不走原奖励流程,不记录原奖励,不触发 T5 再来一次,仅发放豹子奖金
$rewardWinCoin = 0;
$realEv = 0;
@@ -203,6 +234,8 @@ class PlayStartLogic
$rewardId,
$configName,
$ticketType,
$ante,
$paidAmount,
$winCoin,
$superWinCoin,
$rewardWinCoin,
@@ -221,11 +254,13 @@ class PlayStartLogic
'admin_id' => $adminId,
'lottery_config_id' => $configId,
'lottery_type' => $ticketType,
'ante' => $ante,
'paid_amount' => $paidAmount,
'is_win' => $isWin,
'win_coin' => $winCoin,
'super_win_coin' => $superWinCoin,
'reward_win_coin' => $rewardWinCoin,
'use_coins' => 0,
'use_coins' => $paidAmount,
'direction' => $direction,
'reward_config_id' => $rewardId,
'start_index' => $startIndex,
@@ -241,34 +276,55 @@ class PlayStartLogic
throw new \RuntimeException('玩家不存在');
}
$coinBefore = (float) $p->coin;
$coinAfter = $coinBefore + $winCoin;
// 开始前先扣付费金额,再加中奖金额(免费抽奖 paid_amount=0
$coinAfter = $coinBefore - $paidAmount + $winCoin;
$p->coin = $coinAfter;
$p->total_ticket_count = max(0, (int) $p->total_ticket_count - 1);
if ($ticketType === self::LOTTERY_TYPE_PAID) {
$p->paid_ticket_count = max(0, (int) $p->paid_ticket_count - 1);
} else {
// 不再使用抽奖券作为抽奖条件:付费不扣抽奖次数;免费抽奖仅消耗 free_ticket_count
if ($ticketType === self::LOTTERY_TYPE_FREE) {
$p->free_ticket_count = max(0, (int) $p->free_ticket_count - 1);
}
// 记录每次游玩:写入抽奖券记录(用于后台“抽奖券记录”追踪付费/免费游玩与消耗)
$isPaidPlay = $ticketType === self::LOTTERY_TYPE_PAID;
$paidCnt = $isPaidPlay ? 1 : 0;
$freeCnt = $isPaidPlay ? 0 : 1;
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'use_coins' => $paidAmount,
'ante' => $ante,
'total_ticket_count' => $paidCnt + $freeCnt,
'paid_ticket_count' => $paidCnt,
'free_ticket_count' => $freeCnt,
'remark' => ($isPaidPlay ? '付费游玩' : '免费游玩') . '|play_record_id=' . $record->id,
]);
// 若本局中奖档位为 T5则额外赠送 1 次免费抽奖次数(总次数也 +1并记录抽奖券获取记录
if ($isTierT5) {
$p->free_ticket_count = (int) $p->free_ticket_count + 1;
$p->total_ticket_count = (int) $p->total_ticket_count + 1;
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'ante' => $ante,
'free_ticket_count' => 1,
'remark' => '中奖结果为T5',
]);
// 记录免费抽奖注数,用于强制下一局注数一致
Cache::set(self::FREE_ANTE_KEY_PREFIX . $playerId, $ante, self::FREE_ANTE_TTL);
} else {
// 若本次消耗了最后一次免费抽奖,则清理注数锁
if ($ticketType === self::LOTTERY_TYPE_FREE && (int) $p->free_ticket_count <= 0) {
Cache::delete(self::FREE_ANTE_KEY_PREFIX . $playerId);
}
}
$p->save();
// 彩金池累计盈利累加在 name=default 彩金池上:
// 付费:每局按“当前中奖金额(含 BIGWIN - 抽奖费用 100
// 免费券:取消票价成本 100只计入中奖金额
$perPlayProfit = ($ticketType === self::LOTTERY_TYPE_PAID) ? ($winCoin - 100.0) : $winCoin;
// 付费:每局按「本局赢取平台币 win_coin - 抽奖费用 paid_amountante*100)」
// 免费券:paid_amount=0只计入 win_coin
$perPlayProfit = ($ticketType === self::LOTTERY_TYPE_PAID) ? ($winCoin - (float) $paidAmount) : $winCoin;
$addProfit = $perPlayProfit;
try {
DiceLotteryPoolConfig::where('id', $type0ConfigId)->update([
@@ -285,7 +341,8 @@ class PlayStartLogic
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'admin_id' => $adminId,
'coin' => $winCoin,
// 钱包流水记录本局净变化:-付费金额 + 中奖金额(免费抽奖付费金额为 0
'coin' => $winCoin - (float) $paidAmount,
'type' => self::WALLET_TYPE_DRAW,
'wallet_before' => $coinBefore,
'wallet_after' => $coinAfter,
@@ -336,7 +393,6 @@ class PlayStartLogic
$arr['tier'] = $tier ?? '';
// 记录完数据后返回当前玩家余额与抽奖次数
$arr['coin'] = $updated ? (float) $updated->coin : 0;
$arr['total_ticket_count'] = $updated ? (int) $updated->total_ticket_count : 0;
return $arr;
}
@@ -468,10 +524,11 @@ class PlayStartLogic
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig|null $config 奖池配置,自定义档位时可为 null
* @param int $direction 0=顺时针 1=逆时针
* @param int $lotteryType 0=付费 1=免费
* @param int $ante 底注/注数dice_ante_config.mult
* @param array|null $customTierWeights 自定义档位权重 ['T1'=>x, 'T2'=>x, ...],非空时忽略 config 的档位权重
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier用于统计档位概率
*/
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, ?array $customTierWeights = null): array
public function simulateOnePlay($config, int $direction, int $lotteryType = 0, int $ante = 1, ?array $customTierWeights = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
@@ -517,8 +574,8 @@ class PlayStartLogic
$targetIndex = (int) ($chosen['end_index'] ?? 0);
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
$realEv = (float) ($chosen['real_ev'] ?? 0);
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
// 摇色子中奖:按 real_ev 直接结算(与正式抽奖 run() 一致)
$rewardWinCoin = $realEv * $ante;
$superWinCoin = 0;
$isWin = 0;
@@ -547,8 +604,11 @@ class PlayStartLogic
if ($doSuperWin) {
$rollArray = $this->getSuperWinRollArray($rollNumber);
$isWin = 1;
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$bigWinEv = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$superWinCoin = $bigWinEv * $ante;
$rewardWinCoin = 0;
// 中豹子时不走原奖励流程
$realEv = 0.0;
} else {
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
}
@@ -562,6 +622,7 @@ class PlayStartLogic
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
$costRealEv = $realEv + ($isWin === 1 ? $bigWinRealEv : 0.0);
$paidAmount = $lotteryType === 0 ? ($ante * self::UNIT_COST) : 0;
return [
'player_id' => 0,
@@ -570,9 +631,11 @@ class PlayStartLogic
'lottery_type' => $lotteryType,
'is_win' => $isWin,
'win_coin' => $winCoin,
'ante' => $ante,
'paid_amount' => $paidAmount,
'super_win_coin' => $superWinCoin,
'reward_win_coin' => $rewardWinCoin,
'use_coins' => 0,
'use_coins' => $paidAmount,
'direction' => $direction,
'reward_config_id' => $rewardId,
'start_index' => $startIndex,

View File

@@ -0,0 +1,78 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\controller\ante_config;
use app\dice\logic\ante_config\DiceAnteConfigLogic;
use app\dice\validate\ante_config\DiceAnteConfigValidate;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 底注配置控制器
*/
class DiceAnteConfigController extends BaseController
{
public function __construct()
{
$this->logic = new DiceAnteConfigLogic();
$this->validate = new DiceAnteConfigValidate();
parent::__construct();
}
#[Permission('底注配置列表', 'dice:ante_config:index:index')]
public function index(Request $request): Response
{
$where = $request->more([
['name', ''],
['title', ''],
['is_default', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
return $this->success($data);
}
#[Permission('底注配置读取', 'dice:ante_config:index:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
}
#[Permission('底注配置添加', 'dice:ante_config:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
return $result ? $this->success('add success') : $this->fail('add failed');
}
#[Permission('底注配置修改', 'dice:ante_config:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
return $result ? $this->success('update success') : $this->fail('update failed');
}
#[Permission('底注配置删除', 'dice:ante_config:index:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
return $result ? $this->success('delete success') : $this->fail('delete failed');
}
}

View File

@@ -64,9 +64,9 @@ class DicePlayRecordController extends BaseController
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(lottery_type=0)次数×100 - 玩家总收益(win_coin 求和)
$sumQuery = clone $query;
$playerTotalWin = (float) $sumQuery->sum('win_coin');
$paidCountQuery = clone $query;
$paidCount = (int) $paidCountQuery->where('lottery_type', 0)->count();
$totalWinCoin = $paidCount * 100 - $playerTotalWin;
$paidAmountQuery = clone $query;
$paidAmount = (float) $paidAmountQuery->where('lottery_type', 0)->sum('paid_amount');
$totalWinCoin = $paidAmount - $playerTotalWin;
$data = $this->logic->getList($query);
$data['total_win_coin'] = $totalWinCoin;

View File

@@ -38,23 +38,26 @@ class DicePlayRecordTestController extends BaseController
public function index(Request $request): Response
{
$where = $request->more([
['reward_config_record_id', ''],
['lottery_type', ''],
['direction', ''],
['is_win', ''],
['win_coin_min', ''],
['win_coin_max', ''],
['paid_amount', ''],
['ante', ''],
['reward_tier', ''],
['roll_number', ''],
]);
$query = $this->logic->search($where);
$query->with(['diceLotteryPoolConfig', 'diceRewardConfig']);
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(lottery_type=0)次数×100 - 玩家总收益(win_coin 求和)
// 按当前筛选条件统计:平台总盈利 = 付费金额(paid_amount 求和) - 玩家总收益(win_coin 求和)
$sumQuery = clone $query;
$playerTotalWin = (float) $sumQuery->sum('win_coin');
$paidCountQuery = clone $query;
$paidCount = (int) $paidCountQuery->where('lottery_type', 0)->count();
$totalWinCoin = $paidCount * 100 - $playerTotalWin;
$paidAmountQuery = clone $query;
$paidAmount = (float) $paidAmountQuery->where('lottery_type', 0)->sum('paid_amount');
$totalWinCoin = $paidAmount - $playerTotalWin;
$data = $this->logic->getList($query);
$data['total_win_coin'] = $totalWinCoin;

View File

@@ -42,6 +42,7 @@ class DicePlayerTicketRecordController extends BaseController
['username', ''],
['use_coins_min', ''],
['use_coins_max', ''],
['ante', ''],
['total_ticket_count_min', ''],
['total_ticket_count_max', ''],
['paid_ticket_count_min', ''],

View File

@@ -90,6 +90,7 @@ class DiceRewardController extends BaseController
{
$post = is_array($request->post()) ? $request->post() : [];
$params = [
'ante' => $post['ante'] ?? null,
'lottery_config_id' => $post['lottery_config_id'] ?? null,
'paid_lottery_config_id' => $post['paid_lottery_config_id'] ?? null,
'free_lottery_config_id' => $post['free_lottery_config_id'] ?? null,

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\logic\ante_config;
use app\dice\model\ante_config\DiceAnteConfig;
use plugin\saiadmin\basic\think\BaseLogic;
/**
* 底注配置逻辑层
*/
class DiceAnteConfigLogic extends BaseLogic
{
public function __construct()
{
$this->model = new DiceAnteConfig();
}
public function add(array $data): mixed
{
return $this->transaction(function () use ($data) {
$this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults();
}
return parent::add($data);
});
}
public function edit($id, array $data): mixed
{
return $this->transaction(function () use ($id, $data) {
$this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults((int) $id);
}
return parent::edit($id, $data);
});
}
/**
* 防止删除后全表无默认:若删除了默认项,自动把最小 id 设为默认。
*/
public function destroy($ids): bool
{
return $this->transaction(function () use ($ids) {
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
$intIds = [];
foreach ($idList as $v) {
$iv = (int) $v;
if ($iv > 0) {
$intIds[] = $iv;
}
}
if ($intIds === []) {
return false;
}
$deletedDefaultCount = $this->model->whereIn('id', $intIds)->where('is_default', 1)->count();
$result = $this->model->destroy($intIds);
if ($result && $deletedDefaultCount > 0) {
$first = $this->model->order('id', 'asc')->find();
if ($first) {
$this->model->where('id', (int) $first['id'])->update(['is_default' => 1]);
}
}
return (bool) $result;
});
}
private function normalizeDefaultField(array &$data): void
{
if (!array_key_exists('is_default', $data)) {
return;
}
$data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0;
}
private function clearOtherDefaults(?int $excludeId = null): void
{
$query = $this->model->where('is_default', 1);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
$query->update(['is_default' => 0]);
}
}

View File

@@ -22,6 +22,8 @@ class DicePlayRecordTestLogic extends BaseLogic
public function __construct()
{
$this->model = new DicePlayRecordTest();
// 默认按 id 倒序,保证列表默认显示最新记录
$this->setOrderField('id')->setOrderType('DESC');
}
}

View File

@@ -5,6 +5,7 @@
namespace app\dice\logic\reward_config_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
@@ -250,6 +251,15 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
}
$allowed = [100, 500, 1000, 5000];
$ante = isset($params['ante']) ? intval($params['ante']) : 1;
if ($ante <= 0) {
throw new ApiException('ante must be greater than 0');
}
$anteExists = DiceAnteConfig::where('mult', $ante)->count();
if ($anteExists <= 0) {
throw new ApiException('ante not allowed: ' . $ante);
}
$lotteryConfigId = isset($params['lottery_config_id']) ? (int) $params['lottery_config_id'] : 0;
$paidConfigId = isset($params['paid_lottery_config_id']) ? (int) $params['paid_lottery_config_id'] : 0;
$freeConfigId = isset($params['free_lottery_config_id']) ? (int) $params['free_lottery_config_id'] : 0;
@@ -407,6 +417,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$record->result_counts = [];
$record->tier_counts = null;
$record->bigwin_weight = $bigwinWeights ?: null;
$record->ante = $ante;
$record->admin_id = $adminId;
$record->create_time = date('Y-m-d H:i:s');
$record->save();

View File

@@ -33,6 +33,7 @@ class WeightTestRunner
return;
}
$ante = is_numeric($record->ante ?? null) ? intval($record->ante) : 1;
$paidS = (int) ($record->paid_s_count ?? 0);
$paidN = (int) ($record->paid_n_count ?? 0);
$freeS = (int) ($record->free_s_count ?? 0);
@@ -60,28 +61,40 @@ class WeightTestRunner
$safetyLine = (int) ($configType0->safety_line ?? 0);
$killEnabled = ((int) ($configType0->kill_enabled ?? 1)) === 1;
$paidTierWeights = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
$paidTierWeightsCustom = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
? $record->paid_tier_weights
: [
'T1' => (int) ($configType0->t1_weight ?? 0),
'T2' => (int) ($configType0->t2_weight ?? 0),
'T3' => (int) ($configType0->t3_weight ?? 0),
'T4' => (int) ($configType0->t4_weight ?? 0),
'T5' => (int) ($configType0->t5_weight ?? 0),
];
if (array_sum($paidTierWeights) <= 0) {
$this->markFailed($recordId, '需提供 paid_tier_weights玩家权重盈利未达安全线时付费抽奖使用或选择 default 奖池');
return;
: null;
$freeTierWeightsCustom = (is_array($record->free_tier_weights ?? null) && $record->free_tier_weights !== [])
? $record->free_tier_weights
: null;
$paidPoolConfigId = (int) ($record->paid_lottery_config_id ?? 0);
$freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0);
$paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0;
if (!$paidPoolConfig) {
$paidPoolConfig = $configType0;
}
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
if (!$freePoolConfig) {
$freePoolConfig = $configType0;
}
$freeConfig = $configType1 !== null ? $configType1 : $configType0;
if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) {
$this->markFailed($recordId, 'paid_tier_weights玩家权重之和必须大于 0');
return;
}
if ($freeTierWeightsCustom !== null && array_sum($freeTierWeightsCustom) <= 0) {
$this->markFailed($recordId, 'free_tier_weights免费玩家权重之和必须大于 0');
return;
}
// 每次测试开始前清空进程内静态缓存,强制从共享缓存读取最新 BIGWIN/奖励配置,与数据库一致
DiceRewardConfig::clearRequestInstance();
DiceReward::clearRequestInstance();
// 彩金池累计盈利:用于判断是否触发杀分(不再依赖单个玩家累计盈利)
$poolProfitTotal = $configType0->profit_amount ?? 0;
$poolProfitTotal = floatval($configType0->profit_amount ?? 0);
$playLogic = new PlayStartLogic();
$resultCounts = [];
@@ -92,9 +105,9 @@ class WeightTestRunner
try {
for ($i = 0; $i < $paidS; $i++) {
$usePoolWeights = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
$customWeights = $usePoolWeights ? null : $paidTierWeights;
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $customWeights);
$paidConfig = $usePoolWeights ? $configType1 : $paidPoolConfig;
$customWeights = $usePoolWeights ? null : $paidTierWeightsCustom;
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $ante, $customWeights);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
@@ -103,9 +116,9 @@ class WeightTestRunner
}
for ($i = 0; $i < $paidN; $i++) {
$usePoolWeights = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
$customWeights = $usePoolWeights ? null : $paidTierWeights;
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $customWeights);
$paidConfig = $usePoolWeights ? $configType1 : $paidPoolConfig;
$customWeights = $usePoolWeights ? null : $paidTierWeightsCustom;
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $ante, $customWeights);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
@@ -113,7 +126,10 @@ class WeightTestRunner
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeS; $i++) {
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, null);
$useKillMode = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
$freeConfig = $useKillMode ? $configType1 : $freePoolConfig;
$customWeights = $useKillMode ? null : $freeTierWeightsCustom;
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, $ante, $customWeights);
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
@@ -121,7 +137,10 @@ class WeightTestRunner
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeN; $i++) {
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, null);
$useKillMode = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
$freeConfig = $useKillMode ? $configType1 : $freePoolConfig;
$customWeights = $useKillMode ? null : $freeTierWeightsCustom;
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, $ante, $customWeights);
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
@@ -153,7 +172,8 @@ class WeightTestRunner
return;
}
$winCoin = (float) $row['win_coin'];
$playerProfitTotal += $lotteryType === 0 ? ($winCoin - 100.0) : $winCoin;
$paidAmount = (float) ($row['paid_amount'] ?? 0);
$playerProfitTotal += $lotteryType === 0 ? ($winCoin - $paidAmount) : $winCoin;
}
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
@@ -176,6 +196,7 @@ class WeightTestRunner
$keys = [
'player_id', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
'super_win_coin', 'reward_win_coin', 'use_coins', 'direction', 'reward_config_id',
'ante', 'paid_amount',
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
];
foreach ($keys as $k) {
@@ -219,7 +240,7 @@ class WeightTestRunner
/**
* 标记测试成功并记录平台总盈利 platform_profit
* 通过关联 DicePlayRecordTestreward_config_record_id统计付费(lottery_type=0)次数×100 - win_coin 求和
* 通过关联 DicePlayRecordTestreward_config_record_id统计付费金额 paid_amount 求和 - win_coin 求和
*/
private function markSuccess(int $recordId, array $resultCounts, array $tierCounts): void
{

View File

@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\model\ante_config;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 底注配置模型
*
* @property int $id ID
* @property string $name 名称
* @property string $title 标题
* @property int $is_default 是否默认底注0否 1是全表仅允许一条为1
* @property int $mult 底注倍率
* @property string $create_time 创建时间
* @property string $update_time 更新时间
*/
class DiceAnteConfig extends BaseModel
{
protected $pk = 'id';
protected $table = 'dice_ante_config';
public function searchNameAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('name', 'like', '%' . $value . '%');
}
}
public function searchTitleAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('title', 'like', '%' . $value . '%');
}
}
public function searchIsDefaultAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('is_default', (int) $value);
}
}
}

View File

@@ -25,7 +25,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $t3_weight T3池权重
* @property $t4_weight T4池权重
* @property $t5_weight T5池权重
* @property $profit_amount 池子累计盈利(每局抽奖累加 100-real_ev仅展示不可编辑)
* @property $profit_amount 池子累计盈利(每局付费按 win_coin-paid_amount免费按 win_coin 累加;仅展示不可编辑)
*/
class DiceLotteryPoolConfig extends BaseModel
{

View File

@@ -22,10 +22,13 @@ use think\model\relation\BelongsTo;
* @property $admin_id 关联玩家所属管理员IDDicePlayer.admin_id
* @property $lottery_config_id 彩金池配置
* @property $lottery_type 抽奖类型
* @property $ante 底注/注数dice_ante_config.mult
* @property $paid_amount 付费金额(付费局=ante*100免费局=0
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[6,6,6,6,6]为1否则0
* @property $win_coin 赢取平台币(= super_win_coin + reward_win_coin
* @property $super_win_coin 中大奖平台币(豹子时发放)
* @property $reward_win_coin 摇色子中奖平台币
* @property $use_coins 消耗平台币(兼容字段:付费局=paid_amount免费局=0
* @property $direction 方向:0=顺时针,1=逆时针
* @property $reward_config_id 奖励配置id
* @property $lottery_id 奖池

View File

@@ -19,9 +19,11 @@ use think\model\relation\BelongsTo;
*
* @property $id ID
* @property $lottery_config_id 彩金池配置id
* @property $lottery_type 抽奖类型:0=付费,1=赠送
* @property $lottery_type 抽奖类型:0=付费,1=免费
* @property $is_win 中大奖:0=无,1=中奖
* @property $win_coin 赢取平台币
* @property int|null $ante 底注/注数dice_ante_config.mult
* @property int|null $paid_amount 付费金额(付费局=ante*100免费局=0
* @property $direction 方向:0=顺时针,1=逆时针
* @property $reward_config_id 奖励配置id
* @property $create_time 创建时间
@@ -77,7 +79,7 @@ class DicePlayRecordTest extends BaseModel
return $this->belongsTo(DiceRewardConfigRecord::class, 'reward_config_record_id', 'id');
}
/** 抽奖类型 0=付费 1=赠送 */
/** 抽奖类型 0=付费 1=免费 */
public function searchLotteryTypeAttr($query, $value)
{
if ($value !== '' && $value !== null) {
@@ -117,6 +119,22 @@ class DicePlayRecordTest extends BaseModel
}
}
/** 付费金额(付费局=ante*100免费局=0 */
public function searchPaidAmountAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('paid_amount', '=', $value);
}
}
/** 底注/注数dice_ante_config.mult */
public function searchAnteAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('ante', '=', $value);
}
}
/** 中奖档位(按 reward_config_id 对应 DiceRewardConfig.tier */
public function searchRewardTierAttr($query, $value)
{
@@ -138,4 +156,12 @@ class DicePlayRecordTest extends BaseModel
$query->where('roll_number', '=', $value);
}
}
/** 关联 dice_reward_config_record.id权重测试记录 */
public function searchRewardConfigRecordIdAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('reward_config_record_id', '=', $value);
}
}
}

View File

@@ -19,6 +19,7 @@ use think\model\relation\BelongsTo;
* @property $player_id 玩家id
* @property $admin_id 关联玩家所属管理员IDDicePlayer.admin_id
* @property $use_coins 消耗硬币
* @property $ante 底注/注数历史购买记录默认为1T5再来一次写入本次注数
* @property $total_ticket_count 总抽奖次数
* @property $paid_ticket_count 购买抽奖次数
* @property $free_ticket_count 赠送抽奖次数
@@ -143,4 +144,12 @@ class DicePlayerTicketRecord extends BaseModel
$query->where('create_time', '<=', $value);
}
}
/** 底注/注数ante */
public function searchAnteAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('ante', '=', $value);
}
}
}

View File

@@ -26,6 +26,7 @@ use think\model\relation\HasMany;
* @property int $over_play_count 已完成次数
* @property int $status 状态 -1失败 0进行中 1成功
* @property string|null $remark 失败时记录原因
* @property int|null $ante 底注/注数dice_ante_config.mult
* @property int $s_count 顺时针模拟次数(兼容旧数据)
* @property int $n_count 逆时针模拟次数(兼容旧数据)
* @property int $paid_s_count 付费抽奖顺时针次数
@@ -70,18 +71,18 @@ class DiceRewardConfigRecord extends BaseModel
/**
* 根据关联的 DicePlayRecordTest 统计平台赚取平台币
* platform_profit = 关联的付费(lottery_type=0)抽取次数 × 100 - 关联的 win_coin 求和
* platform_profit = 关联的付费(lottery_type=0)付费金额求和(paid_amount) - 关联的 win_coin 求和
* @param int $recordId dice_reward_config_record.id
* @return float
*/
public static function computePlatformProfitFromRelated(int $recordId): float
{
$paidCount = DicePlayRecordTest::where('reward_config_record_id', $recordId)
$paidAmount = (float) DicePlayRecordTest::where('reward_config_record_id', $recordId)
->where('lottery_type', 0)
->count();
->sum('paid_amount');
$sumWinCoin = (float) DicePlayRecordTest::where('reward_config_record_id', $recordId)
->sum('win_coin');
return round($paidCount * 100 - $sumWinCoin, 2);
return round($paidAmount - $sumWinCoin, 2);
}
/**

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\validate\ante_config;
use plugin\saiadmin\basic\BaseValidate;
/**
* 底注配置验证器
*/
class DiceAnteConfigValidate extends BaseValidate
{
protected $rule = [
'name' => 'require|max:64',
'title' => 'require|max:255',
'is_default' => 'require|in:0,1',
'mult' => 'require|integer|gt:0',
];
protected $message = [
'name' => '名称必须填写',
'title' => '标题必须填写',
'is_default' => '默认底注标记必须为 0 或 1',
'mult' => '底注倍率必须为大于 0 的整数',
];
protected $scene = [
'save' => ['name', 'title', 'is_default', 'mult'],
'update' => ['name', 'title', 'is_default', 'mult'],
];
}

View File

@@ -30,7 +30,7 @@ class DicePlayRecordTestValidate extends BaseValidate
*/
protected $message = [
'lottery_config_id' => '彩金池配置id必须填写',
'lottery_type' => '抽奖类型:0=付费,1=赠送必须填写',
'lottery_type' => '抽奖类型:0=付费,1=免费必须填写',
'is_win' => '中大奖:0=无,1=中奖必须填写',
'direction' => '方向:0=顺时针,1=逆时针必须填写',
'reward_config_id' => '奖励配置id必须填写',

View File

@@ -22,7 +22,7 @@ return [
'dirname' => function () {
return date('Ymd');
},
'domain' => 'http://127.0.0.1:6688',
'domain' => 'http://127.0.0.1:8989',
'uri' => '/runtime', // 如果 domain + uri 不在 public 目录下请做好软链接否则生成的url无法访问
'algo' => 'sha1',
],

View File

@@ -16,9 +16,15 @@
use Webman\Channel\Server;
use Workerman\Protocols\Frame;
$listenHost = env('WEBMAN_CHANNEL_LISTEN_HOST', '0.0.0.0');
$listenPort = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($listenPort === false) {
$listenPort = 2207;
}
return [
'server' => [
'listen' => 'frame://0.0.0.0:2206',
'listen' => 'frame://' . $listenHost . ':' . $listenPort,
'protocol' => Frame::class,
'handler' => Server::class,
'reloadable' => false,

View File

@@ -21,7 +21,7 @@ global $argv;
return [
'webman' => [
'handler' => Http::class,
'listen' => 'http://0.0.0.0:6688',
'listen' => 'http://0.0.0.0:8989',
'count' => cpu_count() * 4,
'user' => '',
'group' => '',

View File

@@ -48,6 +48,7 @@ Route::group('/api', function () {
Route::any('/game/config', [app\api\controller\GameController::class, 'config']);
Route::any('/game/buyLotteryTickets', [app\api\controller\GameController::class, 'buyLotteryTickets']);
Route::any('/game/lotteryPool', [app\api\controller\GameController::class, 'lotteryPool']);
Route::any('/game/anteConfig', [app\api\controller\GameController::class, 'anteConfig']);
Route::any('/game/playStart', [app\api\controller\GameController::class, 'playStart']);
})->middleware([
TokenMiddleware::class,

View File

@@ -0,0 +1,17 @@
-- 底注配置表
CREATE TABLE IF NOT EXISTS `dice_ante_config` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`name` varchar(64) NOT NULL COMMENT '名称',
`title` varchar(255) NOT NULL COMMENT '标题',
`is_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否默认底注0否 1是全表只允许一条',
`mult` int NOT NULL DEFAULT 1 COMMENT '底注倍率',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `idx_is_default` (`is_default`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dice 底注配置表';
-- 可选初始化数据(保留一条默认底注)
INSERT INTO `dice_ante_config` (`name`, `title`, `is_default`, `mult`)
SELECT 'default', '默认底注', 1, 1
WHERE NOT EXISTS (SELECT 1 FROM `dice_ante_config` LIMIT 1);

View File

@@ -0,0 +1,62 @@
-- 底注配置菜单与权限
-- 说明默认挂载在「大富翁」目录path=/dice若不存在则自动创建目录。
SET @now = NOW();
-- 1) 找到或创建 Dice 顶级目录
SET @dice_root_id = (
SELECT `id` FROM `sa_system_menu`
WHERE `path` = '/dice' AND `type` = 1
ORDER BY `id` ASC LIMIT 1
);
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT 0, '大富翁', 'Dice', NULL, 1, '/dice', NULL, NULL, 'ri:gamepad-line', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE @dice_root_id IS NULL;
SET @dice_root_id = (
SELECT `id` FROM `sa_system_menu`
WHERE `path` = '/dice' AND `type` = 1
ORDER BY `id` ASC LIMIT 1
);
-- 2) 创建底注配置菜单
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @dice_root_id, '底注配置', 'AnteConfig', NULL, 2, 'ante_config', '/dice/ante_config/index', NULL, 'ri:coins-line', 92, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (
SELECT 1 FROM `sa_system_menu` WHERE `path` = 'ante_config' AND `component` = '/dice/ante_config/index' AND `type` = 2
);
SET @ante_menu_id = (
SELECT `id` FROM `sa_system_menu`
WHERE `path` = 'ante_config' AND `component` = '/dice/ante_config/index' AND `type` = 2
ORDER BY `id` ASC LIMIT 1
);
-- 3) 创建按钮权限
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @ante_menu_id, '数据列表', '', 'dice:ante_config:index:index', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:index' AND `type` = 3);
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @ante_menu_id, '读取', '', 'dice:ante_config:index:read', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:read' AND `type` = 3);
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @ante_menu_id, '添加', '', 'dice:ante_config:index:save', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:save' AND `type` = 3);
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @ante_menu_id, '修改', '', 'dice:ante_config:index:update', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:update' AND `type` = 3);
INSERT INTO `sa_system_menu`
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
SELECT @ante_menu_id, '删除', '', 'dice:ante_config:index:destroy', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:destroy' AND `type` = 3);

View File

@@ -0,0 +1,4 @@
-- DicePlayRecord 新增注数与付费金额字段
ALTER TABLE `dice_play_record`
ADD COLUMN `ante` int unsigned NOT NULL DEFAULT 1 COMMENT '底注/注数(必须为 dice_ante_config.mult 中存在的值)' AFTER `lottery_type`,
ADD COLUMN `paid_amount` int unsigned NOT NULL DEFAULT 0 COMMENT '付费金额(付费局=ante*100免费局=0' AFTER `ante`;

View File

@@ -0,0 +1,3 @@
-- DicePlayerTicketRecord 新增注数字段(用于记录“再来一次”免费抽奖的注数)
ALTER TABLE `dice_player_ticket_record`
ADD COLUMN `ante` int unsigned NOT NULL DEFAULT 1 COMMENT '底注/注数历史购买记录默认为1' AFTER `use_coins`;

View File

@@ -20,6 +20,20 @@ use plugin\saiadmin\exception\ApiException;
*/
class CrontabLogic extends BaseLogic
{
/**
* 获取 webman channel 服务地址
* 需要保证与 server/config/plugin/webman/channel/process.php 的 listen 端口一致
*/
private function channelConfig(): array
{
$host = env('WEBMAN_CHANNEL_HOST', '127.0.0.1');
$port = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($port === false) {
$port = 2207;
}
return ['host' => $host, 'port' => $port];
}
/**
* 构造函数
*/
@@ -67,7 +81,8 @@ class CrontabLogic extends BaseLogic
$id = $model->getKey();
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
return true;
@@ -116,7 +131,8 @@ class CrontabLogic extends BaseLogic
]);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
}
@@ -141,7 +157,8 @@ class CrontabLogic extends BaseLogic
$result = parent::destroy($ids);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $ids]);
}
return $result;
@@ -162,7 +179,8 @@ class CrontabLogic extends BaseLogic
$result = $model->save(['status' => $status]);
if ($result) {
// 连接到Channel服务
ChannelClient::connect();
$channel = $this->channelConfig();
ChannelClient::connect($channel['host'], $channel['port']);
ChannelClient::publish('crontab', ['args' => $id]);
}
return $result;

View File

@@ -118,6 +118,7 @@ Route::group('/core', function () {
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdate', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdate']);
Route::post('/dice/reward_config/DiceRewardConfig/createRewardReference', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'createRewardReference']);
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getOptions']);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getCurrentPool']);

View File

@@ -20,8 +20,13 @@ class Task
$dbName = env('DB_NAME');
if (!empty($dbName)) {
$this->logic = new CrontabLogic();
$channelHost = env('WEBMAN_CHANNEL_HOST', '127.0.0.1');
$channelPort = filter_var(env('WEBMAN_CHANNEL_PORT'), FILTER_VALIDATE_INT);
if ($channelPort === false) {
$channelPort = 2207;
}
// 连接webman channel服务
Client::connect();
Client::connect($channelHost, $channelPort);
// 订阅某个自定义事件并注册回调,收到事件后会自动触发此回调
Client::on('crontab', function ($data) {
$this->reload($data);

146
项目文档.md Normal file
View File

@@ -0,0 +1,146 @@
# 大富翁 · 摇色子 — 项目文档
本文描述**业务玩法**与**服务端抽奖/结算机制**,便于产品、运营与二次开发对齐实现。接口路径、鉴权与联调细节见根目录 [`API对接文档.md`](API对接文档.md)。
---
## 1. 项目概述
- **形态**:平台玩家使用「平台币」参与摇五颗标准六面骰(点数各 16结果对应棋盘/奖励配置;后台可配置档位权重、奖池、杀分策略与展示文案(含中英文)。
- **服务端**PHP [Webman](https://www.workerman.net/webman)`server/`),玩家与平台接口在 `app/api`;骰子业务模型在 `app/dice`
- **管理端**:前端工程 `saiadmin-artd/`(与 SaiAdmin 插件体系配套)。
---
## 2. 核心概念
| 概念 | 说明 |
| --- | --- |
| **平台币 `coin`** | 玩家钱包余额;付费开局、购买套餐、中奖结算均围绕该字段。 |
| **注数 `ante`** | 倍数因子,须存在于表 `dice_ante_config``mult` 中;接口 `/api/game/anteConfig` 返回可选注数。 |
| **单注费用** | 付费抽奖时,开局前扣除 **`ante × 100`** 平台币(代码常量 `UNIT_COST = 100`,即「单注 100 币」口径)。 |
| **方向 `direction`** | 开局参数:`0``1` 对应两套奖励数据(顺时针/逆时针或「无 / 中奖」分支,由前端与配置表共同约定);服务端在 **档位确定后**,按当前方向从 `DiceReward` 缓存结构中取该档位下的条目再按权重抽取。 |
| **档位 T1T5** | 中奖层级;先抽档位,再在该档位 + 当前方向下按 `weight` 抽一条奖励配置。 |
| **`grid_number`530** | 与「五颗骰子点数之和」一致:最小 5全 1最大 30全 6用于关联奖励行与后续生成 `roll_array`。 |
| **`real_ev`** | 奖励配置中的期望调节项;**普通中奖**结算为 **`(100 + real_ev) × ante`**(付费局在开局已扣 `ante×100`,净效果依 `real_ev` 而定)。 |
---
## 3. 玩法流程(玩家视角)
1. **登录 / 进游戏**
平台侧通过 `/api/v1/getGameUrl` 或玩家侧 `/api/user/Login` 换取 token打开前端页面。
2. **(可选)购买「抽奖券」套餐**
`POST /api/game/buyLotteryTickets``count` 仅支持 `1``5``10`
- 1100 币 → 1 次付费计数 + 0 次赠送
- 5500 币 → 5 次付费 + **1 次赠送**(共 6 次计入总次数)
- 101000 币 → 10 次付费 + **3 次赠送**(共 13 次)
会更新玩家身上的 `total_ticket_count` / `paid_ticket_count` / `free_ticket_count`,并记钱包与券流水。
3. **开局抽奖**
`POST /api/game/playStart`,需传 **`direction`0 或 1** 与 **`ante`(正整数,且须在底注配置中)**。
4. **付费 vs 免费**
- **免费抽奖**:当 `free_ticket_count > 0` 时,本局视为免费类型:不扣 `ante×100`,但会消耗 **1 次** `free_ticket_count`
- **付费抽奖**:不依赖「券张数是否大于 0」只要非免费局开局前扣 **`ante × 100`**。
> **重要**:当前实现已**不再用「抽奖券张数」作为能否开局的条件**`buyLotteryTickets` 更新的是统计与赠送次数,**真正开局仍看余额、注数、免费次数等规则**(见下节)。
5. **免费注数锁定**
若上一局因命中 **T5** 赠送了免费次数,服务端会缓存「免费局须与触发时相同的 `ante`」,不一致则拒绝并提示修改注数。
---
## 4. 抽奖与结算机制(服务端逻辑)
以下对应 `PlayStartLogic``LotteryService`,便于理解「先抽什么、再算什么钱」。
### 4.1 前置校验
- 用户存在;`ante` 合法。
- **最低余额**`coin ≥ abs(min_real_ev) × ante``min_real_ev` 来自全表 `DiceRewardConfig` 缓存),防止极端负 EV 下余额不足以覆盖风险口径。
- 付费局:`coin ≥ ante × 100`
### 4.2 使用哪套「档位权重」:默认奖池 vs 杀分奖池
配置表 `dice_lottery_pool_config` 至少要有 **`name = default`**;可选 **`name = killScore`**。
- **`default` 彩金池**维护累计盈利字段 **`profit_amount`**(见 4.5)。
- 记:`safety_line` = 安全线,`kill_enabled` = 是否开启杀分。
**是否按「奖池档位权重」抽档位(`usePoolWeights`**
| 情形 | 档位权重来源 |
| --- | --- |
| **免费局** | 使用 **killScore** 奖池的 T1T5 权重;若无 `killScore` 则退回 `default`。 |
| **付费局****杀分开启****`profit_amount ≥ safety_line`** 且 **存在 killScore** | 使用 **killScore** 的档位权重(杀分模式)。 |
| **其他付费局** | 使用 **玩家**身上的 `t1_weight``t5_weight``DicePlayer` 字段,与 `LotteryService::drawTierByPlayerWeights` 一致)。 |
档位抽出 **T1T5** 后,从 `DiceReward` 缓存中取出 **`[该档位][direction]`** 下的所有奖励行,再按行 **`weight`** 做加权随机(仅 `weight > 0` 参与;全为 0 会重试档位,最多约 10 次)。
### 4.3 杀分模式下的特殊处理
当使用 **killScore / 免费局** 等与杀分一致的权重路径时:
- 在奖励抽取阶段会 **排除 `grid_number` 为 5 和 30 的配置**(这两点数和只能对应「全 1」「全 6」豹子无法做成非豹子展示
- **不会触发豹子大奖**(见 4.4):若摇到豹子点数组,只生成 **非豹子** 的五骰组合,不发放豹子附加奖金。
### 4.4 普通奖与「豹子 / BIGWIN」
- 若本次抽中的 `grid_number` **不是**「豹子集合」`{5,10,15,20,25,30}`:按点数和生成 5 个 16 的骰子(和为 `grid_number`**普通奖金** = **`(100 + real_ev) × ante`**(付费局已预先扣除 `ante×100`)。
- 若点数和落在豹子集合:
- **`grid_number` 为 5 或 30**:若**非**杀分路径,**必定**按豹子结算(五颗相同点数)。
- **10 / 15 / 20 / 25**:读取 `DiceRewardConfig`**`tier = BIGWIN`** 且对应该 `grid_number` 的配置,用其 **`weight`01000010000=100%** 随机决定是否视为真豹子;否则生成**非豹子**但点数和不变的骰子组合。
- **真豹子**时:奖金按 **`(100 + big_win_real_ev) × ante`** 发放(`big_win_real_ev` 来自 BIGWIN 配置;若未配则用代码兜底常量);并**不计入**当次普通 `reward_win` 那条配置(与「中豹子不走普通奖」逻辑一致,详见代码注释)。
杀分路径下:**不触发**豹子奖,仅展示非豹子组合。
### 4.5 T5「再来一次」
若命中奖励属于 **T5** 档位(且未走「仅豹子清掉普通奖」的特殊分支):在事务内为玩家 **`free_ticket_count + 1`**,并写入券流水备注;同时写入 Redis**下一局免费抽奖必须使用本局相同 `ante`**。
### 4.6 彩金池盈利累计
**`default`** 那条池子上更新 **`profit_amount`**
- **付费局**:本局贡献 `+= (本局总中奖 win_coin) - (本局付费 paid_amount)`,其中 `paid_amount = ante × 100`
- **免费局**`+= win_coin`(无票价成本,`paid_amount = 0`)。
该累计值与 **`safety_line``kill_enabled`** 共同决定下一局付费是否进入 **killScore** 档位权重(见 4.2)。
> 注意:仓库中部分数据库迁移脚本对 `profit_amount` 的注释可能仍沿用旧口径(例如按 `100-real_ev` 解释)。当前线上行为应以 `PlayStartLogic` 中对 `profit_amount` 的实际累加逻辑为准。
---
## 5. 数据与配置要点(实现侧)
- **`DiceReward`**:按档位、方向组织好的多语言/展示与 `grid_number``weight``real_ev` 等,供开局加权抽取。
- **`DiceRewardConfig`**:含 **BIGWIN** 档及普通档;`getCachedMinRealEv()` 等用于全局限定。
- **`dice_lottery_pool_config`**`default` / `killScore` 的 T1T5 权重及杀分相关开关、安全线、累计盈利。
- **对局表 `DicePlayRecord`**:记录 `lottery_config_id``lottery_type`(付费/免费)、`ante``paid_amount``roll_array``reward_config_id`、各类中奖拆分字段等,供后台与平台对账。
---
## 6. 接口与文档索引
| 文档 | 内容 |
| --- | --- |
| [`API对接文档.md`](API对接文档.md) | 平台 `/api/v1/*``auth-token`)、玩家 `/api/*``token`)、统一返回码、联调建议。 |
| `server/docs/` | 性能、权重测试、出点分析等专项说明(按需阅读)。 |
**与玩法直接相关的玩家接口示例**
- `GET /api/game/config` — 前端文案与分组配置
- `GET /api/game/anteConfig` — 可选注数
- `GET /api/game/lotteryPool` — 彩金池展示列表(不含 BIGWIN 档)
- `POST /api/game/buyLotteryTickets` — 购买套餐(更新次数统计)
- `POST /api/game/playStart` — 开局一局(`direction``ante`
---
## 7. 修订说明
- 本文档依据 `server/app/api/logic/PlayStartLogic.php``GameLogic.php``LotteryService.php``GameController` 当前实现整理;若业务规则变更,请以代码与数据库迁移为准并同步更新本节与 [`API对接文档.md`](API对接文档.md)。