Compare commits

51 Commits

Author SHA1 Message Date
a5e2f2fdf7 1.优化玩家抽奖时没有记录dept_id的问题 2026-05-19 14:34:17 +08:00
5cd8330c9e 1.优化玩家管理页面/dice/player/index获取游戏链接逻辑 2026-05-19 14:18:31 +08:00
1b65e25f11 1.修复打包报错 2026-05-19 12:25:16 +08:00
1f25280dfd 1.所有接口需要根据agent_id绑定渠道
2.移除所有记录页面的更新按钮,只能查看数据
3.将所有软删除修改为硬删除
2026-05-19 12:04:34 +08:00
b089f302de 1.修复页面/game,报错404 not Found 2026-05-19 09:53:43 +08:00
dd264b1e97 1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道
3.优化后台页面设置
2026-05-19 09:49:02 +08:00
085454fb78 1.优化工作台页面/dashboard/console
2.移除岗位管理相关代码和数据库
2026-05-18 11:41:34 +08:00
52b5ccb8e4 1.优化getPlayerInfo接口 2026-05-13 10:15:49 +08:00
6a1fd639a4 1.优化接口/api/v1/getPlayerGameRecord
2.增加接口日志记录接口request和response
2026-05-13 09:59:15 +08:00
e74fc6069c 优化生成签名脚本 2026-05-13 09:47:25 +08:00
80d39ed1cd 更新对接平台文档 2026-05-12 15:50:45 +08:00
90ba5b0068 新增Dicey Fun 第三方接入英文文档 2026-05-08 18:13:53 +08:00
641bb83f7f 数据库备份-后台新增获取游戏连接按钮 2026-04-28 11:08:58 +08:00
63db23df2d 后台新增获取游戏连接按钮 2026-04-28 11:06:56 +08:00
a7b2f2cd91 修改域名为h55555game.top 2026-04-28 10:24:01 +08:00
40277e677d 1.新增游戏管理接口和菜单
2.创建对接第三方文档
2026-04-22 18:44:55 +08:00
d3ee3faec4 优化抽奖接口/api/game/playStart翻译问题 2026-04-08 17:37:20 +08:00
765f50963a 优化临时插入用户接口/api/user/Login和抽奖接口/api/game/playStart 2026-04-08 17:32:14 +08:00
ef684a1c55 修改访问时报错404 2026-04-02 11:59:09 +08:00
a8973d4e47 优化直接访问API端口地址返回404不泄漏信息 2026-04-01 10:55:12 +08:00
9f42cffd18 [优化]移除/api/game/lotteryPool接口中不虚言显示的键值 2026-04-01 10:22:18 +08:00
edd870457f 优化前端双语配置 2026-03-31 18:20:03 +08:00
7493c4e400 优化页面/dice/reward_config/index中玩家实际中奖金额的计算 2026-03-31 17:52:18 +08:00
b0e5a3f5c0 重新设置抽奖底注金额为1,优化页面样式 2026-03-31 17:31:19 +08:00
6ed34b97df 重新设置抽奖底注金额为1,优化页面样式 2026-03-31 17:23:16 +08:00
d54a9c9281 优化抽奖接口/api/game/playStart,新增消耗平台币use_coin(=0是为免费抽奖) 2026-03-31 12:02:09 +08:00
afd6113927 一键测试权重-新增安全线杀分机制,保证测试数据合理 2026-03-27 17:50:11 +08:00
2f05ac0cd9 优化抽奖记录(测试权重)页面 2026-03-27 14:37:31 +08:00
ded5e82e16 修复打包报错 2026-03-27 14:19:29 +08:00
e2273ef41c 优化一键测试权重 2026-03-27 14:14:59 +08:00
0bdab95ab7 优化首页样式-移除抽奖券 2026-03-27 10:41:00 +08:00
cfc6537f97 优化奖励配置/按规则一键生成表 2026-03-27 10:26:58 +08:00
e32f3890f1 优化抽奖方式,以及记录相关信息 2026-03-26 18:10:41 +08:00
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
294 changed files with 15092 additions and 3378 deletions

6
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/server/docs/PERFORMANCE_AND_QPS_ANALYSIS.md" charset="GB2312" />
</component>
</project>

View File

@@ -10,7 +10,7 @@
由部署方提供:
- 测试环境:`https://dice-api.yuliao666.top`
- 测试环境:`https://dice-api.h55555game.top`
下文所有路径均为相对路径,如:`/api/v1/getGameUrl`
@@ -68,9 +68,9 @@
| secret | 是 | string | 双方约定的密钥(服务端配置 `xF75oK91TQj13s0UmNIr1NBWMWGfflNO` |
| time | 是 | int/string | Unix 时间戳(秒),服务端会做时间容忍校验 |
| signature | 是 | string | 签名:`md5(agent_id + secret + time)` |
- **agent_id**:通过后台获取系统管理-用户管理-代理ID![http://dice-api.yuliao666.top/storage/20260317/20a0d49f016bcc89afa794ed217e762fe3ef6481.png](server/public/img.png)
- **agent_id**:通过后台获取系统管理-用户管理-代理ID![http://dice-api.h55555game.top/storage/20260317/20a0d49f016bcc89afa794ed217e762fe3ef6481.png](server/public/img.png)
- **secret**xF75oK91TQj13s0UmNIr1NBWMWGfflNO服务器配置
- **后台地址**https://dice.yuliao666.top 账号: zhuguan 密码123456
- **后台地址**https://dice.h55555game.top 账号: zhuguan 密码123456
#### 签名规则
- **签名字符串**:直接拼接 `agent_id.secret.time`(无分隔符)
@@ -135,7 +135,7 @@ signature = md5(agent_id + secret + time)
"code": 200,
"message": "success",
"data": {
"url": "https://dice-game.yuliao666.top/?token=...&lang=zh"
"url": "https://dice-game.h55555game.top/?token=...&lang=zh"
}
}
```
@@ -166,15 +166,16 @@ signature = md5(agent_id + secret + time)
| 参数名 | 必填 | 类型 | 说明 |
| --- | --- | --- | --- |
| username | 否 | string | 不传则查询全量(按时间/分页 |
| start_create_time | 否 | string | 开始时间(与数据库存储格式一致) |
| end_create_time | 否 | string | 结束时间(与数据库存储格式一致) |
| page | 否 | int | 默认 1 |
| limit | 否 | int | 默认 20最大 100 |
| username | 否 | string | 不传则不按用户筛选;数据仅来自「最近 7 天」时间窗(见下 |
| start_create_time | 否 | string | 开始时间;与 `end_create_time` 均不传时,服务端默认最近 7 天 |
| end_create_time | 否 | string | 结束时间 |
| limit | 否 | int | 返回条数上限,默认 20小于 1 或大于 2000 时按 20 处理 |
**时间规则**:仅允许查询「当前服务器时间起向前 7 天」内的 `create_time``start_create_time``end_create_time` 的跨度不得超过 7 天;`end_create_time` 晚于当前时间时按当前时间截断。非法区间返回参数错误。
#### 响应说明
返回游玩记录列表,并附带 `dice_player`(包含 `id/username/phone`)。
返回游玩记录列表(按 `id` 倒序,最多 `limit` 条),并附带 `dice_player`(包含 `id/username/phone`)。
### 3.4 获取钱包流水
@@ -182,7 +183,7 @@ signature = md5(agent_id + secret + time)
- **方法**POST
- **请求头**`auth-token`
参数与分页规则同 3.3,返回钱包流水列表(附带 `dice_player`)。
参数与时间规则同 3.3(无 `page`,仅 `limit` 限制条数),返回钱包流水列表(附带 `dice_player`)。
### 3.5 获取中奖券获取记录
@@ -190,7 +191,7 @@ signature = md5(agent_id + secret + time)
- **方法**POST
- **请求头**`auth-token`
参数与分页规则同 3.3,返回中奖券记录列表(附带 `dice_player`)。
参数与时间规则同 3.3,返回中奖券记录列表(附带 `dice_player`)。
### 3.6 平台钱包转入/转出

199
README.md
View File

@@ -1,99 +1,146 @@
<p align="center">
<img src="https://saithink.top/images/logo.png" width="120" />
</p>
<p align="center">
<img src="https://svg.hamm.cn/badge.svg?key=License&value=MIT" />
<img src="https://svg.hamm.cn/badge.svg?key=Version&value=6.x" />
</p>
# 大富翁 · 摇色子 — 项目文档
<div style="padding:18px;max-width: 1024px;margin:0 auto;">
<h1>SaiAdmin 6.x</h1>
## 项目简介
SaiAdmin 是一个基于 [Webman](https://www.workerman.net/webman) 的高性能后台管理系统插件。它提供了完整的权限管理、系统配置、代码生成等功能,帮助开发者快速构建企业级应用。
本文描述**业务玩法**与**服务端抽奖/结算机制**,便于产品、运营与二次开发对齐实现。接口路径、鉴权与联调细节见根目录 [`API对接文档.md`](API对接文档.md)。
---
## ✨ 核心特性
## 1. 项目概述
- **🚀 高性能** - 基于 Webman 常驻内存框架,性能优异
- **🔐 完整权限系统** - RBAC 权限模型,支持用户、角色、部门、岗位管理
- **📝 代码生成器** - 一键生成 CRUD 代码,提升开发效率
- **⚡ 双 ORM 支持** - 同时支持 ThinkORM 和 Eloquent ORM
- **🔧 插件化架构** - 支持插件扩展,便于功能模块化
- **📊 系统监控** - 内置服务器监控、缓存管理功能
- **📋 日志系统** - 完整的登录日志和操作日志记录
- **形态**:平台玩家使用「平台币」参与摇五颗标准六面骰(点数各 16结果对应棋盘/奖励配置;后台可配置档位权重、奖池、杀分策略与展示文案(含中英文)。
- **服务端**PHP [Webman](https://www.workerman.net/webman)`server/`),玩家与平台接口在 `app/api`;骰子业务模型在 `app/dice`
- **管理端**:前端工程 `saiadmin-artd/`(与 SaiAdmin 插件体系配套)。
## 🛠️ 功能模块
---
### 系统管理
## 2. 核心概念
| 模块 | 说明 |
| ---------- | -------------------------------- |
| 用户管理 | 用户增删改查、密码管理、缓存清理 |
| 角色管理 | 角色 CRUD、菜单权限分配 |
| 部门管理 | 组织架构管理、树形结构 |
| 岗位管理 | 岗位信息维护、Excel 模板导入导出 |
| 菜单管理 | 菜单配置、按钮权限 |
| 字典管理 | 字典类型与字典数据维护 |
| 附件管理 | 文件上传、分类管理、资源移动 |
| 系统配置 | 分组配置、邮件设置、动态参数 |
| 日志管理 | 登录日志、操作日志查询与清理 |
| 服务监控 | 服务器状态、缓存信息、一键清理 |
| 数据表维护 | 数据表结构、表优化、碎片整理 |
| 概念 | 说明 |
| --- | --- |
| **平台币 `coin`** | 玩家钱包余额;付费开局、购买套餐、中奖结算均围绕该字段。 |
| **注数 `ante`** | 倍数因子,须存在于表 `dice_ante_config``mult` 中;接口 `/api/game/anteConfig` 返回可选注数。 |
| **单注费用** | 付费抽奖时,开局前扣除 **`ante × 1`** 平台币(代码常量 `UNIT_COST = 1`,即「单注 1 币」口径)。 |
| **方向 `direction`** | 开局参数:`0``1` 对应两套奖励数据(顺时针/逆时针或「无 / 中奖」分支,由前端与配置表共同约定);服务端在 **档位确定后**,按当前方向从 `DiceReward` 缓存结构中取该档位下的条目再按权重抽取。 |
| **档位 T1T5** | 中奖层级;先抽档位,再在该档位 + 当前方向下按 `weight` 抽一条奖励配置。 |
| **`grid_number`530** | 与「五颗骰子点数之和」一致:最小 5全 1最大 30全 6用于关联奖励行与后续生成 `roll_array` |
| **`real_ev`** | 奖励配置中的期望调节项;**普通中奖**结算为 **`real_ev × ante`**(付费局在开局已扣 `ante×1`,净效果依 `real_ev` 而定)。 |
### 开发工具
---
| 模块 | 说明 |
| -------- | ---------------------------- |
| 代码生成 | 根据数据表自动生成 CRUD 代码 |
| 定时任务 | Crontab 任务管理、执行日志 |
## 3. 玩法流程(玩家视角)
<h1>学习</h1>
1. **登录 / 进游戏**
平台侧通过 `/api/v1/getGameUrl` 或玩家侧 `/api/user/Login` 换取 token打开前端页面。
<ul>
<li>
<a href="https://saithink.top" target="_blank">主页 / Home page</a>
</li>
<li>
<a href="https://saithink.top/documents/v6/" target="_blank">文档 / Document</a>
</li>
</ul>
2. **(可选)购买「抽奖券」套餐**
`POST /api/game/buyLotteryTickets``count` 仅支持 `1``5``10`
- 11 币 → 1 次付费计数 + 0 次赠送
- 55 币 → 5 次付费 + **1 次赠送**(共 6 次计入总次数)
- 1010 币 → 10 次付费 + **3 次赠送**(共 13 次)
会更新玩家身上的 `total_ticket_count` / `paid_ticket_count` / `free_ticket_count`,并记钱包与券流水。
<h1>演示地址</h1>
<p>演示地址: <a href="http://v6.saithink.top" target="_blank">http://v6.saithink.top</a></p>
<p>演示账号admin</p>
<p>演示密码123456</p>
3. **开局抽奖**
`POST /api/game/playStart`,需传 **`direction`0 或 1** 与 **`ante`(正整数,且须在底注配置中)**。
<h1>共同交流</h1>
4. **付费 vs 免费**
- **免费抽奖**:当 `free_ticket_count > 0` 时,本局视为免费类型:不扣 `ante×1`,但会消耗 **1 次** `free_ticket_count`
- **付费抽奖**:不依赖「券张数是否大于 0」只要非免费局开局前扣 **`ante × 1`**。
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<img src="https://saithink.top/images/me.png" class="no-zoom" width="180px">
<p>saiadmin交流群(添加我微信备注"saiadmin")</p>
</td>
</tr>
</tbody>
</table>
> **重要**:当前实现已**不再用「抽奖券张数」作为能否开局的条件**`buyLotteryTickets` 更新的是统计与赠送次数,**真正开局仍看余额、注数、免费次数等规则**(见下节)。
<h1>支持项目</h1>
5. **免费注数锁定**
若上一局因命中 **T5** 赠送了免费次数,服务端会缓存「免费局须与触发时相同的 `ante`」,不一致则拒绝并提示修改注数。
如果您正在使用这个项目并感觉良好,或者是想支持我继续开发,您可以通过如下`任意`方式支持我:
---
谢谢! ❤️
## 4. 抽奖与结算机制(服务端逻辑)
以下对应 `PlayStartLogic``LotteryService`,便于理解「先抽什么、再算什么钱」。
| 微信 | 支付宝 |
| :------------------------------------------------------------------------------: | :------------------------------------------------------------------------------: |
| <img src="https://saithink.top/images/wechat.png" alt="Wechat QRcode" width=180> | <img src="https://saithink.top/images/alipay.png" alt="Alipay QRcode" width=180> |
### 4.1 前置校验
<div style="clear: both">
<h1>LICENSE</h1>
This project is open-sourced software licensed under the MIT.
</div>
- 用户存在;`ante` 合法。
- **最低余额**`coin ≥ abs(min_real_ev) × ante``min_real_ev` 来自全表 `DiceRewardConfig` 缓存),防止极端负 EV 下余额不足以覆盖风险口径。
- 付费局:`coin ≥ ante × 1`
</div>
### 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`**普通奖金** = **`real_ev × ante`**(付费局已预先扣除 `ante×1`)。
- 若点数和落在豹子集合:
- **`grid_number` 为 5 或 30**:若**非**杀分路径,**必定**按豹子结算(五颗相同点数)。
- **10 / 15 / 20 / 25**:读取 `DiceRewardConfig`**`tier = BIGWIN`** 且对应该 `grid_number` 的配置,用其 **`weight`01000010000=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 × 1`
- **免费局**`+= win_coin`(无票价成本,`paid_amount = 0`)。
该累计值与 **`safety_line``kill_enabled`** 共同决定下一局付费是否进入 **killScore** 档位权重(见 4.2)。
> 注意:仓库中部分数据库迁移脚本对 `profit_amount` 的注释可能仍沿用旧口径。当前行为应以 `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_tier`、各类中奖拆分字段等,供后台与平台对账。
---
## 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)。

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.h55555game.top
# 登录页是否显示验证码,设为 false 可关闭(需与后端 LOGIN_CAPTCHA_ENABLE 一致)
VITE_LOGIN_CAPTCHA_ENABLED = false

10
saiadmin-artd/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 已忽略包含查询文件的默认文件夹
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/

View File

@@ -0,0 +1,57 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<HTMLCodeStyleSettings>
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</HTMLCodeStyleSettings>
<JSCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0">
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</TypeScriptCodeStyleSettings>
<VueCodeStyleSettings>
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
</VueCodeStyleSettings>
<codeStyleSettings language="HTML">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="Vue">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>

8
saiadmin-artd/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/saiadmin-artd.iml" filepath="$PROJECT_DIR$/.idea/saiadmin-artd.iml" />
</modules>
</component>
</project>

6
saiadmin-artd/.idea/prettier.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PrettierConfiguration">
<option name="myConfigurationMode" value="AUTOMATIC" />
</component>
</project>

8
saiadmin-artd/.idea/saiadmin-artd.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
saiadmin-artd/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

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

@@ -1,32 +1,36 @@
import request from '@/utils/http'
export type DashboardQueryParams = {
dept_id?: number
}
/**
* 大富翁工作台卡片统计(玩家注册、充值、提现、游玩次数,含较上周对比)
* @returns 响应
*/
export function fetchStatistics() {
export function fetchStatistics(params?: DashboardQueryParams) {
return request.get<any>({
url: '/core/dice/dashboard/statistics'
url: '/core/dice/dashboard/statistics',
params
})
}
/**
* 近期玩家充值统计近10天每日充值金额
* @returns 响应
*/
export function fetchRechargeChart() {
export function fetchRechargeChart(params?: DashboardQueryParams) {
return request.get<any>({
url: '/core/dice/dashboard/rechargeChart'
url: '/core/dice/dashboard/rechargeChart',
params
})
}
/**
* 月度玩家充值汇总当年1-12月每月充值金额
* @returns 响应
*/
export function fetchRechargeBarChart() {
export function fetchRechargeBarChart(params?: DashboardQueryParams) {
return request.get<any>({
url: '/core/dice/dashboard/rechargeBarChart'
url: '/core/dice/dashboard/rechargeBarChart',
params
})
}
@@ -39,11 +43,11 @@ export interface WalletRecordItem {
/**
* 工作台-玩家充值记录最新50条
* @returns 列表
*/
export function fetchWalletRecordList() {
export function fetchWalletRecordList(params?: DashboardQueryParams) {
return request.get<WalletRecordItem[]>({
url: '/core/dice/dashboard/walletRecordList'
url: '/core/dice/dashboard/walletRecordList',
params
})
}
@@ -52,15 +56,34 @@ export interface NewPlayerItem {
name: string
coin: number
total_ticket_count: number
create_time: string
}
/** 玩家游玩记录项 */
export interface PlayRecordItem {
player_name: string
reward_tier: string
reward_tier_label: string
win_coin: number
create_time: string
}
/**
* 工作台-新增玩家记录最新50条
* @returns 列表
*/
export function fetchNewPlayerList() {
export function fetchNewPlayerList(params?: DashboardQueryParams) {
return request.get<NewPlayerItem[]>({
url: '/core/dice/dashboard/newPlayerList'
url: '/core/dice/dashboard/newPlayerList',
params
})
}
/**
* 工作台-玩家游玩记录最新50条
*/
export function fetchPlayRecordList(params?: DashboardQueryParams) {
return request.get<PlayRecordItem[]>({
url: '/core/dice/dashboard/playRecordList',
params
})
}

View File

@@ -71,5 +71,19 @@ export default {
return request.get<Api.Common.ApiData[]>({
url: '/core/dept/accessDept'
})
},
destroyPreview(ids: string | number | Array<string | number>) {
const idStr = Array.isArray(ids) ? ids.join(',') : String(ids)
return request.get<Api.Common.ApiData>({
url: '/core/dept/destroyPreview',
params: { ids: idStr }
})
},
syncChannelConfigs() {
return request.post<any>({
url: '/core/dept/syncChannelConfigs'
})
}
}

View File

@@ -1,75 +0,0 @@
import request from '@/utils/http'
/**
* 岗位API
*/
export default {
/**
* 获取数据列表
* @param params 搜索参数
* @returns 数据列表
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/core/post/index',
params
})
},
/**
* 读取数据
* @param id 数据ID
* @returns 数据详情
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/core/post/read?id=' + id
})
},
/**
* 创建数据
* @param params 数据参数
* @returns 执行结果
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/core/post/save',
data: params
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/core/post/update',
data: params
})
},
/**
* 删除数据
* @param id 数据ID
* @returns 执行结果
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/core/post/destroy',
data: params
})
},
/**
* 可操作岗位
* @returns 数据列表
*/
accessPost() {
return request.get<Api.Common.ApiData[]>({
url: '/core/post/accessPost'
})
}
}

View File

@@ -79,9 +79,10 @@ export default {
* 可操作角色
* @returns 数据列表
*/
accessRole() {
accessRole(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData[]>({
url: '/core/role/accessRole'
url: '/core/role/accessRole',
params
})
},

View File

@@ -0,0 +1,138 @@
<template>
<div v-if="props.enabled" class="art-full-height super-admin-channel-shell">
<div class="box-border flex gap-3 h-full max-md:block max-md:gap-0 max-md:h-auto">
<div class="channel-list-panel flex-shrink-0 h-full max-md:w-full max-md:h-auto max-md:mb-5">
<ElCard
class="channel-tree-card tree-card art-card-xs flex flex-col h-full mt-0"
shadow="never"
v-loading="loadingChannels"
>
<template #header>
<b class="channel-list-title">{{ $t('common.channelScope.listTitle') }}</b>
</template>
<ElScrollbar>
<ElTree
:data="displayTreeData"
:props="{ children: 'children', label: 'label' }"
node-key="id"
:current-node-key="selectedDeptId"
default-expand-all
highlight-current
@node-click="onNodeClick"
/>
</ElScrollbar>
</ElCard>
</div>
<div class="flex flex-col flex-grow min-w-0 min-h-0">
<div v-if="selectedDeptLabel" class="channel-banner mb-3 text-sm text-g-500">
{{ bannerLabel }}<b>{{ selectedDeptLabel }}</b>
</div>
<div class="flex flex-col flex-1 min-h-0 min-w-0">
<slot />
</div>
</div>
</div>
</div>
<slot v-else />
</template>
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { isRoleChannelRoute } from '@/utils/channelLayout'
import {
DEFAULT_CHANNEL_ID,
useChannelDeptScope,
type ChannelTreeNode
} from '@/composables/useChannelDeptScope'
const route = useRoute()
defineOptions({ name: 'SuperAdminChannelShell' })
const props = withDefaults(
defineProps<{
enabled?: boolean
}>(),
{
enabled: true
}
)
const { t } = useI18n()
const {
treeData,
selectedDeptId,
loadingChannels,
selectedDeptLabel,
handleChannelClick,
provideScope,
isConfigScope,
showDefaultTemplate
} = useChannelDeptScope()
provideScope()
const displayTreeData = computed(() => {
const nodes = showDefaultTemplate.value
? treeData.value
: treeData.value.filter((n) => n.id !== DEFAULT_CHANNEL_ID)
const defaultLabel = isRoleChannelRoute(route)
? t('common.channelScope.defaultRoleTemplate')
: t('common.channelScope.defaultTemplate')
return nodes.map((node) =>
node.id === DEFAULT_CHANNEL_ID && !node.label ? { ...node, label: defaultLabel } : node
)
})
const bannerLabel = computed(() => {
if (isConfigScope.value) {
return t('common.channelScope.currentConfig')
}
if (isRoleChannelRoute(route)) {
return t('common.channelScope.currentRole')
}
return t('common.channelScope.currentChannel')
})
const onNodeClick = (data: ChannelTreeNode) => {
handleChannelClick(data)
}
</script>
<style scoped>
.super-admin-channel-shell {
min-height: 0;
}
/* 原 w-64(16rem) 的 0.6 倍 */
.channel-list-panel {
width: 9.6rem;
}
.channel-tree-card :deep(.el-card__header) {
padding: 10px 12px;
}
.channel-list-title {
font-size: 13px;
}
.channel-tree-card :deep(.el-tree-node__content) {
height: 30px;
padding-right: 4px;
}
.channel-tree-card :deep(.el-tree-node__label) {
font-size: 13px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.channel-banner b {
color: var(--el-color-primary);
}
</style>

View File

@@ -84,7 +84,7 @@
*/
const clearCache = (): void => {
userStore.clearCache()
ElMessage.success('清理缓存成功')
ElMessage.success(t('uiMsg.clearCacheSuccess'))
}
/**

View File

@@ -18,22 +18,34 @@
<!-- 缓存路由动画 -->
<Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
<KeepAlive :max="10" :exclude="keepAliveExclude">
<SuperAdminChannelShell
v-if="route.meta.keepAlive && shouldWrapChannelLayout(route)"
:key="'ch-' + route.path"
>
<component class="art-page-view" :is="Component" :key="route.path" />
</SuperAdminChannelShell>
<component
v-else-if="route.meta.keepAlive"
class="art-page-view"
:is="Component"
:key="route.path"
v-if="route.meta.keepAlive"
/>
</KeepAlive>
</Transition>
<!-- 非缓存路由动画 -->
<Transition :name="showTransitionMask ? '' : actualTransition" mode="out-in" appear>
<SuperAdminChannelShell
v-if="!route.meta.keepAlive && shouldWrapChannelLayout(route)"
:key="'ch-' + route.path"
>
<component class="art-page-view" :is="Component" :key="route.path" />
</SuperAdminChannelShell>
<component
v-else-if="!route.meta.keepAlive"
class="art-page-view"
:is="Component"
:key="route.path"
v-if="!route.meta.keepAlive"
/>
</Transition>
</RouterView>
@@ -53,6 +65,8 @@
import { useAutoLayoutHeight } from '@/hooks/core/useLayoutHeight'
import { useSettingStore } from '@/store/modules/setting'
import { useWorktabStore } from '@/store/modules/worktab'
import SuperAdminChannelShell from '@/components/channel/SuperAdminChannelShell.vue'
import { shouldWrapSuperAdminChannelLayout as shouldWrapChannelLayout } from '@/utils/channelLayout'
defineOptions({ name: 'ArtPageContent' })

View File

@@ -0,0 +1,12 @@
<!-- 兼容旧引用超管渠道栏已提升至全局 SuperAdminChannelShell -->
<template>
<slot :dept-id="deptId" :dept-params="deptParams" />
</template>
<script setup lang="ts">
import { useInjectedChannelDept, DEFAULT_CHANNEL_ID } from '@/composables/useChannelDeptScope'
const channel = useInjectedChannelDept()
const deptId = computed(() => channel?.selectedDeptId.value ?? DEFAULT_CHANNEL_ID)
const deptParams = computed(() => ({ dept_id: deptId.value }))
</script>

View File

@@ -14,6 +14,7 @@
import { ElMessage, ElMessageBox } from 'element-plus'
import axios from 'axios'
import { useUserStore } from '@/store/modules/user'
import { $t } from '@/locales'
defineOptions({ name: 'SaExport' })
@@ -42,18 +43,18 @@
const handleExport = async () => {
if (loading.value) return
if (!props.url) {
ElMessage.error('未配置导出接口')
ElMessage.error($t('uiMsg.exportNotConfigured'))
return
}
let finalFileName = props.fileName
try {
const { value } = await ElMessageBox.prompt('请输入导出文件名称', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
const { value } = await ElMessageBox.prompt($t('uiMsg.exportPromptFileName'), $t('uiMsg.titlePrompt'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
inputValue: props.fileName,
inputValidator: (val) => !!val.trim() || '文件名不能为空'
inputValidator: (val) => !!val.trim() || $t('uiMsg.exportFileNameRequired')
})
finalFileName = value
} catch {
@@ -87,10 +88,10 @@
reader.onload = () => {
try {
const result = JSON.parse(reader.result as string)
ElMessage.error(result.msg || '导出失败')
ElMessage.error(result.msg || $t('uiMsg.exportFail'))
emit('error', result)
} catch (e) {
ElMessage.error('导出失败')
ElMessage.error($t('uiMsg.exportFail'))
emit('error', e)
}
}
@@ -108,11 +109,11 @@
document.body.removeChild(link)
URL.revokeObjectURL(url)
ElMessage.success('导出成功')
ElMessage.success($t('uiMsg.exportSuccess'))
emit('success')
} catch (error: any) {
console.error(error)
ElMessage.error(error.message || '导出失败')
ElMessage.error(error.message || $t('uiMsg.exportFail'))
emit('error', error)
} finally {
loading.value = false

View File

@@ -0,0 +1,6 @@
/** @deprecated 请使用 useChannelDeptScope */
export {
DEFAULT_CHANNEL_ID,
useChannelDeptScope as useChannelConfigScope,
type ChannelTreeNode
} from './useChannelDeptScope'

View File

@@ -0,0 +1,230 @@
import type { InjectionKey, Ref, ComputedRef } from 'vue'
import { useRoute } from 'vue-router'
import deptApi from '@/api/system/dept'
import { useUserStore } from '@/store/modules/user'
import { isConfigChannelRoute, isRoleChannelRoute, isSuperAdminUser } from '@/utils/channelLayout'
export interface ChannelTreeNode {
id: number
label: string
children?: ChannelTreeNode[]
}
/** 默认配置模板dept_id = 0 */
export const DEFAULT_CHANNEL_ID = 0
export interface ChannelDeptScopeContext {
treeData: Ref<ChannelTreeNode[]>
selectedDeptId: Ref<number>
loadingChannels: Ref<boolean>
isSuperAdmin: Ref<boolean>
selectedDeptLabel: Ref<string>
deptQueryParams: ComputedRef<{ dept_id: number }>
isConfigScope: ComputedRef<boolean>
showDefaultTemplate: ComputedRef<boolean>
}
export const CHANNEL_DEPT_SCOPE_KEY: InjectionKey<ChannelDeptScopeContext> =
Symbol('channelDeptScope')
export function provideChannelDeptScope(ctx: ChannelDeptScopeContext) {
provide(CHANNEL_DEPT_SCOPE_KEY, ctx)
}
export function useInjectedChannelDept(): ChannelDeptScopeContext | null {
return inject(CHANNEL_DEPT_SCOPE_KEY, null)
}
/** 超管全局渠道栏:创建并 provide 渠道上下文 */
export function useChannelDeptScope() {
const route = useRoute()
const userStore = useUserStore()
const treeData = ref<ChannelTreeNode[]>([])
const selectedDeptId = ref<number>(DEFAULT_CHANNEL_ID)
const loadingChannels = ref(false)
const isConfigScope = computed(() => isConfigChannelRoute(route))
const isRoleScope = computed(() => isRoleChannelRoute(route))
const showDefaultTemplate = computed(() => isConfigScope.value || isRoleScope.value)
const isSuperAdmin = computed(() => isSuperAdminUser())
const selectedDeptLabel = computed(() => {
const find = (nodes: ChannelTreeNode[]): string => {
for (const n of nodes) {
if (n.id === selectedDeptId.value) {
return n.label
}
if (n.children?.length) {
const sub = find(n.children)
if (sub) return sub
}
}
return ''
}
return find(treeData.value)
})
const deptQueryParams = computed(() => {
const id = selectedDeptId.value
if (!showDefaultTemplate.value && id <= 0) {
return { dept_id: 0 }
}
return { dept_id: id }
})
const loadChannels = async () => {
loadingChannels.value = true
try {
const list = await deptApi.accessDept()
const channels = Array.isArray(list) ? list : []
const nodes: ChannelTreeNode[] = channels.map((item: Record<string, unknown>) => ({
id: Number(item.id ?? item.value),
label: String(item.label ?? item.name ?? item.id)
}))
if (isSuperAdmin.value) {
if (showDefaultTemplate.value) {
treeData.value = [{ id: DEFAULT_CHANNEL_ID, label: '' }, ...nodes]
if (!treeData.value.some((n) => n.id === selectedDeptId.value)) {
selectedDeptId.value = DEFAULT_CHANNEL_ID
}
} else {
treeData.value = nodes
if (nodes.length > 0) {
const valid = nodes.some((n) => n.id === selectedDeptId.value)
if (!valid || selectedDeptId.value <= 0) {
selectedDeptId.value = nodes[0].id
}
}
}
} else {
treeData.value = nodes
if (nodes.length > 0) {
selectedDeptId.value = nodes[0].id
}
}
} finally {
loadingChannels.value = false
}
}
const handleChannelClick = (data: ChannelTreeNode) => {
selectedDeptId.value = Number(data.id)
}
const ctx: ChannelDeptScopeContext = {
treeData,
selectedDeptId,
loadingChannels,
isSuperAdmin,
selectedDeptLabel,
deptQueryParams,
isConfigScope,
showDefaultTemplate
}
onMounted(() => {
loadChannels()
})
return {
...ctx,
loadChannels,
handleChannelClick,
provideScope: () => provideChannelDeptScope(ctx)
}
}
/** 将当前选中渠道写入列表查询参数并刷新 */
export function bindChannelDeptToSearchParams(
searchParams: Record<string, unknown>,
refresh: () => void,
options?: { immediate?: boolean; enabled?: boolean }
) {
const channel = useInjectedChannelDept()
if (!channel || options?.enabled === false) {
return
}
const apply = (deptId: number) => {
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
searchParams.dept_id = deptId
refresh()
}
watch(
() => channel.selectedDeptId.value,
(deptId) => apply(deptId),
{ immediate: options?.immediate ?? true }
)
}
/** 工作台等非 useTable 页面:渠道切换时重新拉数 */
export function useChannelDeptReload(loadFn: () => void | Promise<void>) {
const channel = useInjectedChannelDept()
if (!channel) {
onMounted(() => {
void loadFn()
})
return
}
watch(
() => channel.selectedDeptId.value,
(deptId) => {
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
void loadFn()
},
{ immediate: true }
)
}
/** 请求参数:业务页附带 dept_id渠道管理员固定本渠道 */
export function getChannelDeptRequestParams(): { dept_id?: number } {
const channel = useInjectedChannelDept()
if (channel?.isSuperAdmin.value) {
const deptId = channel.selectedDeptId.value
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return {}
}
if (deptId > 0) {
return { dept_id: deptId }
}
if (channel.showDefaultTemplate.value) {
return { dept_id: deptId }
}
return {}
}
const userStore = useUserStore()
const dept = userStore.info?.department
if (dept && Number(dept.id) > 0) {
return { dept_id: Number(dept.id) }
}
return {}
}
/** 保存/更新时附带 dept_id优先渠道栏选中值其次表单/行数据中的 dept_id */
export function withChannelDeptParams<T extends Record<string, unknown>>(payload: T): T {
const extra = getChannelDeptRequestParams()
if ('dept_id' in extra) {
return { ...payload, ...extra }
}
const rowDeptId = payload.dept_id
if (rowDeptId !== undefined && rowDeptId !== null && rowDeptId !== '') {
const num = Number(rowDeptId)
if (num > 0) {
return { ...payload, dept_id: num }
}
}
const channel = useInjectedChannelDept()
if (channel && channel.selectedDeptId.value > 0) {
return { ...payload, dept_id: channel.selectedDeptId.value }
}
return payload
}

View File

@@ -1,5 +1,6 @@
import { ref, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
/**
* SaiAdmin Composable
@@ -39,13 +40,13 @@ export function useSaiAdmin() {
apiFn: (params: any) => Promise<any>,
callback?: () => void
): void => {
ElMessageBox.confirm(`确定要删除该数据吗?`, '删除数据', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('uiMsg.deleteConfirmSingle'), $t('uiMsg.titleDelete'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}).then(() => {
apiFn({ ids: [row.id] }).then(() => {
ElMessage.success('删除成功')
ElMessage.success($t('uiMsg.deleteSuccess'))
if (callback) callback()
})
})
@@ -57,20 +58,20 @@ export function useSaiAdmin() {
callback?: () => void
): void => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请选择要删除的行')
ElMessage.warning($t('uiMsg.selectRowsToDelete'))
return
}
ElMessageBox.confirm(
`确定要删除选中的 ${selectedRows.value.length} 条数据吗?`,
'删除选中数据',
$t('uiMsg.deleteConfirmSelected', { n: selectedRows.value.length }),
$t('uiMsg.titleDeleteSelected'),
{
confirmButtonText: '确定',
cancelButtonText: '取消',
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}
).then(() => {
apiFn({ ids: selectedRows.value.map((row) => row.id) }).then(() => {
ElMessage.success('删除成功')
ElMessage.success($t('uiMsg.deleteSuccess'))
if (callback) callback()
selectedRows.value = []
})

View File

@@ -35,11 +35,16 @@ import {
createErrorHandler
} from '../../utils/table/tableUtils'
import { tableConfig } from '../../utils/table/tableConfig'
import { bindChannelDeptToSearchParams, useInjectedChannelDept, getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
// 类型推导工具类型
type InferApiParams<T> = T extends (params: infer P) => any ? P : never
type InferApiResponse<T> = T extends (params: any) => Promise<infer R> ? R : never
type InferRecordType<T> = T extends Api.Common.PaginatedResponse<infer U> ? U : never
type InferRecordType<T> = T extends Api.Common.PaginatedResponse<infer U>
? U
: T extends Api.Common.ApiPage<infer U>
? U
: never
// 优化的配置接口 - 支持自动类型推导
export interface UseTableConfig<
@@ -441,6 +446,23 @@ function useTableImpl<TApiFn extends (params: any) => Promise<any>>(
// 智能防抖搜索函数
const debouncedGetDataByPage = createSmartDebounce(getDataByPage, debounceTime)
const channelScope = useInjectedChannelDept()
const hasChannelScope = !!channelScope
bindChannelDeptToSearchParams(
searchParams as Record<string, unknown>,
() => {
void getDataByPage()
},
{ immediate: hasChannelScope }
)
if (!hasChannelScope) {
const channelDeptParams = getChannelDeptRequestParams()
if (channelDeptParams.dept_id !== undefined) {
Object.assign(searchParams as Record<string, unknown>, channelDeptParams)
}
}
// 重置搜索参数
const resetSearchParams = async (): Promise<void> => {
// 取消防抖的搜索
@@ -645,7 +667,7 @@ function useTableImpl<TApiFn extends (params: any) => Promise<any>>(
}
// 挂载时自动加载数据
if (immediate) {
if (immediate && !hasChannelScope) {
onMounted(async () => {
await getData()
})

View File

@@ -111,7 +111,7 @@ const i18n: I18n = createI18n(i18nOptions)
* 翻译函数类型
*/
interface Translation {
(key: string): string
(key: string, named?: Record<string, unknown>): string
}
/**

View File

@@ -37,7 +37,55 @@
"tips": "Prompt",
"cancel": "Cancel",
"confirm": "Confirm",
"logOutTips": "Do you want to log out?"
"logOutTips": "Do you want to log out?",
"channelScope": {
"listTitle": "Channels",
"defaultTemplate": "Default template",
"defaultRoleTemplate": "Default role template",
"currentConfig": "Current config",
"currentChannel": "Current channel",
"currentRole": "Current roles"
}
},
"uiMsg": {
"titlePrompt": "Prompt",
"titleDelete": "Delete",
"titleDeleteSelected": "Delete selected",
"btnOk": "Confirm",
"btnCancel": "Cancel",
"deleteConfirmSingle": "Are you sure you want to delete this item?",
"deleteConfirmSelected": "Are you sure you want to delete the selected {n} items?",
"deleteSuccess": "Deleted",
"operationSuccess": "Success",
"selectRowsToDelete": "Please select rows to delete",
"selectAtLeastOne": "Please select at least one item",
"clearCacheSuccess": "Cache cleared",
"copySuccess": "Copied",
"copyFail": "Copy failed, please copy manually",
"uploadSuccess": "Uploaded",
"uploadFail": "Upload failed",
"downloadTemplateFail": "Failed to download template",
"importSuccess": "Imported",
"importFail": "Import failed",
"exportFail": "Export failed",
"exportSuccess": "Exported"
,
"exportNotConfigured": "Export API is not configured",
"exportPromptFileName": "Please enter export file name",
"exportFileNameRequired": "File name is required",
"clearCacheSelect": "Please select a cache to clear",
"clearCacheTitle": "Clear selected cache",
"clearCacheConfirmByTag": "Are you sure you want to clear cache for tag: {tag}?"
,
"saipackageWebBuildTitle": "Frontend build & publish",
"saipackageWebBuildConfirm": "Rebuild frontend and publish the project?",
"saipackageWebBuildSuccess": "Frontend built and published",
"saipackageFrontendDepsTitle": "Frontend dependencies",
"saipackageFrontendDepsConfirm": "Update frontend Node dependencies?",
"saipackageFrontendDepsSuccess": "Frontend dependencies updated",
"saipackageComposerTitle": "Composer dependencies",
"saipackageComposerConfirm": "Update backend Composer packages?",
"saipackageComposerSuccess": "Composer packages updated"
},
"form": {
"placeholderInput": "Please enter",
@@ -263,7 +311,16 @@
"subtitle": "Latest 50 new player records",
"player": "Player",
"balance": "Balance",
"ticket": "Tickets"
"ticket": "Tickets",
"registerTime": "Register Time"
},
"playRecord": {
"title": "Player Play Records",
"subtitle": "Latest 50 play records",
"player": "Player",
"reward": "Reward Tier",
"winCoin": "Win Amount",
"playTime": "Play Time"
},
"walletRecord": {
"title": "Player Charge Records",
@@ -338,8 +395,7 @@
"role": "Role Management",
"userCenter": "User Center",
"menu": "Menu Management",
"dept": "Department Management",
"post": "Post Management",
"dept": "Channel Management",
"config": "System Config"
},
"safeguard": {
@@ -361,6 +417,7 @@
"dice": {
"title": "Dice Game",
"lotteryPoolConfig": "Lottery Tier Weight Config",
"anteConfig": "Ante Config",
"player": "Player Management",
"playerWalletRecord": "Player Wallet Records",
"playRecord": "Player Draw Records",
@@ -370,6 +427,9 @@
"rewardConfigRecord": "Dice Weight Test Records",
"playRecordTest": "Draw Records (Test Weight)",
"config": "Game Config"
},
"game": {
"title": "Game Management"
}
},
"table": {
@@ -404,8 +464,6 @@
"placeholderDeptCode": "Dept Code",
"placeholderRoleName": "Role Name",
"placeholderRoleCode": "Role Code",
"placeholderPostName": "Post Name",
"placeholderPostCode": "Post Code",
"placeholderMenuName": "Menu Name",
"placeholderMenuRoute": "Menu Route",
"placeholderOperator": "Operator",
@@ -469,14 +527,12 @@
"system": {
"username": "Username",
"phone": "Phone",
"dept": "Department",
"dept": "Channel",
"dashboard": "Dashboard",
"loginTime": "Last Login",
"agentId": "Agent ID",
"postName": "Post Name",
"postCode": "Post Code",
"deptName": "Dept Name",
"deptCode": "Dept Code",
"deptName": "Channel Name",
"deptCode": "Channel Code",
"leader": "Leader",
"roleName": "Role Name",
"roleCode": "Role Code",

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

@@ -0,0 +1,68 @@
{
"form": {
"dialogTitleAdd": "Add Game",
"dialogTitleEdit": "Edit Game",
"provider": "Provider",
"placeholderProvider": "Enter provider name",
"providerCode": "Provider Code",
"placeholderProviderCode": "Enter provider code",
"gameCode": "Game Code",
"placeholderGameCode": "Enter game code",
"gameKey": "Game Key",
"placeholderGameKey": "Enter unique game key",
"gameName": "Name (ZH)",
"placeholderGameName": "Enter Chinese name",
"gameNameEn": "Name (EN)",
"placeholderGameNameEn": "Enter English name",
"gameType": "Game Type",
"placeholderGameType": "Enter game type",
"sort": "Sort",
"logo": "Logo URL",
"tabPicker": "Pick Image",
"tabUpload": "Upload Image",
"gameUrl": "Game URL",
"placeholderGameUrl": "Enter game URL",
"hallUrl": "Hall URL",
"placeholderHallUrl": "Enter hall URL",
"status": "Status",
"statusEnabled": "Enabled",
"statusDisabled": "Disabled",
"remark": "Remark",
"placeholderRemark": "Enter remark",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully",
"ruleProviderRequired": "Provider is required",
"ruleProviderCodeRequired": "Provider code is required",
"ruleGameCodeRequired": "Game code is required",
"ruleGameKeyRequired": "Game key is required",
"ruleGameNameRequired": "Chinese name is required",
"ruleGameTypeRequired": "Game type is required"
},
"search": {
"providerCode": "Provider Code",
"placeholderProviderCode": "Enter provider code",
"gameCode": "Game Code",
"placeholderGameCode": "Enter game code",
"gameType": "Game Type",
"placeholderGameType": "Enter game type",
"status": "Status",
"placeholderStatus": "Select status",
"statusEnabled": "Enabled",
"statusDisabled": "Disabled"
},
"table": {
"id": "ID",
"provider": "Provider",
"providerCode": "Provider Code",
"gameCode": "Game Code",
"gameKey": "Game Key",
"gameName": "Name (ZH)",
"gameNameEn": "Name (EN)",
"gameType": "Type",
"sort": "Sort",
"status": "Status",
"statusEnabled": "Enabled",
"statusDisabled": "Disabled",
"updateTime": "Update Time"
}
}

View File

@@ -23,9 +23,10 @@
"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×1); 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).",
"enableKillScore": "Enable kill score",
"killScoreWeights": "Kill weights",
"killWeightNote": "(Kill weights from pool config type=1; edit in list.)",
"btnResetProfit": "Reset Player Total Profit",

View File

@@ -30,11 +30,19 @@
"rollArrayHint": "5 numbers, each 16",
"rollNumber": "Roll Sum",
"placeholderRollNumber": "Sum of 5 dice (530)",
"rewardConfig": "Reward Config",
"placeholderRewardConfig": "Select reward config (by UI text)",
"rewardTier": "Reward Tier",
"placeholderRewardTier": "Select reward tier",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully",
"validateFailed": "Validation failed, please check required fields and format"
"validateFailed": "Validation failed, please check required fields and format",
"rulePlayerRequired": "Please select player",
"ruleLotteryConfigRequired": "Please select lottery pool config",
"ruleLotteryTypeRequired": "Please select draw type",
"ruleIsWinRequired": "Please select big win status",
"ruleWinCoinRequired": "Win coin is required",
"ruleRollArrayLength": "Roll array must have 5 numbers",
"ruleRollArrayValues": "Enter 5 numbers, each between 1 and 6",
"ruleRewardTierRequired": "Please select reward tier"
},
"toolbar": {
"platformTotalProfit": "Platform Total Profit"
@@ -47,8 +55,8 @@
"direction": "Direction",
"winCoin": "Win Coin",
"rollNumber": "Roll Number",
"rewardConfig": "Reward Config",
"rewardTier": "Reward Tier",
"rewardConfig": "Reward Config",
"usernameFuzzy": "Username (fuzzy)",
"nameFuzzy": "Name (fuzzy)",
"uiTextFuzzy": "UI Text (fuzzy)",
@@ -64,6 +72,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",
@@ -73,7 +83,7 @@
"targetIndex": "Target Index",
"rollArray": "Roll Array",
"rollNumber": "Roll Number",
"rewardConfig": "Reward Config",
"rewardTier": "Reward Tier",
"createTime": "Create Time",
"updateTime": "Update Time"
}

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",
@@ -31,7 +37,8 @@
"targetIndex": "Target Index",
"rollArray": "Roll Array",
"rollNumber": "Roll Number",
"rewardConfig": "Reward Config",
"rewardTier": "Reward Tier",
"status": "Status",
"createTime": "Create Time"
},
"form": {
@@ -40,9 +47,7 @@
"labelLotteryConfigId": "Lottery Config ID",
"placeholderLotteryConfigId": "Please enter lottery config id",
"placeholderWinCoin": "Win coin",
"placeholderRewardTier": "Please select tier (will auto fill reward config id)",
"rewardConfigId": "Reward Config ID",
"placeholderRewardConfigId": "Auto fill by tier or enter manually",
"placeholderRewardTier": "Please select reward tier",
"placeholderStartIndex": "Please enter start index",
"labelTargetIndex": "Target Index",
"placeholderTargetIndex": "Please enter target index",
@@ -58,9 +63,14 @@
"ruleDrawTypeRequired": "Draw type is required",
"ruleIsBigWinRequired": "Is big win is required",
"ruleDirectionRequired": "Direction is required",
"ruleRewardConfigIdRequired": "Reward config id is required",
"ruleRewardTierRequired": "Reward tier is required",
"ruleStatusRequired": "Status is required",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
},
"ui": {
"clearAllConfirm": "Are you sure you want to clear all player draw test data?",
"clearAllSuccess": "All test data cleared",
"clearAllFail": "Clear failed"
}
}

View File

@@ -14,6 +14,8 @@
"status": "Status",
"adminId": "Admin",
"placeholderAdmin": "Select admin (optional)",
"placeholderAdminTree": "Select admin by channel",
"unassignedChannel": "Unassigned channel",
"coin": "Coin",
"placeholderCoinAdd": "Default 0 on create, read-only",
"lotteryPoolConfig": "Lottery Pool Config",
@@ -44,7 +46,18 @@
"ruleEnterCoin": "Please enter coin change",
"ruleCoinPositive": "Coin change must be greater than 0",
"ruleDeductExceed": "Deduct cannot exceed current balance",
"operateSuccess": "Success"
"operateSuccess": "Success",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully",
"rulePasswordRequired": "Password is required",
"ruleUsernameRequired": "Username is required",
"ruleNicknameRequired": "Nickname is required",
"rulePhoneRequired": "Phone is required",
"ruleStatusRequired": "Status is required",
"ruleCoinRequired": "Coin is required",
"configTypeDefault": "Default",
"configTypeKillScore": "Kill score",
"configTypeUp": "Up score"
},
"search": {
"username": "Username",
@@ -66,6 +79,7 @@
"status": "Status",
"coin": "Coin",
"lotteryPoolConfig": "Lottery Pool Config",
"customConfig": "Custom",
"t1Weight": "T1 Weight",
"t2Weight": "T2 Weight",
"t3Weight": "T3 Weight",
@@ -75,6 +89,9 @@
"paidDrawCount": "Paid Draw Count",
"freeDrawCount": "Free Draw Count",
"createTime": "Create Time",
"updateTime": "Update Time"
"updateTime": "Update Time",
"getGameLink": "Get Game Link",
"getGameLinkSuccess": "Game link copied",
"getGameLinkFail": "Failed to get game link"
}
}

View File

@@ -14,11 +14,17 @@
"placeholderTotalDrawCount": "Auto sum",
"placeholderRemark": "Remark (required)",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
"editSuccess": "Updated successfully",
"rulePlayerRequired": "Please select player",
"ruleUseCoinsRequired": "Coins used is required",
"rulePaidDrawRequired": "Paid draw count is required",
"ruleFreeDrawRequired": "Free draw count is required",
"ruleRemarkRequired": "Remark is required"
},
"search": {
"player": "Player",
"useCoins": "Use Coins",
"ante": "Ante",
"totalDrawCount": "Total Draw Count",
"paidDrawCount": "Paid Draw Count",
"freeDrawCount": "Free Draw Count",
@@ -29,6 +35,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

@@ -1,4 +1,7 @@
{
"toolbar": {
"coinChangeSummary": "Coin Change Summary"
},
"form": {
"dialogTitleAdd": "Add Wallet Record",
"dialogTitleEdit": "Edit Wallet Record",
@@ -19,7 +22,10 @@
"placeholderWalletAfter": "Auto calculated",
"placeholderRemark": "Optional",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
"editSuccess": "Updated successfully",
"ruleUserRequired": "Please select user",
"ruleCoinRequired": "Coin change is required",
"ruleTypeRequired": "Please select type"
},
"search": {
"type": "Type",

View File

@@ -56,11 +56,20 @@
"weightTest": {
"title": "One-Click Weight Test",
"alertTitle": "Bonus pool logic",
"alertBody": "Same as playStart draw: uses name=default safety line and kill switch; when profit is below the line, paid tickets use player tier weights (custom below), free tickets use killScore; when profit reaches the line and kill is on, both use killScore.",
"alertBody": "Test mode is non-kill by default. You can enable kill mode below with switch + safety line: once simulated player cumulative profit reaches the line, paid draws switch to killScore.",
"chainModeHint": "Simulation: set paid spin counts only (CW/CCW). If a paid draw hits “play again” (or T5), the next draw is free with the same ante, lottery type free, paid amount 0. Free-draw tier odds are configured below (including chained free plays).",
"killModeHint": "When test kill mode is enabled: use simulated player cumulative profit as trigger; once cumulative profit >= safety line, subsequent paid draws use killScore. Free draws still follow the configured free settings.",
"labelKillModeEnabled": "Enable test kill mode",
"labelTestSafetyLine": "Test safety line",
"sectionPaid": "Paid draws",
"sectionFreeAfterPlayAgain": "Free draw tier odds (after play-again)",
"tierProbHintFreeChain": "When using custom tier odds: T1T5 below apply when a free draw runs (tier roll; combined with dice_reward row weights).",
"stepPaid": "Paid ticket",
"stepFree": "Free ticket",
"labelLotteryTypePaid": "Test pool type",
"labelLotteryTypeFree": "Test pool type",
"labelAnte": "Ante",
"placeholderAnte": "Select ante config",
"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 +82,9 @@
"btnNext": "Next",
"btnStart": "Start test",
"btnCancel": "Cancel",
"warnAnte": "Please select ante",
"warnPaidSpins": "Paid clockwise + counter-clockwise spin counts must be greater than 0",
"warnTestSafetyLine": "Test safety line must be greater than or equal to 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

@@ -14,6 +14,7 @@
"colDisplayText": "Display Text",
"colDisplayTextEn": "Display Text (EN)",
"colRealEv": "Real Settlement",
"colRealReward": "Player Real Reward",
"colTier": "Tier",
"colRemark": "Remark",
"placeholderTierSelect": "Tier",
@@ -50,7 +51,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 / once again).\n\n[Settlement amount vs tier]\nSettlement < 0 → T4; 0 < Settlement < 100 → T3; 100 < Settlement < 200 → T2; Settlement > 200 → T1; T5 “once again” settlement = 0. You can set a unified settlement standard for each tier below; generated rows write those values into the config, and details can be edited later in the table.\n\n[Inputs in this dialog]\nCount: T1/T4/T5 are fixed; T2 is minimum. Clockwise and counter-clockwise weighted counts (each roll result counts once) must each satisfy the entered values; T1, T4, and T5 are entered separately.\nSettlement standard: all cells in the same tier use the same value. On generation, T1T4 use ui_text / ui_text_en = settlement real_ev; T5 is fixed to \"再来一次\" / \"Once again\". Remarks still distinguish break-even / small win, etc.",
"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 settlement amount must satisfy: value > 200",
"ruleGenInvalidT2RealEv": "T2 settlement amount must satisfy: 100 < value < 200",
"ruleGenInvalidT3RealEv": "T3 settlement amount must satisfy: 0 < value < 100",
"ruleGenInvalidT4RealEv": "T4 settlement amount must satisfy: value < 0",
"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

@@ -2,16 +2,28 @@
"toolbar": {
"viewDetail": "View Detail"
},
"search": {
"paidPlannedSpins": "Planned paid spins",
"ante": "Ante"
},
"table": {
"id": "ID",
"clockwiseAbbr": "CW",
"counterclockwiseAbbr": "CCW",
"status": "Status",
"paidDraw": "Paid Draw",
"freeDraw": "Free Draw",
"chainMode": "Chain play-again",
"chainModeYes": "Yes",
"chainModeNo": "No",
"paidPlannedSpins": "Planned paid spins",
"ante": "Ante",
"playAgainCount": "Play-again count",
"progressDraws": "{over} done",
"progressFailed": "{over} before fail",
"platformProfit": "Platform Profit",
"totalDrawCount": "Total Draw Count",
"totalDrawCount": "Total draws",
"createdBy": "Created By",
"remark": "Remark",
"createTime": "Create Time",
"statusFail": "Failed",
"statusDone": "Done",
@@ -36,6 +48,10 @@
"recordId": "Record ID",
"testCount": "Test count",
"testCountSuffix": " runs",
"testCountProgress": "In progress: {over} done",
"testCountFailed": "{over} before failure",
"chainModeLabel": "Chain play-again",
"paidPlannedSpins": "Planned paid spins",
"createTime": "Created at",
"admin": "Operator",
"paidPoolId": "Paid lottery pool config ID",

View File

@@ -1,38 +1,35 @@
{
"search": {
"deptName": "channel(Department) Name",
"deptCode": "Dept Code",
"deptName": "Channel Name",
"deptCode": "Channel Code",
"status": "Status",
"placeholderDeptName": "Please enter dept name",
"placeholderDeptCode": "Please enter dept code",
"placeholderDeptName": "Please enter channel name",
"placeholderDeptCode": "Please enter channel code",
"searchSelectPlaceholder": "Please select"
},
"table": {
"deptName": "channel(Department) Name",
"deptCode": "Dept Code",
"leader": "Leader",
"deptName": "Channel Name",
"deptCode": "Channel Code",
"leader": "Channel Leader",
"sort": "Sort",
"status": "Status",
"createTime": "Create Time"
},
"form": {
"titleAdd": "Add Department",
"titleEdit": "Edit Department",
"labelParentDept": "Parent Department",
"labelDeptName": "Dept Name",
"labelDeptCode": "Dept Code",
"labelLeader": "Leader",
"titleAdd": "Add Channel",
"titleEdit": "Edit Channel",
"labelDeptName": "Channel Name",
"labelDeptCode": "Channel Code",
"labelLeader": "Channel Leader",
"labelRemark": "Description",
"labelSort": "Sort",
"labelStatus": "Enabled",
"placeholderDeptName": "Please enter dept name",
"placeholderDeptCode": "Please enter dept code",
"placeholderDeptName": "Please enter channel name",
"placeholderDeptCode": "Please enter channel code",
"placeholderRemark": "Please enter description",
"placeholderSort": "Please enter sort",
"noParentDept": "No parent department",
"ruleParentDeptRequired": "Please select parent department",
"ruleDeptNameRequired": "Please enter dept name",
"ruleDeptCodeRequired": "Please enter dept code",
"ruleDeptNameRequired": "Please enter channel name",
"ruleDeptCodeRequired": "Please enter channel code",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
}

View File

@@ -1,34 +0,0 @@
{
"search": {
"postName": "Post Name",
"postCode": "Post Code",
"status": "Status",
"placeholderPostName": "Please enter post name",
"placeholderPostCode": "Please enter post code",
"searchSelectPlaceholder": "Please select"
},
"table": {
"postName": "Post Name",
"postCode": "Post Code",
"sort": "Sort",
"status": "Status",
"createTime": "Create Time"
},
"form": {
"titleAdd": "Add Post",
"titleEdit": "Edit Post",
"labelName": "Post Name",
"labelCode": "Post Code",
"labelRemark": "Description",
"labelSort": "Sort",
"labelStatus": "Enabled",
"placeholderName": "Please enter post name",
"placeholderCode": "Please enter post code",
"placeholderRemark": "Please enter description",
"placeholderSort": "Please enter sort",
"ruleNameRequired": "Please enter post name",
"ruleCodeRequired": "Please enter post code",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
}
}

View File

@@ -10,7 +10,7 @@
"table": {
"username": "Username",
"phone": "Phone",
"dept": "Department",
"dept": "Channel",
"dashboard": "Dashboard",
"loginTime": "Last Login",
"agentId": "Agent ID",
@@ -28,9 +28,8 @@
"labelPasswordConfirm": "Confirm Password",
"labelEmail": "Email",
"labelPhone": "Phone",
"labelDept": "Department",
"labelDept": "Channel",
"labelRole": "Role",
"labelPost": "Post",
"labelGender": "Gender",
"labelStatus": "Status",
"labelRemark": "Remark",
@@ -43,9 +42,18 @@
"rulePasswordRequired": "Please enter password",
"rulePasswordLength": "Length must be between 6 and 20 characters",
"rulePasswordConfirmRequired": "Please enter confirm password",
"ruleDeptRequired": "Please select department",
"ruleDeptRequired": "Please select channel",
"ruleRoleRequired": "Please select role",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
},
"ui": {
"channelList": "Channel List",
"viewingChannel": "Current channel",
"defaultConfigTemplate": "Default config template",
"promptNewPassword": "Please enter a new password",
"passwordLengthError": "Password length must be between 6 and 16",
"passwordChanged": "Password updated",
"clearCacheConfirm": "Are you sure you want to clear cache?"
}
}

View File

@@ -16,5 +16,16 @@
"tplCategory": "Gen Type",
"updateTime": "Update Time",
"createTime": "Create Time"
},
"ui": {
"generating": "Generating code package, please wait...",
"generateSuccess": "Code generated, downloading...",
"downloadFail": "Download failed",
"syncConfirm": "Sync will overwrite the configured table structure. Continue?",
"syncSuccess": "Synced",
"generateToProjectConfirm": "Generate-to-project will overwrite existing files. Continue?",
"generateToProjectSuccess": "Generated to project",
"loadSuccess": "Loaded",
"copyToClipboard": "Code copied to clipboard"
}
}

View File

@@ -58,5 +58,11 @@
"ruleTargetRequired": "Target is required",
"addSuccess": "Added successfully",
"editSuccess": "Updated successfully"
},
"ui": {
"runTitle": "Run Task",
"runConfirm": "Are you sure you want to run task [{name}]?",
"runSuccess": "Task started",
"selectTaskFirst": "Please select a task first"
}
}

View File

@@ -37,7 +37,55 @@
"tips": "提示",
"cancel": "取消",
"confirm": "确定",
"logOutTips": "您是否要退出登录?"
"logOutTips": "您是否要退出登录?",
"channelScope": {
"listTitle": "渠道列表",
"defaultTemplate": "默认配置模板",
"defaultRoleTemplate": "默认角色模板",
"currentConfig": "当前配置",
"currentChannel": "当前渠道",
"currentRole": "当前角色范围"
}
},
"uiMsg": {
"titlePrompt": "提示",
"titleDelete": "删除数据",
"titleDeleteSelected": "删除选中数据",
"btnOk": "确定",
"btnCancel": "取消",
"deleteConfirmSingle": "确定要删除该数据吗?",
"deleteConfirmSelected": "确定要删除选中的 {n} 条数据吗?",
"deleteSuccess": "删除成功",
"operationSuccess": "操作成功",
"selectRowsToDelete": "请选择要删除的行",
"selectAtLeastOne": "至少要选择一条数据",
"clearCacheSuccess": "清理缓存成功",
"copySuccess": "复制成功",
"copyFail": "复制失败,请手动复制",
"uploadSuccess": "上传成功",
"uploadFail": "上传失败",
"downloadTemplateFail": "下载模板失败",
"importSuccess": "导入成功",
"importFail": "导入失败",
"exportFail": "导出失败",
"exportSuccess": "导出成功"
,
"exportNotConfigured": "未配置导出接口",
"exportPromptFileName": "请输入导出文件名称",
"exportFileNameRequired": "文件名不能为空",
"clearCacheSelect": "请选择要清理的缓存",
"clearCacheTitle": "清理选中缓存",
"clearCacheConfirmByTag": "确定要清理标签:【{tag}】的缓存吗?"
,
"saipackageWebBuildTitle": "前端打包发布",
"saipackageWebBuildConfirm": "确认重新打包前端并发布项目吗?",
"saipackageWebBuildSuccess": "前端打包发布成功",
"saipackageFrontendDepsTitle": "前端依赖更新",
"saipackageFrontendDepsConfirm": "确认更新前端Node依赖吗",
"saipackageFrontendDepsSuccess": "前端依赖更新成功",
"saipackageComposerTitle": "composer包更新",
"saipackageComposerConfirm": "确认更新后端composer包吗",
"saipackageComposerSuccess": "composer包更新成功"
},
"form": {
"placeholderInput": "请输入",
@@ -263,7 +311,16 @@
"subtitle": "最新50条新增玩家记录",
"player": "玩家",
"balance": "余额",
"ticket": "抽奖券"
"ticket": "抽奖券",
"registerTime": "注册时间"
},
"playRecord": {
"title": "玩家游玩记录",
"subtitle": "最新50条游玩记录",
"player": "玩家",
"reward": "中奖档位",
"winCoin": "赢取平台币",
"playTime": "游玩时间"
},
"walletRecord": {
"title": "玩家充值记录",
@@ -334,8 +391,7 @@
"role": "角色管理",
"userCenter": "个人中心",
"menu": "菜单管理",
"dept": "渠道(部门)管理",
"post": "岗位管理",
"dept": "渠道管理",
"config": "系统配置"
},
"safeguard": {
@@ -357,6 +413,7 @@
"dice": {
"title": "大富翁-色子游戏",
"lotteryPoolConfig": "彩金池配置",
"anteConfig": "底注配置",
"player": "玩家管理",
"playerWalletRecord": "玩家钱包记录",
"playRecord": "玩家抽奖记录",
@@ -366,6 +423,9 @@
"rewardConfigRecord": "权重测试记录",
"playRecordTest": "抽奖记录(测试权重)",
"config": "游戏配置"
},
"game": {
"title": "游戏管理"
}
},
"table": {
@@ -396,12 +456,10 @@
"placeholderTaskName": "请输入任务名称",
"placeholderTableName": "请输入数据表名称",
"placeholderDataSource": "请输入数据源名称",
"placeholderDeptName": "请输入部门名称",
"placeholderDeptCode": "请输入部门编码",
"placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入渠道编码",
"placeholderRoleName": "请输入角色名称",
"placeholderRoleCode": "请输入角色编码",
"placeholderPostName": "请输入岗位名称",
"placeholderPostCode": "请输入岗位编码",
"placeholderMenuName": "请输入菜单名称",
"placeholderMenuRoute": "请输入菜单路由",
"placeholderOperator": "请输入操作用户",
@@ -465,15 +523,13 @@
"system": {
"username": "用户名",
"phone": "手机号",
"dept": "部门",
"dept": "渠道",
"dashboard": "首页",
"loginTime": "上次登录",
"agentId": "代理ID",
"postName": "岗位名称",
"postCode": "岗位编码",
"deptName": "部门名称",
"deptCode": "部门编码",
"leader": "部门领导",
"deptName": "渠道名称",
"deptCode": "渠道编码",
"leader": "渠道负责人",
"roleName": "角色名称",
"roleCode": "角色编码",
"level": "角色级别",
@@ -493,7 +549,7 @@
"titleEn": "标题(英文)",
"value": "值",
"valueEn": "值(英文)",
"noParentDept": "无上级部门",
"noParentDept": "无上级渠道",
"noParentMenu": "无上级菜单",
"input": "文本框",
"textarea": "文本域",

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

@@ -0,0 +1,68 @@
{
"form": {
"dialogTitleAdd": "新增游戏",
"dialogTitleEdit": "编辑游戏",
"provider": "供应商",
"placeholderProvider": "请输入供应商名称",
"providerCode": "供应商编码",
"placeholderProviderCode": "请输入供应商编码",
"gameCode": "游戏编号",
"placeholderGameCode": "请输入游戏编号",
"gameKey": "游戏唯一值",
"placeholderGameKey": "请输入游戏唯一值",
"gameName": "中文名称",
"placeholderGameName": "请输入中文名称",
"gameNameEn": "英文名称",
"placeholderGameNameEn": "请输入英文名称",
"gameType": "游戏类型",
"placeholderGameType": "请输入游戏类型",
"sort": "排序",
"logo": "Logo地址",
"tabPicker": "图片选择",
"tabUpload": "图片上传",
"gameUrl": "游戏地址",
"placeholderGameUrl": "请输入游戏地址",
"hallUrl": "大厅地址",
"placeholderHallUrl": "请输入大厅地址",
"status": "状态",
"statusEnabled": "启用",
"statusDisabled": "禁用",
"remark": "备注",
"placeholderRemark": "请输入备注",
"addSuccess": "新增成功",
"editSuccess": "更新成功",
"ruleProviderRequired": "请输入供应商",
"ruleProviderCodeRequired": "请输入供应商编码",
"ruleGameCodeRequired": "请输入游戏编号",
"ruleGameKeyRequired": "请输入游戏唯一值",
"ruleGameNameRequired": "请输入中文名称",
"ruleGameTypeRequired": "请输入游戏类型"
},
"search": {
"providerCode": "供应商编码",
"placeholderProviderCode": "请输入供应商编码",
"gameCode": "游戏编号",
"placeholderGameCode": "请输入游戏编号",
"gameType": "游戏类型",
"placeholderGameType": "请输入游戏类型",
"status": "状态",
"placeholderStatus": "请选择状态",
"statusEnabled": "启用",
"statusDisabled": "禁用"
},
"table": {
"id": "ID",
"provider": "供应商",
"providerCode": "供应商编码",
"gameCode": "游戏编号",
"gameKey": "游戏唯一值",
"gameName": "中文名",
"gameNameEn": "英文名",
"gameType": "类型",
"sort": "排序",
"status": "状态",
"statusEnabled": "启用",
"statusDisabled": "禁用",
"updateTime": "更新时间"
}
}

View File

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

View File

@@ -8,7 +8,7 @@
"placeholderLotteryPool": "请选择彩金池配置",
"drawType": "抽奖类型",
"paid": "付费",
"free": "赠送",
"free": "免费",
"isBigWin": "是否中大奖",
"noBigWin": "无",
"bigWin": "中大奖",
@@ -30,11 +30,19 @@
"rollArrayHint": "固定 5 个数,每个 16",
"rollNumber": "摇取点数和",
"placeholderRollNumber": "5 个色子点数之和530",
"rewardConfig": "奖励配置",
"placeholderRewardConfig": "请选择奖励配置(显示前端文本)",
"rewardTier": "中奖档位",
"placeholderRewardTier": "请选择中奖档位",
"addSuccess": "新增成功",
"editSuccess": "修改成功",
"validateFailed": "表单验证失败,请检查必填项与格式"
"validateFailed": "表单验证失败,请检查必填项与格式",
"rulePlayerRequired": "请选择玩家",
"ruleLotteryConfigRequired": "请选择彩金池配置",
"ruleLotteryTypeRequired": "请选择抽奖类型",
"ruleIsWinRequired": "请选择是否中大奖",
"ruleWinCoinRequired": "赢取平台币必填",
"ruleRollArrayLength": "摇取点数必须为 5 个数",
"ruleRollArrayValues": "摇取点数必须填写 5 个数,每个 16",
"ruleRewardTierRequired": "请选择中奖档位"
},
"toolbar": {
"platformTotalProfit": "平台总盈利"
@@ -47,13 +55,13 @@
"direction": "方向",
"winCoin": "赢取平台币",
"rollNumber": "摇取点数和",
"rewardTier": "中奖档位",
"rewardConfig": "奖励配置",
"rewardTier": "奖励档位",
"usernameFuzzy": "用户名模糊",
"nameFuzzy": "名称模糊",
"uiTextFuzzy": "前端显示文本模糊",
"paid": "付费",
"free": "赠送",
"free": "免费",
"noBigWin": "无",
"bigWin": "中大奖",
"clockwise": "顺时针",
@@ -64,6 +72,8 @@
"player": "玩家",
"lotteryPoolConfig": "彩金池配置",
"drawType": "抽奖类型",
"ante": "注数",
"paidAmount": "付费金额",
"isBigWin": "是否中大奖",
"winCoin": "赢取平台币",
"superWinCoin": "中大奖平台币",
@@ -73,7 +83,7 @@
"targetIndex": "终点索引",
"rollArray": "摇取点数",
"rollNumber": "摇取点数和",
"rewardConfig": "奖励配置",
"rewardTier": "中奖档位",
"createTime": "创建时间",
"updateTime": "更新时间"
}

View File

@@ -4,14 +4,17 @@
"platformTotalProfit": "平台总盈利"
},
"search": {
"rewardConfigRecordId": "测试记录ID",
"drawType": "抽奖类型",
"direction": "方向",
"isBigWin": "是否中大奖",
"winCoin": "赢取平台币",
"rewardTier": "奖励档位",
"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": "摇色子中奖平台币",
@@ -31,7 +37,8 @@
"targetIndex": "终点索引",
"rollArray": "摇取点数",
"rollNumber": "摇取点数和",
"rewardConfig": "奖励配置",
"rewardTier": "中奖档位",
"status": "状态",
"createTime": "创建时间"
},
"form": {
@@ -40,9 +47,7 @@
"labelLotteryConfigId": "彩金池配置id",
"placeholderLotteryConfigId": "请输入彩金池配置id",
"placeholderWinCoin": "赢取平台币",
"placeholderRewardTier": "请选择档位(选后自动带出奖励配置ID)",
"rewardConfigId": "奖励配置id",
"placeholderRewardConfigId": "可选中奖档位自动带出或手动输入",
"placeholderRewardTier": "请选择中奖档位",
"placeholderStartIndex": "请输入起始索引",
"labelTargetIndex": "结束索引",
"placeholderTargetIndex": "请输入结束索引",
@@ -58,9 +63,14 @@
"ruleDrawTypeRequired": "抽奖类型必需填写",
"ruleIsBigWinRequired": "是否中大奖必需填写",
"ruleDirectionRequired": "方向必需填写",
"ruleRewardConfigIdRequired": "奖励配置id必需填写",
"ruleRewardTierRequired": "中奖档位必需填写",
"ruleStatusRequired": "状态必需填写",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
},
"ui": {
"clearAllConfirm": "确定清空所有玩家抽奖测试数据?",
"clearAllSuccess": "已清空所有测试数据",
"clearAllFail": "清空失败"
}
}

View File

@@ -14,6 +14,8 @@
"status": "状态",
"adminId": "所属管理员",
"placeholderAdmin": "选择后台管理员(可选)",
"placeholderAdminTree": "按渠道选择后台管理员",
"unassignedChannel": "未分配渠道",
"coin": "平台币",
"placeholderCoinAdd": "创建时默认0不可改",
"lotteryPoolConfig": "彩金池配置",
@@ -44,7 +46,18 @@
"ruleEnterCoin": "请输入平台币变动",
"ruleCoinPositive": "平台币变动必须大于 0",
"ruleDeductExceed": "扣点不能超过当前余额",
"operateSuccess": "操作成功"
"operateSuccess": "操作成功",
"addSuccess": "新增成功",
"editSuccess": "修改成功",
"rulePasswordRequired": "密码必需填写",
"ruleUsernameRequired": "用户名必需填写",
"ruleNicknameRequired": "昵称必需填写",
"rulePhoneRequired": "手机号必需填写",
"ruleStatusRequired": "状态必需填写",
"ruleCoinRequired": "平台币必需填写",
"configTypeDefault": "默认",
"configTypeKillScore": "杀分",
"configTypeUp": "上分"
},
"search": {
"username": "用户名",
@@ -66,6 +79,7 @@
"status": "状态",
"coin": "平台币",
"lotteryPoolConfig": "彩金池配置",
"customConfig": "自定义",
"t1Weight": "T1权重",
"t2Weight": "T2权重",
"t3Weight": "T3权重",
@@ -75,6 +89,9 @@
"paidDrawCount": "购买抽奖次数",
"freeDrawCount": "赠送抽奖次数",
"createTime": "创建时间",
"updateTime": "更新时间"
"updateTime": "更新时间",
"getGameLink": "获取游戏链接",
"getGameLinkSuccess": "游戏链接已复制",
"getGameLinkFail": "获取游戏链接失败"
}
}

View File

@@ -14,11 +14,17 @@
"placeholderTotalDrawCount": "自动求和",
"placeholderRemark": "请输入备注(必填)",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
"editSuccess": "修改成功",
"rulePlayerRequired": "请选择玩家",
"ruleUseCoinsRequired": "消耗硬币必需填写",
"rulePaidDrawRequired": "购买抽奖次数必需填写",
"ruleFreeDrawRequired": "赠送抽奖次数必需填写",
"ruleRemarkRequired": "备注必需填写"
},
"search": {
"player": "玩家",
"useCoins": "消耗硬币",
"ante": "底注",
"totalDrawCount": "总抽奖次数",
"paidDrawCount": "购买抽奖次数",
"freeDrawCount": "赠送抽奖次数",
@@ -29,6 +35,7 @@
"id": "ID",
"playerUsername": "玩家用户名",
"useCoins": "消耗硬币",
"ante": "底注",
"totalDrawCount": "总抽奖次数",
"paidDrawCount": "购买抽奖次数",
"freeDrawCount": "赠送抽奖次数",

View File

@@ -1,4 +1,7 @@
{
"toolbar": {
"coinChangeSummary": "平台币变化统计"
},
"form": {
"dialogTitleAdd": "新增玩家钱包流水",
"dialogTitleEdit": "编辑玩家钱包流水",
@@ -19,7 +22,10 @@
"placeholderWalletAfter": "根据平台币变化自动计算",
"placeholderRemark": "选填",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
"editSuccess": "修改成功",
"ruleUserRequired": "请选择用户",
"ruleCoinRequired": "平台币变化必填",
"ruleTypeRequired": "请选择类型"
},
"search": {
"type": "类型",

View File

@@ -56,11 +56,20 @@
"weightTest": {
"title": "一键测试权重",
"alertTitle": "彩金池逻辑说明",
"alertBody": "与 playStart 抽奖逻辑一致:使用 name=default 的安全线、杀分开关;盈利未达安全线时,付费抽奖券使用玩家自身权重(下方自定义档位),免费抽奖券使用 killScore 配置;盈利达到安全线且杀分开启时,付费/免费均使用 killScore 配置。",
"alertBody": "测试模式默认不启用杀分切换;可通过下方“杀分开关 + 安全线”在测试内启用:当模拟玩家累计盈利达到安全线后,付费抽奖切换到 killScore。",
"chainModeHint": "模拟方式:只配置付费抽奖次数(顺/逆时针)。付费抽到「再来一次」或 T5 时,下一局自动为免费抽奖,底注与触发局相同,抽奖类型记为免费、付费金额记为 0。免费抽奖的档位概率由下方「免费抽奖」配置决定含通过再来一次触发的后续免费局。",
"killModeHint": "杀分开关开启后:以“模拟玩家累计盈利”作为判定值;当累计盈利 >= 安全线时,后续付费抽奖按 killScore 配置抽取;免费抽奖仍按“免费抽奖配置”执行。",
"labelKillModeEnabled": "开启测试内杀分",
"labelTestSafetyLine": "测试安全线",
"sectionPaid": "付费抽奖",
"sectionFreeAfterPlayAgain": "免费抽奖(再来一次后的档位概率)",
"tierProbHintFreeChain": "当使用自定义档位时:以下为「免费抽奖」时 T1T5 的档位概率(仅在有免费局时参与摇档,与 dice_reward 格子权重共同决定结果)。",
"stepPaid": "付费抽奖券",
"stepFree": "免费抽奖券",
"labelLotteryTypePaid": "测试数据档位类型",
"labelLotteryTypeFree": "测试数据档位类型",
"labelAnte": "底注",
"placeholderAnte": "请选择底注配置",
"placeholderPaidPool": "不选则下方自定义档位概率(默认 default",
"placeholderFreePool": "不选则下方自定义档位概率(默认 killScore",
"tierProbHint": "自定义档位概率T1T5每档 0-100%,五档之和不能超过 100%",
@@ -73,6 +82,9 @@
"btnNext": "下一步",
"btnStart": "开始测试",
"btnCancel": "取消",
"warnAnte": "请选择底注",
"warnPaidSpins": "付费抽奖顺时针与逆时针次数之和须大于 0",
"warnTestSafetyLine": "测试安全线必须大于或等于 0",
"warnTotalSpins": "付费或免费至少一种方向次数之和大于 0",
"warnPaidTierSumPositive": "付费未选奖池时T1T5 档位概率之和需大于 0",
"warnPaidTierSumMax": "付费档位概率 T1T5 之和不能超过 100%",

View File

@@ -13,7 +13,8 @@
"colDicePoints": "色子点数",
"colDisplayText": "显示文本",
"colDisplayTextEn": "显示文本(英文)",
"colRealEv": "真实结算",
"colRealEv": "结算金额",
"colRealReward": "玩家实际中奖",
"colTier": "所属档位",
"colRemark": "备注",
"placeholderTierSelect": "档位",
@@ -50,7 +51,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【结算金额 与 档位】\n结算金额 < 0 → T40 < 结算金额 < 100 → T3100 < 结算金额 < 200 → T2200 < 结算金额 → T1T5「再来一次」结算金额=0。下方可为各档位填写统一的 结算金额 标准,生成时写入配置;细则可稍后在表格中再改。\n\n【本弹窗输入】\n条数T1/T4/T5「固定」T2「不少于」——顺时针与逆时针的加权条数每条摇取结果计一次须分别满足所填数值T1、T4 与 T5 分开填写。\n结算金额 标准:同档位各格使用同一数值。生成时 T1T4 的 显示文本 / 显示文本(英文) = 结算金额T5 固定为「再来一次」/「Once again」。备注仍区分完美回本/小赚等。",
"ruleGenT1Row": "T1 大奖",
"ruleGenT2Row": "T2 小赚/回本",
"ruleGenT3RealEvOnly": "T3 抽水",
"ruleGenT4Row": "T4 惩罚",
"ruleGenT5Row": "T5 再来一次",
"ruleGenMinCount": "最少条数",
"ruleGenFixedCount": "固定条数(顺/逆)",
"ruleGenRealEvStd": "结算金额",
"ruleGenRealEvEditHint": "生成并保存后,仍可在本页表格中逐条修改显示文案、英文、真实结算与备注。",
"ruleGenInvalidT1RealEv": "T1 的 结算金额 满足200 < 值",
"ruleGenInvalidT2RealEv": "T2 的 结算金额 满足100 < 值 < 200",
"ruleGenInvalidT3RealEv": "T3 的 结算金额 满足0 < 值 < 100",
"ruleGenInvalidT4RealEv": "T4 的 结算金额 满足:值 < 0",
"ruleGenInvalidT5RealEv": "T5「再来一次」的 结算金额 须为 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

@@ -2,16 +2,28 @@
"toolbar": {
"viewDetail": "查看详情"
},
"search": {
"paidPlannedSpins": "计划付费次数",
"ante": "底注"
},
"table": {
"id": "ID",
"clockwiseAbbr": "顺",
"counterclockwiseAbbr": "逆",
"status": "状态",
"paidDraw": "付费抽取",
"freeDraw": "免费抽取",
"chainMode": "链式再来一次",
"chainModeYes": "是",
"chainModeNo": "否",
"paidPlannedSpins": "计划付费次数",
"ante": "底注",
"playAgainCount": "再来一次次数",
"progressDraws": "已完成 {over} 次",
"progressFailed": "失败前 {over} 次",
"platformProfit": "平台赚取金额",
"totalDrawCount": "总抽奖次数",
"createdBy": "创建管理员",
"remark": "备注",
"createTime": "创建时间",
"statusFail": "失败",
"statusDone": "完成",
@@ -36,6 +48,10 @@
"recordId": "记录ID",
"testCount": "测试次数",
"testCountSuffix": "次",
"testCountProgress": "进行中:已完成 {over} 次",
"testCountFailed": "失败前 {over} 次",
"chainModeLabel": "链式再来一次",
"paidPlannedSpins": "计划付费次数",
"createTime": "创建时间",
"admin": "执行管理员",
"paidPoolId": "付费奖池配置ID",

View File

@@ -1,38 +1,35 @@
{
"search": {
"deptName": "渠道(部门)名称",
"deptCode": "部门编码",
"deptName": "渠道名称",
"deptCode": "渠道编码",
"status": "状态",
"placeholderDeptName": "请输入部门名称",
"placeholderDeptCode": "请输入部门编码",
"placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入渠道编码",
"searchSelectPlaceholder": "请选择"
},
"table": {
"deptName": "渠道(部门)名称",
"deptCode": "部门编码",
"leader": "部门领导",
"deptName": "渠道名称",
"deptCode": "渠道编码",
"leader": "渠道负责人",
"sort": "排序",
"status": "状态",
"createTime": "创建时间"
},
"form": {
"titleAdd": "新增部门",
"titleEdit": "编辑部门",
"labelParentDept": "上级部门",
"labelDeptName": "部门名称",
"labelDeptCode": "部门编码",
"labelLeader": "部门领导",
"titleAdd": "新增渠道",
"titleEdit": "编辑渠道",
"labelDeptName": "渠道名称",
"labelDeptCode": "渠道编码",
"labelLeader": "渠道负责人",
"labelRemark": "描述",
"labelSort": "排序",
"labelStatus": "启用",
"placeholderDeptName": "请输入部门名称",
"placeholderDeptCode": "请输入部门编码",
"placeholderRemark": "请输入部门描述",
"placeholderDeptName": "请输入渠道名称",
"placeholderDeptCode": "请输入渠道编码",
"placeholderRemark": "请输入渠道描述",
"placeholderSort": "请输入排序",
"noParentDept": "无上级部门",
"ruleParentDeptRequired": "请选择上级部门",
"ruleDeptNameRequired": "请输入部门名称",
"ruleDeptCodeRequired": "请输入部门编码",
"ruleDeptNameRequired": "请输入渠道名称",
"ruleDeptCodeRequired": "请输入渠道编码",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
}

View File

@@ -1,34 +0,0 @@
{
"search": {
"postName": "岗位名称",
"postCode": "岗位编码",
"status": "状态",
"placeholderPostName": "请输入岗位名称",
"placeholderPostCode": "请输入岗位编码",
"searchSelectPlaceholder": "请选择"
},
"table": {
"postName": "岗位名称",
"postCode": "岗位编码",
"sort": "排序",
"status": "状态",
"createTime": "创建时间"
},
"form": {
"titleAdd": "新增岗位",
"titleEdit": "编辑岗位",
"labelName": "岗位名称",
"labelCode": "岗位编码",
"labelRemark": "描述",
"labelSort": "排序",
"labelStatus": "启用",
"placeholderName": "请输入岗位名称",
"placeholderCode": "请输入岗位编码",
"placeholderRemark": "请输入岗位描述",
"placeholderSort": "请输入排序",
"ruleNameRequired": "请输入岗位名称",
"ruleCodeRequired": "请输入岗位编码",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
}
}

View File

@@ -10,7 +10,7 @@
"table": {
"username": "用户名",
"phone": "手机号",
"dept": "部门",
"dept": "渠道",
"dashboard": "首页",
"loginTime": "上次登录",
"agentId": "代理ID",
@@ -28,9 +28,8 @@
"labelPasswordConfirm": "确认密码",
"labelEmail": "邮箱",
"labelPhone": "手机号",
"labelDept": "部门",
"labelDept": "渠道",
"labelRole": "角色",
"labelPost": "岗位",
"labelGender": "性别",
"labelStatus": "状态",
"labelRemark": "备注",
@@ -43,9 +42,18 @@
"rulePasswordRequired": "请输入密码",
"rulePasswordLength": "长度在 6 到 20 个字符",
"rulePasswordConfirmRequired": "请输入确认密码",
"ruleDeptRequired": "请选择部门",
"ruleDeptRequired": "请选择渠道",
"ruleRoleRequired": "请选择角色",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
},
"ui": {
"channelList": "渠道列表",
"viewingChannel": "当前配置渠道",
"defaultConfigTemplate": "默认配置模板",
"promptNewPassword": "请输入新密码",
"passwordLengthError": "密码长度在6到16之间",
"passwordChanged": "修改密码成功",
"clearCacheConfirm": "确定要清理缓存吗?"
}
}

View File

@@ -16,5 +16,16 @@
"tplCategory": "生成类型",
"updateTime": "更新时间",
"createTime": "创建时间"
},
"ui": {
"generating": "代码生成下载中,请稍后",
"generateSuccess": "代码生成成功,开始下载",
"downloadFail": "文件下载失败",
"syncConfirm": "执行同步操作将会覆盖已经设置的表结构,确定要同步吗?",
"syncSuccess": "同步成功",
"generateToProjectConfirm": "生成到项目将会覆盖原有文件,确定要生成吗?",
"generateToProjectSuccess": "生成到项目成功",
"loadSuccess": "装载成功",
"copyToClipboard": "代码已复制到剪贴板"
}
}

View File

@@ -58,5 +58,11 @@
"ruleTargetRequired": "调用目标不能为空",
"addSuccess": "新增成功",
"editSuccess": "修改成功"
},
"ui": {
"runTitle": "运行任务",
"runConfirm": "确定要运行任务【{name}】吗?",
"runSuccess": "任务运行成功",
"selectTaskFirst": "请先选择一个任务"
}
}

View File

@@ -46,12 +46,21 @@ export async function loadPageLocale(routePath: string): Promise<void> {
const modules = locale === LanguageEnum.EN ? enModules : zhModules
const tryPaths: string[] = [path]
// 兼容别名路由:例如 /user 实际页面为 /system/user
// 兼容别名路由:菜单 path 为短名但 locale 文件位于模块子目录
// 例如:/user -> system/user/game -> dice/game
if (!path.includes('/')) {
tryPaths.push(`system/${path}`)
}
if (path === 'user') {
tryPaths.push('system/user')
// 兜底:在任意一级子目录下查找同名文件
const suffix = `/${path}.json`
const localePrefix = `./langs/${locale}/`
for (const key of Object.keys(modules)) {
if (key.startsWith(localePrefix) && key.endsWith(suffix)) {
const candidate = key.slice(localePrefix.length, -'.json'.length)
if (!tryPaths.includes(candidate)) {
tryPaths.push(candidate)
}
}
}
}
let matchedPath: string | null = null

View File

@@ -0,0 +1,48 @@
import type { RouteLocationNormalized } from 'vue-router'
import { useUserStore } from '@/store/modules/user'
/** 页面自带左侧渠道栏,不再包一层全局渠道壳 */
const BUILTIN_CHANNEL_LAYOUT_PATHS = [
'/system/user',
'/system/dept'
]
export function isSuperAdminUser(): boolean {
const userStore = useUserStore()
return Number(userStore.info?.id ?? 0) === 1
}
/** 游戏配置类页面:显示「默认配置模板」 */
export function isConfigChannelRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.channelScope === 'config') {
return true
}
return /\/(config|ante_config|lottery_pool_config|reward_config|game)(\/|$)/.test(route.path)
}
/** 角色管理左侧渠道树含默认模板dept_id=0与各渠道角色 */
export function isRoleChannelRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.channelScope === 'role') {
return true
}
return route.path.startsWith('/system/role')
}
export function shouldWrapSuperAdminChannelLayout(route: RouteLocationNormalized): boolean {
if (!isSuperAdminUser()) {
return false
}
if (route.meta?.isFullPage) {
return false
}
if (route.meta?.noChannelLayout === true) {
return false
}
const path = route.path
for (let i = 0; i < BUILTIN_CHANNEL_LAYOUT_PATHS.length; i++) {
if (path.startsWith(BUILTIN_CHANNEL_LAYOUT_PATHS[i])) {
return false
}
}
return true
}

View File

@@ -25,7 +25,6 @@ export const MAP_PATH_TO_MENU_I18N_KEY: Record<string, string> = {
'/system/user-center': 'menus.system.userCenter',
'/system/menu': 'menus.system.menu',
'/system/dept': 'menus.system.dept',
'/system/post': 'menus.system.post',
'/system/config': 'menus.system.config',
'/safeguard': 'menus.safeguard.title',
'/safeguard/dict': 'menus.safeguard.dict',
@@ -42,6 +41,8 @@ export const MAP_PATH_TO_MENU_I18N_KEY: Record<string, string> = {
'/dice': 'menus.dice.title',
'/dice/lottery_pool_config': 'menus.dice.lotteryPoolConfig',
'/dice/lottery_pool_config/index': 'menus.dice.lotteryPoolConfig',
'/dice/ante_config': 'menus.dice.anteConfig',
'/dice/ante_config/index': 'menus.dice.anteConfig',
'/dice/player': 'menus.dice.player',
'/dice/player/index': 'menus.dice.player',
'/dice/player_wallet_record': 'menus.dice.playerWalletRecord',
@@ -60,6 +61,10 @@ export const MAP_PATH_TO_MENU_I18N_KEY: Record<string, string> = {
'/dice/play_record_test/index': 'menus.dice.playRecordTest',
'/dice/config': 'menus.dice.config',
'/dice/config/index': 'menus.dice.config',
'game': 'menus.game.title',
'game/index': 'menus.game.title',
'/game': 'menus.game.title',
'/game/index': 'menus.game.title',
'/result/success': 'menus.result.success',
'/result/fail': 'menus.result.fail',
'/exception/403': 'menus.exception.forbidden',

View File

@@ -1,9 +1,9 @@
<!-- 工作台页面 -->
<!-- 工作台页面大富翁色子游戏数据统计 -->
<template>
<div>
<template v-if="userInfo.dashboard === 'statistics'">
<CardList></CardList>
<CardList />
<template v-if="isStatisticsDashboard">
<ElRow :gutter="20">
<ElCol :sm="24" :md="12" :lg="10">
<ActiveUser />
@@ -12,30 +12,22 @@
<SalesOverview />
</ElCol>
</ElRow>
<ElRow :gutter="20">
<ElCol :sm="24" :md="12" :lg="12">
<WalletRecordList />
</ElCol>
<ElCol :sm="24" :md="12" :lg="12">
<NewPlayerList />
</ElCol>
</ElRow>
</template>
<template v-if="userInfo.dashboard === 'work'">
<ElRow :gutter="20">
<ElCol :sm="24" :md="24" :lg="12">
<NewUser />
</ElCol>
<ElCol :sm="24" :md="12" :lg="6">
<Dynamic />
</ElCol>
<ElCol :sm="24" :md="12" :lg="6">
<TodoList />
</ElCol>
</ElRow>
</template>
<ElRow :gutter="20">
<ElCol :sm="24" :md="12" :lg="12">
<NewPlayerList />
</ElCol>
<ElCol :sm="24" :md="12" :lg="12">
<WalletRecordList />
</ElCol>
</ElRow>
<ElRow :gutter="20">
<ElCol :sm="24" :md="24" :lg="24">
<PlayRecordList />
</ElCol>
</ElRow>
</div>
</template>
@@ -45,16 +37,18 @@
import SalesOverview from './modules/sales-overview.vue'
import WalletRecordList from './modules/wallet-record-list.vue'
import NewPlayerList from './modules/new-player-list.vue'
import NewUser from './modules/new-user.vue'
import Dynamic from './modules/dynamic-stats.vue'
import TodoList from './modules/todo-list.vue'
import PlayRecordList from './modules/play-record-list.vue'
import { useCommon } from '@/hooks/core/useCommon'
import { useUserStore } from '@/store/modules/user'
defineOptions({ name: 'Console' })
const userStore = useUserStore()
const userInfo = userStore.getUserInfo
/** 统计页额外展示充值图表 */
const isStatisticsDashboard = computed(
() => userStore.getUserInfo.dashboard === 'statistics'
)
const { scrollToTop } = useCommon()
scrollToTop()

View File

@@ -18,6 +18,7 @@
<script setup lang="ts">
import { fetchRechargeBarChart } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
/**
* 充值金额数据
@@ -29,10 +30,12 @@
*/
const xData = ref<string[]>([])
onMounted(async () => {
fetchRechargeBarChart().then((data: any) => {
const loadChart = () => {
fetchRechargeBarChart(getChannelDeptRequestParams()).then((data: any) => {
yData.value = data?.recharge_amount ?? []
xData.value = data?.recharge_month ?? []
})
})
}
useChannelDeptReload(loadChart)
</script>

View File

@@ -99,6 +99,7 @@
<script setup lang="ts">
import { fetchStatistics } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const statData = ref({
player_count: 0,
@@ -123,8 +124,8 @@
return 'text-g-600'
}
onMounted(() => {
fetchStatistics().then((data: any) => {
const loadStatistics = () => {
fetchStatistics(getChannelDeptRequestParams()).then((data: any) => {
statData.value = {
player_count: data?.player_count ?? 0,
player_count_change: data?.player_count_change ?? 0,
@@ -136,5 +137,7 @@
play_count_change: data?.play_count_change ?? 0
}
})
})
}
useChannelDeptReload(loadStatistics)
</script>

View File

@@ -17,12 +17,23 @@
>
<template #default>
<ElTableColumn :label="$t('console.newPlayer.player')" prop="name" min-width="120" align="center" />
<ElTableColumn :label="$t('console.newPlayer.balance')" prop="coin" min-width="120" align="center">
<ElTableColumn :label="$t('console.newPlayer.balance')" prop="coin" min-width="100" align="center">
<template #default="scope">
{{ formatCoin(scope.row.coin) }}
</template>
</ElTableColumn>
<ElTableColumn :label="$t('console.newPlayer.ticket')" prop="total_ticket_count" min-width="100" align="center" />
<ElTableColumn
:label="$t('console.newPlayer.ticket')"
prop="total_ticket_count"
min-width="90"
align="center"
/>
<ElTableColumn
:label="$t('console.newPlayer.registerTime')"
prop="create_time"
min-width="170"
align="center"
/>
</template>
</ArtTable>
</div>
@@ -30,6 +41,7 @@
<script setup lang="ts">
import { fetchNewPlayerList, type NewPlayerItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<NewPlayerItem[]>([])
@@ -38,9 +50,11 @@
return Number(val).toFixed(2)
}
onMounted(() => {
fetchNewPlayerList().then((data) => {
const loadList = () => {
fetchNewPlayerList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : []
})
})
}
useChannelDeptReload(loadList)
</script>

View File

@@ -0,0 +1,70 @@
<template>
<div class="art-card p-5 overflow-hidden mb-5 max-sm:mb-4">
<div class="art-card-header mb-4">
<div class="title">
<h4>{{ $t('console.playRecord.title') }}</h4>
<p class="text-g-600 text-sm mt-1">{{ $t('console.playRecord.subtitle') }}</p>
</div>
</div>
<ArtTable
class="w-full"
:data="tableData"
style="width: 100%"
size="default"
:border="false"
:stripe="true"
:header-cell-style="{ background: 'transparent' }"
>
<template #default>
<ElTableColumn
:label="$t('console.playRecord.player')"
prop="player_name"
min-width="120"
align="center"
/>
<ElTableColumn
:label="$t('console.playRecord.reward')"
prop="reward_tier_label"
min-width="140"
align="center"
/>
<ElTableColumn
:label="$t('console.playRecord.winCoin')"
prop="win_coin"
min-width="120"
align="center"
>
<template #default="scope">
{{ formatCoin(scope.row.win_coin) }}
</template>
</ElTableColumn>
<ElTableColumn
:label="$t('console.playRecord.playTime')"
prop="create_time"
min-width="170"
align="center"
/>
</template>
</ArtTable>
</div>
</template>
<script setup lang="ts">
import { fetchPlayRecordList, type PlayRecordItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<PlayRecordItem[]>([])
function formatCoin(val: number | undefined): string {
if (val === undefined || val === null) return '0.00'
return Number(val).toFixed(2)
}
const loadList = () => {
fetchPlayRecordList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : []
})
}
useChannelDeptReload(loadList)
</script>

View File

@@ -17,6 +17,7 @@
<script setup lang="ts">
import { fetchRechargeChart } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
/**
* 充值金额数据
@@ -28,10 +29,12 @@
*/
const xData = ref<string[]>([])
onMounted(async () => {
fetchRechargeChart().then((data: any) => {
const loadChart = () => {
fetchRechargeChart(getChannelDeptRequestParams()).then((data: any) => {
yData.value = data?.recharge_amount ?? []
xData.value = data?.recharge_date ?? []
})
})
}
useChannelDeptReload(loadChart)
</script>

View File

@@ -30,6 +30,7 @@
<script setup lang="ts">
import { fetchWalletRecordList, type WalletRecordItem } from '@/api/dashboard'
import { getChannelDeptRequestParams, useChannelDeptReload } from '@/composables/useChannelDeptScope'
const tableData = ref<WalletRecordItem[]>([])
@@ -38,9 +39,11 @@
return Number(val).toFixed(2)
}
onMounted(() => {
fetchWalletRecordList().then((data) => {
const loadList = () => {
fetchWalletRecordList(getChannelDeptRequestParams()).then((data) => {
tableData.value = Array.isArray(data) ? data : []
})
})
}
useChannelDeptReload(loadList)
</script>

View File

@@ -1,21 +1,23 @@
<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="'core:post:save'" @click="showDialog('add')" v-ripple>
<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="'core:post:destroy'"
v-permission="'dice:ante_config:index:destroy'"
:disabled="selectedRows.length === 0"
@click="deleteSelectedRows(api.delete, refreshData)"
v-ripple
@@ -25,18 +27,10 @@
</template>
{{ $t('table.actions.delete') }}
</ElButton>
<SaImport
v-permission="'core:post:import'"
download-url="/core/post/downloadTemplate"
upload-url="/core/post/import"
@success="refreshData"
/>
<SaExport v-permission="'core:post:export'" url="/core/post/export" />
</ElSpace>
</template>
</ArtTableHeader>
<!-- 表格 -->
<ArtTable
ref="tableRef"
rowKey="id"
@@ -49,16 +43,21 @@
@pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange"
>
<!-- 操作列 -->
<template #is_default="{ row }">
<ElTag :type="row.is_default === 1 ? 'primary' : 'warning'" 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="'core:post:update'"
v-permission="'dice:ante_config:index:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<SaButton
v-permission="'core:post:destroy'"
v-permission="'dice:ante_config:index:destroy'"
type="error"
@click="deleteRow(row, api.delete, refreshData)"
/>
@@ -67,7 +66,6 @@
</ArtTable>
</ElCard>
<!-- 编辑弹窗 -->
<EditDialog
v-model="dialogVisible"
:dialog-type="dialogType"
@@ -80,24 +78,21 @@
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '@/api/system/post'
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,
code: undefined,
status: undefined
title: undefined,
is_default: undefined
})
//
const handleSearch = (params: Record<string, any>) => {
const handleSearch = (params: Record<string, unknown>) => {
Object.assign(searchParams, params)
getData()
}
//
const {
columns,
columnChecks,
@@ -114,21 +109,34 @@
} = useTable({
core: {
apiFn: api.list,
apiParams: { limit: 100 },
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'id', label: 'table.columns.common.no', width: 100, align: 'center' },
{ prop: 'name', label: 'page.table.postName', minWidth: 120 },
{ prop: 'code', label: 'page.table.postCode', minWidth: 120 },
{ prop: 'remark', label: 'table.columns.common.description', minWidth: 150, showOverflowTooltip: true },
{ prop: 'sort', label: 'page.table.sort', width: 100 },
{ prop: 'status', label: 'page.table.status', saiType: 'dict', saiDict: 'data_status', width: 100 },
{ prop: 'create_time', label: 'page.table.createTime', width: 180, sortable: true },
{ prop: 'operation', label: 'table.actions.operation', width: 100, fixed: 'right', useSlot: true }
{ 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,

View File

@@ -2,7 +2,7 @@
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
width="600px"
width="560px"
align-center
:close-on-click-modal="false"
@close="handleClose"
@@ -11,22 +11,17 @@
<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.labelCode')" prop="code">
<el-input v-model="formData.code" :placeholder="$t('page.form.placeholderCode')" />
<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.labelRemark')" prop="remark">
<el-input
v-model="formData.remark"
type="textarea"
:rows="3"
:placeholder="$t('page.form.placeholderRemark')"
/>
<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.labelSort')" prop="sort">
<el-input-number v-model="formData.sort" :placeholder="$t('page.form.placeholderSort')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelStatus')" prop="status">
<sa-radio v-model="formData.status" dict="data_status" />
<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>
@@ -37,130 +32,96 @@
</template>
<script setup lang="ts">
import api from '@/api/system/post'
import api from '../../../api/ante_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
interface Props {
modelValue: boolean
dialogType: string
data?: Record<string, any>
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 { t } = useI18n()
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' }],
code: [{ required: true, message: t('page.form.ruleCodeRequired'), 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' }]
}))
/**
* 初始数据
*/
const initialFormData = {
id: null,
name: '',
code: '',
remark: '',
sort: 100,
status: 1
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,
(newVal) => {
if (newVal) {
initPage()
}
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
}
)
/**
* 初始化页面数据
*/
const initPage = async () => {
//
Object.assign(formData, initialFormData)
//
if (props.data) {
await nextTick()
initForm()
}
}
/**
* 初始化表单数据
*/
const initForm = () => {
if (props.data) {
for (const key in formData) {
if (props.data[key] != null && props.data[key] != undefined) {
;(formData as any)[key] = props.data[key]
}
}
}
}
/**
* 关闭弹窗并重置表单
*/
const handleClose = () => {
function handleClose() {
visible.value = false
formRef.value?.resetFields()
}
/**
* 提交表单
*/
const handleSubmit = async () => {
async function handleSubmit() {
if (!formRef.value) return
try {
await formRef.value.validate()
if (props.dialogType === 'add') {
await api.save(formData)
await api.save(withChannelDeptParams(formData))
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(formData)
await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log('表单验证失败:', 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,51 @@
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
})
},
/** 底注下拉(按渠道) */
async getOptions(params?: Record<string, unknown>) {
const res = await request.get<
Array<{ id: number; name: string; title: string; mult: number; is_default: number }>
>({
url: '/core/dice/ante_config/DiceAnteConfig/getOptions',
params
})
return Array.isArray(res) ? res : []
}
}

View File

@@ -11,7 +11,7 @@ export default {
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/config/DiceConfig/index',
url: '/core/dice/config/DiceConfig/index',
params
})
},
@@ -23,7 +23,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/config/DiceConfig/read?id=' + id
url: '/core/dice/config/DiceConfig/read?id=' + id
})
},
@@ -34,7 +34,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/config/DiceConfig/save',
url: '/core/dice/config/DiceConfig/save',
data: params
})
},
@@ -46,7 +46,7 @@ export default {
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/config/DiceConfig/update',
url: '/core/dice/config/DiceConfig/update',
data: params
})
},
@@ -58,7 +58,7 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/config/DiceConfig/destroy',
url: '/core/dice/config/DiceConfig/destroy',
data: params
})
}

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/game/DiceGame/index',
params
})
},
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/game/DiceGame/read?id=' + id
})
},
save(params: Record<string, unknown>) {
return request.post({
url: '/core/dice/game/DiceGame/save',
data: params
})
},
update(params: Record<string, unknown>) {
return request.put({
url: '/core/dice/game/DiceGame/update',
data: params
})
},
delete(params: Record<string, unknown>) {
return request.del({
url: '/core/dice/game/DiceGame/destroy',
data: params
})
}
}

View File

@@ -20,7 +20,7 @@ export default {
* 获取 DiceLotteryPoolConfig 列表数据,含 id、name、t1_weightt5_weight用于一键测试权重档位类型下拉
* name 映射default=原 type=0killScore=原 type=1up=原 type=2
*/
async getOptions(): Promise<
async getOptions(params?: Record<string, unknown>): Promise<
Array<{
id: number
name: string
@@ -32,7 +32,8 @@ export default {
}>
> {
const res = await request.get<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions'
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions',
params
})
const rows = Array.isArray(res) ? res : (Array.isArray((res as any)?.data) ? (res as any).data : [])
if (!Array.isArray(rows)) return []
@@ -97,7 +98,7 @@ export default {
/**
* 获取当前彩金池Redis 实例化,无则按 type=0 创建),含玩家累计盈利 profit_amount 实时值
*/
getCurrentPool() {
getCurrentPool(params?: { dept_id?: number }) {
return request.get<{
id: number
name: string
@@ -110,14 +111,15 @@ export default {
t5_weight: number
profit_amount: number
}>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool'
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool',
params
})
},
/**
* 更新当前彩金池:仅 safety_line、t1_weightt5_weight不可改 profit_amount
*/
updateCurrentPool(params: { safety_line?: number; kill_enabled?: number }) {
updateCurrentPool(params: { safety_line?: number; kill_enabled?: number; dept_id?: number }) {
return request.post<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool',
data: params
@@ -127,9 +129,10 @@ export default {
/**
* 重置当前彩金池的玩家累计盈利profit_amount 置为 0
*/
resetProfitAmount() {
resetProfitAmount(params?: { dept_id?: number }) {
return request.post<any>({
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount'
url: '/core/dice/lottery_pool_config/DiceLotteryPoolConfig/resetProfitAmount',
data: params || {}
})
}
}

View File

@@ -11,7 +11,7 @@ export default {
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/play_record/DicePlayRecord/index',
url: '/core/dice/play_record/DicePlayRecord/index',
params
})
},
@@ -23,7 +23,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/play_record/DicePlayRecord/read?id=' + id
url: '/core/dice/play_record/DicePlayRecord/read?id=' + id
})
},
@@ -34,19 +34,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/play_record/DicePlayRecord/save',
data: params
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/play_record/DicePlayRecord/update',
url: '/core/dice/play_record/DicePlayRecord/save',
data: params
})
},
@@ -58,29 +46,24 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/play_record/DicePlayRecord/destroy',
url: '/core/dice/play_record/DicePlayRecord/destroy',
data: params
})
},
/** 获取玩家选项id、username */
getPlayerOptions() {
getPlayerOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; username: string }[]>({
url: '/dice/play_record/DicePlayRecord/getPlayerOptions'
url: '/core/dice/play_record/DicePlayRecord/getPlayerOptions',
params
})
},
/** 获取彩金池配置选项id、name */
getLotteryConfigOptions() {
getLotteryConfigOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; name: string }[]>({
url: '/dice/play_record/DicePlayRecord/getLotteryConfigOptions'
})
},
/** 获取奖励配置选项id、ui_text、tier */
getRewardConfigOptions() {
return request.get<{ id: number; ui_text: string; tier: string }[]>({
url: '/dice/play_record/DicePlayRecord/getRewardConfigOptions'
url: '/core/dice/play_record/DicePlayRecord/getLotteryConfigOptions',
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
})
@@ -39,18 +39,6 @@ export default {
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/core/dice/play_record_test/DicePlayRecordTest/update',
data: params
})
},
/**
* 删除数据
* @param id 数据ID

View File

@@ -11,7 +11,7 @@ export default {
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/player/DicePlayer/index',
url: '/core/dice/player/DicePlayer/index',
params
})
},
@@ -23,7 +23,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/player/DicePlayer/read?id=' + id
url: '/core/dice/player/DicePlayer/read?id=' + id
})
},
@@ -34,7 +34,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/player/DicePlayer/save',
url: '/core/dice/player/DicePlayer/save',
data: params
})
},
@@ -46,7 +46,7 @@ export default {
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/player/DicePlayer/update',
url: '/core/dice/player/DicePlayer/update',
data: params
})
},
@@ -58,7 +58,7 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/player/DicePlayer/destroy',
url: '/core/dice/player/DicePlayer/destroy',
data: params
})
},
@@ -68,18 +68,29 @@ export default {
*/
updateStatus(params: { id: number | string; status: number }) {
return request.put<any>({
url: '/dice/player/DicePlayer/updateStatus',
url: '/core/dice/player/DicePlayer/updateStatus',
data: params
})
},
/**
* 获取玩家游戏链接
*/
getGameUrl(params: { id: number | string; lang?: 'zh' | 'en' }) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/player/DicePlayer/getGameUrl',
params
})
},
/**
* 获取彩金池配置选项DiceLotteryPoolConfig.id、name供 lottery_config_id 下拉使用
* @returns [ { id, name } ]
*/
async getLotteryConfigOptions(): Promise<Array<{ id: number; name: string }>> {
async getLotteryConfigOptions(params?: Record<string, unknown>): Promise<Array<{ id: number; name: string }>> {
const res = await request.get<any>({
url: '/dice/player/DicePlayer/getLotteryConfigOptions'
url: '/core/dice/player/DicePlayer/getLotteryConfigOptions',
params
})
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }>
return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
@@ -89,11 +100,12 @@ export default {
* 获取后台管理员选项SystemUser供 admin_id 下拉使用
* @returns [ { id, username, realname, label } ]
*/
async getSystemUserOptions(): Promise<
async getSystemUserOptions(params?: Record<string, unknown>): Promise<
Array<{ id: number; username: string; realname: string; label: string }>
> {
const res = await request.get<any>({
url: '/dice/player/DicePlayer/getSystemUserOptions'
url: '/core/dice/player/DicePlayer/getSystemUserOptions',
params
})
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
id: number
@@ -107,5 +119,29 @@ export default {
realname: String(r.realname ?? ''),
label: String(r.label ?? r.username ?? r.id ?? '')
}))
},
/**
* 超管:按渠道树状展示全部管理员;非超管:扁平列表
*/
async getSystemUserTreeOptions(params?: Record<string, unknown>): Promise<
Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
> {
const res = await request.get<any>({
url: '/core/dice/player/DicePlayer/getSystemUserTreeOptions',
params
})
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
return rows
}
}

View File

@@ -11,7 +11,7 @@ export default {
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/index',
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/index',
params
})
},
@@ -23,7 +23,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/read?id=' + id
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/read?id=' + id
})
},
@@ -34,19 +34,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/save',
data: params
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/update',
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/save',
data: params
})
},
@@ -58,7 +46,7 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/destroy',
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/destroy',
data: params
})
},
@@ -66,9 +54,10 @@ export default {
/**
* 获取玩家选项id、username用于下拉
*/
getPlayerOptions() {
getPlayerOptions(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({
url: '/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions'
url: '/core/dice/player_ticket_record/DicePlayerTicketRecord/getPlayerOptions',
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_coin_change?: number }>({
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/index',
params
})
@@ -39,18 +39,6 @@ export default {
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/update',
data: params
})
},
/**
* 删除数据
* @param id 数据ID
@@ -66,9 +54,10 @@ export default {
/**
* 获取玩家选项id、username用于下拉
*/
getPlayerOptions() {
getPlayerOptions(params?: Record<string, unknown>) {
return request.get<{ id: number; username: string }[]>({
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions'
url: '/core/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions',
params
})
},

View File

@@ -19,19 +19,20 @@ export default {
* 权重编辑弹窗:按档位分组获取当前方向的配置+权重(单方向)
* @param direction 0=顺时针 1=逆时针
*/
weightRatioList(direction: 0 | 1) {
weightRatioList(direction: 0 | 1, params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/reward/DiceReward/weightRatioList',
params: { direction }
params: { direction, ...(params || {}) }
})
},
/**
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重dice_reward 双方向)
*/
weightRatioListWithDirection() {
weightRatioListWithDirection(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/reward/DiceReward/weightRatioListWithDirection'
url: '/core/dice/reward/DiceReward/weightRatioListWithDirection',
params
})
},
@@ -39,10 +40,13 @@ export default {
* 权重编辑弹窗:按 DiceReward 主键 id 批量更新 weight
* @param items [{ id: DiceReward.id, weight: 1-10000 }, ...]
*/
batchUpdateWeights(items: Array<{ id: number; weight: number }>) {
batchUpdateWeights(
items: Array<{ id: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({
url: '/core/dice/reward/DiceReward/batchUpdateWeights',
data: { items }
data: { items, ...(extra || {}) }
})
},
@@ -57,13 +61,18 @@ export default {
},
/**
* 一键测试权重:创建测试记录并启动后台执行,按付费/免费、顺逆方向交替抽奖
* 可选 lottery_config_id不选则传 paid_tier_weights / free_tier_weightsT1-T5
* 一键测试权重:创建测试记录并启动后台执行
* chain_free_mode=true仅模拟付费次数付费抽到再来一次则插入免费抽奖同底注、付费金额 0
*/
startWeightTest(params: {
ante?: number
ante_config_id?: number
lottery_config_id?: number
paid_lottery_config_id?: number
free_lottery_config_id?: number
chain_free_mode?: boolean
kill_mode_enabled?: boolean
test_safety_line?: number
s_count?: number
n_count?: number
paid_s_count?: number

View File

@@ -66,19 +66,23 @@ export default {
/**
* 批量更新奖励索引配置第一页id、grid_number、ui_text、real_ev、tier、remark
*/
batchUpdate(items: Array<{ id: number; grid_number?: number; ui_text?: string; real_ev?: number; tier?: string; remark?: string }>) {
batchUpdate(
items: Array<{ id: number; grid_number?: number; ui_text?: string; real_ev?: number; tier?: string; remark?: string }>,
extra?: Record<string, any>
) {
return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdate',
data: { items }
data: { items, ...(extra || {}) }
})
},
/**
* T1-T5、BIGWIN 权重配比:按档位分组获取配置列表
*/
weightRatioList() {
weightRatioList(params?: Record<string, unknown>) {
return request.get<Api.Common.ApiData>({
url: '/core/dice/reward_config/DiceRewardConfig/weightRatioList'
url: '/core/dice/reward_config/DiceRewardConfig/weightRatioList',
params
})
},
@@ -86,34 +90,41 @@ export default {
* T1-T5、BIGWIN 权重配比:批量更新顺时针/逆时针权重(写入 dice_reward
*/
/** 按 DiceReward 主键 id 批量更新 weightitems: [{ id, weight }, ...] */
batchUpdateWeights(items: Array<{ id: number; weight: number }>) {
batchUpdateWeights(
items: Array<{ id: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/batchUpdateWeights',
data: { items }
data: { items, ...(extra || {}) }
})
},
/**
* 大奖权重:按 grid_number 批量保存 BIGWIN 权重(无需 reward id不存在则自动创建
*/
saveBigwinWeightsByGrid(items: Array<{ grid_number: number; weight: number }>) {
saveBigwinWeightsByGrid(
items: Array<{ grid_number: number; weight: number }>,
extra?: Record<string, unknown>
) {
return request.post<any>({
url: '/core/dice/reward_config/DiceRewardConfig/saveBigwinWeightsByGrid',
data: { items }
data: { items, ...(extra || {}) }
})
},
/**
* 创建奖励对照:按当前奖励配置为顺时针(0)、逆时针(1)生成所有色子可能对应的 dice_reward 记录,权重默认 1可在奖励对照页权重编辑中调整
*/
createRewardReference() {
createRewardReference(params?: Record<string, any>) {
return request.post<{
created_clockwise: number
created_counterclockwise: number
updated_clockwise: number
updated_counterclockwise: number
}>({
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference'
url: '/core/dice/reward_config/DiceRewardConfig/createRewardReference',
data: params || {}
})
}
}

View File

@@ -11,7 +11,7 @@ export default {
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/index',
url: '/core/dice/reward_config_record/DiceRewardConfigRecord/index',
params
})
},
@@ -23,7 +23,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/read?id=' + id
url: '/core/dice/reward_config_record/DiceRewardConfigRecord/read?id=' + id
})
},
@@ -34,19 +34,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/save',
data: params
})
},
/**
* 更新数据
* @param params 数据参数
* @returns 执行结果
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/update',
url: '/core/dice/reward_config_record/DiceRewardConfigRecord/save',
data: params
})
},
@@ -58,7 +46,7 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/destroy',
url: '/core/dice/reward_config_record/DiceRewardConfigRecord/destroy',
data: params
})
},
@@ -77,7 +65,7 @@ export default {
lottery_config_id?: number | null
}) {
return request.post<any>({
url: '/dice/reward_config_record/DiceRewardConfigRecord/importFromRecord',
url: '/core/dice/reward_config_record/DiceRewardConfigRecord/importFromRecord',
data: params
})
}

View File

@@ -107,6 +107,7 @@
} = useTable({
core: {
apiFn: api.list,
apiParams: { limit: 100 },
columnsFactory: () => [
// { type: 'selection' },
{ prop: 'group', label: 'page.table.group', minWidth: 140, align: 'center' },

View File

@@ -47,6 +47,7 @@
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
@@ -162,10 +163,10 @@
try {
await formRef.value.validate()
if (props.dialogType === 'add') {
await api.save(formData)
await api.save(withChannelDeptParams(formData))
ElMessage.success(t('page.form.saveSuccess'))
} else {
await api.update(formData)
await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.updateSuccess'))
}
emit('success')

View File

@@ -0,0 +1,144 @@
<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:game:index:save'" @click="showDialog('add')" v-ripple>
<template #icon>
<ArtSvgIcon icon="ri:add-fill" />
</template>
{{ $t('table.actions.add') }}
</ElButton>
<ElButton
v-permission="'dice:game: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 #status="{ row }">
<ElTag :type="row.status === 1 ? 'success' : 'info'">{{
row.status === 1 ? $t('page.table.statusEnabled') : $t('page.table.statusDisabled')
}}</ElTag>
</template>
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
v-permission="'dice:game:index:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<SaButton
v-permission="'dice:game: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/game/index'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
const searchForm = ref({
provider_code: undefined,
game_code: undefined,
game_type: undefined,
status: 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,
apiParams: { limit: 100 },
columnsFactory: () => [
{ type: 'selection', align: 'center' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
{ prop: 'provider', label: 'page.table.provider', minWidth: 120, align: 'center' },
{ prop: 'provider_code', label: 'page.table.providerCode', minWidth: 120, align: 'center' },
{ prop: 'game_code', label: 'page.table.gameCode', minWidth: 120, align: 'center' },
{ prop: 'game_key', label: 'page.table.gameKey', minWidth: 120, align: 'center' },
{ prop: 'game_name', label: 'page.table.gameName', minWidth: 120, align: 'center' },
{ prop: 'game_name_en', label: 'page.table.gameNameEn', minWidth: 120, align: 'center' },
{ prop: 'game_type', label: 'page.table.gameType', minWidth: 90, align: 'center' },
{ prop: 'sort', label: 'page.table.sort', width: 80, align: 'center' },
{ prop: 'status', label: 'page.table.status', width: 90, align: 'center', useSlot: true },
{ prop: 'update_time', label: 'page.table.updateTime', minWidth: 160, align: 'center' },
{
prop: 'operation',
label: 'table.actions.operation',
width: 110,
align: 'center',
fixed: 'right',
useSlot: true
}
]
}
})
const {
dialogType,
dialogVisible,
dialogData,
showDialog,
deleteRow,
deleteSelectedRows,
handleSelectionChange,
selectedRows
} = useSaiAdmin()
</script>

View File

@@ -0,0 +1,217 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
width="680px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-row :gutter="16">
<el-col :span="12">
<el-form-item :label="$t('page.form.provider')" prop="provider">
<el-input v-model="formData.provider" :placeholder="$t('page.form.placeholderProvider')" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('page.form.providerCode')" prop="provider_code">
<el-input v-model="formData.provider_code" :placeholder="$t('page.form.placeholderProviderCode')" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item :label="$t('page.form.gameCode')" prop="game_code">
<el-input v-model="formData.game_code" :placeholder="$t('page.form.placeholderGameCode')" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('page.form.gameKey')" prop="game_key">
<el-input v-model="formData.game_key" :placeholder="$t('page.form.placeholderGameKey')" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item :label="$t('page.form.gameName')" prop="game_name">
<el-input v-model="formData.game_name" :placeholder="$t('page.form.placeholderGameName')" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('page.form.gameNameEn')" prop="game_name_en">
<el-input v-model="formData.game_name_en" :placeholder="$t('page.form.placeholderGameNameEn')" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col :span="12">
<el-form-item :label="$t('page.form.gameType')" prop="game_type">
<el-input v-model="formData.game_type" :placeholder="$t('page.form.placeholderGameType')" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('page.form.sort')" prop="sort">
<el-input-number v-model="formData.sort" :min="1" :step="1" style="width: 100%" />
</el-form-item>
</el-col>
</el-row>
<el-form-item :label="$t('page.form.logo')" prop="logo">
<el-tabs v-model="logoInputMode" class="w-full">
<el-tab-pane :label="$t('page.form.tabPicker')" name="picker">
<sa-image-picker
v-model="formData.logo"
:multiple="false"
:limit="1"
width="120px"
height="120px"
/>
</el-tab-pane>
<el-tab-pane :label="$t('page.form.tabUpload')" name="upload">
<sa-image-upload
v-model="formData.logo"
:multiple="false"
:limit="1"
:max-size="5"
:show-tips="true"
/>
</el-tab-pane>
</el-tabs>
</el-form-item>
<el-form-item :label="$t('page.form.gameUrl')" prop="game_url">
<el-input v-model="formData.game_url" :placeholder="$t('page.form.placeholderGameUrl')" />
</el-form-item>
<el-form-item :label="$t('page.form.hallUrl')" prop="hall_url">
<el-input v-model="formData.hall_url" :placeholder="$t('page.form.placeholderHallUrl')" />
</el-form-item>
<el-form-item :label="$t('page.form.status')" prop="status">
<el-radio-group v-model="formData.status">
<el-radio :value="1">{{ $t('page.form.statusEnabled') }}</el-radio>
<el-radio :value="0">{{ $t('page.form.statusDisabled') }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item :label="$t('page.form.remark')" prop="remark">
<el-input
v-model="formData.remark"
type="textarea"
:rows="2"
:placeholder="$t('page.form.placeholderRemark')"
/>
</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/game/index'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
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 visible = computed({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val)
})
const formRef = ref<FormInstance>()
const logoInputMode = ref('picker')
const initialFormData = {
id: undefined as number | undefined,
provider: '',
provider_code: '',
game_code: '',
game_key: '',
game_name: '',
game_name_en: '',
game_type: '',
logo: '',
game_url: '',
hall_url: '',
status: 1,
sort: 100,
remark: ''
}
const formData = reactive({ ...initialFormData })
const rules = computed<FormRules>(() => ({
provider: [{ required: true, message: t('page.form.ruleProviderRequired'), trigger: 'blur' }],
provider_code: [{ required: true, message: t('page.form.ruleProviderCodeRequired'), trigger: 'blur' }],
game_code: [{ required: true, message: t('page.form.ruleGameCodeRequired'), trigger: 'blur' }],
game_key: [{ required: true, message: t('page.form.ruleGameKeyRequired'), trigger: 'blur' }],
game_name: [{ required: true, message: t('page.form.ruleGameNameRequired'), trigger: 'blur' }],
game_type: [{ required: true, message: t('page.form.ruleGameTypeRequired'), trigger: 'blur' }]
}))
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.provider === 'string') formData.provider = props.data.provider
if (typeof props.data.provider_code === 'string') formData.provider_code = props.data.provider_code
if (typeof props.data.game_code === 'string') formData.game_code = props.data.game_code
if (typeof props.data.game_key === 'string') formData.game_key = props.data.game_key
if (typeof props.data.game_name === 'string') formData.game_name = props.data.game_name
if (typeof props.data.game_name_en === 'string') formData.game_name_en = props.data.game_name_en
if (typeof props.data.game_type === 'string') formData.game_type = props.data.game_type
if (typeof props.data.logo === 'string') formData.logo = props.data.logo
if (typeof props.data.game_url === 'string') formData.game_url = props.data.game_url
if (typeof props.data.hall_url === 'string') formData.hall_url = props.data.hall_url
formData.status = Number(props.data.status ?? 1) === 1 ? 1 : 0
const sortValue = Number(props.data.sort ?? 100)
formData.sort = Number.isFinite(sortValue) ? sortValue : 100
if (typeof props.data.remark === 'string') formData.remark = props.data.remark
}
)
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(withChannelDeptParams(formData))
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(withChannelDeptParams(formData))
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log(error)
}
}
</script>

View File

@@ -0,0 +1,97 @@
<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.providerCode')" prop="provider_code">
<el-input
v-model="formData.provider_code"
:placeholder="$t('page.search.placeholderProviderCode')"
clearable
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.gameCode')" prop="game_code">
<el-input
v-model="formData.game_code"
:placeholder="$t('page.search.placeholderGameCode')"
clearable
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.gameType')" prop="game_type">
<el-input
v-model="formData.game_type"
:placeholder="$t('page.search.placeholderGameType')"
clearable
/>
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.status')" prop="status">
<el-select
v-model="formData.status"
:placeholder="$t('page.search.placeholderStatus')"
clearable
>
<el-option :label="$t('page.search.statusEnabled')" :value="1" />
<el-option :label="$t('page.search.statusDisabled')" :value="0" />
</el-select>
</el-form-item>
</el-col>
</sa-search-bar>
</template>
<script setup lang="ts">
type GameSearchForm = {
provider_code?: string
game_code?: string
game_type?: string
status?: number
[key: string]: unknown
}
interface Props {
modelValue: GameSearchForm
}
interface Emits {
(e: 'update:modelValue', value: GameSearchForm): void
(e: 'search', params: GameSearchForm): void
(e: 'reset'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const searchBarRef = ref()
const formData = computed<GameSearchForm>({
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

@@ -1,6 +1,5 @@
<template>
<div class="art-full-height">
<!-- 搜索面板 -->
<div class="flex-1 min-h-0 flex flex-col">
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never">

View File

@@ -42,7 +42,7 @@
style="width: 100%"
/>
</el-form-item>
<el-form-item label="开启杀分">
<el-form-item :label="$t('page.form.enableKillScore')">
<el-switch v-model="formData.kill_enabled" :active-value="1" :inactive-value="0" />
</el-form-item>
<el-form-item :label="$t('page.form.killScoreWeights')">
@@ -85,8 +85,13 @@
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import {
getChannelDeptRequestParams,
withChannelDeptParams
} from '@/composables/useChannelDeptScope'
const { t } = useI18n()
const channelDeptParams = () => getChannelDeptRequestParams()
interface PoolData {
id: number
@@ -151,7 +156,7 @@
if (!visible.value) return
try {
loading.value = true
const res = await api.getCurrentPool()
const res = await api.getCurrentPool(channelDeptParams())
const data = res as unknown as PoolData
if (data && typeof data === 'object') {
pool.value = data
@@ -172,7 +177,7 @@
stopPolling()
return
}
api.getCurrentPool().then((res) => {
api.getCurrentPool(channelDeptParams()).then((res) => {
const data = res as unknown as PoolData
if (pool.value && data && typeof data === 'object' && data.profit_amount != null) {
pool.value.profit_amount = data.profit_amount
@@ -193,10 +198,12 @@
try {
await formRef.value?.validate?.()
saving.value = true
await api.updateCurrentPool({
safety_line: formData.safety_line,
kill_enabled: formData.kill_enabled
})
await api.updateCurrentPool(
withChannelDeptParams({
safety_line: formData.safety_line,
kill_enabled: formData.kill_enabled
})
)
ElMessage.success(t('page.form.msgSaveSuccess'))
await loadPool()
emit('success')
@@ -211,7 +218,7 @@
if (!pool.value) return
try {
resetting.value = true
await api.resetProfitAmount()
await api.resetProfitAmount(channelDeptParams())
ElMessage.success(t('page.form.msgResetProfitSuccess'))
await loadPool()
emit('success')

View File

@@ -70,6 +70,7 @@
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { useInjectedChannelDept, withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
@@ -127,6 +128,7 @@
*/
const initialFormData = {
id: null as number | null,
dept_id: undefined as number | undefined,
name: '',
remark: '',
safety_line: 0 as number,
@@ -174,6 +176,7 @@
if (!props.data) return
const numKeys = [
'id',
'dept_id',
'safety_line',
't1_weight',
't2_weight',
@@ -204,6 +207,8 @@
/**
* 提交表单
*/
const channelScope = useInjectedChannelDept()
const handleSubmit = async () => {
if (!formRef.value) return
try {
@@ -212,11 +217,18 @@
ElMessage.warning(t('page.form.msgWeightsMust100'))
return
}
const submitData = withChannelDeptParams({
...formData,
dept_id:
formData.dept_id ??
props.data?.dept_id ??
channelScope?.selectedDeptId.value
})
if (props.dialogType === 'add') {
await api.save(formData)
await api.save(submitData)
ElMessage.success(t('page.form.msgAddSuccess'))
} else {
await api.update(formData)
await api.update(submitData)
ElMessage.success(t('page.form.msgUpdateSuccess'))
}
emit('success')

View File

@@ -56,21 +56,52 @@
<!-- 抽奖类型 tag -->
<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>
<!-- 是否中大奖 tag -->
<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>
<!-- 方向 tag -->
<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>
<!-- 平台币相关统一整数显示 -->
<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 #paid_amount="{ row }">
<span>{{ formatPlatformCoin(row?.paid_amount) }}</span>
</template>
<!-- 摇取点数 tag -->
<template #roll_array="{ row }">
<ElTag size="small">
@@ -129,7 +160,7 @@
direction: undefined
})
/** 当前筛选下平台总盈利(付费抽奖次数×100 - 玩家总收益) */
/** 当前筛选下平台总盈利(付费金额 paid_amount 求和 - 玩家总收益) */
const totalWinCoin = ref<number | null>(null)
const listApi = async (params: Record<string, any>) => {
@@ -148,8 +179,7 @@
row?.dicePlayer?.username ?? row?.player_id ?? '-'
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
const rewardTierFormatter = (row: Record<string, any>) =>
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'
const rewardTierFormatter = (row: Record<string, any>) => row?.reward_tier ?? '-'
/** 摇取点数格式化为 1,3,4,5,6,6 */
function formatRollArray(val: unknown): string {
@@ -166,6 +196,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 n.toFixed(2)
}
// 表格配置
const {
columns,
@@ -199,23 +236,32 @@
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: 'direction', label: 'page.table.direction', width: 90, useSlot: true },
{ prop: 'ante', label: 'page.table.ante', width: 80, align: 'center' },
{ prop: 'paid_amount', label: 'page.table.paidAmount', width: 110, align: 'center', useSlot: true },
{ prop: 'is_win', label: 'page.table.isBigWin', width: 100, useSlot: true },
{ 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: 'start_index', label: 'page.table.startIndex', width: 90 },
{ prop: 'target_index', label: 'page.table.targetIndex', width: 90 },
{ prop: 'roll_array', label: 'page.table.rollArray', width: 140, useSlot: true },
{ prop: 'roll_number', label: 'page.table.rollNumber', width: 110, sortable: true },
{
prop: 'reward_config_id',
label: 'page.table.rewardConfig',
prop: 'reward_tier',
label: 'page.table.rewardTier',
width: 100,
formatter: (row: Record<string, any>) => rewardTierFormatter(row)
},
{ prop: 'create_time', label: 'page.table.createTime', width: 170 },
{ prop: 'update_time', label: 'page.table.updateTime', 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

@@ -1,13 +1,13 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
:title="$t('page.form.dialogTitleEdit')"
width="600px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form ref="formRef" :model="formData" label-width="120px">
<el-form-item :label="$t('page.form.player')" prop="player_id">
<el-select
v-model="formData.player_id"
@@ -15,7 +15,7 @@
clearable
filterable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option
v-for="item in playerOptions"
@@ -32,7 +32,7 @@
clearable
filterable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option
v-for="item in lotteryConfigOptions"
@@ -48,7 +48,7 @@
:placeholder="$t('form.placeholderSelect')"
clearable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option :label="$t('page.form.paid')" :value="0" />
<el-option :label="$t('page.form.free')" :value="1" />
@@ -60,7 +60,7 @@
:placeholder="$t('form.placeholderSelect')"
clearable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option :label="$t('page.form.noBigWin')" :value="0" />
<el-option :label="$t('page.form.bigWin')" :value="1" />
@@ -70,29 +70,29 @@
<el-input-number
v-model="formData.win_coin"
:placeholder="$t('page.form.placeholderWinCoin')"
:precision="2"
:precision="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.superWinCoin')" prop="super_win_coin">
<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'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.rewardWinCoin')" prop="reward_win_coin">
<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'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.direction')" prop="direction">
@@ -101,7 +101,7 @@
:placeholder="$t('page.form.placeholderDirection')"
clearable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option :label="$t('page.form.clockwise')" :value="0" />
<el-option :label="$t('page.form.anticlockwise')" :value="1" />
@@ -113,7 +113,7 @@
:placeholder="$t('page.form.placeholderStartIndex')"
:min="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.targetIndex')" prop="target_index">
@@ -122,7 +122,7 @@
:placeholder="$t('page.form.placeholderTargetIndex')"
:min="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.rollArray')" prop="rollArrayItems">
@@ -137,7 +137,7 @@
controls-position="right"
placeholder=""
class="roll-array-input"
:disabled="dialogType === 'edit'"
disabled
/>
</div>
<div class="roll-array-hint">{{ $t('page.form.rollArrayHint') }}</div>
@@ -150,45 +150,37 @@
:max="30"
:precision="0"
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.rewardConfig')" prop="reward_config_id">
<el-form-item :label="$t('page.form.rewardTier')" prop="reward_tier">
<el-select
v-model="formData.reward_config_id"
:placeholder="$t('page.form.placeholderRewardConfig')"
v-model="formData.reward_tier"
:placeholder="$t('page.form.placeholderRewardTier')"
clearable
filterable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option
v-for="item in rewardConfigOptions"
:key="item.id"
:label="
item.ui_text
? `${item.ui_text}${item.tier ? ' (' + item.tier + ')' : ''}`
: String(item.id)
"
:value="item.id"
/>
<el-option label="T1" value="T1" />
<el-option label="T2" value="T2" />
<el-option label="T3" value="T3" />
<el-option label="T4" value="T4" />
<el-option label="T5" value="T5" />
<el-option label="BIGWIN" value="BIGWIN" />
</el-select>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">{{ dialogType === 'edit' ? $t('form.close') : $t('common.cancel') }}</el-button>
<el-button v-if="dialogType === 'add'" type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
<el-button @click="handleClose">{{ $t('form.close') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/play_record/index'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
const { t } = useI18n()
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
import type { FormInstance } from 'element-plus'
interface Props {
modelValue: boolean
@@ -203,7 +195,7 @@
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
dialogType: 'edit',
data: undefined
})
@@ -216,35 +208,8 @@
set: (value) => emit('update:modelValue', value)
})
const rules = reactive<FormRules>({
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
lottery_config_id: [{ required: true, message: '请选择彩金池配置', trigger: 'change' }],
lottery_type: [{ required: true, message: '请选择抽奖类型', trigger: 'change' }],
is_win: [{ required: true, message: '请选择是否中大奖', trigger: 'change' }],
win_coin: [{ required: true, message: '赢取平台币必填', trigger: 'blur' }],
rollArrayItems: [
{
validator: (_rule: any, value: (number | null)[], callback: (e?: Error) => void) => {
if (!value || value.length !== 5) {
callback(new Error('摇取点数必须为 5 个数'))
return
}
const ok = value.every((n) => n != null && n >= 1 && n <= 6)
if (!ok) {
callback(new Error('摇取点数必须填写 5 个数,每个 16'))
return
}
callback()
},
trigger: 'change'
}
],
reward_config_id: [{ required: true, message: '请选择奖励配置', trigger: 'change' }]
})
const playerOptions = ref<Array<{ id: number; username: string }>>([])
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
const rewardConfigOptions = ref<Array<{ id: number; ui_text: string; tier: string }>>([])
const initialFormData = {
id: null as number | null,
@@ -260,7 +225,7 @@
target_index: null as number | null,
roll_array: null as string | number[] | null,
roll_number: null as number | null,
reward_config_id: null as number | null
reward_tier: '' as string
}
/** 摇取点数固定 5 位 [n0..n4],每项 16 */
@@ -277,22 +242,18 @@
if (open) {
initPage()
try {
const [players, lotteryConfigs, rewardConfigs] = await Promise.all([
api.getPlayerOptions(),
api.getLotteryConfigOptions(),
api.getRewardConfigOptions()
const deptParams = getChannelDeptRequestParams()
const [players, lotteryConfigs] = await Promise.all([
api.getPlayerOptions(deptParams),
api.getLotteryConfigOptions(deptParams)
])
playerOptions.value = Array.isArray(players) ? players : ((players as any)?.data ?? [])
lotteryConfigOptions.value = Array.isArray(lotteryConfigs)
? lotteryConfigs
: ((lotteryConfigs as any)?.data ?? [])
rewardConfigOptions.value = Array.isArray(rewardConfigs)
? rewardConfigs
: ((rewardConfigs as any)?.data ?? [])
} catch {
playerOptions.value = []
lotteryConfigOptions.value = []
rewardConfigOptions.value = []
}
}
}
@@ -322,7 +283,7 @@
'target_index',
'roll_array',
'roll_number',
'reward_config_id'
'reward_tier'
]
keys.forEach((key) => {
const val = props.data![key]
@@ -384,46 +345,6 @@
visible.value = false
formRef.value?.resetFields()
}
const handleSubmit = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
const payload = { ...formData } as Record<string, unknown>
// 将 5 个输入值拼成 [1,2,3,4,5] 格式,确保每项为 16 的整数
const items = formData.rollArrayItems
const rollArray = items.map((n) => {
const v = n != null ? Number(n) : 1
return Math.min(6, Math.max(1, Number.isNaN(v) ? 1 : Math.floor(v)))
})
payload.roll_array = rollArray
payload.roll_number = formData.roll_number ?? rollArray.reduce((s, n) => s + n, 0)
delete payload.rollArrayItems
if (props.dialogType === 'add') {
delete payload.id
await api.save(payload)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(payload)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error: any) {
let msg = t('page.form.validateFailed')
if (error?.message) {
msg = error.message
} else if (typeof error === 'string') {
msg = error
} else if (error && typeof error === 'object') {
const first = Object.values(error).find((v: any) => v?.[0]?.message)
if (first && Array.isArray(first)) {
msg = (first[0] as any).message || msg
}
}
ElMessage.warning(msg)
}
}
</script>
<style lang="scss" scoped>

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"
/>
@@ -101,6 +101,7 @@
<el-option label="T3" value="T3" />
<el-option label="T4" value="T4" />
<el-option label="T5" value="T5" />
<el-option label="BIGWIN" value="BIGWIN" />
</el-select>
</el-form-item>
</el-col>

View File

@@ -8,7 +8,9 @@
<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 +60,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>
<!-- 摇取点数 -->
@@ -79,10 +99,20 @@
{{ formatRollArray(row.roll_array) }}
</ElTag>
</template>
<!-- 奖励档位显示 DiceRewardConfig.tier -->
<template #reward_config_id="{ row }">
<!-- 奖励档位优先显示记录自带 reward_tier -->
<template #reward_tier="{ 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,28 +159,30 @@
// 搜索表单(与 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,
roll_number: undefined
})
// 当前筛选下平台总盈利(付费抽奖次数×100 - 玩家总收益)
// 当前筛选下平台总盈利(付费金额 paid_amount 求和 - 玩家总收益)
const totalWinCoin = ref<number | null>(null)
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
}
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
const rewardTierFormatter = (row: Record<string, any>) =>
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'
const rewardTierFormatter = (row: Record<string, any>) => row?.reward_tier ?? '-'
/** 摇取点数格式化为 1,3,4,5,6 */
function formatRollArray(val: unknown): string {
@@ -167,17 +199,24 @@
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 n.toFixed(2)
}
const handleClearAll = async () => {
try {
await ElMessageBox.confirm('确定清空所有玩家抽奖测试数据?', '提示', {
await ElMessageBox.confirm(t('page.ui.clearAllConfirm'), t('uiMsg.titlePrompt'), {
type: 'warning'
})
await api.clearAll()
ElMessage.success('已清空所有测试数据')
ElMessage.success(t('page.ui.clearAllSuccess'))
getData()
} catch (e: any) {
if (e !== 'cancel') {
ElMessage.error(e?.message || '清空失败')
ElMessage.error(e?.message || t('page.ui.clearAllFail'))
}
}
}
@@ -208,21 +247,39 @@
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: 'direction', label: 'page.table.direction', width: 90, useSlot: true },
{ prop: 'ante', label: 'page.table.ante', width: 90 },
{ prop: 'is_win', label: 'page.table.isBigWin', width: 100, useSlot: true },
{ prop: 'paid_amount', label: 'page.table.paidAmount', width: 130 },
{ 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: 'start_index', label: 'page.table.startIndex', width: 90 },
{ prop: 'target_index', label: 'page.table.targetIndex', width: 90 },
{ prop: 'roll_array', label: 'page.table.rollArray', width: 140, useSlot: true },
{ prop: 'roll_number', label: 'page.table.rollNumber', width: 110, sortable: true },
{ prop: 'reward_config_id', label: 'page.table.rewardConfig', width: 100, useSlot: true },
{ prop: 'reward_tier', label: 'page.table.rewardTier', 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

@@ -1,15 +1,15 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
:title="$t('page.form.titleEdit')"
width="600px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form ref="formRef" :model="formData" label-width="120px">
<el-form-item :label="$t('page.form.labelLotteryConfigId')" prop="lottery_config_id">
<el-input v-model="formData.lottery_config_id" :placeholder="$t('page.form.placeholderLotteryConfigId')" />
<el-input v-model="formData.lottery_config_id" :placeholder="$t('page.form.placeholderLotteryConfigId')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.drawType')" prop="lottery_type">
<el-select
@@ -17,19 +17,46 @@
:placeholder="$t('form.placeholderSelect')"
clearable
style="width: 100%"
disabled
>
<el-option :label="$t('page.search.paid')" :value="0" />
<el-option :label="$t('page.search.free')" :value="1" />
</el-select>
</el-form-item>
<el-form-item :label="$t('page.search.direction')" prop="direction">
<el-select v-model="formData.direction" :placeholder="$t('form.placeholderSelect')" clearable style="width: 100%">
<el-select
v-model="formData.direction"
:placeholder="$t('form.placeholderSelect')"
clearable
style="width: 100%"
disabled
>
<el-option :label="$t('page.search.clockwise')" :value="0" />
<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%"
disabled
/>
</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%"
disabled
/>
</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-select v-model="formData.is_win" :placeholder="$t('form.placeholderSelect')" clearable style="width: 100%" disabled>
<el-option :label="$t('page.search.noBigWin')" :value="0" />
<el-option :label="$t('page.search.bigWin')" :value="1" />
</el-select>
@@ -38,9 +65,10 @@
<el-input-number
v-model="formData.win_coin"
:placeholder="$t('page.form.placeholderWinCoin')"
:precision="2"
:precision="0"
controls-position="right"
style="width: 100%"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.search.rewardTier')" prop="reward_tier">
@@ -49,59 +77,63 @@
:placeholder="$t('page.form.placeholderRewardTier')"
clearable
style="width: 100%"
@change="onRewardTierChange"
disabled
>
<el-option label="T1" value="T1" />
<el-option label="T2" value="T2" />
<el-option label="T3" value="T3" />
<el-option label="T4" value="T4" />
<el-option label="T5" value="T5" />
<el-option label="BIGWIN" value="BIGWIN" />
</el-select>
</el-form-item>
<el-form-item :label="$t('page.form.rewardConfigId')" prop="reward_config_id">
<el-input
v-model="formData.reward_config_id"
:placeholder="$t('page.form.placeholderRewardConfigId')"
/>
</el-form-item>
<el-form-item :label="$t('page.table.startIndex')" prop="start_index">
<el-input v-model="formData.start_index" :placeholder="$t('page.form.placeholderStartIndex')" />
<el-input v-model="formData.start_index" :placeholder="$t('page.form.placeholderStartIndex')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.labelTargetIndex')" prop="target_index">
<el-input v-model="formData.target_index" :placeholder="$t('page.form.placeholderTargetIndex')" />
<el-input v-model="formData.target_index" :placeholder="$t('page.form.placeholderTargetIndex')" disabled />
</el-form-item>
<el-form-item :label="$t('page.search.rollNumber')" prop="roll_number">
<el-input v-model="formData.roll_number" :placeholder="$t('page.form.placeholderRollNumber')" />
<el-input v-model="formData.roll_number" :placeholder="$t('page.form.placeholderRollNumber')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.labelRollArray')" prop="roll_array">
<el-input v-model="formData.roll_array" :placeholder="$t('page.form.placeholderRollArray')" />
<el-input v-model="formData.roll_array" :placeholder="$t('page.form.placeholderRollArray')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.labelStatus')" prop="status">
<sa-radio v-model="formData.status" dict="data_status" />
<sa-radio v-model="formData.status" dict="data_status" disabled />
</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%"
disabled
/>
</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%"
disabled
/>
</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')" />
<el-input v-model="formData.admin_id" :placeholder="$t('page.form.placeholderAdminId')" disabled />
</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>
<el-button @click="handleClose">{{ $t('form.close') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/play_record_test/index'
import rewardConfigApi from '../../../api/reward_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import type { FormInstance } from 'element-plus'
interface Props {
modelValue: boolean
@@ -116,12 +148,11 @@
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
dialogType: 'edit',
data: undefined
})
const emit = defineEmits<Emits>()
const { t } = useI18n()
const formRef = ref<FormInstance>()
@@ -133,18 +164,6 @@
set: (value) => emit('update:modelValue', value)
})
/**
* 表单验证规则
*/
const rules = computed<FormRules>(() => ({
lottery_config_id: [{ required: true, message: t('page.form.ruleLotteryConfigIdRequired'), trigger: 'blur' }],
lottery_type: [{ required: true, message: t('page.form.ruleDrawTypeRequired'), trigger: 'blur' }],
is_win: [{ required: true, message: t('page.form.ruleIsBigWinRequired'), trigger: 'blur' }],
direction: [{ required: true, message: t('page.form.ruleDirectionRequired'), trigger: 'blur' }],
reward_config_id: [{ required: true, message: t('page.form.ruleRewardConfigIdRequired'), trigger: 'blur' }],
status: [{ required: true, message: t('page.form.ruleStatusRequired'), trigger: 'blur' }]
}))
/**
* 初始数据
*/
@@ -153,17 +172,18 @@
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,
reward_config_id: null,
start_index: null,
target_index: null,
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
}
@@ -173,7 +193,7 @@
const formData = reactive({ ...initialFormData })
/**
* 监听弹窗打开,初始化表单数据
* 监听弹窗打开,初始化表单数据(仅查看)
*/
watch(
() => props.modelValue,
@@ -188,9 +208,7 @@
* 初始化页面数据
*/
const initPage = async () => {
// 先重置为初始值
Object.assign(formData, initialFormData)
// 如果有数据,则填充数据
if (props.data) {
await nextTick()
initForm()
@@ -198,75 +216,33 @@
}
/**
* 初始化表单数据
* 回填表单数据
*/
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) {
if (key === 'reward_tier') continue
if (props.data[key] != null && props.data[key] !== undefined) {
;(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)
}
}
/**
* 中奖档位变更:按档位拉取奖励配置并取第一条的 id 填入 reward_config_id
*/
async function onRewardTierChange(tier: string) {
if (!tier) {
formData.reward_config_id = null
return
}
try {
const res = await rewardConfigApi.list({
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])
if (first && first.id != null) {
formData.reward_config_id = first.id
} else {
formData.reward_config_id = null
}
} catch {
formData.reward_config_id = null
}
}
/**
* 关闭弹窗并重置表单
* 关闭弹窗
*/
const handleClose = () => {
visible.value = false
formRef.value?.resetFields()
}
/**
* 提交表单
*/
const handleSubmit = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
const payload = { ...formData }
delete (payload as Record<string, unknown>).reward_tier
if (props.dialogType === 'add') {
await api.save(payload)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(payload)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log('表单验证失败:', error)
}
}
</script>

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"
/>
@@ -61,6 +95,7 @@
<el-option label="T3" value="T3" />
<el-option label="T4" value="T4" />
<el-option label="T5" value="T5" />
<el-option label="BIGWIN" value="BIGWIN" />
</el-select>
</el-form-item>
</el-col>

View File

@@ -64,7 +64,14 @@
</template>
<!-- 操作 -->
<template #operation="{ row }">
<div class="flex gap-2">
<div class="flex items-center justify-center gap-1">
<SaButton
v-permission="'dice:player:index:getGameUrl'"
type="success"
icon="ri:links-line"
:tool-tip="$t('page.table.getGameLink')"
@click="handleGetGameUrl(row)"
/>
<SaButton
v-permission="'dice:player:index:update'"
type="secondary"
@@ -98,13 +105,20 @@
</template>
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { useClipboard } from '@vueuse/core'
import { useI18n } from 'vue-i18n'
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/player/index'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
import WalletOperateDialog from './modules/WalletOperateDialog.vue'
const { t } = useI18n()
const { copy } = useClipboard()
// 搜索表单
const searchForm = ref({
username: undefined,
@@ -129,7 +143,8 @@
// 根据 lottery_config_id 显示彩金池配置名称
const lotteryConfigNameFormatter = (row: any) =>
row?.diceLotteryPoolConfig?.name ?? (row?.lottery_config_id ? `#${row.lottery_config_id}` : '未知')
row?.diceLotteryPoolConfig?.name ??
(row?.lottery_config_id ? `#${row.lottery_config_id}` : t('page.table.customConfig'))
// 表格
const {
@@ -163,7 +178,7 @@
{
prop: 'coin',
label: 'page.table.coin',
width: 100,
width: 110,
align: 'center',
useSlot: true
},
@@ -217,7 +232,7 @@
{
prop: 'operation',
label: 'table.actions.operation',
width: 100,
width: 132,
align: 'center',
fixed: 'right',
useSlot: true
@@ -230,7 +245,7 @@
const handleStatusChange = async (row: Record<string, any>, status: number) => {
row._statusLoading = true
try {
await api.updateStatus({ id: row.id, status })
await api.updateStatus(withChannelDeptParams({ id: row.id, status }))
row.status = status
} catch {
refreshData()
@@ -264,4 +279,21 @@
}
walletDialogVisible.value = true
}
async function handleGetGameUrl(row: Record<string, any>) {
try {
const res = await api.getGameUrl({ id: row.id })
const url =
typeof res?.url === 'string' ? res.url : typeof res?.data?.url === 'string' ? res.data.url : ''
if (!url) {
ElMessage.warning(t('page.table.getGameLinkFail'))
return
}
await copy(url)
ElMessage.success(t('page.table.getGameLinkSuccess'))
} catch (e: any) {
const msg = typeof e?.message === 'string' && e.message !== '' ? e.message : t('page.table.getGameLinkFail')
ElMessage.warning(msg)
}
}
</script>

View File

@@ -59,6 +59,7 @@
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
@@ -157,12 +158,14 @@
return
}
submitting.value = true
await walletRecordApi.adminOperate({
player_id: props.player.id,
type: formData.type!,
coin,
remark: formData.remark?.trim() || undefined
})
await walletRecordApi.adminOperate(
withChannelDeptParams({
player_id: props.player.id,
type: formData.type!,
coin,
remark: formData.remark?.trim() || undefined
})
)
ElMessage.success(t('page.form.operateSuccess'))
emit('success')
handleClose()

View File

@@ -35,7 +35,20 @@
<sa-switch v-model="formData.status" />
</el-form-item>
<el-form-item :label="$t('page.form.adminId')" prop="admin_id">
<el-tree-select
v-if="useAdminTreeSelect"
v-model="formData.admin_id"
:data="systemUserTreeOptions"
:props="systemUserTreeProps"
:placeholder="$t('page.form.placeholderAdminTree')"
clearable
filterable
check-strictly
style="width: 100%"
:loading="systemUserOptionsLoading"
/>
<el-select
v-else
v-model="formData.admin_id"
:placeholder="$t('page.form.placeholderAdmin')"
clearable
@@ -172,6 +185,8 @@
import api from '../../../api/player/index'
import lotteryConfigApi from '../../../api/lottery_pool_config/index'
import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams, withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { isSuperAdminUser } from '@/utils/channelLayout'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
@@ -222,16 +237,18 @@
/** 新增时密码必填,编辑时选填 */
const passwordRules = computed(() =>
props.dialogType === 'add' ? [{ required: true, message: '密码必需填写', trigger: 'blur' }] : []
props.dialogType === 'add'
? [{ required: true, message: t('page.form.rulePasswordRequired'), trigger: 'blur' }]
: []
)
const rules = reactive<FormRules>({
username: [{ required: true, message: '用户名必需填写', trigger: 'blur' }],
name: [{ required: true, message: '昵称必需填写', trigger: 'blur' }],
phone: [{ required: true, message: '手机号必需填写', trigger: 'blur' }],
status: [{ required: true, message: '状态必需填写', trigger: 'blur' }],
coin: [{ required: true, message: '平台币必需填写', trigger: 'blur' }]
})
const rules = computed<FormRules>(() => ({
username: [{ required: true, message: t('page.form.ruleUsernameRequired'), trigger: 'blur' }],
name: [{ required: true, message: t('page.form.ruleNicknameRequired'), trigger: 'blur' }],
phone: [{ required: true, message: t('page.form.rulePhoneRequired'), trigger: 'blur' }],
status: [{ required: true, message: t('page.form.ruleStatusRequired'), trigger: 'blur' }],
coin: [{ required: true, message: t('page.form.ruleCoinRequired'), trigger: 'blur' }]
}))
const initialFormData = {
id: null as number | null,
@@ -262,6 +279,22 @@
const systemUserOptions = ref<
Array<{ id: number; username: string; realname: string; label: string }>
>([])
/** 超管:按渠道分组的管理员树 */
const systemUserTreeOptions = ref<
Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
>([])
const useAdminTreeSelect = computed(() => isSuperAdminUser())
const systemUserTreeProps = {
label: 'label',
value: 'id',
children: 'children',
disabled: 'disabled'
}
/** 管理员选项加载中 */
const systemUserOptionsLoading = ref(false)
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
@@ -269,9 +302,9 @@
function lotteryConfigTypeText(name: unknown): string {
const n = String(name ?? '')
if (n === 'default') return '默认'
if (n === 'killScore') return '杀分'
if (n === 'up') return '上分'
if (n === 'default') return t('page.form.configTypeDefault')
if (n === 'killScore') return t('page.form.configTypeKillScore')
if (n === 'up') return t('page.form.configTypeUp')
return n || '-'
}
@@ -335,12 +368,43 @@
}
/** 加载后台管理员选项 */
function normalizeAdminTreeLabels(
nodes: Array<{
id: number | string
label: string
disabled?: boolean
children?: Array<{ id: number; username: string; realname: string; label: string }>
}>
) {
return nodes.map((node) => {
const item = { ...node }
if (item.label === '__unassigned__') {
item.label = t('page.form.unassignedChannel')
}
if (item.children?.length) {
item.children = item.children.map((child) => ({
...child,
label: child.label || child.username || `#${child.id}`
}))
}
return item
})
}
async function loadSystemUserOptions() {
systemUserOptionsLoading.value = true
try {
systemUserOptions.value = await api.getSystemUserOptions()
if (useAdminTreeSelect.value) {
const tree = await api.getSystemUserTreeOptions(getChannelDeptRequestParams())
systemUserTreeOptions.value = normalizeAdminTreeLabels(tree)
systemUserOptions.value = []
} else {
systemUserOptions.value = await api.getSystemUserOptions(getChannelDeptRequestParams())
systemUserTreeOptions.value = []
}
} catch {
systemUserOptions.value = []
systemUserTreeOptions.value = []
} finally {
systemUserOptionsLoading.value = false
}
@@ -363,7 +427,7 @@
async function loadLotteryConfigOptions() {
lotteryConfigLoading.value = true
try {
lotteryConfigOptions.value = await api.getLotteryConfigOptions()
lotteryConfigOptions.value = await api.getLotteryConfigOptions(getChannelDeptRequestParams())
} catch {
lotteryConfigOptions.value = []
} finally {
@@ -376,6 +440,7 @@
'status',
'coin',
'lottery_config_id',
'admin_id',
't1_weight',
't2_weight',
't3_weight',
@@ -397,7 +462,7 @@
;(formData as any)[key] = val != null ? Number(val) || null : null
} else if (key === 'lottery_config_id' || key === 'admin_id') {
const num = Number(val)
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null
;(formData as any)[key] = val != null && !Number.isNaN(num) && num > 0 ? num : null
} else {
;(formData as any)[key] = Number(val) || 0
}
@@ -429,10 +494,10 @@
delete (payload as any).password
}
if (props.dialogType === 'add') {
await api.save(payload)
await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(payload)
await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')

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

@@ -1,13 +1,13 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
:title="$t('page.form.dialogTitleEdit')"
width="600px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form ref="formRef" :model="formData" label-width="120px">
<el-form-item :label="$t('page.form.player')" prop="player_id">
<el-select
v-model="formData.player_id"
@@ -15,7 +15,7 @@
clearable
filterable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option
v-for="item in playerOptions"
@@ -30,7 +30,7 @@
v-model="formData.use_coins"
:placeholder="$t('page.form.placeholderUseCoins')"
:min="0"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.paidDrawCount')" prop="paid_ticket_count">
@@ -38,8 +38,7 @@
v-model="formData.paid_ticket_count"
:placeholder="$t('page.form.placeholderPaidDrawCount')"
:min="0"
@change="onTicketCountChange"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.freeDrawCount')" prop="free_ticket_count">
@@ -47,8 +46,7 @@
v-model="formData.free_ticket_count"
:placeholder="$t('page.form.placeholderFreeDrawCount')"
:min="0"
@change="onTicketCountChange"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.totalDrawCount')" prop="total_ticket_count">
@@ -68,24 +66,20 @@
maxlength="500"
show-word-limit
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
/>
</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>
<el-button @click="handleClose">{{ $t('form.close') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/player_ticket_record/index'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
const { t } = useI18n()
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
import type { FormInstance } from 'element-plus'
interface Props {
modelValue: boolean
@@ -100,7 +94,7 @@
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
dialogType: 'edit',
data: undefined
})
@@ -116,17 +110,6 @@
set: (value) => emit('update:modelValue', value)
})
/**
* 表单验证规则
*/
const rules = reactive<FormRules>({
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
use_coins: [{ required: true, message: '消耗硬币必需填写', trigger: 'blur' }],
paid_ticket_count: [{ required: true, message: '购买抽奖次数必需填写', trigger: 'blur' }],
free_ticket_count: [{ required: true, message: '赠送抽奖次数必需填写', trigger: 'blur' }],
remark: [{ required: true, message: '备注必需填写', trigger: 'blur' }]
})
/** 玩家下拉选项id、username */
const playerOptions = ref<Array<{ id: number; username: string }>>([])
@@ -137,10 +120,6 @@
return paid + free
})
function onTicketCountChange() {
formData.total_ticket_count = totalTicketCountComputed.value
}
/**
* 初始数据
*/
@@ -160,7 +139,7 @@
const formData = reactive({ ...initialFormData })
/**
* 监听弹窗打开,初始化表单并拉取玩家选项(与 player_wallet_record 一致)
* 监听弹窗打开,初始化表单并拉取玩家选项
*/
watch(
() => props.modelValue,
@@ -168,7 +147,7 @@
if (open) {
initPage()
try {
const list = await api.getPlayerOptions()
const list = await api.getPlayerOptions(getChannelDeptRequestParams())
const arr = Array.isArray(list) ? list : (list as any)?.data
playerOptions.value = Array.isArray(arr)
? (arr as Array<{ id: number; username: string }>)
@@ -181,7 +160,7 @@
)
/**
* 初始化页面数据(仅重置表单、回填编辑数据,不在此处请求玩家列表)
* 初始化页面数据
*/
const initPage = async () => {
Object.assign(formData, { ...initialFormData })
@@ -192,7 +171,7 @@
}
/**
* 初始化表单数据
* 回填表单数据
*/
const initForm = () => {
if (!props.data) return
@@ -214,34 +193,10 @@
}
/**
* 关闭弹窗并重置表单
* 关闭弹窗
*/
const handleClose = () => {
visible.value = false
formRef.value?.resetFields()
}
/**
* 提交表单total_ticket_count 由 paid_ticket_count + free_ticket_count 自动求和,提交前写入)
*/
const handleSubmit = async () => {
if (!formRef.value) return
try {
formData.total_ticket_count = totalTicketCountComputed.value
await formRef.value.validate()
if (props.dialogType === 'add') {
const rest = { ...formData } as Record<string, unknown>
delete rest.id
await api.save(rest)
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

@@ -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

@@ -7,6 +7,11 @@
<!-- 表格头部 -->
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<span v-if="totalCoinChange !== null" class="table-summary-inline">
{{ $t('page.toolbar.coinChangeSummary') }}<strong :class="coinSummaryClass">{{
formatMoney2(totalCoinChange)
}}</strong>
</span>
<!-- <ElSpace wrap>-->
<!-- <ElButton-->
<!-- v-permission="'dice:player_wallet_record:index:save'"-->
@@ -83,6 +88,7 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useTable } from '@/hooks/core/useTable'
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/player_wallet_record/index'
import TableSearch from './modules/table-search.vue'
@@ -97,15 +103,55 @@
create_time: undefined as [string, string] | undefined
})
// 搜索处理:将 create_time 区间转为 create_time_min / create_time_max
const handleSearch = (params: Record<string, any>) => {
/** 当前筛选条件下平台币变化合计 */
const totalCoinChange = ref<number | null>(null)
const coinSummaryClass = computed(() => {
if (totalCoinChange.value === null) return ''
if (totalCoinChange.value > 0) return 'coin-summary-positive'
if (totalCoinChange.value < 0) return 'coin-summary-negative'
return ''
})
const WALLET_SEARCH_KEYS = [
'type',
'username',
'coin_min',
'coin_max',
'create_time_min',
'create_time_max'
] as const
let summaryRequestSeq = 0
const listApi = async (params: Record<string, any>) => {
const reqId = ++summaryRequestSeq
const res = await api.list(params)
if (reqId === summaryRequestSeq) {
const summary = (res as Record<string, unknown> | undefined)?.total_coin_change
totalCoinChange.value =
summary !== undefined && summary !== null && summary !== '' ? Number(summary) : null
}
return res
}
const applySearchParams = (params: Record<string, any>) => {
const p = { ...params }
if (Array.isArray(p.create_time) && p.create_time.length === 2) {
p.create_time_min = p.create_time[0]
p.create_time_max = p.create_time[1]
}
delete p.create_time
const paramsRecord = searchParams as Record<string, unknown>
WALLET_SEARCH_KEYS.forEach((key) => {
delete paramsRecord[key]
})
Object.assign(searchParams, p)
}
// 搜索处理:将 create_time 区间转为 create_time_min / create_time_max
const handleSearch = (params: Record<string, any>) => {
applySearchParams(params)
getData()
}
@@ -146,6 +192,13 @@
return player?.username ?? row.player_id ?? '-'
}
function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return n.toFixed(2)
}
// 表格配置
const {
columns,
@@ -162,8 +215,9 @@
refreshData
} = useTable({
core: {
apiFn: api.list,
apiFn: listApi,
apiParams: { limit: 100 },
excludeParams: ['create_time'],
columnsFactory: () => [
{ type: 'selection', align: 'center' },
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
@@ -190,8 +244,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>) => formatMoney2(row?.wallet_before)
},
{
prop: 'wallet_after',
label: 'page.table.walletAfter',
width: 110,
align: 'center',
formatter: (row: Record<string, any>) => formatMoney2(row?.wallet_after)
},
{
prop: 'remark',
label: 'page.table.remark',
@@ -212,6 +278,25 @@
useSlot: true
}
]
},
hooks: {
onSuccess(_data, response) {
const raw = response as unknown as Record<string, unknown>
const summary = raw?.total_coin_change
if (summary !== undefined && summary !== null && summary !== '') {
totalCoinChange.value = Number(summary)
}
}
},
transform: {
responseAdapter(response) {
const raw = (response ?? {}) as Record<string, unknown>
const base = defaultResponseAdapter(response)
if (raw.total_coin_change !== undefined && raw.total_coin_change !== null) {
;(base as Record<string, unknown>).total_coin_change = raw.total_coin_change
}
return base
}
}
})
@@ -229,6 +314,25 @@
</script>
<style lang="scss" scoped>
.table-summary-inline {
margin-right: 12px;
font-size: 14px;
color: var(--el-text-color-regular);
white-space: nowrap;
}
.table-summary-inline strong {
font-weight: 600;
}
.coin-summary-positive {
color: var(--el-color-success);
}
.coin-summary-negative {
color: var(--el-color-danger);
}
/* 类型 tag 放大一倍large + scale */
:deep(.wallet-record-type-tag) {
transform: scale(0.8);

View File

@@ -1,13 +1,13 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.dialogTitleAdd') : $t('page.form.dialogTitleEdit')"
:title="$t('page.form.dialogTitleEdit')"
width="600px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form ref="formRef" :model="formData" label-width="120px">
<el-form-item :label="$t('page.form.user')" prop="player_id">
<el-select
v-model="formData.player_id"
@@ -15,8 +15,7 @@
clearable
filterable
style="width: 100%"
:disabled="dialogType === 'edit'"
@change="onPlayerChange"
disabled
>
<el-option
v-for="item in playerOptions"
@@ -32,7 +31,7 @@
:placeholder="$t('page.form.placeholderType')"
clearable
style="width: 100%"
:disabled="dialogType === 'edit'"
disabled
>
<el-option :label="$t('page.form.typeRecharge')" :value="0" />
<el-option :label="$t('page.form.typeWithdraw')" :value="1" />
@@ -46,9 +45,9 @@
v-model="formData.coin"
:placeholder="$t('page.form.placeholderCoinChange')"
:precision="2"
:step="1"
style="width: 100%"
@change="onCoinChange"
:disabled="dialogType === 'edit'"
disabled
/>
</el-form-item>
<el-form-item :label="$t('page.form.walletBefore')" prop="wallet_before">
@@ -77,24 +76,20 @@
:placeholder="$t('page.form.placeholderRemark')"
maxlength="500"
show-word-limit
:disabled="dialogType === 'edit'"
disabled
/>
</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>
<el-button @click="handleClose">{{ $t('form.close') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/player_wallet_record/index'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
const { t } = useI18n()
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
import type { FormInstance } from 'element-plus'
interface Props {
modelValue: boolean
@@ -109,7 +104,7 @@
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
dialogType: 'edit',
data: undefined
})
@@ -125,61 +120,33 @@
set: (value) => emit('update:modelValue', value)
})
const rules = reactive<FormRules>({
player_id: [{ required: true, message: '请选择用户', trigger: 'change' }],
coin: [{ required: true, message: '平台币变化必填', trigger: 'blur' }],
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 })
/** 选择用户后拉取当前平台币作为钱包操作前 */
async function onPlayerChange(playerId: number | null) {
if (playerId == null) {
formData.wallet_before = 0
calcWalletAfter()
return
}
try {
const res = await api.getPlayerWalletBefore(playerId)
const before = res?.wallet_before ?? 0
formData.wallet_before = Number(before)
calcWalletAfter()
} catch {
formData.wallet_before = 0
calcWalletAfter()
}
}
/** 平台币变化时重算钱包操作后 */
function onCoinChange() {
calcWalletAfter()
}
/** 钱包操作后 = 钱包操作前 + 平台币变化 */
function calcWalletAfter() {
const before = Number(formData.wallet_before) || 0
const coin = Number(formData.coin) || 0
formData.wallet_after = Math.round((before + coin) * 100) / 100
}
watch(
() => props.modelValue,
async (open) => {
if (open) {
initPage()
try {
const list = await api.getPlayerOptions()
const list = await api.getPlayerOptions(getChannelDeptRequestParams())
playerOptions.value = Array.isArray(list) ? list : []
} catch {
playerOptions.value = []
@@ -196,47 +163,28 @@
}
}
const numKeys = ['id', 'player_id', 'coin', 'type', 'wallet_before', 'wallet_after']
function normalizeMoney2(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 Number(n.toFixed(2))
}
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 = normalizeMoney2(props.data.coin, 0)
formData.wallet_before = normalizeMoney2(props.data.wallet_before, 0)
formData.wallet_after = normalizeMoney2(props.data.wallet_after, 0)
formData.remark = props.data.remark ?? ''
}
const handleClose = () => {
visible.value = false
formRef.value?.resetFields()
}
const handleSubmit = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
calcWalletAfter()
const payload = { ...formData }
if (props.dialogType === 'add') {
await api.save(payload)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(payload)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
handleClose()
} catch (error) {
console.log('表单验证失败:', error)
}
}
</script>

View File

@@ -46,17 +46,25 @@
</ElCard>
<WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" />
<WeightTestDialog v-model="weightTestVisible" @success="refreshData" />
<WeightTestDialog
v-model="weightTestVisible"
:channel-dept-id="channelDeptId"
@success="refreshData"
/>
</div>
</template>
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useInjectedChannelDept } from '@/composables/useChannelDeptScope'
import api from '../../api/reward/index'
import TableSearch from './modules/table-search.vue'
import WeightRatioDialog from './modules/weight-ratio-dialog.vue'
import WeightTestDialog from './modules/weight-test-dialog.vue'
const channelScope = useInjectedChannelDept()
const channelDeptId = computed(() => channelScope?.selectedDeptId.value)
const currentDirection = ref<0 | 1>(0)
const weightRatioVisible = ref(false)
const weightTestVisible = ref(false)
@@ -70,6 +78,13 @@
return api.list({ ...params, direction: currentDirection.value })
}
function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return n.toFixed(2)
}
const handleSearch = (params: Record<string, any>) => {
Object.assign(searchParams, { ...params, direction: currentDirection.value })
getData()
@@ -117,7 +132,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>) => formatMoney2(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>{{ formatMoney2(row?.real_ev) }}</span>
</template>
</el-table-column>
<el-table-column
:label="$t('page.weightShared.colUiText')"
prop="ui_text"
@@ -250,7 +254,15 @@
import api from '../../../api/reward/index'
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus'
function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return n.toFixed(2)
}
import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
@@ -436,7 +448,7 @@
function loadData() {
loading.value = true
api
.weightRatioListWithDirection()
.weightRatioListWithDirection(getChannelDeptRequestParams())
.then((res: any) => {
grouped.value = parsePayload(res)
})
@@ -472,7 +484,7 @@
}
submitting.value = true
api
.batchUpdateWeights(items)
.batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => {
ElMessage.success(t('page.weightShared.saveSuccess'))
emit('success')

View File

@@ -54,7 +54,11 @@
width="90"
align="center"
show-overflow-tooltip
/>
>
<template #default="{ row }">
<span>{{ formatMoney2(row?.real_ev) }}</span>
</template>
</el-table-column>
<el-table-column
:label="$t('page.weightShared.colUiText')"
prop="ui_text"
@@ -315,6 +319,14 @@
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return n.toFixed(2)
}
const { t, locale } = useI18n()
@@ -471,7 +483,7 @@
function loadData() {
loading.value = true
api
.weightRatioListWithDirection()
.weightRatioListWithDirection(getChannelDeptRequestParams())
.then((res: any) => {
grouped.value = parsePayload(res)
})
@@ -510,7 +522,7 @@
}
submitting.value = true
api
.batchUpdateWeights(items)
.batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => {
ElMessage.success(t('page.weightShared.saveSuccess'))
emit('success')

View File

@@ -2,161 +2,173 @@
<ElDialog
v-model="visible"
:title="$t('page.weightTest.title')"
width="560px"
width="920px"
top="4vh"
class="weight-test-dialog"
:close-on-click-modal="false"
destroy-on-close
@close="onClose"
>
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip">
<template #title>{{ $t('page.weightTest.alertTitle') }}</template>
{{ $t('page.weightTest.alertBody') }}
</ElAlert>
<ElForm ref="formRef" :model="form" label-width="140px">
<ElSteps :active="currentStep" finish-status="success" simple class="steps-wrap">
<ElStep :title="$t('page.weightTest.stepPaid')" />
<ElStep :title="$t('page.weightTest.stepFree')" />
</ElSteps>
<div class="weight-test-dialog-body">
<ElAlert type="info" :closable="false" show-icon class="weight-test-tip compact-tip">
<div class="tip-lines">
<div>{{ $t('page.weightTest.alertBody') }}</div>
<div>{{ $t('page.weightTest.chainModeHint') }}</div>
<div>{{ $t('page.weightTest.killModeHint') }}</div>
</div>
</ElAlert>
<!-- 第一页付费抽奖券 -->
<div v-show="currentStep === 0" class="step-panel">
<ElFormItem
:label="$t('page.weightTest.labelLotteryTypePaid')"
prop="paid_lottery_config_id"
>
<ElSelect
v-model="form.paid_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderPaidPool')"
clearable
filterable
style="width: 100%"
>
<ElOption
v-for="item in paidLotteryOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</ElSelect>
</ElFormItem>
<template v-if="form.paid_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
<ElRow :gutter="12" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
<div class="tier-field">
<label class="tier-field-label">{{
$t('page.weightTest.tierFieldLabel', { tier: t })
}}</label>
<input
type="number"
:value="getPaidTier(t)"
min="0"
max="100"
placeholder="0"
class="tier-input"
@input="setPaidTier(t, $event)"
<ElForm :model="form" label-width="108px" class="weight-test-form">
<ElRow :gutter="16">
<ElCol :span="8">
<ElFormItem :label="$t('page.weightTest.labelAnte')" prop="ante_config_id" required>
<ElSelect
v-model="form.ante_config_id"
:placeholder="$t('page.weightTest.placeholderAnte')"
filterable
style="width: 100%"
@change="syncAnteFromSelect"
>
<ElOption
v-for="item in anteOptions"
:key="item.id"
:label="anteOptionLabel(item)"
:value="item.id"
/>
</div>
</ElCol>
</ElRow>
<div v-if="paidTierSum > 100" class="tier-error">{{
$t('page.weightTest.tierSumError', { sum: paidTierSum })
}}</div>
</template>
<ElFormItem :label="$t('page.weightTest.labelCwCount')" prop="paid_s_count" required>
<ElSelect
v-model="form.paid_s_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
<ElFormItem :label="$t('page.weightTest.labelCcwCount')" prop="paid_n_count" required>
<ElSelect
v-model="form.paid_n_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
</div>
</ElSelect>
</ElFormItem>
</ElCol>
<ElCol :span="8">
<ElFormItem :label="$t('page.weightTest.labelKillModeEnabled')" prop="kill_mode_enabled">
<ElSwitch v-model="form.kill_mode_enabled" />
</ElFormItem>
</ElCol>
<ElCol :span="8">
<ElFormItem :label="$t('page.weightTest.labelTestSafetyLine')" prop="test_safety_line">
<ElInputNumber
v-model="form.test_safety_line"
:min="0"
:step="100"
:disabled="!form.kill_mode_enabled"
controls-position="right"
style="width: 100%"
/>
</ElFormItem>
</ElCol>
</ElRow>
<!-- 第二页免费抽奖券 -->
<div v-show="currentStep === 1" class="step-panel">
<ElFormItem
:label="$t('page.weightTest.labelLotteryTypeFree')"
prop="free_lottery_config_id"
>
<ElSelect
v-model="form.free_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderFreePool')"
clearable
filterable
style="width: 100%"
>
<ElOption
v-for="item in freeLotteryOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</ElSelect>
</ElFormItem>
<template v-if="form.free_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
<ElRow :gutter="12" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
<div class="tier-field">
<label class="tier-field-label">{{
$t('page.weightTest.tierFieldLabel', { tier: t })
}}</label>
<input
type="number"
:value="getFreeTier(t)"
min="0"
max="100"
placeholder="0"
class="tier-input"
@input="setFreeTier(t, $event)"
<ElRow :gutter="20" class="section-row">
<ElCol :span="12">
<div class="section-title">{{ $t('page.weightTest.sectionPaid') }}</div>
<ElFormItem :label="$t('page.weightTest.labelLotteryTypePaid')" prop="paid_lottery_config_id">
<ElSelect
v-model="form.paid_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderPaidPool')"
clearable
filterable
style="width: 100%"
>
<ElOption
v-for="item in paidLotteryOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</div>
</ElCol>
</ElRow>
<div v-if="freeTierSum > 100" class="tier-error">{{
$t('page.weightTest.tierSumError', { sum: freeTierSum })
}}</div>
</template>
<ElFormItem :label="$t('page.weightTest.labelCwCount')" prop="free_s_count" required>
<ElSelect
v-model="form.free_s_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
<ElFormItem :label="$t('page.weightTest.labelCcwCount')" prop="free_n_count" required>
<ElSelect
v-model="form.free_n_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
</div>
</ElForm>
</ElSelect>
</ElFormItem>
<template v-if="form.paid_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHint') }}</div>
<ElRow :gutter="8" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'paid-' + t" :span="8">
<div class="tier-field">
<label class="tier-field-label">{{
$t('page.weightTest.tierFieldLabel', { tier: t })
}}</label>
<input
type="number"
:value="getPaidTier(t)"
min="0"
max="100"
placeholder="0"
class="tier-input"
@input="setPaidTier(t, $event)"
/>
</div>
</ElCol>
</ElRow>
<div v-if="paidTierSum > 100" class="tier-error">{{
$t('page.weightTest.tierSumError', { sum: paidTierSum })
}}</div>
</template>
<ElFormItem :label="$t('page.weightTest.labelCwCount')" prop="paid_s_count" required>
<ElSelect
v-model="form.paid_s_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
<ElFormItem :label="$t('page.weightTest.labelCcwCount')" prop="paid_n_count" required>
<ElSelect
v-model="form.paid_n_count"
:placeholder="$t('page.weightTest.placeholderSelect')"
style="width: 100%"
>
<ElOption v-for="c in countOptions" :key="'n-' + c" :label="String(c)" :value="c" />
</ElSelect>
</ElFormItem>
</ElCol>
<ElCol :span="12">
<div class="section-title">{{ $t('page.weightTest.sectionFreeAfterPlayAgain') }}</div>
<ElFormItem :label="$t('page.weightTest.labelLotteryTypeFree')" prop="free_lottery_config_id">
<ElSelect
v-model="form.free_lottery_config_id"
:placeholder="$t('page.weightTest.placeholderFreePool')"
clearable
filterable
style="width: 100%"
>
<ElOption
v-for="item in freeLotteryOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</ElSelect>
</ElFormItem>
<template v-if="form.free_lottery_config_id == null">
<div class="tier-label">{{ $t('page.weightTest.tierProbHintFreeChain') }}</div>
<ElRow :gutter="8" class="tier-row">
<ElCol v-for="t in tierKeys" :key="'free-' + t" :span="8">
<div class="tier-field">
<label class="tier-field-label">{{
$t('page.weightTest.tierFieldLabel', { tier: t })
}}</label>
<input
type="number"
:value="getFreeTier(t)"
min="0"
max="100"
placeholder="0"
class="tier-input"
@input="setFreeTier(t, $event)"
/>
</div>
</ElCol>
</ElRow>
<div v-if="freeTierSum > 100" class="tier-error">{{
$t('page.weightTest.tierSumError', { sum: freeTierSum })
}}</div>
</template>
</ElCol>
</ElRow>
</ElForm>
</div>
<template #footer>
<ElButton v-if="currentStep > 0" :disabled="running" @click="currentStep--">{{
$t('page.weightTest.btnPrev')
}}</ElButton>
<ElButton v-if="currentStep < 1" type="primary" :disabled="running" @click="currentStep++">{{
$t('page.weightTest.btnNext')
}}</ElButton>
<ElButton
v-if="currentStep === 1"
v-permission="'dice:reward:index:startWeightTest'"
type="primary"
:loading="running"
@@ -172,11 +184,23 @@
<script setup lang="ts">
import api from '../../../api/reward/index'
import anteConfigApi from '../../../api/ante_config/index'
import lotteryPoolApi from '../../../api/lottery_pool_config/index'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
import {
getChannelDeptRequestParams,
useInjectedChannelDept,
withChannelDeptParams
} from '@/composables/useChannelDeptScope'
const props = defineProps<{
/** 父页面渠道栏选中值(弹窗 teleport 后 inject 可能失效) */
channelDeptId?: number
}>()
const { t } = useI18n()
const channelScope = useInjectedChannelDept()
const countOptions = [0, 100, 500, 1000, 5000]
const tierKeys = ['T1', 'T2', 'T3', 'T4', 'T5'] as const
@@ -184,24 +208,26 @@
const visible = defineModel<boolean>({ default: false })
const emit = defineEmits<{ (e: 'success'): void }>()
const formRef = ref()
const currentStep = ref(0)
const anteOptions = ref<
Array<{ id: number; name: string; title: string; mult: number; is_default: number }>
>([])
const form = reactive({
ante: 1,
ante_config_id: undefined as number | undefined,
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>,
free_tier_weights: { T1: 20, T2: 20, T3: 20, T4: 20, T5: 20 } as Record<string, number>,
paid_s_count: 100,
paid_n_count: 100,
free_s_count: 100,
free_n_count: 100
kill_mode_enabled: false,
test_safety_line: 5000
})
const lotteryOptions = ref<Array<{ id: number; name: string }>>([])
/** 付费抽奖券可选档位name=default */
const paidLotteryOptions = computed(() =>
lotteryOptions.value.filter((r) => r.name === 'default')
)
/** 免费抽奖券可选档位:优先 name=killScore若无则显示全部以便下拉有选项 */
const freeLotteryOptions = computed(() => {
const list = lotteryOptions.value.filter((r) => r.name === 'killScore')
return list.length > 0 ? list : lotteryOptions.value
@@ -210,7 +236,6 @@
function onClose() {
running.value = false
currentStep.value = 0
}
function getPaidTier(t: string): string {
@@ -244,19 +269,69 @@
tierKeys.reduce((s, t) => s + (form.free_tier_weights[t] ?? 0), 0)
)
function resolveDeptParams(): { dept_id?: number } {
if (props.channelDeptId !== undefined && props.channelDeptId !== null) {
return { dept_id: props.channelDeptId }
}
const extra = getChannelDeptRequestParams()
if (extra.dept_id !== undefined) {
return extra
}
if (channelScope) {
return { dept_id: channelScope.selectedDeptId.value }
}
return {}
}
function resolveSubmitDeptId(): number | undefined {
const params = resolveDeptParams()
if (params.dept_id !== undefined) {
return params.dept_id
}
return undefined
}
function anteOptionLabel(item: { name: string; title: string; mult: number }): string {
const label = (item.title || item.name || '').trim()
return label ? `${label} (×${item.mult})` : `×${item.mult}`
}
function syncAnteFromSelect() {
const opt = anteOptions.value.find((o) => o.id === form.ante_config_id)
if (opt) {
form.ante = opt.mult
}
}
async function loadAnteOptions() {
try {
const list = await anteConfigApi.getOptions(resolveDeptParams())
anteOptions.value = list
const def = list.find((i) => i.is_default === 1) ?? list[0]
if (def) {
form.ante_config_id = def.id
form.ante = def.mult
} else {
form.ante_config_id = undefined
form.ante = 1
}
} catch {
anteOptions.value = []
form.ante_config_id = undefined
}
}
async function loadLotteryOptions() {
try {
const list = await lotteryPoolApi.getOptions()
const list = await lotteryPoolApi.getOptions(resolveDeptParams())
lotteryOptions.value = list.map((r: { id: number; name: string }) => ({
id: r.id,
name: r.name
}))
// 付费抽奖券默认使用 name=default
const normal = list.find((r: { name?: string }) => r.name === 'default')
if (normal) {
form.paid_lottery_config_id = normal.id
}
// 免费抽奖券默认使用 name=killScore若无则默认选第一项
const kill = list.find((r: { name?: string }) => r.name === 'killScore')
if (kill) {
form.free_lottery_config_id = kill.id
@@ -270,10 +345,15 @@
function buildPayload() {
const payload: Record<string, unknown> = {
ante: form.ante,
ante_config_id: form.ante_config_id,
paid_s_count: form.paid_s_count,
paid_n_count: form.paid_n_count,
free_s_count: form.free_s_count,
free_n_count: form.free_n_count
free_s_count: 0,
free_n_count: 0,
chain_free_mode: true,
kill_mode_enabled: form.kill_mode_enabled,
test_safety_line: form.test_safety_line
}
if (form.paid_lottery_config_id != null) {
payload.paid_lottery_config_id = form.paid_lottery_config_id
@@ -289,8 +369,21 @@
}
function validateForm(): boolean {
if (form.paid_s_count + form.paid_n_count + form.free_s_count + form.free_n_count <= 0) {
ElMessage.warning(t('page.weightTest.warnTotalSpins'))
if (form.ante_config_id == null || form.ante_config_id <= 0) {
ElMessage.warning(t('page.weightTest.warnAnte'))
return false
}
syncAnteFromSelect()
if (form.ante == null || form.ante <= 0) {
ElMessage.warning(t('page.weightTest.warnAnte'))
return false
}
if (form.paid_s_count + form.paid_n_count <= 0) {
ElMessage.warning(t('page.weightTest.warnPaidSpins'))
return false
}
if (form.kill_mode_enabled && (form.test_safety_line == null || form.test_safety_line < 0)) {
ElMessage.warning(t('page.weightTest.warnTestSafetyLine'))
return false
}
const needPaidTier = form.paid_lottery_config_id == null
@@ -324,7 +417,12 @@
if (!validateForm()) return
running.value = true
try {
await api.startWeightTest(buildPayload())
const payload = buildPayload()
const deptId = resolveSubmitDeptId()
if (deptId !== undefined) {
payload.dept_id = deptId
}
await api.startWeightTest(withChannelDeptParams(payload))
ElMessage.success(t('page.weightTest.successCreated'))
visible.value = false
emit('success')
@@ -337,79 +435,122 @@
watch(visible, (v) => {
if (v) {
loadLotteryOptions()
void loadAnteOptions()
void loadLotteryOptions()
} else {
onClose()
}
})
// 切换到免费步骤时,若当前选中 id 不在免费档位列表中,则重置为第一个 killScore 的选项,避免显示错误
watch(currentStep, (step) => {
if (step === 1) {
const freeOpts = freeLotteryOptions.value
const id = form.free_lottery_config_id
if (freeOpts.length && (id == null || !freeOpts.some((o) => o.id === id))) {
form.free_lottery_config_id = freeOpts[0].id
watch(
() => props.channelDeptId ?? channelScope?.selectedDeptId.value,
() => {
if (visible.value) {
void loadAnteOptions()
void loadLotteryOptions()
}
}
})
)
</script>
<style lang="scss" scoped>
.weight-test-tip {
margin-bottom: 16px;
.weight-test-dialog-body {
max-height: calc(100vh - 168px);
overflow: visible;
}
.steps-wrap {
margin-bottom: 16px;
.compact-tip {
margin-bottom: 12px;
:deep(.el-alert__content) {
line-height: 1.45;
}
}
.step-panel {
min-height: 200px;
.tip-lines {
font-size: 12px;
color: var(--el-text-color-regular);
div + div {
margin-top: 4px;
}
}
.tier-label {
.weight-test-form {
:deep(.el-form-item) {
margin-bottom: 12px;
}
}
.section-row {
margin-top: 4px;
}
.section-title {
font-size: 13px;
font-weight: 600;
color: var(--el-text-color-primary);
margin: 0 0 10px;
padding-bottom: 4px;
border-bottom: 1px solid var(--el-border-color-lighter);
}
.tier-label {
font-size: 12px;
color: var(--el-text-color-secondary);
margin-bottom: 6px;
}
.tier-row {
margin-bottom: 8px;
}
.tier-row {
margin-bottom: 12px;
}
.tier-field {
margin-bottom: 12px;
margin-bottom: 6px;
}
.tier-field-label {
display: block;
font-size: 14px;
font-size: 12px;
color: var(--el-text-color-regular);
margin-bottom: 4px;
line-height: 1.5;
margin-bottom: 2px;
line-height: 1.4;
}
.tier-input {
display: block;
width: 100%;
padding: 8px 12px;
font-size: 14px;
line-height: 1.5;
padding: 4px 8px;
font-size: 13px;
line-height: 1.4;
color: var(--el-text-color-regular);
background-color: var(--el-fill-color-blank);
border: 1px solid var(--el-border-color);
border-radius: var(--el-border-radius-base);
box-sizing: border-box;
}
.tier-input:hover {
border-color: var(--el-border-color-hover);
}
.tier-input:focus {
outline: none;
border-color: var(--el-color-primary);
box-shadow: 0 0 0 2px var(--el-color-primary-light-7);
}
.tier-input::placeholder {
color: var(--el-text-color-placeholder);
}
.tier-error {
font-size: 12px;
color: var(--el-color-danger);
margin-top: 4px;
margin-bottom: 8px;
margin-bottom: 6px;
}
</style>
<style lang="scss">
.weight-test-dialog.el-dialog {
margin-bottom: 4vh;
}
.weight-test-dialog .el-dialog__body {
padding-top: 12px;
padding-bottom: 8px;
}
</style>

View File

@@ -1,6 +1,6 @@
<template>
<div class="art-full-height reward-config-form">
<ElCard shadow="never" class="form-card">
<div class="reward-config-form flex-1 min-h-0 flex flex-col">
<ElCard shadow="never" class="form-card flex-1 min-h-0 flex flex-col">
<template #header>
<div class="card-header">
<span>{{ $t('page.toolbar.gameRewardConfig') }}</span>
@@ -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"
@@ -29,12 +39,21 @@
size="default"
class="config-table"
>
<ElTableColumn :label="$t('page.configPage.colId')" prop="id" width="60" align="center">
<ElTableColumn
:label="$t('page.configPage.colId')"
prop="id"
width="60"
align="center"
>
<template #default="{ row }">
<span>{{ row.id }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colDicePoints')" min-width="100" align="center">
<ElTableColumn
:label="$t('page.configPage.colDicePoints')"
min-width="100"
align="center"
>
<template #default="{ row }">
<ElInputNumber
v-model="row.grid_number"
@@ -46,7 +65,11 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colDisplayText')" min-width="100" align="center">
<ElTableColumn
:label="$t('page.configPage.colDisplayText')"
min-width="100"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.ui_text"
@@ -55,7 +78,11 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colDisplayTextEn')" min-width="120" align="center">
<ElTableColumn
:label="$t('page.configPage.colDisplayTextEn')"
min-width="120"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.ui_text_en"
@@ -64,16 +91,31 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colRealEv')" min-width="110" align="center">
<ElTableColumn
:label="$t('page.configPage.colRealEv')"
min-width="110"
align="center"
>
<template #default="{ row }">
<ElInputNumber
v-model="row.real_ev"
@change="handleRealEvChange(row)"
controls-position="right"
size="small"
:step="1"
class="full-width"
/>
</template>
</ElTableColumn>
<ElTableColumn
:label="$t('page.configPage.colRealReward')"
min-width="130"
align="center"
>
<template #default="{ row }">
<span>{{ formatMoney2(calcRealReward(row.real_ev)) }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colTier')" width="100" align="center">
<template #default="{ row }">
<ElSelect
@@ -91,7 +133,11 @@
</ElSelect>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colRemark')" min-width="140" align="center">
<ElTableColumn
:label="$t('page.configPage.colRemark')"
min-width="140"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.remark"
@@ -125,12 +171,20 @@
size="default"
class="config-table bigwin-table"
>
<ElTableColumn :label="$t('page.configPage.colBigwinPoints')" width="100" align="center">
<ElTableColumn
:label="$t('page.configPage.colBigwinPoints')"
width="100"
align="center"
>
<template #default="{ row }">
<span class="readonly-value">{{ row.grid_number }}</span>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colDisplayInfo')" min-width="140" align="center">
<ElTableColumn
:label="$t('page.configPage.colDisplayInfo')"
min-width="140"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.ui_text"
@@ -139,7 +193,11 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colDisplayInfoEn')" min-width="160" align="center">
<ElTableColumn
:label="$t('page.configPage.colDisplayInfoEn')"
min-width="160"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.ui_text_en"
@@ -148,17 +206,27 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colRealPrize')" min-width="120" align="center">
<ElTableColumn
:label="$t('page.configPage.colRealPrize')"
min-width="120"
align="center"
>
<template #default="{ row }">
<ElInputNumber
v-model="row.real_ev"
@change="handleRealEvChange(row)"
controls-position="right"
size="small"
:step="1"
class="full-width"
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colRemark')" min-width="140" align="center">
<ElTableColumn
:label="$t('page.configPage.colRemark')"
min-width="140"
align="center"
>
<template #default="{ row }">
<ElInput
v-model="row.remark"
@@ -167,7 +235,11 @@
/>
</template>
</ElTableColumn>
<ElTableColumn :label="$t('page.configPage.colWeightRange')" min-width="220" align="center">
<ElTableColumn
:label="$t('page.configPage.colWeightRange')"
min-width="220"
align="center"
>
<template #default="{ row }">
<div class="weight-cell">
<ElSlider
@@ -212,16 +284,200 @@
</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 {
DEFAULT_CHANNEL_ID,
getChannelDeptRequestParams,
useChannelDeptReload,
useInjectedChannelDept
} from '@/composables/useChannelDeptScope'
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
@@ -234,11 +490,42 @@
weight: number
}
const channelScope = useInjectedChannelDept()
const filterDeptId = computed(() => {
const scopedId = channelScope?.selectedDeptId.value
if (scopedId !== undefined && scopedId !== null) {
if (scopedId > 0 || channelScope?.showDefaultTemplate.value) {
return scopedId
}
}
const extra = getChannelDeptRequestParams()
if (extra.dept_id !== undefined) {
return extra.dept_id
}
return DEFAULT_CHANNEL_ID
})
const activeTab = ref<'index' | 'bigwin'>('index')
const loading = ref(false)
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
/** 第一页数据(来自 api.list即 DiceRewardConfig 表) */
const indexRows = ref<IndexRow[]>([])
@@ -249,6 +536,15 @@
/** 原始 list 快照,用于重置 */
let indexRowsSnapshot: IndexRow[] = []
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
}
function toWeight(v: unknown): number {
const n = typeof v === 'number' && !Number.isNaN(v) ? v : Number(v)
if (Number.isNaN(n)) return 0
@@ -268,6 +564,31 @@
}
}
function calcRealReward(realEv: unknown): number {
const n = typeof realEv === 'number' && !Number.isNaN(realEv) ? realEv : Number(realEv)
if (Number.isNaN(n)) {
return -1
}
return n - 1
}
function handleRealEvChange(row: IndexRow) {
const n =
typeof row.real_ev === 'number' && !Number.isNaN(row.real_ev)
? row.real_ev
: Number(row.real_ev)
const text = Number.isNaN(n) ? '' : Number(n).toFixed(2)
row.ui_text = text
row.ui_text_en = text
}
function formatMoney2(val: unknown): string {
if (val === '' || val === null || val === undefined) return '-'
const n = typeof val === 'number' ? val : Number(val)
if (!Number.isFinite(n)) return '-'
return n.toFixed(2)
}
async function handleCreateRewardReference() {
try {
await ElMessageBox.confirm(
@@ -284,7 +605,7 @@
}
createRewardLoading.value = true
try {
const res: any = await api.createRewardReference()
const res: any = await api.createRewardReference({ dept_id: filterDeptId.value as number })
const data = res?.data ?? res
let msg = t('page.configPage.createRefSuccessSimple')
if (typeof data === 'object' && data !== null) {
@@ -308,15 +629,28 @@
}
}
function extractIndexList(res: unknown): Record<string, unknown>[] {
if (Array.isArray(res)) {
return res as Record<string, unknown>[]
}
if (res && typeof res === 'object') {
const obj = res as Record<string, unknown>
if (Array.isArray(obj.data)) {
return obj.data as Record<string, unknown>[]
}
if (Array.isArray(obj.records)) {
return obj.records as Record<string, unknown>[]
}
}
return []
}
function loadIndexList() {
loading.value = true
return api
.list({ limit: 200 })
.then((res: any) => {
const list = res?.data?.records ?? res?.records ?? res?.data ?? []
const rows = Array.isArray(list)
? list.map((r: Record<string, unknown>) => normalizeIndexRow(r))
: []
.list({ saiType: 'all', limit: 200, dept_id: filterDeptId.value })
.then((res: unknown) => {
const rows = extractIndexList(res).map((r) => normalizeIndexRow(r))
indexRows.value = rows
indexRowsSnapshot = rows.map((r) => ({ ...r }))
})
@@ -328,6 +662,17 @@
})
}
/** 挂载时拉数;超管切换左侧渠道时重新拉数 */
useChannelDeptReload(loadIndexList)
watch(
() => filterDeptId.value,
(deptId, prev) => {
if (deptId !== prev) {
loadIndexList()
}
}
)
function isBigwinWeightDisabled(row: IndexRow): boolean {
return row.grid_number === 5 || row.grid_number === 30
}
@@ -349,8 +694,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 +715,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, { dept_id: filterDeptId.value })
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()
@@ -389,7 +899,7 @@
tier: r.tier,
remark: r.remark
}))
await api.batchUpdate(indexPayload)
await api.batchUpdate(indexPayload, { dept_id: filterDeptId.value })
ElMessage.success(t('page.configPage.saveSuccess'))
indexRowsSnapshot = indexRows.value.map((r) => ({ ...r }))
} catch (e: any) {
@@ -450,14 +960,14 @@
tier: r.tier,
remark: r.remark
}))
await api.batchUpdate(batchPayload)
await api.batchUpdate(batchPayload, { dept_id: filterDeptId.value })
const weightItems = rows.map((r) => ({
grid_number: r.grid_number,
weight: isBigwinWeightDisabled(r)
? 10000
: Math.max(0, Math.min(10000, Math.floor(r.weight)))
}))
await api.saveBigwinWeightsByGrid(weightItems)
await api.saveBigwinWeightsByGrid(weightItems, { dept_id: filterDeptId.value })
ElMessage.success(t('page.configPage.saveSuccess'))
loadIndexList()
} catch (e: any) {
@@ -473,9 +983,6 @@
ElMessage.info(t('page.configPage.resetBigwinReloaded'))
}
onMounted(() => {
loadIndexList()
})
</script>
<style lang="scss" scoped>
@@ -551,6 +1058,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

@@ -22,7 +22,11 @@
<el-input v-model="formData.ui_text_en" :placeholder="$t('page.form.placeholderUiTextEn')" />
</el-form-item>
<el-form-item :label="$t('page.form.labelRealEv')" prop="real_ev">
<el-input-number v-model="formData.real_ev" :placeholder="$t('page.form.placeholderRealEv')" />
<el-input-number
v-model="formData.real_ev"
:placeholder="$t('page.form.placeholderRealEv')"
@change="handleRealEvChange"
/>
</el-form-item>
<el-form-item :label="$t('page.form.labelTier')" prop="tier">
<el-select
@@ -79,6 +83,7 @@
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
interface Props {
modelValue: boolean
@@ -225,10 +230,10 @@
delete payload.weight
}
if (props.dialogType === 'add') {
await api.save(payload)
await api.save(withChannelDeptParams(payload))
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(payload)
await api.update(withChannelDeptParams(payload))
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')
@@ -237,6 +242,16 @@
console.log('表单验证失败:', error)
}
}
const handleRealEvChange = () => {
const n =
typeof formData.real_ev === 'number' && !Number.isNaN(formData.real_ev)
? formData.real_ev
: Number(formData.real_ev)
const text = Number.isNaN(n) ? '' : String(n)
formData.ui_text = text
formData.ui_text_en = text
}
</script>
<style lang="scss" scoped>

View File

@@ -173,6 +173,7 @@
import ArtBarChart from '@/components/core/charts/art-bar-chart/index.vue'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { getChannelDeptRequestParams } from '@/composables/useChannelDeptScope'
const { t } = useI18n()
@@ -360,7 +361,7 @@
function loadData() {
api
.weightRatioList()
.weightRatioList(getChannelDeptRequestParams())
.then((res: any) => {
grouped.value = parseWeightRatioPayload(res)
})
@@ -393,7 +394,7 @@
}
submitting.value = true
api
.batchUpdateWeights(items)
.batchUpdateWeights(items, getChannelDeptRequestParams())
.then(() => {
ElMessage.success(t('page.weightRatio.saveSuccess'))
emit('success')

View File

@@ -0,0 +1,426 @@
/**
* 按与后端 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
}
/** 默认标准(与规则弹窗说明一致) */
export const DEFAULT_TIER_REAL_EV_STANDARDS: TierRealEvStandards = {
T1: 3,
T2: 1.5,
T3: 0.5,
T4: -0.4,
T5: 0
}
/**
* 校验档位与 real_ev 区间是否一致;通过返回 null否则返回 i18n 键名(不含 page.configPage. 前缀)
*/
export function validateTierRealEvStandards(s: TierRealEvStandards): string | null {
if (!Number.isFinite(s.T1) || !(s.T1 > 2)) {
return 'ruleGenInvalidT1RealEv'
}
if (!Number.isFinite(s.T2) || !(s.T2 > 1 && s.T2 < 2)) {
return 'ruleGenInvalidT2RealEv'
}
if (!Number.isFinite(s.T3) || !(s.T3 > 0 && s.T3 < 1)) {
return 'ruleGenInvalidT3RealEv'
}
if (!Number.isFinite(s.T4) || !(s.T4 < 0)) {
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 下限后重试' }
}
function uiTextByTierWhenStandards(
tier: IndexTier,
realEv: number
): { ui_text: string; ui_text_en: string } {
if (tier === 'T5') {
return { ui_text: '再来一次', ui_text_en: 'Once again' }
}
const value = Number.isFinite(realEv) ? realEv.toFixed(2) : String(realEv)
return { ui_text: value, ui_text_en: value }
}
/** 展示文案:直接使用真实结算值(中英文相同) */
function uiTextFromRealEv(realEv: number): { ui_text: string; ui_text_en: string } {
const value = Number.isFinite(realEv) ? realEv.toFixed(2) : String(realEv)
return { ui_text: value, ui_text_en: value }
}
/**
* 按 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 = uiTextByTierWhenStandards(tier, 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 = uiTextByTierWhenStandards(tier, 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 = uiTextByTierWhenStandards(tier, 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 = uiTextByTierWhenStandards(tier, real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '惩罚'
} else {
real_ev = standards.T5
const f = uiTextByTierWhenStandards(tier, real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '前端需要在播放一次动画(特殊)'
}
} else if (tier === 'T1') {
real_ev = 101 + ((id * 17 + grid_number * 3) % 398)
if (real_ev >= 500) {
real_ev = 498
}
const f = uiTextFromRealEv(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 = uiTextFromRealEv(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 = uiTextFromRealEv(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 = uiTextFromRealEv(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
remark = '惩罚'
} else {
real_ev = 0
const f = uiTextFromRealEv(real_ev)
ui_text = f.ui_text
ui_text_en = f.ui_text_en
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

@@ -40,19 +40,18 @@
<template #status="{ row }">
<span>{{ formatStatus(row.status) }}</span>
</template>
<!-- 付费抽取顺时针逆时针抽取次数兼容旧数据用 s_count/n_count -->
<!-- 付费抽取顺时针逆时针抽取次数 -->
<template #paid_draw="{ row }">
<span
>{{ $t('page.table.clockwiseAbbr') }} {{ getPaidS(row) }} /
{{ $t('page.table.counterclockwiseAbbr') }} {{ getPaidN(row) }}</span
>
</template>
<!-- 免费抽取顺时针逆时针抽取次数 -->
<template #free_draw="{ row }">
<span
>{{ $t('page.table.clockwiseAbbr') }} {{ row.free_s_count ?? 0 }} /
{{ $t('page.table.counterclockwiseAbbr') }} {{ row.free_n_count ?? 0 }}</span
>
<template #chain_mode="{ row }">
<span>{{ formatChainMode(row) }}</span>
</template>
<template #total_draw="{ row }">
<span>{{ formatTotalDraw(row) }}</span>
</template>
<!-- 平台赚取金额 -->
<template #platform_profit="{ row }">
@@ -136,16 +135,12 @@
return t('page.detail.dash')
}
// 付费抽取次数(兼容旧数据:无 paid_s_count 时用 s_count
// 付费抽取次数
function getPaidS(row: Record<string, any>): number {
const v = row.paid_s_count
if (v !== undefined && v !== null && (Number(v) || 0) > 0) return Number(v)
return Number(row.s_count ?? 0)
return Number(row.paid_s_count ?? 0)
}
function getPaidN(row: Record<string, any>): number {
const v = row.paid_n_count
if (v !== undefined && v !== null && (Number(v) || 0) > 0) return Number(v)
return Number(row.n_count ?? 0)
return Number(row.paid_n_count ?? 0)
}
// 平台赚取金额展示(未完成或空显示 —)
@@ -154,7 +149,32 @@
if (v === null || v === undefined || v === '') return dash
const n = Number(v)
if (Number.isNaN(n)) return dash
return String(n)
return n.toFixed(2)
}
/** 链式再来一次1=是新库字段JSON 旧数据用 tier_weights_snapshot.chain_free_mode */
function formatChainMode(row: Record<string, any>): string {
const v = row.chain_free_mode
if (v === 1 || v === '1' || v === true) return t('page.table.chainModeYes')
const snap = row.tier_weights_snapshot
if (snap && typeof snap === 'object' && (snap as { chain_free_mode?: boolean }).chain_free_mode) {
return t('page.table.chainModeYes')
}
return t('page.table.chainModeNo')
}
/** 总抽奖次数:仅完成态写最终值;测试中显示已完成次数 */
function formatTotalDraw(row: Record<string, any>): string {
const status = Number(row.status)
const done = Number(row.total_play_count ?? 0)
const over = Number(row.over_play_count ?? 0)
if (status === 1) {
return String(done)
}
if (status === -1) {
return over > 0 ? t('page.table.progressFailed', { over }) : t('page.detail.dash')
}
return t('page.table.progressDraws', { over })
}
// 表格配置
@@ -193,12 +213,30 @@
useSlot: true
},
{
prop: 'free_draw',
label: 'page.table.freeDraw',
width: 160,
prop: 'chain_mode',
label: 'page.table.chainMode',
width: 110,
align: 'center',
useSlot: true
},
{
prop: 'paid_planned_spins',
label: 'page.table.paidPlannedSpins',
width: 120,
align: 'center'
},
{
prop: 'ante',
label: 'page.table.ante',
width: 90,
align: 'center'
},
{
prop: 'play_again_count',
label: 'page.table.playAgainCount',
width: 120,
align: 'center'
},
{
prop: 'platform_profit',
label: 'page.table.platformProfit',
@@ -206,7 +244,13 @@
align: 'center',
useSlot: true
},
{ prop: 'total_play_count', label: 'page.table.totalDrawCount', width: 110, align: 'center' },
{
prop: 'total_draw',
label: 'page.table.totalDrawCount',
width: 140,
align: 'center',
useSlot: true
},
{
prop: 'admin_name',
label: 'page.table.createdBy',
@@ -214,6 +258,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

@@ -14,9 +14,15 @@
<el-descriptions-item :label="$t('page.detail.recordId')">
{{ record.id }}
</el-descriptions-item>
<el-descriptions-item :label="$t('page.detail.testCount')"
>{{ record.test_count }}{{ $t('page.detail.testCountSuffix') }}</el-descriptions-item
>
<el-descriptions-item :label="$t('page.detail.chainModeLabel')">
{{ formatChainModeDetail(record) }}
</el-descriptions-item>
<el-descriptions-item :label="$t('page.detail.paidPlannedSpins')">
{{ record.paid_planned_spins ?? $t('page.detail.dash') }}
</el-descriptions-item>
<el-descriptions-item :label="$t('page.detail.testCount')">
{{ formatTestCountDisplay(record) }}
</el-descriptions-item>
<el-descriptions-item :label="$t('page.detail.createTime')">
{{ record.create_time || $t('page.detail.dash') }}
</el-descriptions-item>
@@ -231,6 +237,11 @@
interface RecordRow {
id?: number
test_count?: number
total_play_count?: number
status?: number
over_play_count?: number
chain_free_mode?: number | boolean | string
paid_planned_spins?: number
create_time?: string
admin_id?: number | null
admin_name?: string
@@ -238,7 +249,6 @@
paid_lottery_config_id?: number | null
free_lottery_config_id?: number | null
bigwin_weight?: Record<string, number> | Array<[number, number]> | null
// 新结构:{ paid: {T1..T5}, free: {T1..T5} },兼容旧结构直接是 {T1..T5}
tier_weights_snapshot?:
| {
paid?: Record<string, number>
@@ -257,6 +267,32 @@
result_counts?: Record<string, number>
}
function formatChainModeDetail(record: RecordRow | null): string {
if (!record) return t('page.detail.dash')
const v = record.chain_free_mode
if (v === 1 || v === '1' || v === true) return t('page.table.chainModeYes')
const snap = record.tier_weights_snapshot
if (snap && typeof snap === 'object' && (snap as { chain_free_mode?: boolean }).chain_free_mode) {
return t('page.table.chainModeYes')
}
return t('page.table.chainModeNo')
}
function formatTestCountDisplay(record: RecordRow | null): string {
if (!record) return t('page.detail.dash')
const status = Number(record.status)
if (status === 1) {
const n = record.test_count ?? record.total_play_count
return `${n ?? 0}${t('page.detail.testCountSuffix')}`
}
if (status === -1) {
const over = Number(record.over_play_count ?? 0)
return over > 0 ? t('page.detail.testCountFailed', { over }) : t('page.detail.dash')
}
const over = Number(record.over_play_count ?? 0)
return t('page.detail.testCountProgress', { over })
}
interface Props {
modelValue: boolean
record: RecordRow | null

View File

@@ -1,35 +1,31 @@
<template>
<el-dialog
v-model="visible"
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
:title="$t('page.form.titleEdit')"
width="600px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form ref="formRef" :model="formData" label-width="120px">
<el-form-item :label="$t('page.form.labelTestCount')" prop="test_count">
<el-input v-model="formData.test_count" :placeholder="$t('page.form.placeholderTestCount')" />
<el-input v-model="formData.test_count" :placeholder="$t('page.form.placeholderTestCount')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.labelWeightSnapshot')" prop="weight_config_snapshot">
<el-input v-model="formData.weight_config_snapshot" :placeholder="$t('page.form.placeholderWeightSnapshot')" />
<el-input v-model="formData.weight_config_snapshot" :placeholder="$t('page.form.placeholderWeightSnapshot')" disabled />
</el-form-item>
<el-form-item :label="$t('page.form.labelResultCounts')" prop="result_counts">
<el-input v-model="formData.result_counts" :placeholder="$t('page.form.placeholderResultCounts')" />
<el-input v-model="formData.result_counts" :placeholder="$t('page.form.placeholderResultCounts')" disabled />
</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>
<el-button @click="handleClose">{{ $t('form.close') }}</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '../../../api/reward_config_record/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
import type { FormInstance } from 'element-plus'
interface Props {
modelValue: boolean
@@ -44,12 +40,11 @@
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
dialogType: 'add',
dialogType: 'edit',
data: undefined
})
const emit = defineEmits<Emits>()
const { t } = useI18n()
const formRef = ref<FormInstance>()
@@ -61,13 +56,6 @@
set: (value) => emit('update:modelValue', value)
})
/**
* 表单验证规则
*/
const rules = computed<FormRules>(() => ({
test_count: [{ required: true, message: t('page.form.ruleTestCountRequired'), trigger: 'blur' }]
}))
/**
* 初始数据
*/
@@ -75,7 +63,7 @@
id: null,
test_count: 100,
weight_config_snapshot: '',
result_counts: '',
result_counts: ''
}
/**
@@ -84,7 +72,7 @@
const formData = reactive({ ...initialFormData })
/**
* 监听弹窗打开,初始化表单数据
* 监听弹窗打开,初始化表单数据(仅查看)
*/
watch(
() => props.modelValue,
@@ -99,9 +87,7 @@
* 初始化页面数据
*/
const initPage = async () => {
// 先重置为初始值
Object.assign(formData, initialFormData)
// 如果有数据,则填充数据
if (props.data) {
await nextTick()
initForm()
@@ -109,7 +95,7 @@
}
/**
* 初始化表单数据
* 回填表单数据
*/
const initForm = () => {
if (props.data) {
@@ -122,31 +108,10 @@
}
/**
* 关闭弹窗并重置表单
* 关闭弹窗
*/
const handleClose = () => {
visible.value = false
formRef.value?.resetFields()
}
/**
* 提交表单
*/
const handleSubmit = async () => {
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

@@ -8,6 +8,32 @@
@search="handleSearch"
@expand="handleExpand"
>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.paidPlannedSpins')" prop="paid_planned_spins">
<el-input-number
v-model="formData.paid_planned_spins"
:placeholder="$t('table.searchBar.all')"
:min="0"
: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.ante')" prop="ante">
<el-input-number
v-model="formData.ante"
:placeholder="$t('table.searchBar.all')"
:min="1"
:precision="0"
:step="1"
controls-position="right"
style="width: 100%"
/>
</el-form-item>
</el-col>
</sa-search-bar>
</template>

View File

@@ -143,6 +143,7 @@
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useTerminalStore, TaskStatus } from '../store/terminal'
import { $t } from '@/locales'
const emit = defineEmits<{
(e: 'success'): void
@@ -157,51 +158,51 @@
}
const webBuild = () => {
ElMessageBox.confirm('确认重新打包前端并发布项目吗?', '前端打包发布', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('uiMsg.saipackageWebBuildConfirm'), $t('uiMsg.saipackageWebBuildTitle'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
terminal.addNodeTask('web-build', '', () => {
ElMessage.success('前端打包发布成功')
ElMessage.success($t('uiMsg.saipackageWebBuildSuccess'))
})
})
}
const handleFronted = () => {
ElMessageBox.confirm('确认更新前端Node依赖吗', '前端依赖更新', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('uiMsg.saipackageFrontendDepsConfirm'), $t('uiMsg.saipackageFrontendDepsTitle'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
terminal.addNodeTask('web-install', '', () => {
ElMessage.success('前端依赖更新成功')
ElMessage.success($t('uiMsg.saipackageFrontendDepsSuccess'))
})
})
}
const handleBackend = () => {
ElMessageBox.confirm('确认更新后端composer包吗', 'composer包更新', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('uiMsg.saipackageComposerConfirm'), $t('uiMsg.saipackageComposerTitle'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
terminal.addTask('composer.update', '', () => {
ElMessage.success('composer包更新成功')
ElMessage.success($t('uiMsg.saipackageComposerSuccess'))
})
})
}
const frontInstall = (extend = '') => {
terminal.addNodeTask('web-install', extend, () => {
ElMessage.success('前端依赖更新成功')
ElMessage.success($t('uiMsg.saipackageFrontendDepsSuccess'))
emit('success')
})
}
const backendInstall = (extend = '') => {
terminal.addTask('composer.update', extend, () => {
ElMessage.success('composer包更新成功')
ElMessage.success($t('uiMsg.saipackageComposerSuccess'))
setTimeout(() => {
emit('success')
}, 500)

View File

@@ -186,6 +186,7 @@
import api from '@/api/safeguard/server'
import { onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
const loading = ref(false)
@@ -219,16 +220,16 @@
*/
const handleClearCache = (tag: string): void => {
if (!tag) {
ElMessage.warning('请选择要清理的缓存')
ElMessage.warning($t('uiMsg.clearCacheSelect'))
return
}
ElMessageBox.confirm(`确定要清理标签:【${tag}】的缓存吗?`, '清理选中缓存', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('uiMsg.clearCacheConfirmByTag', { tag }), $t('uiMsg.clearCacheTitle'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}).then(() => {
api.clear({ tag }).then(() => {
ElMessage.success('操作成功')
ElMessage.success($t('uiMsg.operationSuccess'))
updateCacheInfo()
})
})

View File

@@ -84,7 +84,8 @@
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import { ElMessageBox } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
import api from '@/api/safeguard/database'
import TableSearch from './modules/table-search.vue'
import TableDialog from './modules/table-dialog.vue'
@@ -126,7 +127,12 @@
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'name', label: 'page.table.tableName', minWidth: 200 },
{ prop: 'comment', label: 'page.table.tableComment', minWidth: 150, showOverflowTooltip: true },
{
prop: 'comment',
label: 'page.table.tableComment',
minWidth: 150,
showOverflowTooltip: true
},
{ prop: 'engine', label: 'page.table.tableEngine', width: 120 },
{ prop: 'update_time', label: 'page.table.updateTime', width: 180, sortable: true },
{ prop: 'rows', label: 'page.table.totalRows', width: 120 },
@@ -134,7 +140,13 @@
{ prop: 'data_length', label: 'page.table.dataSize', width: 120 },
{ prop: 'collation', label: 'page.table.collation', width: 180 },
{ prop: 'create_time', label: 'page.table.createTime', width: 180, sortable: true },
{ prop: 'operation', label: 'table.actions.operation', width: 100, fixed: 'right', useSlot: true }
{
prop: 'operation',
label: 'table.actions.operation',
width: 100,
fixed: 'right',
useSlot: true
}
]
}
})
@@ -167,20 +179,20 @@
*/
const handleOptimizeRows = (): void => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请选择要优化的行')
ElMessage.warning($t('page.ui.selectRowsToOptimize'))
return
}
ElMessageBox.confirm(
`确定要优化选中的 ${selectedRows.value.length} 条数据吗?`,
'优化选中数据',
$t('page.ui.optimizeConfirm', { n: selectedRows.value.length }),
$t('page.ui.optimizeTitle'),
{
confirmButtonText: '确定',
cancelButtonText: '取消',
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}
).then(() => {
api.optimize({ tables: selectedRows.value.map((row) => row.name) }).then(() => {
ElMessage.success('操作成功')
ElMessage.success($t('uiMsg.operationSuccess'))
refreshData()
selectedRows.value = []
})
@@ -192,20 +204,20 @@
*/
const handleFragmentRows = (): void => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请选择要清理碎片的行')
ElMessage.warning($t('page.ui.selectRowsToFragment'))
return
}
ElMessageBox.confirm(
`确定要清理选中的 ${selectedRows.value.length} 条数据吗?`,
'清理碎片操作',
$t('page.ui.fragmentConfirm', { n: selectedRows.value.length }),
$t('page.ui.fragmentTitle'),
{
confirmButtonText: '确定',
cancelButtonText: '取消',
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}
).then(() => {
api.fragment({ tables: selectedRows.value.map((row) => row.name) }).then(() => {
ElMessage.success('操作成功')
ElMessage.success($t('uiMsg.operationSuccess'))
refreshData()
selectedRows.value = []
})

View File

@@ -1,10 +1,8 @@
<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>
@@ -14,30 +12,22 @@
</template>
{{ $t('table.actions.add') }}
</ElButton>
<ElButton @click="toggleExpand" v-ripple>
<template #icon>
<ArtSvgIcon v-if="isExpanded" icon="ri:collapse-diagonal-line" />
<ArtSvgIcon v-else icon="ri:expand-diagonal-line" />
</template>
{{ isExpanded ? $t('table.searchBar.collapse') : $t('table.searchBar.expand') }}
<ElButton v-permission="'core:dept:update'" @click="handleSyncConfigs" v-ripple>
补齐渠道配置
</ElButton>
</ElSpace>
</template>
</ArtTableHeader>
<!-- 表格 -->
<ArtTable
ref="tableRef"
rowKey="id"
:loading="loading"
:data="data"
:columns="columns"
:default-expand-all="true"
@sort-change="handleSortChange"
@pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange"
>
<!-- 操作列 -->
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
@@ -48,20 +38,26 @@
<SaButton
v-permission="'core:dept:destroy'"
type="error"
@click="deleteRow(row, api.delete, refreshData)"
@click="openDeleteDialog(row)"
/>
</div>
</template>
</ArtTable>
</ElCard>
<!-- 编辑弹窗 -->
<EditDialog
v-model="dialogVisible"
:dialog-type="dialogType"
:data="dialogData"
@success="refreshData"
/>
<DeleteChannelDialog
v-model="deleteDialogVisible"
:dept-id="deleteDeptId"
:dept-name="deleteDeptName"
@success="refreshData"
/>
</div>
</template>
@@ -69,27 +65,26 @@
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '@/api/system/dept'
import { ElMessage } from 'element-plus'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
import DeleteChannelDialog from './modules/delete-channel-dialog.vue'
// 状态管理
const isExpanded = ref(true)
const tableRef = ref()
// 搜索表单
const searchForm = ref({
name: undefined,
code: undefined,
status: undefined
})
// 搜索处理
const deleteDialogVisible = ref(false)
const deleteDeptId = ref<number | null>(null)
const deleteDeptName = ref('')
const handleSearch = (params: Record<string, any>) => {
Object.assign(searchParams, params)
getData()
}
// 表格配置
const {
columns,
columnChecks,
@@ -118,26 +113,20 @@
}
})
// 编辑配置
const { dialogType, dialogVisible, dialogData, showDialog, deleteRow } = useSaiAdmin()
const { dialogType, dialogVisible, dialogData, showDialog } = useSaiAdmin()
/**
* 切换展开/收起所有菜单
*/
const toggleExpand = (): void => {
isExpanded.value = !isExpanded.value
nextTick(() => {
if (tableRef.value?.elTableRef && data.value) {
const processRows = (rows: any[]) => {
rows.forEach((row) => {
if (row.children?.length) {
tableRef.value.elTableRef.toggleRowExpansion(row, isExpanded.value)
processRows(row.children)
}
})
}
processRows(data.value)
}
})
const openDeleteDialog = (row: any) => {
deleteDeptId.value = row.id
deleteDeptName.value = row.name
deleteDialogVisible.value = true
}
const handleSyncConfigs = async () => {
try {
await api.syncChannelConfigs()
ElMessage.success('已为缺失配置的渠道补齐默认配置')
} catch (e: any) {
ElMessage.error(e?.message || '补齐失败')
}
}
</script>

View File

@@ -0,0 +1,115 @@
<template>
<el-dialog
v-model="visible"
title="删除渠道"
width="560px"
align-center
:close-on-click-modal="false"
@close="handleClose"
>
<div v-loading="loading">
<p class="mb-3 text-sm text-gray-600">确定删除渠道{{ deptName }}可勾选一并删除的关联数据</p>
<el-alert
v-if="preview?.user_count > 0"
type="error"
:closable="false"
class="mb-3"
:title="`该渠道下仍有 ${preview.user_count} 个用户,请先转移或删除用户`"
/>
<el-checkbox-group v-model="checkedTables" class="flex flex-col gap-2">
<el-checkbox
v-for="item in preview?.relations || []"
:key="item.table"
:label="item.table"
:disabled="preview?.user_count > 0"
>
{{ item.label }}{{ item.count }}
</el-checkbox>
</el-checkbox-group>
<p v-if="!preview?.relations?.length" class="text-sm text-gray-500">无关联业务数据仅删除渠道本身</p>
</div>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button
type="danger"
:loading="submitting"
:disabled="preview?.user_count > 0"
@click="handleConfirm"
>
确认删除
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import api from '@/api/system/dept'
import { ElMessage } from 'element-plus'
interface Props {
modelValue: boolean
deptId?: number | null
deptName?: string
}
const props = withDefaults(defineProps<Props>(), {
modelValue: false,
deptId: null,
deptName: ''
})
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void
(e: 'success'): void
}>()
const visible = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v)
})
const loading = ref(false)
const submitting = ref(false)
const preview = ref<any>(null)
const checkedTables = ref<string[]>([])
watch(
() => props.modelValue,
async (open) => {
if (!open || !props.deptId) {
return
}
loading.value = true
checkedTables.value = []
try {
const res: any = await api.destroyPreview(props.deptId)
const list = res?.data ?? res
preview.value = Array.isArray(list) ? list[0] : list
checkedTables.value = (preview.value?.relations || []).map((r: any) => r.table)
} finally {
loading.value = false
}
}
)
const handleClose = () => {
visible.value = false
}
const handleConfirm = async () => {
if (!props.deptId) {
return
}
submitting.value = true
try {
await api.delete({ ids: props.deptId, delete_tables: checkedTables.value })
ElMessage.success('删除成功')
emit('success')
handleClose()
} catch (e: any) {
ElMessage.error(e?.message || '删除失败')
} finally {
submitting.value = false
}
}
</script>

View File

@@ -8,15 +8,6 @@
@close="handleClose"
>
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
<el-form-item :label="$t('page.form.labelParentDept')" prop="parent_id">
<el-tree-select
v-model="formData.parent_id"
:data="optionData.treeData"
:render-after-expand="false"
check-strictly
clearable
/>
</el-form-item>
<el-form-item :label="$t('page.form.labelDeptName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderDeptName')" />
</el-form-item>
@@ -75,36 +66,21 @@
const { t } = useI18n()
const formRef = ref<FormInstance>()
const optionData = reactive({
treeData: <any[]>[]
})
/**
* 弹窗显示状态双向绑定
*/
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
/**
* 表单验证规则
*/
const rules = computed<FormRules>(() => ({
parent_id: [
{ required: true, message: t('page.form.ruleParentDeptRequired'), trigger: 'change' }
],
name: [{ required: true, message: t('page.form.ruleDeptNameRequired'), trigger: 'blur' }],
code: [{ required: true, message: t('page.form.ruleDeptCodeRequired'), trigger: 'blur' }]
}))
/**
* 初始数据
*/
const initialFormData = {
id: null,
parent_id: null,
level: '',
parent_id: 0,
level: '0',
name: '',
code: '',
leader_id: null,
@@ -113,14 +89,8 @@
status: 1
}
/**
* 表单数据
*/
const formData = reactive({ ...initialFormData })
/**
* 监听弹窗打开,初始化表单数据
*/
watch(
() => props.modelValue,
(newVal) => {
@@ -130,33 +100,14 @@
}
)
/**
* 初始化页面数据
*/
const initPage = async () => {
// 先重置为初始值
Object.assign(formData, initialFormData)
const data = await api.list({ tree: true })
optionData.treeData = [
{
id: 0,
value: 0,
label: t('page.form.noParentDept'),
children: data
}
]
// 如果有数据,则填充数据
if (props.data) {
await nextTick()
initForm()
}
}
/**
* 初始化表单数据
*/
const initForm = () => {
if (props.data) {
for (const key in formData) {
@@ -167,21 +118,17 @@
}
}
/**
* 关闭弹窗并重置表单
*/
const handleClose = () => {
visible.value = false
formRef.value?.resetFields()
}
/**
* 提交表单
*/
const handleSubmit = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
formData.parent_id = 0
formData.level = '0'
if (props.dialogType === 'add') {
await api.save(formData)
ElMessage.success(t('page.form.addSuccess'))

View File

@@ -1,77 +0,0 @@
<template>
<sa-search-bar
ref="searchBarRef"
v-model="formData"
label-width="100px"
:showExpand="false"
@reset="handleReset"
@search="handleSearch"
@expand="handleExpand"
>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.postName')" prop="name">
<el-input v-model="formData.name" :placeholder="$t('page.search.placeholderPostName')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.postCode')" prop="code">
<el-input v-model="formData.code" :placeholder="$t('page.search.placeholderPostCode')" clearable />
</el-form-item>
</el-col>
<el-col v-bind="setSpan(6)">
<el-form-item :label="$t('page.search.status')" prop="status">
<sa-select v-model="formData.status" dict="data_status" :placeholder="$t('page.search.searchSelectPlaceholder')" clearable />
</el-form-item>
</el-col>
</sa-search-bar>
</template>
<script setup lang="ts">
interface Props {
modelValue: Record<string, any>
}
interface Emits {
(e: 'update:modelValue', value: Record<string, any>): void
(e: 'search', params: Record<string, any>): void
(e: 'reset'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
// 展开/收起
const isExpanded = ref<boolean>(false)
// 表单数据双向绑定
const searchBarRef = ref()
const formData = computed({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val)
})
// 重置
function handleReset() {
searchBarRef.value?.ref.resetFields()
emit('reset')
}
// 搜索
async function handleSearch() {
emit('search', formData.value)
}
// 展开/收起
function handleExpand(expanded: boolean) {
isExpanded.value = expanded
}
// 栅格占据的列数
const setSpan = (span: number) => {
return {
span: span,
xs: 24, // 手机:满宽显示
sm: span >= 12 ? span : 12, // 平板大于等于12保持否则用半宽
md: span >= 8 ? span : 8, // 中等屏幕大于等于8保持否则用三分之一宽
lg: span,
xl: span
}
}
</script>

View File

@@ -41,6 +41,7 @@
<script setup lang="ts">
import api from '@/api/system/role'
import { withChannelDeptParams } from '@/composables/useChannelDeptScope'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { useI18n } from 'vue-i18n'
@@ -155,11 +156,12 @@
if (!formRef.value) return
try {
await formRef.value.validate()
const payload = withChannelDeptParams({ ...formData })
if (props.dialogType === 'add') {
await api.save(formData)
await api.save(payload)
ElMessage.success(t('page.form.addSuccess'))
} else {
await api.update(formData)
await api.update(payload)
ElMessage.success(t('page.form.editSuccess'))
}
emit('success')

View File

@@ -1,16 +1,24 @@
<template>
<div class="art-full-height">
<div class="box-border flex gap-4 h-full max-md:block max-md:gap-0 max-md:h-auto">
<div class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5">
<ElCard class="tree-card art-card-xs flex flex-col h-full mt-0" shadow="never">
<div
v-show="showChannelSidebar"
class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5"
>
<ElCard
class="tree-card art-card-xs flex flex-col h-full mt-0"
shadow="never"
v-loading="channelTreeLoading"
>
<template #header>
<b>部门列表</b>
<b>{{ $t('page.ui.channelList') }}</b>
</template>
<ElScrollbar>
<ElTree
:data="treeData"
:props="{ children: 'children', label: 'label' }"
node-key="id"
:current-node-key="currentChannelId"
default-expand-all
highlight-current
@node-click="handleNodeClick"
@@ -129,16 +137,26 @@
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import { useUserStore } from '@/store/modules/user'
import { ElMessageBox } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
import WorkDialog from './modules/work-dialog.vue'
import api from '@/api/system/user'
import deptApi from '@/api/system/dept'
import { isSuperAdminUser } from '@/utils/channelLayout'
const userStore = useUserStore()
const treeData = ref([])
interface ChannelTreeNode {
id: number
label: string
children?: ChannelTreeNode[]
}
const treeData = ref<ChannelTreeNode[]>([])
const channelTreeLoading = ref(false)
const currentChannelId = ref<number | undefined>(undefined)
// 编辑框
const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange, deleteRow } =
@@ -227,24 +245,79 @@
const handleReset = () => {
searchForm.value.dept_id = undefined
resetSearchParams()
if (isSuperAdminUser()) {
currentChannelId.value = undefined
} else {
applyDefaultChannelSelection()
}
}
/**
* 切换部门
* @param data
*/
const handleNodeClick = (data: any) => {
const handleNodeClick = (data: ChannelTreeNode) => {
currentChannelId.value = data.id
searchParams.dept_id = data.id
getData()
}
/** 仅超管显示左侧渠道列表;渠道管理员固定本渠道,由后端过滤 */
const showChannelSidebar = computed(() => isSuperAdminUser())
const normalizeChannelTree = (list: unknown[]): ChannelTreeNode[] => {
if (!Array.isArray(list)) {
return []
}
return list
.map((item) => {
const row = item as Record<string, unknown>
const id = Number(row.id ?? row.value ?? 0)
const label = String(row.label ?? row.name ?? '')
return { id, label }
})
.filter((node) => node.id > 0 && node.label !== '')
}
const fallbackChannelTree = (): ChannelTreeNode[] => {
const dept = userStore.info?.department
if (!dept || Number(dept.id) <= 0) {
return []
}
return [
{
id: Number(dept.id),
label: String(dept.name ?? '')
}
]
}
const applyDefaultChannelSelection = () => {
if (treeData.value.length === 0 || isSuperAdminUser()) {
return
}
const first = treeData.value[0]
currentChannelId.value = first.id
searchParams.dept_id = first.id
getData()
}
/**
* 获取部门数据
* 获取可操作渠道(渠道管理员至少展示本渠道)
*/
const getDeptList = () => {
deptApi.accessDept().then((data: any) => {
treeData.value = data
})
const getDeptList = async () => {
channelTreeLoading.value = true
try {
const data = await deptApi.accessDept()
const nodes = normalizeChannelTree(Array.isArray(data) ? data : [])
treeData.value = nodes.length > 0 ? nodes : fallbackChannelTree()
applyDefaultChannelSelection()
} catch {
treeData.value = fallbackChannelTree()
applyDefaultChannelSelection()
} finally {
channelTreeLoading.value = false
}
}
/**
@@ -252,15 +325,15 @@
* @param row
*/
const handlePassword = (row: any) => {
ElMessageBox.prompt('请输入新密码', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.prompt($t('page.ui.promptNewPassword'), $t('uiMsg.titlePrompt'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
inputPattern: /^.{6,16}$/,
inputErrorMessage: '密码长度在6到16之间',
inputErrorMessage: $t('page.ui.passwordLengthError'),
type: 'warning'
}).then(({ value }) => {
api.changePassword({ id: row.id, password: value }).then(() => {
ElMessage.success('修改密码成功')
ElMessage.success($t('page.ui.passwordChanged'))
})
})
}
@@ -270,18 +343,22 @@
* @param row
*/
const handleCache = (row: any) => {
ElMessageBox.confirm('确定要清理缓存吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('page.ui.clearCacheConfirm'), $t('uiMsg.titlePrompt'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
api.clearCache({ id: row.id }).then(() => {
ElMessage.success('清理缓存成功')
ElMessage.success($t('uiMsg.clearCacheSuccess'))
})
})
}
onMounted(() => {
getDeptList()
if (isSuperAdminUser()) {
getDeptList()
} else {
applyDefaultChannelSelection()
}
})
</script>

View File

@@ -52,13 +52,14 @@
<el-row>
<el-col :span="12">
<el-form-item :label="$t('page.form.labelDept')" prop="dept_id">
<el-tree-select
v-model="formData.dept_id"
:data="optionData.deptData"
:render-after-expand="false"
check-strictly
clearable
/>
<el-select v-model="formData.dept_id" clearable filterable>
<el-option
v-for="item in optionData.deptData"
:key="item.id"
:label="item.label"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
@@ -76,18 +77,6 @@
</el-row>
<el-row>
<el-col :span="12">
<el-form-item :label="$t('page.form.labelPost')" prop="post_ids">
<el-select v-model="formData.post_ids" multiple clearable>
<el-option
v-for="post in optionData.postList"
:key="(post as any)?.id"
:value="(post as any)?.id"
:label="(post as any)?.name"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('page.form.labelGender')" prop="gender">
<sa-radio v-model="formData.gender" dict="gender" valueType="string" />
@@ -129,7 +118,6 @@
import api from '@/api/system/user'
import deptApi from '@/api/system/dept'
import roleApi from '@/api/system/role'
import postApi from '@/api/system/post'
import { ElMessage } from 'element-plus'
import { useI18n } from 'vue-i18n'
@@ -156,8 +144,7 @@
const formRef = ref<FormInstance>()
const optionData = reactive({
deptData: <any>[],
roleList: <any>[],
postList: <any>[]
roleList: <any>[]
})
/**
@@ -207,7 +194,6 @@
phone: '',
email: '',
role_ids: [],
post_ids: [],
status: 1,
gender: '',
remark: ''
@@ -221,6 +207,41 @@
/**
* 监听弹窗打开,初始化表单数据
*/
const flattenDeptOptions = (list: any[], result: { id: number; label: string }[] = []) => {
for (const item of list) {
const id = item.id ?? item.value
if (id !== undefined && id !== null) {
result.push({
id,
label: String(item.label ?? item.name ?? id)
})
}
if (item.children?.length) {
flattenDeptOptions(item.children, result)
}
}
return result
}
const loadRoleOptions = async () => {
const deptId = formData.dept_id
const params =
deptId !== undefined && deptId !== null && deptId !== ''
? { dept_id: deptId }
: undefined
const roleData = await roleApi.accessRole(params)
optionData.roleList = Array.isArray(roleData) ? roleData : []
}
watch(
() => formData.dept_id,
() => {
if (props.modelValue) {
void loadRoleOptions()
}
}
)
watch(
() => props.modelValue,
(newVal) => {
@@ -229,33 +250,23 @@
}
}
)
// 初始化页面数据
const initPage = async () => {
// 先重置为初始值
Object.assign(formData, initialFormData)
// 部门数据
const deptData = await deptApi.accessDept()
optionData.deptData = deptData
optionData.deptData = flattenDeptOptions(Array.isArray(deptData) ? deptData : [])
// 角色数据
const roleData = await roleApi.accessRole()
optionData.roleList = roleData
// 岗位数据
const postData = await postApi.accessPost()
optionData.postList = postData
// 如果有数据,则填充数据
if (props.data) {
if (props.data?.id) {
await nextTick()
if (props.data.id) {
let data = await api.read(props.data.id)
if (data.postList) {
const post = (data.postList as any[])?.map((item: any) => item.id)
data.post_ids = post
}
const role = (data.roleList as any[])?.map((item: any) => item.id)
data.role_ids = role
data.password = ''
initForm(data)
}
const data = await api.read(props.data.id)
const role = (data.roleList as any[])?.map((item: any) => item.id)
data.role_ids = role
data.password = ''
initForm(data)
await loadRoleOptions()
} else {
await loadRoleOptions()
}
}

View File

@@ -80,6 +80,7 @@
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { $t } from '@/locales'
import api from '@/api/safeguard/database'
import { useTable } from '@/hooks/core/useTable'
import generate from '@/api/tool/generate'
@@ -172,7 +173,7 @@
// 确认选择装载数据表
const handleLoadTable = async () => {
if (selectedRows.value.length < 1) {
ElMessage.info('至少要选择一条数据')
ElMessage.info($t('uiMsg.selectAtLeastOne'))
return
}
const names = selectedRows.value.map((item) => ({
@@ -185,7 +186,7 @@
source: searchForm.value.source,
names
})
ElMessage.success('装载成功')
ElMessage.success($t('page.ui.loadSuccess'))
emit('success')
handleClose()
}

View File

@@ -24,6 +24,7 @@
<script setup lang="ts">
import { useClipboard } from '@vueuse/core'
import { ElMessage } from 'element-plus'
import { $t } from '@/locales'
import generate from '@/api/tool/generate'
interface Props {
@@ -94,9 +95,9 @@
const handleCopy = async (code: string) => {
try {
await copy(code)
ElMessage.success('代码已复制到剪贴板')
ElMessage.success($t('page.ui.copyToClipboard'))
} catch {
ElMessage.error('复制失败,请手动复制')
ElMessage.error($t('uiMsg.copyFail'))
}
}
</script>

View File

@@ -133,6 +133,7 @@
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
import api from '@/api/tool/generate'
import { downloadFile } from '@/utils/tool'
@@ -211,15 +212,15 @@
* 生成代码下载
*/
const generateCode = async (ids: number | string) => {
ElMessage.info('代码生成下载中,请稍后')
ElMessage.info($t('page.ui.generating'))
const response = await api.generateCode({
ids: ids.toString().split(',')
})
if (response) {
downloadFile(response, 'code.zip')
ElMessage.success('代码生成成功,开始下载')
ElMessage.success($t('page.ui.generateSuccess'))
} else {
ElMessage.error('文件下载失败')
ElMessage.error($t('page.ui.downloadFail'))
}
}
@@ -227,13 +228,13 @@
* 同步表结构
*/
const syncTable = async (id: number) => {
ElMessageBox.confirm('执行同步操作将会覆盖已经设置的表结构,确定要同步吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('page.ui.syncConfirm'), $t('uiMsg.titlePrompt'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
api.async({ id }).then(() => {
ElMessage.success('同步成功')
ElMessage.success($t('page.ui.syncSuccess'))
})
})
}
@@ -242,13 +243,13 @@
* 生成到项目
*/
const generateFile = async (id: number) => {
ElMessageBox.confirm('生成到项目将会覆盖原有文件,确定要生成吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('page.ui.generateToProjectConfirm'), $t('uiMsg.titlePrompt'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
api.generateFile({ id }).then(() => {
ElMessage.success('生成到项目成功')
ElMessage.success($t('page.ui.generateToProjectSuccess'))
})
})
}
@@ -258,7 +259,7 @@
*/
const batchGenerate = () => {
if (selectedRows.value.length === 0) {
ElMessage.error('至少要选择一条数据')
ElMessage.error($t('uiMsg.selectAtLeastOne'))
return
}
generateCode(selectedRows.value.map((item: any) => item.id).join(','))

View File

@@ -79,6 +79,7 @@
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
import api from '@/api/tool/crontab'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
@@ -146,13 +147,13 @@
// 运行任务
const handleRun = (row: any) => {
ElMessageBox.confirm(`确定要运行任务【${row.name}】吗?`, '运行任务', {
confirmButtonText: '确定',
cancelButtonText: '取消',
ElMessageBox.confirm($t('page.ui.runConfirm', { name: row.name }), $t('page.ui.runTitle'), {
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'warning'
}).then(() => {
api.run({ id: row.id }).then(() => {
ElMessage.success('任务运行成功')
ElMessage.success($t('page.ui.runSuccess'))
refreshData()
})
})

View File

@@ -76,6 +76,7 @@
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus'
import { $t } from '@/locales'
import api from '@/api/tool/crontab'
import { useTable } from '@/hooks/core/useTable'
@@ -128,7 +129,7 @@
*/
const initPage = async () => {
if (!props.data?.id) {
ElMessage.error('请先选择一个任务')
ElMessage.error($t('page.ui.selectTaskFirst'))
return
}
searchForm.value.crontab_id = props.data.id
@@ -166,20 +167,20 @@
// 确认选择装载数据表
const handleLoadTable = async () => {
if (selectedRows.value.length < 1) {
ElMessage.info('至少要选择一条数据')
ElMessage.info($t('uiMsg.selectAtLeastOne'))
return
}
ElMessageBox.confirm(
`确定要删除选中的 ${selectedRows.value.length} 条数据吗?`,
'删除选中数据',
$t('uiMsg.deleteConfirmSelected', { n: selectedRows.value.length }),
$t('uiMsg.titleDeleteSelected'),
{
confirmButtonText: '确定',
cancelButtonText: '取消',
confirmButtonText: $t('uiMsg.btnOk'),
cancelButtonText: $t('uiMsg.btnCancel'),
type: 'error'
}
).then(() => {
api.deleteCrontabLog({ ids: selectedRows.value.map((row) => row.id) }).then(() => {
ElMessage.success('删除成功')
ElMessage.success($t('uiMsg.deleteSuccess'))
refreshData()
})
})

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.h55555game.top
# API 鉴权与用户(可选,不填则用默认值)
# authToken 签名密钥(必填,与客户端约定,用于 signature 校验)

View File

@@ -238,6 +238,17 @@ class UserCache
return (int) config('api.player_cache_ttl', 300);
}
/** /api/v1/getPlayerInfo 快照 key 前缀 */
private static function playerInfoSnapshotPrefix(): string
{
return config('api.player_info_snapshot_prefix', 'api:v1:player_info:');
}
private static function playerInfoSnapshotTtl(): int
{
return (int) config('api.player_info_snapshot_ttl', 180);
}
/**
* 按 username 缓存玩家信息(仅 id + username供中间件注入 request->player 后使用)
* 登录/信息变更时需调用 deletePlayerByUsername 失效
@@ -280,6 +291,54 @@ class UserCache
return false;
}
$key = self::playerCachePrefix() . $username;
return Cache::delete($key);
$r1 = Cache::delete($key);
$snapKey = self::playerInfoSnapshotPrefix() . $username;
$r2 = Cache::delete($snapKey);
return $r1 || $r2;
}
/**
* 读取 getPlayerInfo 接口用的玩家公开信息快照(未命中返回 null
* @return array<string, mixed>|null
*/
public static function getPlayerInfoSnapshotByUsername(string $username): ?array
{
if ($username === '') {
return null;
}
if (self::playerInfoSnapshotTtl() <= 0) {
return null;
}
$key = self::playerInfoSnapshotPrefix() . $username;
$val = Cache::get($key);
if ($val === null || $val === '') {
return null;
}
$data = json_decode((string) $val, true);
if (!is_array($data) || !array_key_exists('username', $data)) {
return null;
}
return $data;
}
/**
* 写入 getPlayerInfo 返回体快照(已脱敏数组)
* @param array<string, mixed> $info
*/
public static function setPlayerInfoSnapshotByUsername(string $username, array $info): bool
{
if ($username === '' || empty($info)) {
return false;
}
$ttl = self::playerInfoSnapshotTtl();
if ($ttl <= 0) {
return true;
}
$key = self::playerInfoSnapshotPrefix() . $username;
$payload = json_encode($info, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
if ($payload === false) {
return false;
}
return Cache::set($key, $payload, $ttl);
}
}

View File

@@ -10,7 +10,9 @@ use support\think\Db;
use app\api\logic\GameLogic;
use app\api\logic\PlayStartLogic;
use app\api\util\ReturnCode;
use app\dice\helper\AdminScopeHelper;
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;
@@ -33,7 +35,12 @@ class GameController extends BaseController
*/
public function config(Request $request): Response
{
$rows = DiceConfig::select('name', 'group', 'title', 'title_en', 'value', 'value_en', 'create_time', 'update_time')->get();
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$rows = (new DiceConfig())
->field('name,group,title,title_en,value,value_en,create_time,update_time')
->where('dept_id', $configDeptId)
->select()
->toArray();
$lang = $request->header('lang', 'zh');
if (!is_string($lang) || $lang === '') {
$lang = 'zh';
@@ -42,15 +49,15 @@ class GameController extends BaseController
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
$data = [];
foreach ($rows as $row) {
$group = $row->group ?? '';
$group = $row['group'] ?? '';
if (!isset($data[$group])) {
$data[$group] = [];
}
$title = $row->title;
$value = $row->value;
$title = $row['title'] ?? '';
$value = $row['value'] ?? '';
if ($isEn) {
$titleEn = $row->title_en ?? '';
$valueEn = $row->value_en ?? '';
$titleEn = $row['title_en'] ?? '';
$valueEn = $row['value_en'] ?? '';
if ($titleEn !== '') {
$title = $titleEn;
}
@@ -59,11 +66,11 @@ class GameController extends BaseController
}
}
$data[$group][] = [
'name' => $row->name,
'name' => $row['name'] ?? '',
'title' => $title,
'value' => $value,
'create_time' => $row->create_time,
'update_time' => $row->update_time,
'create_time' => $row['create_time'] ?? '',
'update_time' => $row['update_time'] ?? '',
];
}
return $this->success($data);
@@ -73,30 +80,30 @@ class GameController extends BaseController
* 购买抽奖券
* POST /api/game/buyLotteryTickets
* header: token由 TokenMiddleware 注入 request->player_id
* body: count = 1 | 5 | 101次/100coin, 5次/500coin, 10次/1000coin
* body: count = 1 | 5 | 101次/1coin, 5次/5coin, 10次/10coin
*/
public function buyLotteryTickets(Request $request): Response
{
$userId = (int) ($request->player_id ?? 0);
$count = (int) $request->post('count', 0);
if (!in_array($count, [1, 5, 10], true)) {
return $this->fail('Invalid lottery ticket purchase', ReturnCode::PARAMS_ERROR);
}
try {
$logic = new GameLogic();
$data = $logic->buyLotteryTickets($userId, $count);
return $this->success($data);
} catch (ApiException $e) {
$msg = $e->getMessage();
if ($msg === '平台币不足') {
$player = DicePlayer::find($userId);
$coin = $player ? (float) $player->coin : 0;
return $this->success(['coin' => $coin], $msg);
}
return $this->fail($msg, ReturnCode::BUSINESS_ERROR);
}
}
// public function buyLotteryTickets(Request $request): Response
// {
// $userId = (int) ($request->player_id ?? 0);
// $count = (int) $request->post('count', 0);
// if (!in_array($count, [1, 5, 10], true)) {
// return $this->fail('Invalid lottery ticket purchase', ReturnCode::PARAMS_ERROR);
// }
//
// try {
// $logic = new GameLogic();
// $data = $logic->buyLotteryTickets($userId, $count);
// return $this->success($data);
// } catch (ApiException $e) {
// $msg = $e->getMessage();
// if ($msg === '平台币不足') {
// $player = DicePlayer::find($userId);
// $coin = $player ? (float) $player->coin : 0;
// return $this->success(['coin' => $coin], $msg);
// }
// return $this->fail($msg, ReturnCode::BUSINESS_ERROR);
// }
// }
/**
* 获取彩金池(中奖配置表)
@@ -106,7 +113,8 @@ class GameController extends BaseController
*/
public function lotteryPool(Request $request): Response
{
$list = DiceRewardConfig::getCachedList();
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$list = DiceRewardConfig::getCachedList($configDeptId);
$list = array_values(array_filter($list, function ($row) {
return (string) ($row['tier'] ?? '') !== 'BIGWIN';
}));
@@ -127,6 +135,8 @@ class GameController extends BaseController
if ($uiEn !== '') {
$row['ui_text'] = $uiEn;
}
//移除掉其中的s_start_index和n_start_index
$row = array_diff_key($row, ['s_start_index'=>'', 's_end_index'=>'', 'weight'=>'', 'ui_text_en'=>'', 'create_time'=>'', 'update_time'=>'', 'type'=>'']);
$list[$index] = $row;
}
}
@@ -134,6 +144,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
{
$configDeptId = $this->resolvePlayerConfigDeptIdFromRequest($request);
$anteConfigModel = new DiceAnteConfig();
$rows = $anteConfigModel->where('dept_id', $configDeptId)->order('id', 'asc')->select()->toArray();
return $this->success($rows);
}
/**
* 开始游戏(抽奖一局)
* POST /api/game/playStart
@@ -147,21 +171,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 +194,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 === '') {
@@ -179,10 +203,12 @@ class GameController extends BaseController
$langLower = strtolower($lang);
$isEn = $langLower === 'en' || str_starts_with($langLower, 'en-');
if (is_array($data) && array_key_exists('reward_config_id', $data)) {
$rewardConfigId = (int) $data['reward_config_id'];
if ($rewardConfigId > 0) {
$configRow = DiceRewardConfig::getCachedById($rewardConfigId);
if (is_array($data)) {
$rewardTier = array_key_exists('reward_tier', $data) ? (string) ($data['reward_tier'] ?? '') : '';
$targetIndex = array_key_exists('target_index', $data) ? (int) ($data['target_index'] ?? 0) : 0;
if ($rewardTier !== 'BIGWIN' && $targetIndex > 0) {
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$configRow = DiceRewardConfig::getCachedById($targetIndex, $configDeptId);
if ($configRow !== null) {
$uiText = '';
$uiTextEn = '';
@@ -201,6 +227,7 @@ class GameController extends BaseController
}
}
}
$data['tier'] = $data['reward_tier'] ?? '';
return $this->success($data);
} catch (ApiException $e) {
@@ -217,14 +244,19 @@ class GameController extends BaseController
$timeoutRecord = null;
$timeout_message = '';
$adminId = null;
$timeoutDeptId = null;
try {
$timeoutPlayer = DicePlayer::find($userId);
$adminId = ($timeoutPlayer && ($timeoutPlayer->admin_id ?? null)) ? (int) $timeoutPlayer->admin_id : null;
if ($timeoutPlayer && isset($timeoutPlayer->dept_id) && $timeoutPlayer->dept_id !== null && $timeoutPlayer->dept_id !== '') {
$timeoutDeptId = (int) $timeoutPlayer->dept_id;
}
} catch (\Throwable $_) {
}
try {
$timeoutRecord = DicePlayRecord::create([
'player_id' => $userId,
'dept_id' => $timeoutDeptId,
'admin_id' => $adminId,
'lottery_config_id' => 0,
'lottery_type' => 0,
@@ -232,9 +264,8 @@ class GameController extends BaseController
'win_coin' => 0,
'super_win_coin' => 0,
'reward_win_coin' => 0,
'use_coins' => 0,
'direction' => $direction,
'reward_config_id' => 0,
'reward_tier' => '',
'start_index' => 0,
'target_index' => 0,
'roll_array' => '[]',
@@ -255,4 +286,20 @@ class GameController extends BaseController
Db::execute('SELECT RELEASE_LOCK(?)', [$lockName]);
}
}
/**
* 从 token 注入的 player_id 解析所属渠道配置 ID
*/
private function resolvePlayerConfigDeptIdFromRequest(Request $request): int
{
$userId = (int) ($request->player_id ?? 0);
if ($userId <= 0) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$player = DicePlayer::find($userId);
if (!$player) {
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
return AdminScopeHelper::resolvePlayerConfigDeptId($player);
}
}

View File

@@ -26,9 +26,13 @@ class UserController extends BaseController
*/
public function Login(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$password = trim((string) ($request->post('password', '')));
$lang = trim((string) ($request->post('lang', 'chs')));
$usernameRaw = $request->post('username', '');
$passwordRaw = $request->post('password', '');
$langRaw = $request->post('lang', 'zh');
$username = is_string($usernameRaw) ? trim($usernameRaw) : '';
$password = is_string($passwordRaw) ? trim($passwordRaw) : '';
$lang = is_string($langRaw) ? trim($langRaw) : 'zh';
$coin = $request->post('coin');
$coin = $coin !== null && $coin !== '' ? (float) $coin : 0.0;
$time = $request->post('time');
@@ -91,7 +95,7 @@ class UserController extends BaseController
if (empty($user)) {
return $this->fail('User not found', ReturnCode::NOT_FOUND);
}
$fields = ['id', 'username', 'phone', 'uid', 'name', 'coin', 'total_ticket_count'];
$fields = ['id', 'username', 'phone', 'uid', 'name', 'coin', 'total_ticket_count', 'free_ticket'];
$info = [];
foreach ($fields as $field) {
if (array_key_exists($field, $user)) {

View File

@@ -6,6 +6,7 @@ namespace app\api\controller\v1;
use app\api\cache\AuthTokenCache;
use app\api\controller\BaseController;
use app\api\util\ReturnCode;
use plugin\saiadmin\app\model\system\SystemUser;
use support\Request;
use support\Response;
use Tinywan\Jwt\JwtToken;
@@ -54,6 +55,14 @@ class AuthTokenController extends BaseController
return $this->fail('Signature verification failed', ReturnCode::FORBIDDEN);
}
$agent = SystemUser::where('agent_id', $agentId)->find();
if (!$agent || (int) ($agent->status ?? 0) !== 1) {
return $this->fail('Invalid agent_id', ReturnCode::FORBIDDEN);
}
if (empty($agent->dept_id) || (int) $agent->dept_id <= 0) {
return $this->fail('Agent channel is not configured', ReturnCode::FORBIDDEN);
}
$exp = (int) config('api.auth_token_exp', 86400);
$tokenResult = JwtToken::generateToken([
'id' => 0,

View File

@@ -5,8 +5,8 @@ namespace app\api\controller\v1;
use app\api\logic\UserLogic;
use app\api\util\ReturnCode;
use app\dice\model\game\DiceGame;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -22,6 +22,69 @@ use app\api\cache\UserCache;
*/
class GameController extends BaseController
{
/** 游戏记录 / 钱包流水 / 中奖券记录等拉取类接口的条数上限(与对接文档一致) */
private const PLAYER_PULL_RECORD_MAX_LIMIT = 2000;
private const PLAYER_PULL_RECORD_DEFAULT_LIMIT = 20;
/** 拉取类流水仅允许查询「当前时间起向前」的最大天数(含起止) */
private const PLAYER_PULL_RECORD_MAX_RANGE_DAYS = 7;
private const GAME_PUBLIC_FIELDS = [
'provider',
'provider_code',
'game_code',
'game_key',
'game_type',
'logo',
'game_url',
'hall_url',
'status',
'sort',
];
/** getPlayerInfo 仅查询需返回的列,减轻 IO敏感/内部字段不入库查询) */
private const PLAYER_INFO_DB_FIELDS = [
'id', 'username', 'phone', 'uid', 'name', 'status', 'coin', 'is_up', 'admin_id',
'total_ticket_count', 'paid_ticket_count', 'free_ticket_count', 'free_ticket',
'total_win_coin',
'create_time', 'update_time',
];
/**
* 获取游戏列表
* POST 参数lang可选zh/en默认 zh
* 当前返回启用中的游戏列表
*/
public function getGameList(Request $request): Response
{
$lang = $this->resolveLang($request->post('lang', 'zh'));
$games = $this->buildPublicGameList($lang, $this->agentDeptId($request));
return $this->success([
'game_list' => $games,
]);
}
/**
* 获取游戏大厅信息(脱敏)
* POST 参数lang可选zh/en默认 zh
*/
public function getGameHall(Request $request): Response
{
$lang = $this->resolveLang($request->post('lang', 'zh'));
$games = $this->buildPublicGameList($lang, $this->agentDeptId($request));
$hallUrl = '';
if (!empty($games)) {
$hallUrl = $games[0]['hall_url'] ?? '';
}
return $this->success([
'provider' => 'Dicey Fun',
'provider_code' => 'DF',
'hall_url' => $hallUrl,
'game_list' => $games,
]);
}
/**
* 获取游戏地址
* 根据 username 创建登录 tokenJWT拼接游戏地址返回
@@ -42,28 +105,21 @@ class GameController extends BaseController
$time = (string) time();
}
$adminId = null;
$adminIdsInTopDept = null;
$agentId = trim((string) ($request->agent_id ?? ''));
if ($agentId !== '') {
$systemUser = SystemUser::where('agent_id', $agentId)->find();
if ($systemUser) {
$adminId = (int) $systemUser->id;
$adminIdsInTopDept = UserLogic::getAdminIdsByAgentIdTopDept($agentId);
}
}
$deptId = $this->agentDeptId($request);
$adminId = $this->agentAdminId($request);
$adminIdsInTopDept = UserLogic::getAdminIdsByAgentIdTopDept(trim((string) ($request->agent_id ?? '')));
$lang = trim((string) ($request->post('lang', 'zh')));
$lang = in_array($lang, ['en', 'zh'], true) ? $lang : 'zh';
try {
$logic = new UserLogic();
$result = $logic->loginByUsername($username, $password, $lang === 'en' ? 'en' : 'chs', 0.0, $time, $adminId, $adminIdsInTopDept);
$result = $logic->loginByUsername($username, $password, $lang, 0.0, $time, $adminId, $adminIdsInTopDept, $deptId);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
}
$gameUrlBase = rtrim(config('api.game_url', 'dice-game.yuliao666.top'), '/');
$gameUrlBase = rtrim(config('api.game_url', 'dice-game.h55555game.top'), '/');
$tokenInUrl = str_replace('%3D', '=', urlencode($result['token']));
$url = $gameUrlBase . '/?token=' . $tokenInUrl . '&lang=' . $lang;
@@ -74,69 +130,171 @@ class GameController extends BaseController
/**
* 获取用户信息
* POST 参数username
* 返回 DicePlayer 中非敏感信息
* 参数usernamePOST JSON / 表单 / Query 均可input 合并读取降低偶发空参)
* 返回 DicePlayer 中非敏感信息;短期 Redis 快照 + 窄字段查询降低延迟
*/
public function getPlayerInfo(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$usernameRaw = $request->input('username', '');
$username = is_string($usernameRaw) ? trim($usernameRaw) : '';
$deptId = $this->agentDeptId($request);
if ($username === '') {
return $this->fail('username is required', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::where('username', $username)->find();
$cached = UserCache::getPlayerInfoSnapshotByUsername($this->scopedUsername($deptId, $username));
if ($cached !== null) {
return $this->success($cached);
}
$player = DicePlayer::field(self::PLAYER_INFO_DB_FIELDS)->where('username', $username)->where('dept_id', $deptId)->find();
if (!$player) {
return $this->fail('User not found', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::PARAMS_ERROR);
}
$hidden = ['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight', 'delete_time'];
$info = $player->hidden($hidden)->toArray();
UserCache::setPlayerInfoSnapshotByUsername($this->scopedUsername($deptId, $username), $info);
return $this->success($info);
}
/**
* 解析拉取类流水接口的 limit与 getPlayerGameRecord / getPlayerWalletRecord / getPlayerTicketRecord 共用)
*/
private function resolvePullRecordLimit(Request $request): int
{
$limit = (int) $request->post('limit', self::PLAYER_PULL_RECORD_DEFAULT_LIMIT);
if ($limit < 1 || $limit > self::PLAYER_PULL_RECORD_MAX_LIMIT) {
$limit = self::PLAYER_PULL_RECORD_DEFAULT_LIMIT;
}
return $limit;
}
/**
* 将 start_create_time / end_create_time 规范为「最近 7 天内」且跨度不超过 7 天的闭区间。
*
* @return array{ok: true, start: string, end: string}|array{ok: false, message: string}
*/
private function resolvePullRecordTimeWindow(string $startRaw, string $endRaw): array
{
$nowTs = time();
$weekAgoTs = strtotime('-' . self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS . ' days', $nowTs);
if ($weekAgoTs === false) {
$weekAgoTs = $nowTs - self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS * 86400;
}
$nowStr = date('Y-m-d H:i:s', $nowTs);
$weekAgoStr = date('Y-m-d H:i:s', $weekAgoTs);
if ($startRaw === '' && $endRaw === '') {
return ['ok' => true, 'start' => $weekAgoStr, 'end' => $nowStr];
}
$startTs = $startRaw === '' ? null : strtotime($startRaw);
$endTs = $endRaw === '' ? null : strtotime($endRaw);
if ($startRaw !== '' && $startTs === false) {
return ['ok' => false, 'message' => 'Invalid start_create_time'];
}
if ($endRaw !== '' && $endTs === false) {
return ['ok' => false, 'message' => 'Invalid end_create_time'];
}
if ($startRaw === '' && $endRaw !== '' && $endTs !== null) {
$endTs = min($endTs, $nowTs);
if ($endTs < $weekAgoTs) {
return ['ok' => false, 'message' => 'end_create_time must be within the last 7 days'];
}
$startTs = strtotime('-' . self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS . ' days', $endTs);
if ($startTs === false) {
$startTs = $endTs - self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS * 86400;
}
if ($startTs < $weekAgoTs) {
$startTs = $weekAgoTs;
}
return ['ok' => true, 'start' => date('Y-m-d H:i:s', $startTs), 'end' => date('Y-m-d H:i:s', $endTs)];
}
if ($startRaw !== '' && $startTs !== null && $endRaw === '') {
if ($startTs > $nowTs) {
return ['ok' => false, 'message' => 'start_create_time cannot be in the future'];
}
if ($startTs < $weekAgoTs) {
return ['ok' => false, 'message' => 'start_create_time cannot be earlier than 7 days ago'];
}
$endTs = strtotime('+' . self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS . ' days', $startTs);
if ($endTs === false) {
$endTs = $startTs + self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS * 86400;
}
$endTs = min($endTs, $nowTs);
return ['ok' => true, 'start' => date('Y-m-d H:i:s', $startTs), 'end' => date('Y-m-d H:i:s', $endTs)];
}
if ($startTs !== null && $endTs !== null) {
if ($endTs > $nowTs) {
$endTs = $nowTs;
}
if ($startTs > $endTs) {
return ['ok' => false, 'message' => 'start_create_time cannot be after end_create_time'];
}
if ($startTs < $weekAgoTs) {
return ['ok' => false, 'message' => 'start_create_time cannot be earlier than 7 days ago'];
}
if ($endTs < $weekAgoTs) {
return ['ok' => false, 'message' => 'end_create_time must be within the last 7 days'];
}
$maxEndForStart = strtotime('+' . self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS . ' days', $startTs);
if ($maxEndForStart === false) {
$maxEndForStart = $startTs + self::PLAYER_PULL_RECORD_MAX_RANGE_DAYS * 86400;
}
if ($endTs > $maxEndForStart) {
return ['ok' => false, 'message' => 'Time range cannot exceed 7 days'];
}
return ['ok' => true, 'start' => date('Y-m-d H:i:s', $startTs), 'end' => date('Y-m-d H:i:s', $endTs)];
}
return ['ok' => false, 'message' => 'Invalid time parameters'];
}
/**
* 获取游戏记录
* POST 参数username非必填,没填则不按用户筛选, start_create_time, end_create_time非必填,没填则不筛选时间
* POST 参数username非必填, start_create_time, end_create_time可选,须在「最近 7 天」内且跨度不超过 7 天;均不传则默认最近 7 天), limit非必填返回条数上限
* 返回 DicePlayRecord 中非敏感信息
*/
public function getPlayerGameRecord(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$deptId = $this->agentDeptId($request);
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
$page = (int) $request->post('page', 1);
$limit = (int) $request->post('limit', 20);
if ($page < 1) {
$page = 1;
}
if ($limit < 1 || $limit > 100) {
$limit = 20;
$window = $this->resolvePullRecordTimeWindow($startCreateTime, $endCreateTime);
if (!$window['ok']) {
return $this->fail($window['message'], ReturnCode::PARAMS_ERROR);
}
$limit = $this->resolvePullRecordLimit($request);
$query = DicePlayRecord::order('id', 'desc');
$query = DicePlayRecord::where('dept_id', $deptId)->order('id', 'desc');
if ($username !== '') {
$player = DicePlayer::where('username', $username)->find();
$player = $this->findPlayerByUsername($username, $deptId);
if (!$player) {
return $this->success([]);
}
$query->where('player_id', (int) $player->id);
}
if ($startCreateTime !== '') {
$query->where('create_time', '>=', $startCreateTime);
}
if ($endCreateTime !== '') {
$query->where('create_time', '<=', $endCreateTime);
}
$query->where('create_time', '>=', $window['start']);
$query->where('create_time', '<=', $window['end']);
$list = $query->page($page, $limit)->select()->toArray();
$list = $query->limit($limit)->select()->toArray();
$playerIds = array_unique(array_column($list, 'player_id'));
if (!empty($playerIds)) {
$players = DicePlayer::whereIn('id', $playerIds)->field('id,username,phone')->select()->toArray();
$players = DicePlayer::whereIn('id', $playerIds)->where('dept_id', $deptId)->field('id,username,phone')->select()->toArray();
$playerMap = [];
foreach ($players as $p) {
$playerMap[(int) ($p['id'] ?? 0)] = $p;
@@ -151,88 +309,74 @@ class GameController extends BaseController
/**
* 获取钱包流水
* POST 参数username非必填,没填则不按用户筛选, start_create_time, end_create_time非必填,没填则不筛选时间
* POST 参数username非必填, start_create_time, end_create_time可选,规则同 getPlayerGameRecord, limit非必填)
* 返回 DicePlayerWalletRecord 中非敏感信息
*/
public function getPlayerWalletRecord(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$deptId = $this->agentDeptId($request);
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
$page = (int) $request->post('page', 1);
$limit = (int) $request->post('limit', 20);
if ($page < 1) {
$page = 1;
}
if ($limit < 1 || $limit > 100) {
$limit = 20;
$window = $this->resolvePullRecordTimeWindow($startCreateTime, $endCreateTime);
if (!$window['ok']) {
return $this->fail($window['message'], ReturnCode::PARAMS_ERROR);
}
$limit = $this->resolvePullRecordLimit($request);
$query = DicePlayerWalletRecord::order('id', 'desc');
$query = DicePlayerWalletRecord::where('dept_id', $deptId)->order('id', 'desc');
if ($username !== '') {
$player = DicePlayer::where('username', $username)->find();
$player = $this->findPlayerByUsername($username, $deptId);
if (!$player) {
return $this->success([]);
}
$query->where('player_id', (int) $player->id);
}
if ($startCreateTime !== '') {
$query->where('create_time', '>=', $startCreateTime);
}
if ($endCreateTime !== '') {
$query->where('create_time', '<=', $endCreateTime);
}
$query->where('create_time', '>=', $window['start']);
$query->where('create_time', '<=', $window['end']);
$list = $query->with(['dicePlayer' => function ($q) {
$q->field('id,username,phone');
}])->page($page, $limit)->select()->toArray();
}])->limit($limit)->select()->toArray();
return $this->success($list);
}
/**
* 获取用户中奖券获取记录
* POST 参数username非必填,没填则不按用户筛选, start_create_time, end_create_time非必填,没填则不筛选时间
* POST 参数username非必填, start_create_time, end_create_time可选,规则同 getPlayerGameRecord, limit非必填)
* 返回 DicePlayerTicketRecord 中非敏感信息
*/
public function getPlayerTicketRecord(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$deptId = $this->agentDeptId($request);
$startCreateTime = trim((string) ($request->post('start_create_time', '')));
$endCreateTime = trim((string) ($request->post('end_create_time', '')));
$page = (int) $request->post('page', 1);
$limit = (int) $request->post('limit', 20);
if ($page < 1) {
$page = 1;
}
if ($limit < 1 || $limit > 100) {
$limit = 20;
$window = $this->resolvePullRecordTimeWindow($startCreateTime, $endCreateTime);
if (!$window['ok']) {
return $this->fail($window['message'], ReturnCode::PARAMS_ERROR);
}
$limit = $this->resolvePullRecordLimit($request);
$query = DicePlayerTicketRecord::order('id', 'desc');
$query = DicePlayerTicketRecord::where('dept_id', $deptId)->order('id', 'desc');
if ($username !== '') {
$player = DicePlayer::where('username', $username)->find();
$player = $this->findPlayerByUsername($username, $deptId);
if (!$player) {
return $this->success([]);
}
$query->where('player_id', (int) $player->id);
}
if ($startCreateTime !== '') {
$query->where('create_time', '>=', $startCreateTime);
}
if ($endCreateTime !== '') {
$query->where('create_time', '<=', $endCreateTime);
}
$query->where('create_time', '>=', $window['start']);
$query->where('create_time', '<=', $window['end']);
$list = $query->with(['dicePlayer' => function ($q) {
$q->field('id,username,phone');
}])->page($page, $limit)->select()->toArray();
}])->limit($limit)->select()->toArray();
return $this->success($list);
}
@@ -246,6 +390,7 @@ class GameController extends BaseController
public function setPlayerWallet(Request $request): Response
{
$username = trim((string) ($request->post('username', '')));
$deptId = $this->agentDeptId($request);
$coin = $request->post('coin');
if ($username === '') {
@@ -260,9 +405,9 @@ class GameController extends BaseController
return $this->fail('coin cannot be 0', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::where('username', $username)->find();
$player = $this->findPlayerByUsername($username, $deptId);
if (!$player) {
return $this->fail('User not found', ReturnCode::NOT_FOUND);
return $this->fail('User not found', ReturnCode::PARAMS_ERROR);
}
$walletBefore = (float) ($player->coin ?? 0);
@@ -282,6 +427,7 @@ class GameController extends BaseController
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$record = DicePlayerWalletRecord::create([
'dept_id' => $deptId,
'player_id' => (int) $player->id,
'admin_id' => $adminId,
'coin' => $coinVal,
@@ -304,10 +450,71 @@ class GameController extends BaseController
UserCache::deleteUser($player->id);
if ($player->username !== '') {
UserCache::deletePlayerByUsername($player->username);
UserCache::deletePlayerByUsername($this->scopedUsername($deptId, (string) $player->username));
}
$recordArr = $record->toArray();
$recordArr['dice_player'] = ['id' => (int) $player->id, 'username' => $player->username ?? '', 'phone' => $player->phone ?? ''];
return $this->success($recordArr);
}
private function resolveLang($lang): string
{
if (!is_string($lang)) {
return 'zh';
}
$langValue = strtolower(trim($lang));
if (!in_array($langValue, ['zh', 'en'], true)) {
return 'zh';
}
return $langValue;
}
private function buildPublicGameList(string $lang, int $deptId): array
{
$rows = DiceGame::where('status', 1)
->where('dept_id', $deptId)
->order('sort', 'asc')
->order('id', 'asc')
->field(array_merge(self::GAME_PUBLIC_FIELDS, ['game_name', 'game_name_en']))
->select()
->toArray();
if (empty($rows)) {
return [];
}
$games = [];
foreach ($rows as $row) {
$game = [];
foreach (self::GAME_PUBLIC_FIELDS as $fieldName) {
$game[$fieldName] = $row[$fieldName] ?? '';
}
$gameNameEn = $row['game_name_en'] ?? '';
$game['game_name'] = $lang === 'en' && $gameNameEn !== '' ? $gameNameEn : ($row['game_name'] ?? '');
$games[] = $game;
}
return $games;
}
private function agentDeptId(Request $request): int
{
return (int) ($request->agent_dept_id ?? 0);
}
private function agentAdminId(Request $request): ?int
{
$adminId = (int) ($request->agent_admin_id ?? 0);
return $adminId > 0 ? $adminId : null;
}
private function scopedUsername(int $deptId, string $username): string
{
return $deptId . ':' . $username;
}
private function findPlayerByUsername(string $username, int $deptId): ?DicePlayer
{
$player = DicePlayer::where('username', $username)->where('dept_id', $deptId)->find();
return $player ?: null;
}
}

View File

@@ -36,4 +36,26 @@ return [
'BATCH_DELETE_FORBIDDEN' => 'Batch delete is not allowed',
'SUPER_ADMIN_CANNOT_DELETE' => 'Super admin cannot be deleted',
'OLD_PASSWORD_WRONG' => 'Old password is incorrect',
'ADD_SUCCESS' => 'Added successfully',
'UPDATE_SUCCESS' => 'Updated successfully',
'DELETE_SUCCESS' => 'Deleted successfully',
'ADD_FAILED' => 'Add failed',
'UPDATE_FAILED' => 'Update failed',
'DELETE_FAILED' => 'Delete failed',
'NOT_FOUND' => 'Data not found',
'ANTE_MUST_POSITIVE' => 'Ante must be greater than 0',
'ANTE_NOT_ALLOWED' => 'Ante %s is not available for current channel, please select from ante config',
'ANTE_CONFIG_NOT_FOUND' => 'Ante config not found',
'ANTE_CONFIG_NOT_IN_CHANNEL' => 'Ante config does not belong to current channel',
'POOL_CONFIG_NOT_IN_CHANNEL' => 'Pool config does not belong to current channel',
'CHANNEL_DEPT_ID_REQUIRED' => 'Please select a channel, or assign a valid administrator/player for this record',
'INVALID_CHANNEL_DEPT_ID' => 'Invalid channel. Please reselect channel or administrator',
'PLAYER_USERNAME_DEPT_UNIQUE' => 'Username already exists in this channel',
'NO_PERMISSION_UPDATE' => 'No permission to update this record',
'NO_PERMISSION_VIEW' => 'No permission to view this record',
'NO_PERMISSION_OPERATE_PLAYER' => 'No permission to operate this player',
'PLEASE_SELECT_DATA' => 'Please select data to delete',
'OPERATION_SUCCESS' => 'Operation successful',
'TEST_DATA_CLEARED' => 'Test data cleared',
'CLEAR_FAILED' => 'Clear failed: %s',
];

View File

@@ -9,6 +9,28 @@ declare(strict_types=1);
return [
'success' => 'Success',
'fail' => 'Fail',
'add success' => 'Added successfully',
'update success' => 'Updated successfully',
'save success' => 'Saved successfully',
'delete success' => 'Deleted successfully',
'add failed' => 'Add failed',
'update failed' => 'Update failed',
'delete failed' => 'Delete failed',
'not found' => 'Data not found',
'operation success' => 'Operation successful',
'test data cleared' => 'Test data cleared',
'ante must be greater than 0' => 'Ante must be greater than 0',
'ante not allowed: %s' => 'Ante %s is not available for current channel, please select from ante config',
'pool config does not belong to current channel' => 'Pool config does not belong to current channel',
'no permission to update this record' => 'No permission to update this record',
'no permission to view this record' => 'No permission to view this record',
'no permission to operate this player' => 'No permission to operate this player',
'please select data to delete' => 'Please select data to delete',
'please select player' => 'Please select player',
'please login first' => 'Please login first',
'missing player_id' => 'Missing player_id',
'Player not found' => 'Player not found',
'record not found' => 'Record not found',
'username、password 不能为空' => 'username and password are required',
'请携带 token' => 'Please provide token',
'token 无效' => 'Invalid or expired token',
@@ -19,6 +41,7 @@ return [
'账号已被禁用,无法登录' => 'Account is disabled and cannot log in',
'购买抽奖券错误' => 'Invalid lottery ticket purchase',
'平台币不足' => 'Insufficient balance',
'余额不足' => 'Insufficient balance',
'direction 必须为 0 或 1' => 'direction must be 0 or 1',
'当前玩家余额%s小于%s无法继续游戏' => 'Balance %s is less than %s, cannot continue',
'服务超时,' => 'Service timeout: ',

View File

@@ -36,5 +36,27 @@ return [
'BATCH_DELETE_FORBIDDEN' => '禁止批量删除操作',
'SUPER_ADMIN_CANNOT_DELETE' => '超级管理员禁止删除',
'OLD_PASSWORD_WRONG' => '原密码错误',
'ADD_SUCCESS' => '添加成功',
'UPDATE_SUCCESS' => '修改成功',
'DELETE_SUCCESS' => '删除成功',
'ADD_FAILED' => '添加失败',
'UPDATE_FAILED' => '修改失败',
'DELETE_FAILED' => '删除失败',
'NOT_FOUND' => '数据不存在',
'ANTE_MUST_POSITIVE' => '底注必须大于 0',
'ANTE_NOT_ALLOWED' => '底注 %s 在当前渠道不可用,请从底注配置中选择',
'ANTE_CONFIG_NOT_FOUND' => '底注配置不存在',
'ANTE_CONFIG_NOT_IN_CHANNEL' => '底注配置不属于当前渠道',
'POOL_CONFIG_NOT_IN_CHANNEL' => '奖池配置不属于当前渠道',
'CHANNEL_DEPT_ID_REQUIRED' => '请选择所属渠道,或为记录指定有效的所属管理员/玩家',
'INVALID_CHANNEL_DEPT_ID' => '渠道无效,请重新选择所属渠道或管理员',
'PLAYER_USERNAME_DEPT_UNIQUE' => '该渠道下用户名已存在',
'NO_PERMISSION_UPDATE' => '无权限修改该记录',
'NO_PERMISSION_VIEW' => '无权限查看该记录',
'NO_PERMISSION_OPERATE_PLAYER' => '无权限操作该玩家',
'PLEASE_SELECT_DATA' => '请选择要删除的数据',
'OPERATION_SUCCESS' => '操作成功',
'TEST_DATA_CLEARED' => '测试数据已清空',
'CLEAR_FAILED' => '清空失败:%s',
];

View File

@@ -17,9 +17,9 @@ use support\think\Db;
class GameLogic
{
public const PACKAGES = [
1 => ['coin' => 100, 'paid' => 1, 'free' => 0], // 1次/100coin
5 => ['coin' => 500, 'paid' => 5, 'free' => 1], // 5张/500coin5购买+1赠送共6次
10 => ['coin' => 1000, 'paid' => 10, 'free' => 3], // 10张/1000coin10购买+3赠送共13次
1 => ['coin' => 1, 'paid' => 1, 'free' => 0], // 1次/1coin
5 => ['coin' => 5, 'paid' => 5, 'free' => 1], // 5张/5coin5购买+1赠送共6次
10 => ['coin' => 10, 'paid' => 10, 'free' => 3], // 10张/10coin10购买+3赠送共13次
];
/** 钱包流水类型:购买抽奖次数 */
@@ -52,7 +52,7 @@ class GameLogic
throw new ApiException('Insufficient balance');
}
$coinAfter = $coinBefore - $cost;
$coinAfter = round($coinBefore - $cost, 2);
$totalBefore = (int) ($player->total_ticket_count ?? 0);
$paidBefore = (int) ($player->paid_ticket_count ?? 0);
$freeBefore = (int) ($player->free_ticket_count ?? 0);
@@ -70,10 +70,14 @@ class GameLogic
UserCache::setUser($playerId, $updatedUserArr);
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$playerDeptId = isset($player->dept_id) && $player->dept_id !== null && $player->dept_id !== ''
? (int) $player->dept_id
: null;
try {
Db::transaction(function () use (
$player,
$playerId,
$playerDeptId,
$adminId,
$cost,
$coinBefore,
@@ -93,8 +97,9 @@ class GameLogic
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'admin_id' => $adminId,
'coin' => -$cost,
'coin' => round(-$cost, 2),
'type' => self::WALLET_TYPE_BUY_DRAW,
'wallet_before' => $coinBefore,
'wallet_after' => $coinAfter,
@@ -106,8 +111,10 @@ class GameLogic
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'admin_id' => $adminId,
'use_coins' => $cost,
'use_coins' => round($cost, 2),
'ante' => 1,
'total_ticket_count' => $addTotal,
'paid_ticket_count' => $addPaid,
'free_ticket_count' => $addFree,
@@ -120,7 +127,7 @@ class GameLogic
}
return [
'coin' => (float) $coinAfter,
'coin' => round((float) $coinAfter, 2),
'total_ticket_count' => (int) $totalAfter,
'paid_ticket_count' => (int) $paidAfter,
'free_ticket_count' => (int) $freeAfter,

View File

@@ -6,8 +6,10 @@ namespace app\api\logic;
use app\api\cache\UserCache;
use app\api\util\ApiLang;
use app\api\service\LotteryService;
use app\dice\helper\AdminScopeHelper;
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;
@@ -23,6 +25,8 @@ use support\think\Db;
*/
class PlayStartLogic
{
/** 钱包流水类型:购买抽奖次数 */
public const WALLET_TYPE_BUY_DRAW = 2;
/** 抽奖类型:付费 */
public const LOTTERY_TYPE_PAID = 0;
/** 抽奖类型:免费 */
@@ -34,8 +38,12 @@ class PlayStartLogic
/** 对局状态:超时/失败 */
public const RECORD_STATUS_TIMEOUT = 0;
/** 开启对局最低余额 = |DiceRewardConfig 最小 real_ev + 100| */
private const MIN_COIN_EXTRA = 100;
/** 单注费用(抽奖券基础费用) */
private const UNIT_COST = 1.0;
/** 免费抽奖注数缓存 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 +55,98 @@ 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);
$configDeptId = AdminScopeHelper::resolvePlayerConfigDeptId($player);
$playerDeptId = isset($player->dept_id) && $player->dept_id !== null && $player->dept_id !== ''
? (int) $player->dept_id
: null;
$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)->where('dept_id', $configDeptId)->count();
if ($exists <= 0) {
throw new ApiException('当前注数不合规,请选择正确的注数');
}
$lotteryService = LotteryService::getOrCreate($playerId);
$ticketType = LotteryService::drawTicketType($paid, $free);
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
// 免费抽奖:优先使用 free_ticket带 ante 与 count兼容旧字段 free_ticket_count
$freeTicket = $player->free_ticket ?? null;
$freeTicketAnte = null;
$freeTicketCount = 0;
if (is_array($freeTicket)) {
$a = $freeTicket['ante'] ?? null;
$c = $freeTicket['count'] ?? null;
if ($a !== null && $a !== '' && is_numeric($a)) {
$freeTicketAnte = (int) $a;
}
if ($c !== null && $c !== '' && is_numeric($c)) {
$freeTicketCount = (int) $c;
}
}
$legacyFreeCount = (int) ($player->free_ticket_count ?? 0);
$isFree = ($freeTicketAnte !== null && $freeTicketCount > 0) || $legacyFreeCount > 0;
$ticketType = $isFree ? self::LOTTERY_TYPE_FREE : self::LOTTERY_TYPE_PAID;
// 若为 free_ticket 免费抽奖:注数必须与券的 ante 一致
if ($ticketType === self::LOTTERY_TYPE_FREE && $freeTicketAnte !== null && $freeTicketCount > 0) {
if ($ante !== $freeTicketAnte) {
throw new ApiException('您有一张底注为' . $freeTicketAnte . '的免费抽奖券');
}
}
// 若为免费抽奖(旧逻辑):注数必须与上一次触发免费抽奖时的注数一致
if ($isFree) {
$requiredAnte = Cache::get(self::FREE_ANTE_KEY_PREFIX . $playerId);
if ($requiredAnte !== null && $requiredAnte !== '' && (int) $requiredAnte !== $ante) {
throw new ApiException('免费抽奖注数必须与上一次一致,请修改注数后继续');
}
}
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->where('dept_id', $configDeptId)->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->where('dept_id', $configDeptId)->find();
if (!$configType0) {
throw new ApiException('Lottery pool config not found (name=default required)');
}
// 付费抽奖:开始前扣除费用 ante * UNIT_COST
$paidAmount = $ticketType === self::LOTTERY_TYPE_PAID ? round($ante * self::UNIT_COST, 2) : 0.0;
// 游玩前余额校验(按 T4 惩罚最大值兜底):
// 门槛 = paidAmount(压注*1) + abs(T4最小real_ev)*ante
$t4List = DiceRewardConfig::getCachedByTier('T4', $configDeptId);
$t4MinRealEv = null;
foreach ($t4List as $row) {
$ev = $row['real_ev'] ?? null;
if ($ev === null || $ev === '') {
continue;
}
$evFloat = filter_var($ev, FILTER_VALIDATE_FLOAT);
if ($evFloat === false) {
continue;
}
if ($t4MinRealEv === null || $evFloat < $t4MinRealEv) {
$t4MinRealEv = $evFloat;
}
}
$t4PenaltyAbs = $t4MinRealEv === null ? 0.0 : abs($t4MinRealEv) * $ante;
$needMinBalance = round($paidAmount + $t4PenaltyAbs, 2);
if ($coin < $needMinBalance) {
throw new ApiException('余额不足');
}
// 彩金池累计盈利:用于判断是否触发杀分(不再依赖单个玩家累计盈利)
// 该值来自 dice_lottery_pool_config.profit_amount
$poolProfitTotal = $configType0->profit_amount ?? 0;
@@ -91,7 +161,7 @@ class PlayStartLogic
: $configType0;
// 按档位 T1-T5 抽取后,从 DiceReward 表按当前方向取该档位数据,再按 weight 抽取一条得到 grid_number
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10;
$chosen = null;
@@ -132,12 +202,17 @@ class PlayStartLogic
$targetIndex = (int) ($chosen['end_index'] ?? 0);
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
$realEv = (float) ($chosen['real_ev'] ?? 0);
// T5/再来一次:以奖励行 tier 为准,并以摇奖档位 $tier 兜底(与 reward_tier 展示一致,避免 dice_reward 行缺 tier 时不发券)
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
if ($isTierT5 === false && (string) ($tier ?? '') === 'T5') {
$isTierT5 = true;
}
// 摇色子中奖:按 dice_reward_config.real_ev 直接结算(已乘 ante
$rewardWinCoin = round($realEv * $ante, 2);
// 豹子判定5/30 必豹子10/15/20/25 按 DiceRewardConfig 中 BIGWIN 该点数的 weight 判定0-1000010000=100%
// 杀分档位不触发豹子5/30 已在上方抽取时排除10/15/20/25 仅生成非豹子组合
$superWinCoin = 0;
$superWinCoin = 0.0;
$isWin = 0;
$bigWinRealEv = 0.0;
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
@@ -147,7 +222,7 @@ class PlayStartLogic
$superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) {
@@ -166,10 +241,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 = round($bigWinEv * $ante, 2);
// 中 BIGWIN 豹子:不走原奖励流程,不记录原奖励,不触发 T5 再来一次,仅发放豹子奖金
$rewardWinCoin = 0;
$realEv = 0;
$rewardWinCoin = 0.0;
$realEv = 0.0;
$isTierT5 = false;
} else {
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
@@ -186,7 +262,7 @@ class PlayStartLogic
$startIndex,
$targetIndex
));
$winCoin = $superWinCoin + $rewardWinCoin; // 赢取平台币 = 中大奖 + 摇色子中奖(豹子时 rewardWinCoin 已为 0
$winCoin = round($superWinCoin + $rewardWinCoin, 2); // 赢取平台币 = 中大奖 + 摇色子中奖(豹子时 rewardWinCoin 已为 0
$record = null;
$configId = (int) $config->id;
@@ -197,12 +273,14 @@ class PlayStartLogic
try {
Db::transaction(function () use (
$playerId,
$playerDeptId,
$adminId,
$configId,
$type0ConfigId,
$rewardId,
$configName,
$ticketType,
$ante,
$paidAmount,
$winCoin,
$superWinCoin,
$rewardWinCoin,
@@ -214,25 +292,28 @@ class PlayStartLogic
$targetIndex,
$rollArray,
$isTierT5,
$tier,
&$record
) {
$rewardTier = ($isWin === 1 && $superWinCoin > 0) ? 'BIGWIN' : (string) ($tier ?? '');
$record = DicePlayRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'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,
'direction' => $direction,
'reward_config_id' => $rewardId,
'reward_tier' => $rewardTier,
'start_index' => $startIndex,
'target_index' => $targetIndex,
'roll_array' => is_array($rollArray) ? json_encode($rollArray) : $rollArray,
'roll_number' => is_array($rollArray) ? array_sum($rollArray) : 0,
'lottery_name' => $configName,
'status' => self::RECORD_STATUS_SUCCESS,
]);
@@ -241,38 +322,118 @@ class PlayStartLogic
throw new \RuntimeException('玩家不存在');
}
$coinBefore = (float) $p->coin;
$coinAfter = $coinBefore + $winCoin;
// 开始前先扣付费金额,再加中奖金额(免费抽奖 paid_amount=0
$coinAfter = round($coinBefore - $paidAmount + $winCoin, 2);
// T4 惩罚兜底:扣完购券费用后若余额不足以承受本次惩罚(导致为负),统一按“余额不足”提示
if ($rewardTier === 'T4' && $coinAfter < 0) {
throw new ApiException('余额不足');
}
$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 {
$p->free_ticket_count = max(0, (int) $p->free_ticket_count - 1);
// 免费抽奖消耗:优先消耗 free_ticket.count,耗尽则清空 free_ticket否则兼容旧 free_ticket_count
if ($ticketType === self::LOTTERY_TYPE_FREE) {
$ft = $p->free_ticket ?? null;
$ftAnte = null;
$ftCount = 0;
if (is_array($ft)) {
$a = $ft['ante'] ?? null;
$c = $ft['count'] ?? null;
if ($a !== null && $a !== '' && is_numeric($a)) {
$ftAnte = (int) $a;
}
if ($c !== null && $c !== '' && is_numeric($c)) {
$ftCount = (int) $c;
}
}
if ($ftAnte !== null && $ftCount > 0) {
$next = $ftCount - 1;
if ($next <= 0) {
$p->free_ticket = null;
} else {
$p->free_ticket = ['ante' => $ftAnte, 'count' => $next];
}
} else {
$p->free_ticket_count = max(0, (int) $p->free_ticket_count - 1);
}
}
// 若本局中奖档位为 T5则额外赠送 1 次免费抽奖次数(总次数也 +1并记录抽奖券获取记录
// 记录每次游玩:写入抽奖券记录(用于后台“抽奖券记录”追踪付费/免费游玩与消耗)
$isPaidPlay = $ticketType === self::LOTTERY_TYPE_PAID;
$paidCnt = $isPaidPlay ? 1 : 0;
$freeCnt = $isPaidPlay ? 0 : 1;
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'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 次免费抽奖次数:
// - 新结构:写入 free_ticketante=本局注数count+1
// - 兼容旧结构free_ticket_count +1
if ($isTierT5) {
$p->free_ticket_count = (int) $p->free_ticket_count + 1;
$p->total_ticket_count = (int) $p->total_ticket_count + 1;
$ft = $p->free_ticket ?? null;
$ftAnte = null;
$ftCount = 0;
if (is_array($ft)) {
$a = $ft['ante'] ?? null;
$c = $ft['count'] ?? null;
if ($a !== null && $a !== '' && is_numeric($a)) {
$ftAnte = (int) $a;
}
if ($c !== null && $c !== '' && is_numeric($c)) {
$ftCount = (int) $c;
}
}
if ($ftAnte === null) {
$ftAnte = $ante;
}
if ($ftAnte === $ante) {
$p->free_ticket = ['ante' => $ante, 'count' => $ftCount + 1];
} else {
// 若已有不同注数的免费券,则仍保留旧字段累加,避免覆盖玩家已有券
$p->free_ticket_count = (int) $p->free_ticket_count + 1;
}
DicePlayerTicketRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'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 {
// 若本次消耗了最后一次免费抽奖,则清理注数锁
$ft = $p->free_ticket ?? null;
$ftCount = 0;
if (is_array($ft)) {
$c = $ft['count'] ?? null;
if ($c !== null && $c !== '' && is_numeric($c)) {
$ftCount = (int) $c;
}
}
if ($ticketType === self::LOTTERY_TYPE_FREE && $ftCount <= 0 && (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;
$addProfit = $perPlayProfit;
// 付费:每局按「本局赢取平台币 win_coin - 抽奖费用 paid_amountante*UNIT_COST
// 免费券:paid_amount=0只计入 win_coin
$perPlayProfit = ($ticketType === self::LOTTERY_TYPE_PAID) ? ($winCoin - $paidAmount) : $winCoin;
$addProfit = round($perPlayProfit, 2);
try {
DiceLotteryPoolConfig::where('id', $type0ConfigId)->update([
'profit_amount' => Db::raw('IFNULL(profit_amount,0) + ' . (float) $addProfit),
'profit_amount' => Db::raw('IFNULL(profit_amount,0) + ' . sprintf('%.2f', $addProfit)),
]);
} catch (\Throwable $e) {
Log::warning('彩金池盈利累加失败', [
@@ -282,14 +443,32 @@ class PlayStartLogic
]);
}
// 钱包流水拆分:先记录购券扣费,再记录抽奖结果(中奖/惩罚)
if ($paidAmount > 0) {
$walletAfterBuy = round($coinBefore - $paidAmount, 2);
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'admin_id' => $adminId,
'coin' => round(-$paidAmount, 2),
'type' => self::WALLET_TYPE_BUY_DRAW,
'wallet_before' => $coinBefore,
'wallet_after' => $walletAfterBuy,
'remark' => '抽奖购券扣费|play_record_id=' . $record->id,
]);
}
$walletBeforeDraw = $coinBefore - $paidAmount;
$drawRemark = ($winCoin >= 0 ? '抽奖中奖' : '抽奖惩罚') . '|play_record_id=' . $record->id;
DicePlayerWalletRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'admin_id' => $adminId,
'coin' => $winCoin,
'type' => self::WALLET_TYPE_DRAW,
'wallet_before' => $coinBefore,
'wallet_before' => round($walletBeforeDraw, 2),
'wallet_after' => $coinAfter,
'remark' => '抽奖|play_record_id=' . $record->id,
'remark' => $drawRemark,
]);
});
} catch (\Throwable $e) {
@@ -297,6 +476,7 @@ class PlayStartLogic
try {
$record = DicePlayRecord::create([
'player_id' => $playerId,
'dept_id' => $playerDeptId,
'admin_id' => $adminId ?? null,
'lottery_config_id' => $configId ?? 0,
'lottery_type' => $ticketType,
@@ -304,9 +484,8 @@ class PlayStartLogic
'win_coin' => 0,
'super_win_coin' => 0,
'reward_win_coin' => 0,
'use_coins' => 0,
'direction' => $direction,
'reward_config_id' => 0,
'reward_tier' => '',
'start_index' => $startIndex,
'target_index' => 0,
'roll_array' => '[]',
@@ -333,10 +512,11 @@ class PlayStartLogic
$arr['roll_array'] = json_decode($arr['roll_array'], true) ?? [];
}
$arr['roll_number'] = is_array($arr['roll_array'] ?? null) ? array_sum($arr['roll_array']) : 0;
$arr['tier'] = $tier ?? '';
$arr['reward_tier'] = ($isWin === 1 && $superWinCoin > 0) ? 'BIGWIN' : (string) ($tier ?? '');
// 记录完数据后返回当前玩家余额与抽奖次数
$arr['coin'] = $updated ? (float) $updated->coin : 0;
$arr['total_ticket_count'] = $updated ? (int) $updated->total_ticket_count : 0;
$arr['coin'] = $updated ? round((float) $updated->coin, 2) : 0.0;
// 本局从玩家货币中扣除的金额:付费抽奖为 ante*UNIT_COST免费抽奖为 0与 paid_amount 一致)
$arr['use_coin'] = round($paidAmount, 2);
return $arr;
}
@@ -468,12 +648,13 @@ 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, ?int $configDeptId = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($configDeptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$maxTierRetry = 10;
$chosen = null;
@@ -517,10 +698,10 @@ 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 = round($realEv * $ante, 2);
$superWinCoin = 0;
$superWinCoin = 0.0;
$isWin = 0;
$bigWinRealEv = 0.0;
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
@@ -530,7 +711,7 @@ class PlayStartLogic
$superWinCoin = 0.0;
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
} else {
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber, $configDeptId);
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
$doSuperWin = $alwaysSuperWin;
if (!$doSuperWin) {
@@ -547,8 +728,11 @@ class PlayStartLogic
if ($doSuperWin) {
$rollArray = $this->getSuperWinRollArray($rollNumber);
$isWin = 1;
$superWinCoin = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$rewardWinCoin = 0;
$bigWinEv = $bigWinRealEv > 0 ? $bigWinRealEv : self::SUPER_WIN_BONUS;
$superWinCoin = round($bigWinEv * $ante, 2);
$rewardWinCoin = 0.0;
// 中豹子时不走原奖励流程
$realEv = 0.0;
} else {
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
}
@@ -557,11 +741,14 @@ class PlayStartLogic
$rollArray = $this->generateRollArrayFromSum($rollNumber);
}
$winCoin = $superWinCoin + $rewardWinCoin;
$winCoin = round($superWinCoin + $rewardWinCoin, 2);
$configId = $config !== null ? (int) $config->id : 0;
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
$configName = $config !== null ? (string) ($config->name ?? '') : '自定义';
$costRealEv = $realEv + ($isWin === 1 ? $bigWinRealEv : 0.0);
$paidAmount = $lotteryType === 0 ? round($ante * self::UNIT_COST, 2) : 0.0;
$rewardTier = ($isWin === 1 && $superWinCoin > 0) ? 'BIGWIN' : (string) ($tier ?? '');
// 与写入记录的 reward_tier 完全一致:仅当展示档位为 T5非豹子大奖时触发「再来一次」链式免费局
$grantsFreeTicket = ($rewardTier === 'T5');
return [
'player_id' => 0,
@@ -570,22 +757,23 @@ 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,
'direction' => $direction,
'reward_config_id' => $rewardId,
'reward_tier' => $rewardTier,
'start_index' => $startIndex,
'target_index' => $targetIndex,
'roll_array' => json_encode($rollArray),
'roll_number' => array_sum($rollArray),
'lottery_name' => $configName,
'status' => self::RECORD_STATUS_SUCCESS,
'tier' => $tier,
'roll_number_for_count' => $rollNumber,
'real_ev' => $realEv,
'bigwin_real_ev' => $isWin === 1 ? $bigWinRealEv : 0.0,
'cost_ev' => $costRealEv,
'grants_free_ticket' => $grantsFreeTicket,
];
}
}

View File

@@ -5,7 +5,6 @@ namespace app\api\logic;
use app\dice\model\player\DicePlayer;
use app\api\cache\UserCache;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use Tinywan\Jwt\JwtToken;
@@ -44,46 +43,8 @@ class UserLogic
}
/**
* 根据 parent_id 向上遍历找到顶级部门parent_id=0
*/
private static function getTopDeptIdByParentId(int $deptId): ?int
{
$currentId = $deptId;
$visited = [];
while ($currentId > 0 && !isset($visited[$currentId])) {
$visited[$currentId] = true;
$dept = SystemDept::find($currentId);
if (!$dept) {
return null;
}
$parentId = (int) ($dept->parent_id ?? 0);
if ($parentId === 0) {
return $currentId;
}
$currentId = $parentId;
}
return $currentId > 0 ? $currentId : null;
}
/**
* 根据顶级部门 id递归获取其下所有部门 id含自身仅用 id 和 parent_id
*/
private static function getAllDeptIdsUnderTop(int $topId): array
{
$deptIds = [$topId];
$prevCount = 0;
while (count($deptIds) > $prevCount) {
$prevCount = count($deptIds);
$children = SystemDept::whereIn('parent_id', $deptIds)->column('id');
$deptIds = array_unique(array_merge($deptIds, array_map('intval', $children)));
}
return array_values($deptIds);
}
/**
* 根据 agent_id 获取当前管理员所在顶级部门下的所有管理员 ID 列表
* 使用 SystemDept 的 id 和 parent_id 字段遍历:先向上找顶级部门(parent_id=0),再向下收集所有子部门
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该部门,同顶级部门下不重复创建玩家
* 根据 agent_id 获取同渠道下的所有管理员 ID 列表
* 用于 getGameUrl 接口判断 DicePlayer 是否属于该渠道,同渠道下不重复创建玩家
*
* @param string $agentId 代理标识sa_system_user.agent_id
* @return int[] 管理员 ID 列表,空数组表示未找到或无法解析
@@ -103,16 +64,8 @@ class UserLogic
return [(int) $admin->id];
}
$deptId = (int) $deptId;
$topId = self::getTopDeptIdByParentId($deptId);
if ($topId === null) {
return [(int) $admin->id];
}
$deptIds = self::getAllDeptIdsUnderTop($topId);
if (empty($deptIds)) {
$deptIds = [$deptId];
}
$adminIds = SystemUser::whereIn('dept_id', $deptIds)->column('id');
return array_map('intval', $adminIds);
$adminIds = SystemUser::where('dept_id', $deptId)->column('id');
return array_map('intval', $adminIds ?: [(int) $admin->id]);
}
/**
@@ -123,7 +76,7 @@ class UserLogic
* @param int|null $adminId 创建新用户时关联的后台管理员IDsa_system_user.id可选
* @param int[]|null $adminIdsInTopDept 当前管理员顶级部门下的所有管理员ID用于按部门范围查找玩家为空时退化为仅按 username 查找
*/
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null, ?array $adminIdsInTopDept = null): array
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null, ?array $adminIdsInTopDept = null, ?int $deptId = null): array
{
$username = trim($username);
if ($username === '') {
@@ -131,6 +84,9 @@ class UserLogic
}
$query = DicePlayer::where('username', $username);
if ($deptId !== null && $deptId > 0) {
$query->where('dept_id', $deptId);
}
if ($adminIdsInTopDept !== null && !empty($adminIdsInTopDept)) {
$query->whereIn('admin_id', $adminIdsInTopDept);
}
@@ -153,8 +109,15 @@ class UserLogic
$player->password = $this->hashPassword($password);
$player->status = self::STATUS_NORMAL;
$player->coin = $coin;
if ($deptId !== null && $deptId > 0) {
$player->dept_id = $deptId;
}
if ($adminId !== null && $adminId > 0) {
$player->admin_id = $adminId;
$adminUser = SystemUser::find($adminId);
if (($deptId === null || $deptId <= 0) && $adminUser && !empty($adminUser->dept_id)) {
$player->dept_id = $adminUser->dept_id;
}
}
$player->save();
}
@@ -168,13 +131,17 @@ class UserLogic
]);
$token = $tokenResult['access_token'];
UserCache::setSessionByUsername($username, $token);
UserCache::setCurrentUserToken((int) $player->id, $token);
$userArr = $player->hidden(['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
UserCache::setUser((int) $player->id, $userArr);
UserCache::setPlayerByUsername($username, $userArr);
$baseUrl = rtrim(config('api.login_url_base', 'https://127.0.0.1:6777'), '/');
$lang = in_array($lang, ['chs', 'en'], true) ? $lang : 'chs';
$lang = strtolower(trim($lang));
if ($lang !== 'en') {
$lang = 'zh';
}
$tokenInUrl = str_replace('%3D', '=', urlencode($token));
$url = $baseUrl . '?token=' . $tokenInUrl . '&lang=' . $lang;

View File

@@ -0,0 +1,201 @@
<?php
declare(strict_types=1);
namespace app\api\middleware;
use support\Log;
use Throwable;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
/**
* 记录 /api 相关接口的访问参数与响应摘要(敏感头、敏感字段脱敏)
*/
class ApiAccessLogMiddleware implements MiddlewareInterface
{
private const REQUEST_PARAM_MAX_LEN = 4096;
private const RESPONSE_BODY_MAX_LEN = 8192;
/** 请求头名称(小写) */
private const SENSITIVE_HEADER_NAMES = [
'auth-token',
'token',
'authorization',
'cookie',
];
/** 参数键名(小写匹配) */
private const SENSITIVE_PARAM_KEYS = [
'password',
'secret',
'signature',
'token',
'auth-token',
'auth_token',
'old_token',
];
public function process(Request $request, callable $handler): Response
{
$startedAt = microtime(true);
$response = null;
$thrown = null;
try {
$response = $handler($request);
return $response;
} catch (Throwable $e) {
$thrown = $e;
throw $e;
} finally {
$durationMs = round((microtime(true) - $startedAt) * 1000, 3);
$requestLog = $this->buildRequestLog($request);
$responseLog = null;
if ($response instanceof Response) {
$responseLog = $this->buildResponseLog($response);
}
Log::info('api_access', [
'request' => $requestLog,
'response' => $responseLog,
'duration_ms' => $durationMs,
'exception' => $thrown ? [
'class' => $thrown::class,
'message' => $thrown->getMessage(),
] : null,
]);
}
}
/**
* @return array<string, mixed>
*/
private function buildRequestLog(Request $request): array
{
$headers = $request->header();
if (!is_array($headers)) {
$headers = [];
}
$headersOut = [];
foreach ($headers as $name => $value) {
$nameStr = strtolower((string) $name);
if ($this->isSensitiveHeaderName($nameStr)) {
$headersOut[$nameStr] = $this->maskToken(is_string($value) ? $value : (string) $value);
} else {
$headersOut[$nameStr] = $value;
}
}
$get = $request->get();
$post = $request->post();
$params = [];
if (is_array($get)) {
$params = array_merge($params, $get);
}
if (is_array($post)) {
$params = array_merge($params, $post);
}
$params = $this->sanitizeForLog($params);
$paramsJson = json_encode($params, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
if (!is_string($paramsJson)) {
$paramsJson = '';
}
if (strlen($paramsJson) > self::REQUEST_PARAM_MAX_LEN) {
$paramsJson = substr($paramsJson, 0, self::REQUEST_PARAM_MAX_LEN) . '...(truncated)';
}
return [
'method' => $request->method(),
'path' => $request->path(),
'uri' => $request->uri(),
'ip' => method_exists($request, 'getRealIp') ? $request->getRealIp() : ($request->getRemoteIp() ?? ''),
'content_type' => $request->header('content-type', ''),
'headers' => $headersOut,
'params' => $paramsJson,
'agent_id' => $request->agent_id ?? null,
'player_id' => $request->player_id ?? null,
];
}
/**
* @return array<string, mixed>
*/
private function buildResponseLog(Response $response): array
{
$raw = method_exists($response, 'rawBody') ? $response->rawBody() : '';
if (!is_string($raw)) {
$raw = '';
}
$bodyForLog = $raw;
$decoded = json_decode($raw, true);
if (is_array($decoded)) {
$sanitized = $this->sanitizeForLog($decoded);
$encoded = json_encode($sanitized, JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
if (is_string($encoded)) {
$bodyForLog = $encoded;
}
}
if (strlen($bodyForLog) > self::RESPONSE_BODY_MAX_LEN) {
$bodyForLog = substr($bodyForLog, 0, self::RESPONSE_BODY_MAX_LEN) . '...(truncated)';
}
return [
'status' => $response->getStatusCode(),
'body' => $bodyForLog,
];
}
private function isSensitiveHeaderName(string $name): bool
{
return in_array($name, self::SENSITIVE_HEADER_NAMES, true);
}
private function isSensitiveParamKey(string $keyLower): bool
{
foreach (self::SENSITIVE_PARAM_KEYS as $s) {
if ($keyLower === $s) {
return true;
}
}
return false;
}
private function maskToken(string $value): string
{
$t = trim($value);
if ($t === '') {
return '';
}
if (strlen($t) <= 12) {
return '***';
}
return substr($t, 0, 8) . '***' . substr($t, -4);
}
/**
* @param mixed $value
* @return mixed
*/
private function sanitizeForLog($value)
{
if (!is_array($value)) {
return $value;
}
$out = [];
foreach ($value as $k => $v) {
$keyLower = is_string($k) ? strtolower($k) : '';
if ($keyLower !== '' && $this->isSensitiveParamKey($keyLower)) {
$out[$k] = '***';
continue;
}
if (is_array($v)) {
$out[$k] = $this->sanitizeForLog($v);
continue;
}
$out[$k] = $v;
}
return $out;
}
}

View File

@@ -5,6 +5,7 @@ namespace app\api\middleware;
use app\api\cache\AuthTokenCache;
use app\api\util\ReturnCode;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use Tinywan\Jwt\JwtToken;
use Tinywan\Jwt\Exception\JwtTokenException;
@@ -47,12 +48,23 @@ class AuthTokenMiddleware implements MiddlewareInterface
throw new ApiException('auth-token invalid', ReturnCode::TOKEN_INVALID);
}
$currentToken = AuthTokenCache::getTokenByAgentId($agentId);
if ($currentToken === null || $currentToken !== $token) {
// 单次 Redistoken → agent_id与 JWT 内 agent_id 一致即有效(减少一次按 agent 取当前 token 的往返)
$agentIdFromStore = AuthTokenCache::getAgentIdByToken($token);
if ($agentIdFromStore === null || $agentIdFromStore !== $agentId) {
throw new ApiException('auth-token invalid or expired', ReturnCode::TOKEN_INVALID);
}
$agent = SystemUser::where('agent_id', $agentId)->find();
if (!$agent || (int) ($agent->status ?? 0) !== 1) {
throw new ApiException('Invalid agent_id', ReturnCode::FORBIDDEN);
}
if (empty($agent->dept_id) || (int) $agent->dept_id <= 0) {
throw new ApiException('Agent channel is not configured', ReturnCode::FORBIDDEN);
}
$request->agent_id = $agentId;
$request->agent_admin_id = (int) $agent->id;
$request->agent_dept_id = (int) $agent->dept_id;
return $handler($request);
}
}

View File

@@ -53,10 +53,14 @@ class TokenMiddleware implements MiddlewareInterface
if ($username === '') {
throw new ApiException('Invalid or expired token', ReturnCode::TOKEN_INVALID);
}
$userId = (int) ($extend['id'] ?? 0);
if ($userId <= 0) {
throw new ApiException('Invalid or expired token', ReturnCode::TOKEN_INVALID);
}
$currentToken = UserCache::getSessionTokenByUsername($username);
$currentToken = UserCache::getCurrentUserToken($userId);
if ($currentToken === null || $currentToken === '') {
$player = DicePlayer::where('username', $username)->find();
$player = DicePlayer::find($userId);
if (!$player) {
throw new ApiException('Please register', ReturnCode::TOKEN_INVALID);
}
@@ -68,17 +72,17 @@ class TokenMiddleware implements MiddlewareInterface
// 优先从 Redis 缓存取玩家,避免每次请求都查库
$player = null;
$cached = UserCache::getPlayerByUsername($username);
if ($cached !== null && isset($cached['id'])) {
$cached = UserCache::getUser($userId);
if (!empty($cached) && isset($cached['id']) && (int) $cached['id'] === $userId) {
$player = (new DicePlayer())->data($cached, true);
}
if ($player === null) {
$player = DicePlayer::where('username', $username)->find();
$player = DicePlayer::find($userId);
if (!$player) {
UserCache::deleteSessionByUsername($username);
throw new ApiException('Please login again', ReturnCode::TOKEN_INVALID);
}
UserCache::setPlayerByUsername($username, $player->hidden(['password'])->toArray());
UserCache::setUser($userId, $player->hidden(['password'])->toArray());
}
$request->player_id = (int) $player->id;
$request->player = $player;

View File

@@ -62,6 +62,17 @@ class ApiLang
return (string) $map[$key];
}
// 兼容旧版:历史代码直接抛中文 messagelang=en 时从 legacy_en.php 映射到英文
if ($lang === self::LANG_EN) {
$legacy = self::loadLegacyEnMessages();
if (isset($legacy[$message])) {
return (string) $legacy[$message];
}
if ($key !== null && isset($legacy[$key])) {
return (string) $legacy[$key];
}
}
return $message;
}
@@ -108,6 +119,22 @@ class ApiLang
return 'MSG_' . strtoupper(sprintf('%08X', crc32($trim)));
}
/**
* 加载中文原文 => 英文 的兼容映射(仅 lang=en 使用)
* @return array<string, string>
*/
private static function loadLegacyEnMessages(): array
{
$path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'legacy_en.php';
if (is_file($path)) {
$data = require $path;
if (is_array($data)) {
return $data;
}
}
return [];
}
/**
* 带占位符的翻译,如 translateParams('当前玩家余额%s小于%s无法继续游戏', [$coin, $minCoin])
* 先翻译再替换en 文案使用 %s 占位)

View File

@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace app\dice\basic;
use plugin\saiadmin\basic\think\BaseLogic;
/**
* 大富翁逻辑层基类:删除均为硬删除
*/
class DiceBaseLogic extends BaseLogic
{
/**
* @param mixed $ids
*/
public function destroy($ids): bool
{
return $this->model->destroy($ids, true);
}
}

View File

@@ -7,8 +7,10 @@ use app\dice\helper\AdminScopeHelper;
use app\dice\model\player\DicePlayer;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
use support\think\Db;
@@ -21,7 +23,7 @@ class DiceDashboardController extends BaseController
* 工作台卡片统计:玩家注册、充值、提现、游玩次数(含较上周对比)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function statistics(): Response
public function statistics(Request $request): Response
{
$thisWeekStart = date('Y-m-d 00:00:00', strtotime('monday this week'));
$thisWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday this week'));
@@ -29,11 +31,12 @@ class DiceDashboardController extends BaseController
$lastWeekEnd = date('Y-m-d 23:59:59', strtotime('sunday last week'));
$adminInfo = $this->adminInfo ?? null;
$filterDeptId = $request->input('dept_id');
$playerQueryThis = DicePlayer::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playerQueryLast = DicePlayer::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($playerQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playerQueryLast, $adminInfo, $filterDeptId);
$playerThis = $playerQueryThis->count();
$playerLast = $playerQueryLast->count();
@@ -43,8 +46,8 @@ class DiceDashboardController extends BaseController
$chargeQueryLast = DicePlayerWalletRecord::where('type', 0)
->where('coin', '>', 0)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($chargeQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($chargeQueryLast, $adminInfo, $filterDeptId);
$chargeThis = $chargeQueryThis->sum('coin');
$chargeLast = $chargeQueryLast->sum('coin');
@@ -52,15 +55,15 @@ class DiceDashboardController extends BaseController
->whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$withdrawQueryLast = DicePlayerWalletRecord::where('type', 1)
->whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($withdrawQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($withdrawQueryLast, $adminInfo, $filterDeptId);
$withdrawThis = $withdrawQueryThis->sum(Db::raw('ABS(coin)'));
$withdrawLast = $withdrawQueryLast->sum(Db::raw('ABS(coin)'));
$playQueryThis = DicePlayRecord::whereBetween('create_time', [$thisWeekStart, $thisWeekEnd]);
$playQueryLast = DicePlayRecord::whereBetween('create_time', [$lastWeekStart, $lastWeekEnd]);
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo);
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo);
AdminScopeHelper::applyAdminScope($playQueryThis, $adminInfo, $filterDeptId);
AdminScopeHelper::applyAdminScope($playQueryLast, $adminInfo, $filterDeptId);
$playThis = $playQueryThis->count();
$playLast = $playQueryLast->count();
@@ -85,13 +88,11 @@ class DiceDashboardController extends BaseController
* 近期玩家充值统计近10天每日充值金额
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function rechargeChart(): Response
public function rechargeChart(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
$adminCondition = '';
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
if ($deptCondition === '__empty__') {
$data = [];
foreach (range(0, 9) as $n) {
$data[] = ['recharge_date' => date('Y-m-d', strtotime("-{$n} days")), 'recharge_amount' => 0];
@@ -101,9 +102,6 @@ class DiceDashboardController extends BaseController
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
'recharge_date' => array_column($data, 'recharge_date'),
]);
}
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = "
SELECT
@@ -116,7 +114,7 @@ class DiceDashboardController extends BaseController
UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
) d
LEFT JOIN dice_player_wallet_record w
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$adminCondition}
ON DATE(w.create_time) = d.date AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY d.date
ORDER BY d.date ASC
";
@@ -131,13 +129,11 @@ class DiceDashboardController extends BaseController
* 月度玩家充值汇总当年1-12月每月充值金额
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function rechargeBarChart(): Response
public function rechargeBarChart(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$allowedIds = AdminScopeHelper::getAllowedAdminIds($adminInfo);
$adminCondition = '';
if ($allowedIds !== null) {
if (empty($allowedIds)) {
$deptCondition = $this->buildWalletSqlDeptCondition($adminInfo, $request->input('dept_id'));
if ($deptCondition === '__empty__') {
$data = [];
for ($m = 1; $m <= 12; $m++) {
$data[] = ['recharge_month' => sprintf('%02d月', $m), 'recharge_amount' => 0];
@@ -146,9 +142,6 @@ class DiceDashboardController extends BaseController
'recharge_amount' => array_map('floatval', array_column($data, 'recharge_amount')),
'recharge_month' => array_column($data, 'recharge_month'),
]);
}
$idsStr = implode(',', array_map('intval', $allowedIds));
$adminCondition = " AND w.admin_id IN ({$idsStr})";
}
$sql = "
SELECT
@@ -162,7 +155,7 @@ class DiceDashboardController extends BaseController
LEFT JOIN dice_player_wallet_record w
ON YEAR(w.create_time) = YEAR(CURDATE())
AND MONTH(w.create_time) = m.month_num
AND w.type = 0 AND w.coin > 0 {$adminCondition}
AND w.type = 0 AND w.coin > 0 {$deptCondition}
GROUP BY m.month_num
ORDER BY m.month_num ASC
";
@@ -178,7 +171,7 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(DicePlayer.username)、充值金额(coin)、充值时间(create_time)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function walletRecordList(): Response
public function walletRecordList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayerWalletRecord::with([
@@ -189,7 +182,7 @@ class DiceDashboardController extends BaseController
->where('type', 0)
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$rows = [];
foreach ($list as $row) {
@@ -208,13 +201,13 @@ class DiceDashboardController extends BaseController
* 返回:玩家账号(username)、余额(coin)、抽奖券(total_ticket_count)
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function newPlayerList(): Response
public function newPlayerList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayer::field('username,coin,total_ticket_count,create_time')
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$rows = [];
foreach ($list as $row) {
@@ -222,11 +215,66 @@ class DiceDashboardController extends BaseController
'name' => $row->getAttr('username'),
'coin' => $row->getAttr('coin'),
'total_ticket_count' => $row->getAttr('total_ticket_count'),
'create_time' => $row->getAttr('create_time'),
];
}
return $this->success($rows);
}
/**
* 工作台-玩家游玩记录最新50条
* 返回:玩家账号、中奖档位、赢取平台币、游玩时间
*/
#[Permission('工作台数据统计', 'core:console:list')]
public function playRecordList(Request $request): Response
{
$adminInfo = $this->adminInfo ?? null;
$query = DicePlayRecord::with([
'dicePlayer' => function ($q) {
$q->field('id,username');
},
])
->where('status', 1)
->field('id,player_id,reward_tier,win_coin,create_time')
->order('create_time', 'desc')
->limit(50);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $request->input('dept_id'));
$list = $query->select();
$tierLabels = $this->buildRewardTierLabels();
$rows = [];
foreach ($list as $row) {
$player = $row->dicePlayer;
$tier = $row->getAttr('reward_tier');
$rows[] = [
'player_name' => $player ? $player->getAttr('username') : '',
'reward_tier' => $tier,
'reward_tier_label' => $tierLabels[$tier] ?? $tier,
'win_coin' => $row->getAttr('win_coin'),
'create_time' => $row->getAttr('create_time'),
];
}
return $this->success($rows);
}
/**
* @return array<string, string>
*/
private function buildRewardTierLabels(): array
{
$rows = DiceRewardConfig::field('tier,ui_text')->select();
$labels = [];
foreach ($rows as $row) {
$tier = $row->getAttr('tier');
if ($tier === '' || $tier === null) {
continue;
}
if (!isset($labels[$tier])) {
$labels[$tier] = $row->getAttr('ui_text') ?: $tier;
}
}
return $labels;
}
private function calcWeekChange($current, $last): float
{
if ($last == 0) {
@@ -234,4 +282,23 @@ class DiceDashboardController extends BaseController
}
return round((($current - $last) / $last) * 100, 1);
}
/**
* 钱包流水 SQL 渠道条件;非超管无渠道时返回 __empty__
*/
private function buildWalletSqlDeptCondition(?array $adminInfo, $requestDeptId): string
{
if (AdminScopeHelper::getDeptId($adminInfo) !== null) {
$deptId = AdminScopeHelper::getDeptId($adminInfo);
if ($deptId <= 0) {
return '__empty__';
}
return ' AND w.dept_id = ' . $deptId;
}
$target = AdminScopeHelper::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
return ' AND w.dept_id = ' . $target;
}
return '';
}
}

View File

@@ -0,0 +1,114 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\controller\ante_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\ante_config\DiceAnteConfigLogic;
use app\dice\model\ante_config\DiceAnteConfig;
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);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query);
return $this->success($data);
}
/**
* 底注下拉选项(按渠道),供一键测试权重等使用
*/
#[Permission('底注配置列表', 'dice:ante_config:index:index')]
public function getOptions(Request $request): Response
{
$query = DiceAnteConfig::field('id,name,title,mult,is_default')->order('mult', 'asc')->order('id', 'asc');
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(static function ($item) {
return [
'id' => (int) $item['id'],
'name' => (string) ($item['name'] ?? ''),
'title' => (string) ($item['title'] ?? ''),
'mult' => (int) ($item['mult'] ?? 0),
'is_default' => (int) ($item['is_default'] ?? 0),
];
})->toArray();
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);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $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();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
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

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\controller\config;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\config\DiceConfigLogic;
use app\dice\validate\config\DiceConfigValidate;
@@ -42,6 +43,7 @@ class DiceConfigController extends BaseController
['title', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query);
return $this->success($data);
}
@@ -74,6 +76,7 @@ class DiceConfigController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -91,8 +94,20 @@ class DiceConfigController extends BaseController
public function update(Request $request): Response
{
$data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) {
return $this->success('update success');
} else {

View File

@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\controller\game;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\game\DiceGameLogic;
use app\dice\validate\game\DiceGameValidate;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 游戏管理控制器
*/
class DiceGameController extends BaseController
{
public function __construct()
{
$this->logic = new DiceGameLogic();
$this->validate = new DiceGameValidate();
parent::__construct();
}
#[Permission('游戏管理列表', 'dice:game:index:index')]
public function index(Request $request): Response
{
$where = $request->more([
['provider_code', ''],
['game_code', ''],
['game_type', ''],
['status', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query);
return $this->success($data);
}
#[Permission('游戏管理读取', 'dice:game:index:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
if (!$model) {
return $this->fail('not found');
}
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
}
#[Permission('游戏管理添加', 'dice:game:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if (!$result) {
return $this->fail('add failed');
}
return $this->success('add success');
}
#[Permission('游戏管理修改', 'dice:game:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if (!$result) {
return $this->fail('update failed');
}
return $this->success('update success');
}
#[Permission('游戏管理删除', 'dice:game:index:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if ($ids === '' || $ids === null) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
if (!$result) {
return $this->fail('delete failed');
}
return $this->success('delete success');
}
}

View File

@@ -7,6 +7,7 @@
namespace app\dice\controller\lottery_pool_config;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
@@ -37,9 +38,10 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(Request $request): Response
{
$list = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
->order('id', 'asc')
->select();
$query = DiceLotteryPoolConfig::field('id,name,t1_weight,t2_weight,t3_weight,t4_weight,t5_weight')
->order('id', 'asc');
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(function ($item) {
return [
'id' => (int) $item['id'],
@@ -67,6 +69,7 @@ class DiceLotteryPoolConfigController extends BaseController
['type', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query);
return $this->success($data);
}
@@ -99,6 +102,7 @@ class DiceLotteryPoolConfigController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -116,8 +120,19 @@ class DiceLotteryPoolConfigController extends BaseController
public function update(Request $request): Response
{
$data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) {
return $this->success('update success');
} else {
@@ -152,7 +167,8 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:getCurrentPool')]
public function getCurrentPool(Request $request): Response
{
$data = $this->logic->getCurrentPool();
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getCurrentPool($deptId);
return $this->success($data);
}
@@ -163,7 +179,12 @@ class DiceLotteryPoolConfigController extends BaseController
public function updateCurrentPool(Request $request): Response
{
$data = $request->post();
$this->logic->updateCurrentPool($data);
if ($data === [] || $data === null) {
$data = $request->all();
}
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$this->logic->updateCurrentPool($data, $deptId);
return $this->success('save success');
}
@@ -173,7 +194,8 @@ class DiceLotteryPoolConfigController extends BaseController
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:resetProfitAmount')]
public function resetProfitAmount(Request $request): Response
{
$this->logic->resetProfitAmount();
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$this->logic->resetProfitAmount($deptId);
return $this->success('reset success');
}
}

View File

@@ -12,7 +12,6 @@ use app\dice\logic\play_record\DicePlayRecordLogic;
use app\dice\validate\play_record\DicePlayRecordValidate;
use app\dice\model\player\DicePlayer;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
@@ -54,19 +53,18 @@ class DicePlayRecordController extends BaseController
['direction', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with([
'dicePlayer',
'diceRewardConfig',
'diceLotteryPoolConfig',
]);
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(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 = round($paidAmount - $playerTotalWin, 2);
$data = $this->logic->getList($query);
$data['total_win_coin'] = $totalWinCoin;
@@ -80,7 +78,7 @@ class DicePlayRecordController extends BaseController
public function getPlayerOptions(Request $request): Response
{
$query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -94,26 +92,15 @@ class DicePlayRecordController extends BaseController
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
public function getLotteryConfigOptions(Request $request): Response
{
$list = DiceLotteryPoolConfig::field('id,name')->select();
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => $item['id'], 'name' => $item['name'] ?? ''];
})->toArray();
return $this->success($data);
}
/**
* 获取奖励配置选项id、ui_text、tier
*/
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
public function getRewardConfigOptions(Request $request): Response
{
$list = DiceRewardConfig::field('id,ui_text,tier')->select();
$data = $list->map(function ($item) {
return [
'id' => $item['id'],
'ui_text' => $item['ui_text'] ?? '',
'tier' => $item['tier'] ?? ''
];
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
})->toArray();
return $this->success($data);
}
@@ -131,8 +118,7 @@ class DicePlayRecordController extends BaseController
if (!$model) {
return $this->fail('not found');
}
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
return $this->fail('no permission to view this record');
}
$data = is_array($model) ? $model : $model->toArray();
@@ -149,6 +135,7 @@ class DicePlayRecordController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -157,24 +144,6 @@ class DicePlayRecordController extends BaseController
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('玩家抽奖记录修改', 'dice:play_record:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\controller\play_record_test;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
@@ -30,7 +31,7 @@ class DicePlayRecordTestController extends BaseController
}
/**
* 数据列表,并在结果中附带当前筛选条件下测试数据的平台总盈利 total_win_coin付费抽奖次数×100 - 玩家总收益)
* 数据列表,并在结果中附带当前筛选条件下测试数据的平台总盈利 total_win_coin付费金额 paid_amount 求和 - 玩家总收益)
* @param Request $request
* @return Response
*/
@@ -38,23 +39,27 @@ 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']);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with(['diceLotteryPoolConfig']);
// 按当前筛选条件统计:平台总盈利 = 付费抽奖(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 = round($paidAmount - $playerTotalWin, 2);
$data = $this->logic->getList($query);
$data['total_win_coin'] = $totalWinCoin;
@@ -89,6 +94,7 @@ class DicePlayRecordTestController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -97,24 +103,6 @@ class DicePlayRecordTestController extends BaseController
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('玩家抽奖记录(测试数据)修改', 'dice:play_record_test:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request

View File

@@ -8,6 +8,7 @@ namespace app\dice\controller\player;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\player\DicePlayerLogic;
@@ -16,6 +17,7 @@ use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
use app\api\cache\UserCache;
use Tinywan\Jwt\JwtToken;
use app\dice\model\player\DicePlayer;
/**
@@ -41,7 +43,13 @@ class DicePlayerController extends BaseController
#[Permission('玩家列表', 'dice:player:index:index')]
public function getLotteryConfigOptions(Request $request): Response
{
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
$query = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $requestDeptId);
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
})->toArray();
@@ -56,12 +64,17 @@ class DicePlayerController extends BaseController
#[Permission('玩家列表', 'dice:player:index:index')]
public function getSystemUserOptions(Request $request): Response
{
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
$deptList = $this->adminInfo['deptList'] ?? [];
if (!empty($deptList)) {
$query->auth($deptList);
$query = SystemUser::field('id,username,realname,dept_id')->where('status', 1)->order('id', 'asc');
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null) {
if ($allowedIds === []) {
return $this->success([]);
}
$query->whereIn('id', $allowedIds);
}
$list = $query->select();
$data = $list->map(function ($item) {
@@ -70,12 +83,89 @@ class DicePlayerController extends BaseController
'id' => (int) $item['id'],
'username' => (string) ($item['username'] ?? ''),
'realname' => (string) ($item['realname'] ?? ''),
'dept_id' => isset($item['dept_id']) ? (int) $item['dept_id'] : null,
'label' => $label ?: (string) $item['id'],
];
})->toArray();
return $this->success($data);
}
/**
* 超管:按渠道树状展示全部管理员;非超管:同 getSystemUserOptions 扁平列表
*/
#[Permission('玩家列表', 'dice:player:index:index')]
public function getSystemUserTreeOptions(Request $request): Response
{
if (!AdminScopeHelper::isSuperAdmin($this->adminInfo ?? null)) {
return $this->getSystemUserOptions($request);
}
$users = SystemUser::field('id,username,realname,dept_id')
->where('status', 1)
->order('id', 'asc')
->select()
->toArray();
$depts = SystemDept::field('id,name')
->where('status', 1)
->order('id', 'asc')
->select()
->toArray();
$deptNameMap = [];
foreach ($depts as $dept) {
$deptNameMap[(int) $dept['id']] = (string) ($dept['name'] ?? $dept['id']);
}
$grouped = [];
$unassigned = [];
foreach ($users as $user) {
$item = [
'id' => (int) $user['id'],
'username' => (string) ($user['username'] ?? ''),
'realname' => (string) ($user['realname'] ?? ''),
'dept_id' => isset($user['dept_id']) ? (int) $user['dept_id'] : null,
];
$label = trim($item['realname']) ?: $item['username'];
$item['label'] = $label ?: (string) $item['id'];
$deptId = $item['dept_id'] ?? 0;
if ($deptId > 0 && isset($deptNameMap[$deptId])) {
if (!isset($grouped[$deptId])) {
$grouped[$deptId] = [];
}
$grouped[$deptId][] = $item;
} else {
$unassigned[] = $item;
}
}
$tree = [];
foreach ($depts as $dept) {
$deptId = (int) $dept['id'];
$children = $grouped[$deptId] ?? [];
if ($children === []) {
continue;
}
$tree[] = [
'id' => 'dept_' . $deptId,
'label' => (string) ($dept['name'] ?? $deptId),
'disabled' => true,
'children' => $children,
];
}
if ($unassigned !== []) {
$tree[] = [
'id' => 'dept_unassigned',
'label' => '__unassigned__',
'disabled' => true,
'children' => $unassigned,
];
}
return $this->success($tree);
}
/**
* 数据列表
* @param Request $request
@@ -93,7 +183,7 @@ class DicePlayerController extends BaseController
['lottery_config_id', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with(['diceLotteryPoolConfig']);
$data = $this->logic->getList($query);
return $this->success($data);
@@ -112,8 +202,7 @@ class DicePlayerController extends BaseController
if (!$model) {
return $this->fail('not found');
}
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
return $this->fail('no permission to view this record');
}
$data = is_array($model) ? $model : $model->toArray();
@@ -129,20 +218,32 @@ class DicePlayerController extends BaseController
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
// 类型转化
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
$data['admin_id'] = (int) $this->adminInfo['id'];
}
$result = $this->logic->add($data);
if ($result && isset($result['id'])) {
// 出于安全:删除该玩家缓存,后续 API 按需重建
UserCache::deleteUser($result['id']);
$player = DicePlayer::find($result['id']);
AdminScopeHelper::prepareBusinessSaveData(
$data,
$this->adminInfo ?? null,
$request->input('dept_id'),
$data
);
$this->validate('save', $data);
try {
$result = $this->logic->add($data);
} catch (\Throwable $e) {
if (self::isDeptUsernameDuplicateException($e)) {
return $this->fail('PLAYER_USERNAME_DEPT_UNIQUE');
}
throw $e;
}
$playerId = is_array($result) ? ($result['id'] ?? null) : $result;
if ($playerId) {
UserCache::deleteUser($playerId);
$player = DicePlayer::find($playerId);
if ($player && $player->username !== '') {
UserCache::deletePlayerByUsername($player->username);
}
return $this->success('add success');
return $this->success('ADD_SUCCESS');
}
return $this->fail('add failed');
}
@@ -156,14 +257,16 @@ class DicePlayerController extends BaseController
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
$data['dept_id'] = $model->dept_id ?? null;
}
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
// 出于安全:删除该玩家缓存,后续 API 按需重建
@@ -172,7 +275,7 @@ class DicePlayerController extends BaseController
if ($player && $player->username !== '') {
UserCache::deletePlayerByUsername($player->username);
}
return $this->success('update success');
return $this->success('UPDATE_SUCCESS');
}
return $this->fail('update failed');
}
@@ -195,8 +298,7 @@ class DicePlayerController extends BaseController
}
$model = $this->logic->read($id);
if ($model) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
return $this->fail('no permission to update this record');
}
}
@@ -210,6 +312,66 @@ class DicePlayerController extends BaseController
return $this->success('update success');
}
/**
* 获取游戏链接
* @param Request $request
* @return Response
*/
#[Permission('获取游戏链接', 'dice:player:index:getGameUrl')]
public function getGameUrl(Request $request): Response
{
$id = $request->input('id');
if ($id === null || $id === '') {
return $this->fail('missing parameter id');
}
$player = $this->logic->read($id);
if (!$player) {
return $this->fail('not found');
}
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
return $this->fail('no permission to view this record');
}
if ((int) ($player->status ?? 1) === 0) {
return $this->fail('account is disabled');
}
$username = trim((string) ($player->username ?? ''));
if ($username === '') {
return $this->fail('username is empty');
}
$lang = trim((string) $request->input('lang', 'zh'));
if (!in_array($lang, ['zh', 'en'], true)) {
$lang = 'zh';
}
$exp = (int) config('api.session_expire', 604800);
$tokenResult = JwtToken::generateToken([
'id' => (int) $player->id,
'username' => $username,
'plat' => 'api_login',
'access_exp' => $exp,
]);
$token = (string) ($tokenResult['access_token'] ?? '');
if ($token === '') {
return $this->fail('generate token failed');
}
UserCache::setSessionByUsername($username, $token);
UserCache::setCurrentUserToken((int) $player->id, $token);
$userArr = $player->hidden(['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
UserCache::setUser((int) $player->id, $userArr);
UserCache::setPlayerByUsername($username, $userArr);
$gameUrlBase = rtrim((string) env('GAME_URL', (string) config('api.game_url', '')), '/');
if ($gameUrlBase === '') {
return $this->fail('GAME_URL is not configured');
}
if (!str_starts_with($gameUrlBase, 'http://') && !str_starts_with($gameUrlBase, 'https://')) {
$gameUrlBase = 'https://' . $gameUrlBase;
}
$tokenInUrl = str_replace('%3D', '=', urlencode($token));
$url = $gameUrlBase . '/?token=' . $tokenInUrl . '&lang=' . $lang;
return $this->success(['url' => $url]);
}
/**
* 删除数据
* @param Request $request
@@ -223,13 +385,12 @@ class DicePlayerController extends BaseController
return $this->fail('please select data to delete');
}
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null) {
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id');
$deptId = AdminScopeHelper::getDeptId($this->adminInfo ?? null);
if ($deptId !== null) {
$models = $this->logic->model->whereIn('id', $ids)->column('dept_id', 'id');
$validIds = [];
foreach ($ids as $id) {
$adminId = (int) ($models[$id] ?? 0);
if (in_array($adminId, $allowedIds, true)) {
if (AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $models[$id] ?? null)) {
$validIds[] = $id;
}
}
@@ -253,4 +414,17 @@ class DicePlayerController extends BaseController
return $this->fail('delete failed');
}
/**
* 判断是否违反 dice_player (dept_id, username) 唯一索引
*/
private static function isDeptUsernameDuplicateException(\Throwable $e): bool
{
$message = $e->getMessage();
if ($message === '') {
return false;
}
return str_contains($message, 'uk_dice_player_dept_username')
|| (str_contains($message, 'Duplicate entry') && str_contains($message, 'username'));
}
}

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', ''],
@@ -52,7 +53,7 @@ class DicePlayerTicketRecordController extends BaseController
['create_time_max', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$query->with([
'dicePlayer',
]);
@@ -69,7 +70,7 @@ class DicePlayerTicketRecordController extends BaseController
public function getPlayerOptions(Request $request): Response
{
$query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -90,8 +91,7 @@ class DicePlayerTicketRecordController extends BaseController
if (!$model) {
return $this->fail('not found');
}
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null, $request->input('dept_id'))) {
return $this->fail('no permission to view this record');
}
$data = is_array($model) ? $model : $model->toArray();
@@ -108,6 +108,7 @@ class DicePlayerTicketRecordController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -116,24 +117,6 @@ class DicePlayerTicketRecordController extends BaseController
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('抽奖券获取记录修改', 'dice:player_ticket_record:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request

View File

@@ -47,13 +47,18 @@ class DicePlayerWalletRecordController extends BaseController
['create_time_min', ''],
['create_time_max', ''],
]);
$deptId = $request->input('dept_id');
$totalCoinChange = $this->logic->sumCoinBySearch($where, $this->adminInfo ?? null, $deptId);
$query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $deptId);
$query->with([
'dicePlayer',
'operator',
]);
$data = $this->logic->getList($query);
$data['total_coin_change'] = $totalCoinChange;
return $this->success($data);
}
@@ -66,7 +71,7 @@ class DicePlayerWalletRecordController extends BaseController
public function getPlayerOptions(Request $request): Response
{
$query = DicePlayer::field('id,username');
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$list = $query->select();
$data = $list->map(function ($item) {
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
@@ -87,12 +92,11 @@ class DicePlayerWalletRecordController extends BaseController
if ($playerId === null || $playerId === '') {
return $this->fail('missing player_id');
}
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find();
$player = DicePlayer::field('coin,dept_id')->where('id', $playerId)->find();
if (!$player) {
return $this->fail('Player not found');
}
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null)) {
return $this->fail('no permission to operate this player');
}
return $this->success(['wallet_before' => (float) $player['coin']]);
@@ -111,8 +115,7 @@ class DicePlayerWalletRecordController extends BaseController
if (!$model) {
return $this->fail('not found');
}
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
if (!AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $model->dept_id ?? null)) {
return $this->fail('no permission to view this record');
}
$data = is_array($model) ? $model : $model->toArray();
@@ -166,12 +169,9 @@ class DicePlayerWalletRecordController extends BaseController
return $this->fail('please login first');
}
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
if ($player) {
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
return $this->fail('no permission to operate this player');
}
$player = DicePlayer::field('dept_id')->where('id', $playerId)->find();
if ($player && !AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $player->dept_id ?? null, $request->input('dept_id'))) {
return $this->fail('no permission to operate this player');
}
try {
@@ -183,20 +183,21 @@ class DicePlayerWalletRecordController extends BaseController
}
/**
* 更新数据
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('玩家钱包流水修改', 'dice:player_wallet_record:index:update')]
public function update(Request $request): Response
#[Permission('玩家钱包流水添加', 'dice:player_wallet_record:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
return $this->success('add success');
}
return $this->fail('add failed');
}
}

View File

@@ -4,6 +4,7 @@
// +----------------------------------------------------------------------
namespace app\dice\controller\reward;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
use app\dice\model\reward\DiceReward;
@@ -42,11 +43,18 @@ class DiceRewardController extends BaseController
$orderType = $request->input('orderType', 'asc');
$logic = new DiceRewardLogic();
$data = $logic->getListWithConfig($direction, [
'tier' => $tier,
'orderField' => $orderField,
'orderType' => $orderType,
], $page, $limit);
$data = $logic->getListWithConfig(
$direction,
[
'tier' => $tier,
'orderField' => $orderField,
'orderType' => $orderType,
],
$page,
$limit,
$this->adminInfo ?? null,
$request->input('dept_id')
);
return $this->success($data);
}
@@ -61,8 +69,10 @@ class DiceRewardController extends BaseController
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
$direction = DiceReward::DIRECTION_CLOCKWISE;
}
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$logic = new DiceRewardLogic();
$data = $logic->getListGroupedByTierForDirection($direction);
$data = $logic->getListGroupedByTierForDirection($direction, $deptId);
return $this->success($data);
}
@@ -74,38 +84,44 @@ class DiceRewardController extends BaseController
#[Permission('奖励对照列表', 'dice:reward:index:index')]
public function weightRatioListWithDirection(Request $request): Response
{
DiceReward::refreshCache();
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$logic = new DiceRewardLogic();
$data = $logic->getListGroupedByTierWithDirection();
$data = $logic->getListGroupedByTierWithDirection($deptId);
return $this->success($data);
}
/**
* 一键测试权重:创建测试记录并启动单进程后台执行,按付费/免费、顺逆方向交替写入 dice_play_record_test
* 参数lottery_config_id 可选,不选则传 paid_tier_weights / free_tier_weights 自定义档位;
* paid_s_count, paid_n_count, free_s_count, free_n_count或兼容旧版 s_count, n_count
* 一键测试权重:创建测试记录并启动单进程后台执行,写入 dice_play_record_test
* 参数lottery_config_id 可选paid_tier_weights / free_tier_weights 自定义档位;
* paid_s_count, paid_n_count
* chain_free_mode=1仅按付费次数模拟付费抽到再来一次/T5 则在队列中插入免费局同底注、lottery_type=免费、paid_amount=0
* kill_mode_enabled=1测试内启用杀分当模拟玩家累计盈利达到 test_safety_line 后,付费抽奖切到 killScore
*/
#[Permission('一键测试权重', 'dice:reward:index:startWeightTest')]
public function startWeightTest(Request $request): Response
{
$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,
's_count' => $post['s_count'] ?? null,
'n_count' => $post['n_count'] ?? null,
'paid_s_count' => $post['paid_s_count'] ?? null,
'paid_n_count' => $post['paid_n_count'] ?? null,
'free_s_count' => $post['free_s_count'] ?? null,
'free_n_count' => $post['free_n_count'] ?? null,
'paid_tier_weights' => $post['paid_tier_weights'] ?? null,
'free_tier_weights' => $post['free_tier_weights'] ?? null,
'chain_free_mode' => $post['chain_free_mode'] ?? null,
'kill_mode_enabled' => $post['kill_mode_enabled'] ?? null,
'test_safety_line' => $post['test_safety_line'] ?? null,
'dept_id' => $post['dept_id'] ?? null,
'ante_config_id' => $post['ante_config_id'] ?? null,
];
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $post);
try {
$logic = new DiceRewardConfigRecordLogic();
$recordId = $logic->createWeightTestRecord($params, $adminId);
$recordId = $logic->createWeightTestRecord($params, $adminId, $this->adminInfo ?? null, $requestDeptId);
return $this->success(['record_id' => $recordId]);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());
@@ -165,8 +181,9 @@ class DiceRewardController extends BaseController
return $this->fail('parameter items must be an array');
}
try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$logic = new DiceRewardLogic();
$logic->batchUpdateWeights($items);
$logic->batchUpdateWeights($items, $deptId);
return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());
@@ -189,8 +206,9 @@ class DiceRewardController extends BaseController
return $this->fail('parameter items must be an array');
}
try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$logic = new DiceRewardLogic();
$logic->batchUpdateWeightsByDirection($direction, $items);
$logic->batchUpdateWeightsByDirection($direction, $items, $deptId);
return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());

View File

@@ -6,9 +6,11 @@
// +----------------------------------------------------------------------
namespace app\dice\controller\reward_config;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\reward_config\DiceRewardConfigLogic;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\reward\DiceReward;
use app\dice\validate\reward_config\DiceRewardConfigValidate;
use plugin\saiadmin\service\Permission;
use support\Request;
@@ -46,7 +48,9 @@ class DiceRewardConfigController extends BaseController
['tier', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
AdminScopeHelper::applyConfigScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
// 奖励索引 + 大奖权重共约 32 条,配置页需一次返回本渠道全部数据
$data = $query->order('id', 'asc')->select()->toArray();
return $this->success($data);
}
@@ -78,6 +82,7 @@ class DiceRewardConfigController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareConfigSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -95,8 +100,19 @@ class DiceRewardConfigController extends BaseController
public function update(Request $request): Response
{
$data = $request->post();
if ($data === [] || $data === null) {
$data = $request->all();
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), is_array($data) ? $data : []);
$model = $this->logic->read($data['id'] ?? 0);
if ($model) {
$recordDeptId = is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null);
if (! AdminScopeHelper::canAccessDept($this->adminInfo ?? null, $recordDeptId, $requestDeptId)) {
return $this->fail('no permission to update this record');
}
}
$result = $this->logic->edit($data['id'], $data, $this->adminInfo ?? null, $requestDeptId);
if ($result) {
return $this->success('update success');
} else {
@@ -123,7 +139,9 @@ class DiceRewardConfigController extends BaseController
foreach ($items as $item) {
$this->validate('batch_update', array_merge($item, ['id' => $item['id']]));
}
$this->logic->batchUpdate($items);
$requestDeptId = AdminScopeHelper::pickRequestDeptId($request->input('dept_id'), $request->post());
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $requestDeptId);
$this->logic->batchUpdate($items, $deptId);
return $this->success('save success');
}
@@ -139,7 +157,7 @@ class DiceRewardConfigController extends BaseController
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
$result = $this->logic->destroy($ids, $this->adminInfo ?? null, $request->input('dept_id'));
if ($result) {
return $this->success('delete success');
} else {
@@ -155,8 +173,10 @@ class DiceRewardConfigController extends BaseController
#[Permission('奖励配置列表', 'dice:reward_config:index:index')]
public function weightRatioList(Request $request): Response
{
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
DiceReward::refreshCache($deptId);
$rewardLogic = new DiceRewardLogic();
$data = $rewardLogic->getListGroupedByTierWithDirection();
$data = $rewardLogic->getListGroupedByTierWithDirection($deptId);
return $this->success($data);
}
@@ -174,8 +194,9 @@ class DiceRewardConfigController extends BaseController
return $this->fail('parameter items must be an array');
}
try {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$rewardLogic = new DiceRewardLogic();
$rewardLogic->batchUpdateWeights($items);
$rewardLogic->batchUpdateWeights($items, $deptId);
return $this->success('save success');
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());
@@ -199,7 +220,8 @@ class DiceRewardConfigController extends BaseController
if ($err !== null) {
return $this->fail($err);
}
$this->logic->batchUpdateBigwinWeight($items);
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$this->logic->batchUpdateBigwinWeight($items, $deptId);
return $this->success('save success');
}
@@ -214,7 +236,8 @@ class DiceRewardConfigController extends BaseController
{
try {
$rewardLogic = new DiceRewardLogic();
$result = $rewardLogic->createRewardReferenceFromConfig();
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo ?? null, $request->input('dept_id'));
$result = $rewardLogic->createRewardReferenceFromConfig($deptId);
return $this->success($result, 'create reward mapping success');
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage());

View File

@@ -8,6 +8,7 @@ namespace app\dice\controller\reward_config_record;
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
use app\dice\validate\reward_config_record\DiceRewardConfigRecordValidate;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\service\Permission;
@@ -38,8 +39,11 @@ class DiceRewardConfigRecordController extends BaseController
public function index(Request $request): Response
{
$where = $request->more([
['paid_planned_spins', ''],
['ante', ''],
]);
$query = $this->logic->search($where);
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null, $request->input('dept_id'));
$data = $this->logic->getList($query);
return $this->success($data);
}
@@ -94,6 +98,7 @@ class DiceRewardConfigRecordController extends BaseController
{
$data = $request->post();
$this->validate('save', $data);
AdminScopeHelper::prepareBusinessSaveData($data, $this->adminInfo ?? null, $request->input('dept_id'), $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
@@ -102,24 +107,6 @@ class DiceRewardConfigRecordController extends BaseController
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('奖励配置权重测试记录修改', 'dice:reward_config_record:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request

View File

@@ -3,21 +3,75 @@ declare(strict_types=1);
namespace app\dice\helper;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
/**
* 管理员数据范围辅助类
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
* 大富翁数据范围:按渠道 dept_id 隔离(关联 sa_system_dept
*/
class AdminScopeHelper
{
/** 超管查看默认配置模板 */
public const DEFAULT_TEMPLATE_DEPT = 0;
/**
* 获取当前管理员可访问的 admin_id 列表
* 超级管理员(id=1) 返回 null 表示不限制
* 普通管理员返回其本人及部门下属管理员的 id 列表
* 当前管理员所属渠道 ID超级管理员(id=1) 返回 null 表示不限制
*/
public static function getDeptId(?array $adminInfo): ?int
{
if (empty($adminInfo) || !isset($adminInfo['id'])) {
return null;
}
$adminId = (int) $adminInfo['id'];
if ($adminId <= 1) {
return null;
}
$deptList = $adminInfo['deptList'] ?? [];
if (!empty($deptList['id'])) {
return (int) $deptList['id'];
}
if (!empty($adminInfo['dept_id'])) {
return (int) $adminInfo['dept_id'];
}
return 0;
}
public static function isSuperAdmin(?array $adminInfo): bool
{
return !empty($adminInfo['id']) && (int) $adminInfo['id'] <= 1;
}
/**
* 解析配置类接口的渠道 ID请求参数 dept_id
* 超管0 或空=默认模板(null)>0=指定渠道
* 普通管理员:固定本渠道
*/
public static function resolveConfigDeptId(?array $adminInfo, $requestDeptId): int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : self::DEFAULT_TEMPLATE_DEPT;
}
if ($requestDeptId === null || $requestDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
$id = (int) $requestDeptId;
if ($id === self::DEFAULT_TEMPLATE_DEPT) {
return self::DEFAULT_TEMPLATE_DEPT;
}
return $id > 0 ? $id : self::DEFAULT_TEMPLATE_DEPT;
}
public static function isTemplateDeptId($deptId): bool
{
return $deptId === null || $deptId === '' || (int) $deptId === self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 同渠道下可访问的管理员 ID
*
* @param array|null $adminInfo 当前登录管理员信息(含 id、deptList
* @return int[]|null null=不限制(超级管理员),否则为可访问的 admin_id 数组
* @return int[]|null null=不限制
*/
public static function getAllowedAdminIds(?array $adminInfo): ?array
{
@@ -28,33 +82,285 @@ class AdminScopeHelper
if ($adminId <= 1) {
return null;
}
$deptList = $adminInfo['deptList'] ?? [];
if (empty($deptList) || !isset($deptList['id'])) {
$deptId = self::getDeptId($adminInfo);
if ($deptId === null) {
return null;
}
if ($deptId <= 0) {
return [$adminId];
}
$query = SystemUser::field('id');
$query->auth($deptList);
$ids = $query->column('id');
return array_map('intval', $ids ?: []);
$ids = SystemUser::where('dept_id', $deptId)->column('id');
return array_map('intval', $ids ?: [$adminId]);
}
public static function fillDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
return;
}
$deptId = self::resolveConfigDeptId($adminInfo, $requestDeptId ?? ($data['filter_dept_id'] ?? null));
if ($deptId > 0) {
$data['dept_id'] = $deptId;
} elseif (!isset($data['dept_id']) || self::isTemplateDeptId($data['dept_id'])) {
$data['dept_id'] = self::DEFAULT_TEMPLATE_DEPT;
}
}
/**
* 对查询应用 admin_id 范围过滤
*
* @param object $query ThinkORM 查询对象
* @param array|null $adminInfo 当前登录管理员信息
* @return void
* 业务数据新增:按渠道写入 dept_id玩家、记录等
* 优先级:已有 dept_id → 所属管理员 admin_id → 请求渠道 → 当前登录人渠道
*/
public static function applyAdminScope($query, ?array $adminInfo): void
public static function fillBusinessDeptId(array &$data, ?array $adminInfo, $requestDeptId = null): void
{
$allowedIds = self::getAllowedAdminIds($adminInfo);
if ($allowedIds === null) {
if (isset($data['dept_id']) && $data['dept_id'] !== '' && $data['dept_id'] !== null) {
$data['dept_id'] = (int) $data['dept_id'];
if ($data['dept_id'] > 0) {
return;
}
}
if (!empty($data['player_id'])) {
$playerDeptId = self::resolveDeptIdByPlayerId($data['player_id']);
if ($playerDeptId !== null && $playerDeptId > 0) {
$data['dept_id'] = $playerDeptId;
return;
}
}
if (!empty($data['admin_id'])) {
$ownerDeptId = self::resolveDeptIdByAdminId($data['admin_id']);
if ($ownerDeptId !== null && $ownerDeptId > 0) {
$data['dept_id'] = $ownerDeptId;
return;
}
}
$deptId = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($deptId !== null && $deptId > 0) {
$data['dept_id'] = $deptId;
return;
}
if (empty($allowedIds)) {
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
$data['dept_id'] = $scopeDeptId;
}
}
/**
* 业务新增:解析请求渠道并填充 dept_id缺失时抛错
*/
public static function prepareBusinessSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillBusinessDeptId($data, $adminInfo, $requestDeptId);
self::assertBusinessDeptId($data);
}
/**
* 配置新增:解析请求渠道并填充 dept_id
*/
public static function prepareConfigSaveData(
array &$data,
?array $adminInfo,
$inputDeptId = null,
array $body = []
): void {
$requestDeptId = self::pickRequestDeptId($inputDeptId, $body);
self::fillDeptId($data, $adminInfo, $requestDeptId);
}
/**
* 业务表 dept_id 必须 > 0非默认模板
*/
public static function assertBusinessDeptId(array $data): void
{
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
throw new ApiException('CHANNEL_DEPT_ID_REQUIRED');
}
if ((int) $data['dept_id'] <= 0) {
throw new ApiException('INVALID_CHANNEL_DEPT_ID');
}
}
/**
* 根据玩家 ID 解析所属渠道
*/
public static function resolveDeptIdByPlayerId($playerId): ?int
{
if ($playerId === null || $playerId === '') {
return null;
}
$player = DicePlayer::field('dept_id,admin_id')->find($playerId);
if (!$player || $player->isEmpty()) {
return null;
}
$deptId = $player->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if (!empty($player->admin_id)) {
return self::resolveDeptIdByAdminId($player->admin_id);
}
return null;
}
/**
* 根据后台管理员 ID 解析所属渠道
*/
public static function resolveDeptIdByAdminId($adminId): ?int
{
if ($adminId === null || $adminId === '') {
return null;
}
$admin = SystemUser::find($adminId);
if (!$admin || $admin->isEmpty()) {
return null;
}
$deptId = $admin->dept_id ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return null;
}
/**
* 规范化记录上的 dept_idnull 视为默认模板 0
*/
public static function normalizeRecordDeptId($recordDeptId): int
{
if ($recordDeptId === null || $recordDeptId === '') {
return self::DEFAULT_TEMPLATE_DEPT;
}
return (int) $recordDeptId;
}
/**
* 玩家端读取游戏配置时使用的渠道 ID玩家 dept_id 优先,否则按所属管理员)
*/
public static function resolvePlayerConfigDeptId($player): int
{
$deptId = null;
$adminId = null;
if (is_array($player)) {
$deptId = $player['dept_id'] ?? null;
$adminId = $player['admin_id'] ?? null;
} elseif (is_object($player)) {
$deptId = $player->dept_id ?? null;
$adminId = $player->admin_id ?? null;
}
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
if ($adminId !== null && $adminId !== '') {
$fromAdmin = self::resolveDeptIdByAdminId($adminId);
if ($fromAdmin !== null && $fromAdmin > 0) {
return $fromAdmin;
}
}
return self::DEFAULT_TEMPLATE_DEPT;
}
/**
* 从请求参数或请求体中解析 dept_id兼容 PUT JSON 仅出现在 body 的情况)
*/
public static function pickRequestDeptId($inputDeptId, array $body = [])
{
if ($inputDeptId !== null && $inputDeptId !== '') {
return $inputDeptId;
}
if (isset($body['dept_id']) && $body['dept_id'] !== '' && $body['dept_id'] !== null) {
return $body['dept_id'];
}
return null;
}
public static function canAccessDept(?array $adminInfo, $recordDeptId, $requestDeptId = null): bool
{
$recordDeptId = self::normalizeRecordDeptId($recordDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId === null) {
if ($requestDeptId === null || $requestDeptId === '') {
return true;
}
$target = self::resolveConfigDeptId($adminInfo, $requestDeptId);
if (self::isTemplateDeptId($target)) {
return self::isTemplateDeptId($recordDeptId);
}
return $recordDeptId === $target;
}
if ($recordDeptId === self::DEFAULT_TEMPLATE_DEPT && $scopeDeptId > 0) {
return false;
}
return $recordDeptId === $scopeDeptId;
}
/**
* 业务页渠道 ID超管通过请求 dept_id 筛选;未传或 <=0 时不限制
*/
public static function resolveBusinessDeptId(?array $adminInfo, $requestDeptId): ?int
{
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null) {
return $scopeDeptId > 0 ? $scopeDeptId : null;
}
if ($requestDeptId === null || $requestDeptId === '') {
return null;
}
$id = (int) $requestDeptId;
return $id > 0 ? $id : null;
}
/**
* 业务数据列表(玩家、记录、工作台等)
*/
public static function applyAdminScope($query, ?array $adminInfo, $requestDeptId = null): void
{
if (self::getDeptId($adminInfo) === null) {
$target = self::resolveBusinessDeptId($adminInfo, $requestDeptId);
if ($target !== null && $target > 0) {
$query->where('dept_id', $target);
}
return;
}
$deptId = self::getDeptId($adminInfo);
if ($deptId <= 0) {
$query->whereRaw('1=0');
return;
}
$query->whereIn('admin_id', $allowedIds);
$query->where('dept_id', $deptId);
}
/**
* 配置类列表:超管按所选渠道/默认模板筛选
*/
public static function applyConfigScope($query, ?array $adminInfo, $requestDeptId = null, string $deptColumn = 'dept_id'): void
{
$targetDeptId = self::resolveConfigDeptId($adminInfo, $requestDeptId);
$scopeDeptId = self::getDeptId($adminInfo);
if ($scopeDeptId !== null && !self::isSuperAdmin($adminInfo)) {
if ($scopeDeptId <= 0) {
$query->whereRaw('1=0');
return;
}
$query->where($deptColumn, $scopeDeptId);
return;
}
if (self::isTemplateDeptId($targetDeptId)) {
$templateId = self::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId, $deptColumn) {
$q->where($deptColumn, $templateId)->whereOr($deptColumn, null);
});
return;
}
$query->where($deptColumn, $targetDeptId);
}
}

View File

@@ -0,0 +1,139 @@
<?php
declare(strict_types=1);
namespace app\dice\helper;
use plugin\saiadmin\exception\ApiException;
/**
* 配置类数据按渠道隔离的更新(防止 find(id) 误更新其他渠道同业务主键行)
*/
class ConfigScopeEditHelper
{
/**
* 在查询上附加渠道条件
*/
public static function applyDeptIdWhere($query, int $deptId, string $column = 'dept_id'): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) use ($deptId, $column) {
$q->where($column, $deptId);
if (method_exists($q, 'orWhereNull')) {
$q->orWhereNull($column);
} else {
$q->whereOr($column, null);
}
});
return;
}
$query->where($column, $deptId);
}
/**
* 按主键 + 渠道更新配置行
*
* @param Model $model 模型实例(用于取表名、主键)
* @param mixed $primaryKeyValue 列表/表单中的主键值
* @param int $deptId 渠道 ID0=默认模板)
* @param array $data 更新字段
* @param array $forbidden 禁止写入的字段名
*/
/**
* 按主键更新(主键全局唯一表如 dice_lottery_pool_config
* 以库中记录的 dept_id 为准,避免请求未带 dept_id 时误按默认模板 0 查找失败
*/
public static function updateByPkAndDept(
object $model,
$primaryKeyValue,
int $requestDeptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
?array $adminInfo = null,
$rawRequestDeptId = null
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$pk = self::resolvePk($model);
$record = $model->where($pk, $primaryKeyValue)->find();
if ($record === null) {
throw new ApiException('data not found');
}
$recordDeptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($record) ? ($record['dept_id'] ?? null) : ($record->dept_id ?? null)
);
if ($adminInfo !== null && ! AdminScopeHelper::canAccessDept($adminInfo, $recordDeptId, $rawRequestDeptId)) {
throw new ApiException('no permission to update this record');
}
if ($rawRequestDeptId !== null && $rawRequestDeptId !== '') {
$targetDeptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $rawRequestDeptId);
if ($targetDeptId !== $recordDeptId) {
throw new ApiException('record does not belong to selected channel');
}
}
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $recordDeptId);
$affected = $query->update($data);
return $affected !== false;
}
/**
* dice_reward_config / dice_config业务 id025 等)+ 渠道更新
*/
public static function updateByBusinessIdAndDept(
object $model,
int $businessId,
int $deptId,
array $data,
array $forbidden = ['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id']
): bool {
foreach ($forbidden as $field) {
unset($data[$field]);
}
if ($data === []) {
return true;
}
$query = $model->where('id', $businessId);
self::applyDeptIdWhere($query, $deptId);
$record = (clone $query)->find();
if ($record === null) {
throw new ApiException('config id=' . $businessId . ' not found for current channel');
}
$affected = $query->update($data);
return $affected !== false;
}
/**
* 列表/读取:按主键 + 渠道取单条(避免 find(pk) 命中其他渠道)
*/
private static function resolvePk(object $model): string
{
if (method_exists($model, 'getPk')) {
return (string) $model->getPk();
}
if (method_exists($model, 'getKeyName')) {
return (string) $model->getKeyName();
}
return 'id';
}
public static function findByPkAndDept(object $model, $primaryKeyValue, int $deptId)
{
$pk = self::resolvePk($model);
$query = $model->where($pk, $primaryKeyValue);
self::applyDeptIdWhere($query, $deptId);
return $query->find();
}
}

View File

@@ -0,0 +1,104 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\logic\ante_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\basic\DiceBaseLogic;
/**
* 底注配置逻辑层
*/
class DiceAnteConfigLogic extends DiceBaseLogic
{
public function __construct()
{
$this->model = new DiceAnteConfig();
}
public function add(array $data): mixed
{
return $this->transaction(function () use ($data) {
$this->normalizeDefaultField($data);
$deptId = AdminScopeHelper::resolveConfigDeptId(null, $data['dept_id'] ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults(null, $deptId);
}
return parent::add($data);
});
}
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return $this->transaction(function () use ($id, $data, $deptId, $adminInfo, $pickedDeptId) {
$this->normalizeDefaultField($data);
if ((int) ($data['is_default'] ?? 0) === 1) {
$this->clearOtherDefaults((int) $id, $deptId);
}
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
});
}
/**
* 防止删除后全表无默认:若删除了默认项,自动把最小 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, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$query = $this->model->where('is_default', 1);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
$query->update(['is_default' => 0]);
}
}

View File

@@ -6,7 +6,9 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\config;
use plugin\saiadmin\basic\eloquent\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\config\DiceConfig;
@@ -14,7 +16,7 @@ use app\dice\model\config\DiceConfig;
/**
* 摇色子配置逻辑层
*/
class DiceConfigLogic extends BaseLogic
class DiceConfigLogic extends DiceBaseLogic
{
/**
* 构造函数
@@ -24,4 +26,13 @@ class DiceConfigLogic extends BaseLogic
$this->model = new DiceConfig();
}
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
return ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
}
}

View File

@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\logic\game;
use app\dice\basic\DiceBaseLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\game\DiceGame;
/**
* 游戏管理逻辑层
*/
class DiceGameLogic extends DiceBaseLogic
{
public function __construct()
{
$this->model = new DiceGame();
}
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
}

View File

@@ -6,8 +6,10 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\lottery_pool_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\think\Cache;
@@ -15,7 +17,7 @@ use support\think\Cache;
/**
* 色子奖池配置逻辑层
*/
class DiceLotteryPoolConfigLogic extends BaseLogic
class DiceLotteryPoolConfigLogic extends DiceBaseLogic
{
/** Redis 当前彩金池type=0 实例key无则按 type=0 创建 */
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
@@ -30,19 +32,55 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
$this->model = new DiceLotteryPoolConfig();
}
/**
* 按渠道隔离更新(主键 id 全局唯一,仍校验 dept_id 防止越权)
*/
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$pickedDeptId = AdminScopeHelper::pickRequestDeptId($requestDeptId, $data);
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $pickedDeptId);
return ConfigScopeEditHelper::updateByPkAndDept(
$this->model,
$id,
$deptId,
$data,
['id', 'dept_id', 'create_time', 'update_time', 'delete_time', 'row_id'],
$adminInfo,
$pickedDeptId
);
}
/**
* 获取当前彩金池type=0+ 杀分权重为 type=1 的只读展示
* profit_amount 每次从 DB 实时读取t1_weightt5_weight 来自 type=1杀分权重不可在弹窗内修改
*
* @return array{id:int,name:string,safety_line:int,kill_enabled:int,t1_weight:int,...,t5_weight:int,profit_amount:float}
*/
public function getCurrentPool(): array
public function getCurrentPool(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): array
{
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$query0 = DiceLotteryPoolConfig::where('name', 'default');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query0->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query0->where('dept_id', $deptId);
}
$configType0 = $query0->find();
if (!$configType0) {
throw new ApiException('No name=default pool config found, please create one first');
}
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$query1 = DiceLotteryPoolConfig::where('name', 'killScore');
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query1->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query1->where('dept_id', $deptId);
}
$configType1 = $query1->find();
$row0 = $configType0->toArray();
$profitAmount = isset($row0['profit_amount']) ? (float) $row0['profit_amount'] : (isset($row0['ev']) ? (float) $row0['ev'] : 0.0);
$pool = [
@@ -66,9 +104,9 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
*
* @param array{safety_line?:int,kill_enabled?:int} $data
*/
public function updateCurrentPool(array $data): void
public function updateCurrentPool(array $data, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$pool = $this->getCurrentPool();
$pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id'];
if (!array_key_exists('safety_line', $data) && !array_key_exists('kill_enabled', $data)) {
return;
@@ -83,17 +121,21 @@ class DiceLotteryPoolConfigLogic extends BaseLogic
if ($update === []) {
return;
}
DiceLotteryPoolConfig::where('id', $id)->update($update);
$query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update($update);
}
/**
* 重置当前彩金池的玩家累计盈利:将 profit_amount 置为 0并刷新 Redis 缓存
*/
public function resetProfitAmount(): void
public function resetProfitAmount(int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$pool = $this->getCurrentPool();
$pool = $this->getCurrentPool($deptId);
$id = (int) $pool['id'];
DiceLotteryPoolConfig::where('id', $id)->update(['profit_amount' => 0]);
$query = DiceLotteryPoolConfig::where('id', $id);
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$query->update(['profit_amount' => 0]);
$pool['profit_amount'] = 0.0;
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\play_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record\DicePlayRecord;
@@ -14,7 +14,7 @@ use app\dice\model\play_record\DicePlayRecord;
/**
* 玩家抽奖记录逻辑层
*/
class DicePlayRecordLogic extends BaseLogic
class DicePlayRecordLogic extends DiceBaseLogic
{
/**
* 构造函数

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\play_record_test;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\play_record_test\DicePlayRecordTest;
@@ -14,7 +14,7 @@ use app\dice\model\play_record_test\DicePlayRecordTest;
/**
* 玩家抽奖记录(测试数据)逻辑层
*/
class DicePlayRecordTestLogic extends BaseLogic
class DicePlayRecordTestLogic extends DiceBaseLogic
{
/**
* 构造函数
@@ -22,6 +22,8 @@ class DicePlayRecordTestLogic extends BaseLogic
public function __construct()
{
$this->model = new DicePlayRecordTest();
// 默认按 id 倒序,保证列表默认显示最新记录
$this->setOrderField('id')->setOrderType('DESC');
}
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\player\DicePlayer;
@@ -14,7 +14,7 @@ use app\dice\model\player\DicePlayer;
/**
* 大富翁-玩家逻辑层
*/
class DicePlayerLogic extends BaseLogic
class DicePlayerLogic extends DiceBaseLogic
{
/** 密码加密盐(可与 config 统一) */
private const PASSWORD_SALT = 'dice_player_salt_2024';

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player_ticket_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -14,7 +14,7 @@ use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
/**
* 抽奖券获取记录逻辑层
*/
class DicePlayerTicketRecordLogic extends BaseLogic
class DicePlayerTicketRecordLogic extends DiceBaseLogic
{
/**
* 构造函数

View File

@@ -6,7 +6,8 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\player_wallet_record;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
use app\dice\model\player\DicePlayer;
@@ -15,7 +16,7 @@ use app\api\cache\UserCache;
/**
* 玩家钱包流水逻辑层
*/
class DicePlayerWalletRecordLogic extends BaseLogic
class DicePlayerWalletRecordLogic extends DiceBaseLogic
{
/**
* 构造函数
@@ -27,6 +28,18 @@ class DicePlayerWalletRecordLogic extends BaseLogic
$this->setOrderType('DESC');
}
/**
* 按与列表相同的筛选条件汇总平台币变化(不含 with / 分页 / 排序)
*/
public function sumCoinBySearch(array $where, ?array $adminInfo, $requestDeptId = null): float
{
$query = $this->search($where);
AdminScopeHelper::applyAdminScope($query, $adminInfo, $requestDeptId);
$table = $this->model->getTable();
$sum = $query->sum($table . '.coin');
return round((float) $sum, 2);
}
/**
* 添加数据(补全抽奖次数字段默认值)
*/
@@ -83,9 +96,11 @@ class DicePlayerWalletRecordLogic extends BaseLogic
}
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
$playerDeptId = ($player->dept_id ?? null) ? (int) $player->dept_id : null;
$record = [
'player_id' => $playerId,
'admin_id' => $playerAdminId,
'dept_id' => $playerDeptId,
'coin' => $type === 3 ? $coin : -$coin,
'type' => $type,
'wallet_before' => $walletBefore,

View File

@@ -4,6 +4,8 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\exception\ApiException;
@@ -29,8 +31,14 @@ class DiceRewardLogic
* @param int $limit
* @return array{total: int, per_page: int, current_page: int, data: array}
*/
public function getListWithConfig(int $direction, array $where, int $page = 1, int $limit = 10): array
{
public function getListWithConfig(
int $direction,
array $where,
int $page = 1,
int $limit = 10,
?array $adminInfo = null,
$requestDeptId = null
): array {
$tier = isset($where['tier']) ? trim((string) $where['tier']) : '';
$orderField = isset($where['orderField']) && $where['orderField'] !== '' ? (string) $where['orderField'] : 'r.tier';
$orderType = isset($where['orderType']) && strtoupper((string) $where['orderType']) === 'DESC' ? 'desc' : 'asc';
@@ -41,6 +49,10 @@ class DiceRewardLogic
->order($orderField, $orderType)
->order('r.end_index', 'asc');
if ($adminInfo !== null) {
AdminScopeHelper::applyConfigScope($query, $adminInfo, $requestDeptId, 'r.dept_id');
}
if ($tier !== '') {
$query->where('r.tier', $tier);
}
@@ -74,7 +86,7 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针
* @param array<int, array{id: int, weight: int}> $items id 为 end_indexDiceRewardConfig.id
*/
public function batchUpdateWeightsByDirection(int $direction, array $items): void
public function batchUpdateWeightsByDirection(int $direction, array $items, ?int $deptId = null): void
{
if (empty($items)) {
return;
@@ -90,23 +102,36 @@ class DiceRewardLogic
}
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$tier = DiceRewardConfig::where('id', $id)->value('tier');
$configQuery = DiceRewardConfig::where('id', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
}
$tier = $configQuery->value('tier');
if ($tier === null || $tier === '') {
throw new ApiException(\app\api\util\ApiLang::translateParams('配置ID %s 不存在或档位为空', [$id]));
}
$tier = (string) $tier;
$affected = DiceReward::where('tier', $tier)->where('direction', $direction)->where('end_index', $id)->update(['weight' => $weight]);
$rewardQuery = DiceReward::where('tier', $tier)
->where('direction', $direction)
->where('end_index', $id);
if ($deptId !== null) {
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $deptId);
}
$affected = $rewardQuery->update(['weight' => $weight]);
if ($affected === 0) {
$m = new DiceReward();
$m->tier = $tier;
$m->direction = $direction;
$m->end_index = $id;
$m->weight = $weight;
if ($deptId !== null && $deptId > 0) {
$m->dept_id = $deptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/**
@@ -114,11 +139,11 @@ class DiceRewardLogic
* @param int $direction 0=顺时针 1=逆时针
* @return array<string, array> 键 T1|T2|...|BIGWIN值为该档位下带 weight 的行数组
*/
public function getListGroupedByTierForDirection(int $direction): array
public function getListGroupedByTierForDirection(int $direction, ?int $deptId = null): array
{
$configInstance = DiceRewardConfig::getCachedInstance();
$configInstance = DiceRewardConfig::getCachedInstance($deptId);
$byTier = $configInstance['by_tier'] ?? [];
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = [];
@@ -153,9 +178,9 @@ class DiceRewardLogic
*
* @return array<string, array{0: array, 1: array}>
*/
public function getListGroupedByTierWithDirection(): array
public function getListGroupedByTierWithDirection(?int $deptId = null): array
{
$rewardInstance = DiceReward::getCachedInstance();
$rewardInstance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
$result = [];
@@ -185,7 +210,7 @@ class DiceRewardLogic
* @param array<int, array{id: int, weight: int}> $items 每项 id 为 dice_reward 表主键weight 为 1-10000
* @throws ApiException
*/
public function batchUpdateWeights(array $items): void
public function batchUpdateWeights(array $items, ?int $deptId = null): void
{
if (empty($items)) {
return;
@@ -203,13 +228,24 @@ class DiceRewardLogic
}
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
$model = DiceReward::find($id);
$query = DiceReward::where('id', $id);
if ($deptId !== null) {
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
}
$model = $query->find();
if ($model !== null) {
$model->weight = $weight;
$model->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/** BIGWIN 权重范围0=0% 中奖10000=100% 中奖grid_number=5/30 固定 100% 不可改 */
@@ -219,9 +255,9 @@ class DiceRewardLogic
* 按 grid_number 获取 BIGWIN 档位权重(取顺时针方向,用于编辑展示)
* 若 DiceReward 无该点数则 5/30 返回 10000其余返回 0
*/
public function getBigwinWeightByGridNumber(int $gridNumber): int
public function getBigwinWeightByGridNumber(int $gridNumber, ?int $deptId = null): int
{
$inst = DiceReward::getCachedInstance();
$inst = DiceReward::getCachedInstance($deptId);
$rows = $inst['by_tier_direction']['BIGWIN'][DiceReward::DIRECTION_CLOCKWISE] ?? [];
foreach ($rows as $row) {
if ((int) ($row['grid_number'] ?? 0) === $gridNumber) {
@@ -235,21 +271,24 @@ class DiceRewardLogic
* 更新 BIGWIN 档位某点数的权重(顺/逆时针同时更新0=0% 中奖10000=100% 中奖
* 表 dice_reward 唯一键为 (direction, grid_number),同一点数同一方向仅一条记录,故先按该键查找再更新,避免重复插入
*/
public function updateBigwinWeight(int $gridNumber, int $weight): void
public function updateBigwinWeight(int $gridNumber, int $weight, ?int $deptId = null): void
{
$weight = min(self::BIGWIN_WEIGHT_MAX, max(0, $weight));
$config = DiceRewardConfig::where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->find();
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$configQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($configQuery, $deptId);
$config = $configQuery->find();
if (! $config) {
return;
}
$configArr = $config->toArray();
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
// 按唯一键 (direction, grid_number) 查找,存在则更新,不存在则插入
$row = DiceReward::where('direction', $direction)
->where('grid_number', $gridNumber)
->find();
$rowQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($rowQuery, $deptId);
$row = $rowQuery->find();
if ($row) {
$row->tier = 'BIGWIN';
$row->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
@@ -272,10 +311,13 @@ class DiceRewardLogic
$m->remark = (string) ($configArr['remark'] ?? '');
$m->type = $configArr['type'] ?? null;
$m->weight = $weight > 0 ? $weight : self::WEIGHT_MIN;
if (!AdminScopeHelper::isTemplateDeptId($deptId)) {
$m->dept_id = $deptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId);
}
/** 盘面格数(用于顺时针/逆时针计算 end_index */
@@ -309,9 +351,19 @@ class DiceRewardLogic
* @return array{created_clockwise: int, created_counterclockwise: int, updated_clockwise: int, updated_counterclockwise: int, skipped: int}
* @throws ApiException
*/
public function createRewardReferenceFromConfig(): array
public function createRewardReferenceFromConfig(?int $deptId = null): array
{
$list = DiceRewardConfig::order('id', 'asc')->select()->toArray();
$configQuery = DiceRewardConfig::order('id', 'asc');
if ($deptId === null || $deptId === \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = \app\dice\helper\AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$configQuery->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
$deptId = null;
} else {
$configQuery->where('dept_id', $deptId);
}
$list = $configQuery->select()->toArray();
if (empty($list)) {
throw new ApiException('Reward config is empty, please maintain dice_reward_config first');
}
@@ -326,8 +378,12 @@ class DiceRewardLogic
}
$table = (new DiceReward())->getTable();
Db::execute('DELETE FROM `' . $table . '`');
DiceReward::refreshCache();
if ($deptId === null) {
Db::table($table)->whereNull('dept_id')->delete();
} else {
Db::table($table)->where('dept_id', $deptId)->delete();
}
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
// 按 id 排序后,盘面位置 0..25 对应 $list[$pos],避免 config.id 非 0-25/1-26 时取模结果找不到
$gridToPosition = [];
@@ -379,7 +435,13 @@ class DiceRewardLogic
'remark' => $configCw['remark'] ?? '',
'type' => isset($configCw['type']) ? (int) $configCw['type'] : 0,
];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber)->find();
$existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_CLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCw);
$updatedCw++;
@@ -395,6 +457,9 @@ class DiceRewardLogic
$m->real_ev = $configCw['real_ev'] ?? null;
$m->remark = $configCw['remark'] ?? '';
$m->type = isset($configCw['type']) ? (int) $configCw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save();
$createdCw++;
}
@@ -419,7 +484,13 @@ class DiceRewardLogic
'remark' => $configCcw['remark'] ?? '',
'type' => isset($configCcw['type']) ? (int) $configCcw['type'] : 0,
];
$existing = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber)->find();
$existingQuery = DiceReward::where('direction', DiceReward::DIRECTION_COUNTERCLOCKWISE)->where('grid_number', $gridNumber);
if ($deptId === null) {
$existingQuery->whereNull('dept_id');
} else {
$existingQuery->where('dept_id', $deptId);
}
$existing = $existingQuery->find();
if ($existing) {
DiceReward::where('id', $existing->id)->update($payloadCcw);
$updatedCcw++;
@@ -435,6 +506,9 @@ class DiceRewardLogic
$m->real_ev = $configCcw['real_ev'] ?? null;
$m->remark = $configCcw['remark'] ?? '';
$m->type = isset($configCcw['type']) ? (int) $configCcw['type'] : 0;
if ($deptId !== null) {
$m->dept_id = $deptId;
}
$m->save();
$createdCcw++;
}
@@ -442,7 +516,7 @@ class DiceRewardLogic
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($deptId ?? AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
return [
'created_clockwise' => $createdCw,
'created_counterclockwise' => $createdCcw,

View File

@@ -6,11 +6,13 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\Log;
@@ -19,7 +21,7 @@ use support\Log;
* 奖励配置逻辑层DiceRewardConfig
* weight 1-10000各档位权重和不限制
*/
class DiceRewardConfigLogic extends BaseLogic
class DiceRewardConfigLogic extends DiceBaseLogic
{
/** weight 取值范围 */
private const WEIGHT_MIN = 1;
@@ -36,18 +38,23 @@ class DiceRewardConfigLogic extends BaseLogic
public function add(array $data): mixed
{
$result = parent::add($data);
DiceRewardConfig::refreshCache();
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 修改:保存后刷新缓存BIGWIN 的 weight 直接写入 dice_reward_config 表,抽奖时从 Config 读取
* 修改:按业务 id + 渠道更新;保存后刷新该渠道缓存
*/
public function edit($id, array $data): mixed
public function edit($id, array $data, ?array $adminInfo = null, $requestDeptId = null): mixed
{
$result = parent::edit($id, $data);
DiceRewardConfig::refreshCache();
return $result;
$deptId = AdminScopeHelper::resolveConfigDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, $data)
);
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, (int) $id, $deptId, $data);
DiceRewardConfig::refreshCache($deptId);
return true;
}
/**
@@ -152,8 +159,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新奖励索引配置grid_number、ui_text、real_ev、tier、remark不含 weightBIGWIN 权重单独接口)
* @param array $items 每项 [id, grid_number?, ui_text?, real_ev?, tier?, remark?]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdate(array $items): void
public function batchUpdate(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
foreach ($items as $row) {
if (! array_key_exists('id', $row) || $row['id'] === null || $row['id'] === '') {
@@ -167,10 +175,18 @@ class DiceRewardConfigLogic extends BaseLogic
}
}
if (! empty($data)) {
parent::edit($id, $data);
$this->updateByBusinessIdAndDept($id, $deptId, $data);
}
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 按业务 id025与渠道更新单条配置
*/
private function updateByBusinessIdAndDept(int $businessId, int $deptId, array $data): void
{
ConfigScopeEditHelper::updateByBusinessIdAndDept($this->model, $businessId, $deptId, $data);
}
/**
@@ -201,8 +217,9 @@ class DiceRewardConfigLogic extends BaseLogic
/**
* 批量更新 BIGWIN 档位权重(仅写 dice_reward_config 表,不操作 dice_reward
* @param array $items 每项 [grid_number => 5-30, weight => 0-10000]
* @param int $deptId 渠道 ID0=默认模板)
*/
public function batchUpdateBigwinWeight(array $items): void
public function batchUpdateBigwinWeight(array $items, int $deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT): void
{
$weightMin = 0;
$weightMax = 10000;
@@ -213,21 +230,33 @@ class DiceRewardConfigLogic extends BaseLogic
continue;
}
$weight = max($weightMin, min($weightMax, $weight));
$this->model->where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->update(['weight' => $weight]);
$query = $this->model->where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
$query->where(function ($q) {
$q->where('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT)
->whereOr('dept_id', null);
});
} else {
$query->where('dept_id', $deptId);
}
$exists = (clone $query)->find();
if ($exists === null) {
throw new ApiException('BIGWIN grid_number=' . $gridNumber . ' not found for current channel');
}
$query->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
/**
* 删除后刷新缓存
*/
public function destroy($ids): bool
public function destroy($ids, ?array $adminInfo = null, $requestDeptId = null): bool
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
$result = parent::destroy($ids);
if ($result) {
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($deptId);
}
return $result;
}
@@ -403,6 +432,12 @@ class DiceRewardConfigLogic extends BaseLogic
$record->lottery_config_id = $config ? (int) $config->id : null;
$record->result_counts = $counts;
$record->admin_id = $adminId;
if ($adminId > 0) {
$admin = \plugin\saiadmin\app\model\system\SystemUser::find($adminId);
if ($admin && !empty($admin->dept_id)) {
$record->dept_id = $admin->dept_id;
}
}
$record->create_time = date('Y-m-d H:i:s');
$record->save();
$recordId = (int) $record->id;

View File

@@ -4,18 +4,23 @@
// +----------------------------------------------------------------------
namespace app\dice\logic\reward_config_record;
use app\api\util\ApiLang;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\ante_config\DiceAnteConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward\DiceRewardConfig;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use plugin\saiadmin\basic\think\BaseLogic;
use app\dice\basic\DiceBaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemUser;
/**
* 奖励配置权重测试记录逻辑层
*
*/
class DiceRewardConfigRecordLogic extends BaseLogic
class DiceRewardConfigRecordLogic extends DiceBaseLogic
{
public function __construct()
{
@@ -86,6 +91,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
throw new ApiException('Test record not found');
}
$record = is_array($record) ? $record : $record->toArray();
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($record['dept_id'] ?? null);
$snapshot = $record['weight_config_snapshot'] ?? null;
if (is_string($snapshot)) {
@@ -110,9 +116,9 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$tier = $tierFromDb !== null ? (string) $tierFromDb : '';
}
// 仅按方向 + 点数更新 DiceReward若存在则更新不存在才插入避免唯一键冲突
$reward = DiceReward::where('direction', $direction)
->where('grid_number', $gridNumber)
->find();
$rewardQuery = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($rewardQuery, $configDeptId);
$reward = $rewardQuery->find();
if ($reward) {
$reward->weight = $weight;
// 若快照中有 tier补齐 tier 信息
@@ -128,10 +134,13 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$m->direction = $direction;
$m->grid_number = $gridNumber;
$m->weight = $weight;
if (!AdminScopeHelper::isTemplateDeptId($configDeptId)) {
$m->dept_id = $configDeptId;
}
$m->save();
}
}
DiceReward::refreshCache();
DiceReward::refreshCache($configDeptId);
}
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
@@ -150,11 +159,11 @@ class DiceRewardConfigRecordLogic extends BaseLogic
if ($weight < 0) {
$weight = 0;
}
DiceRewardConfig::where('tier', 'BIGWIN')
->where('grid_number', $gridNumber)
->update(['weight' => $weight]);
$bigwinQuery = DiceRewardConfig::where('tier', 'BIGWIN')->where('grid_number', $gridNumber);
ConfigScopeEditHelper::applyDeptIdWhere($bigwinQuery, $configDeptId);
$bigwinQuery->update(['weight' => $weight]);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($configDeptId);
}
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
@@ -223,33 +232,44 @@ class DiceRewardConfigRecordLogic extends BaseLogic
DiceLotteryPoolConfig::where('id', $freeTargetId)->update($update);
}
DiceRewardConfig::refreshCache();
DiceRewardConfig::refreshCache($configDeptId);
DiceReward::refreshCache($configDeptId);
DiceRewardConfig::clearRequestInstance();
}
/**
* 创建一键测试权重记录并返回 ID供后台执行器按付费/免费、顺逆方向交替写入 dice_play_record_test
* 创建一键测试权重记录并返回 ID供后台执行器写入 dice_play_record_test
* 支持两种模式1选择奖池配置 lottery_config_id档位概率取自配置2不选配置使用自定义 paid_tier_weights / free_tier_weights
* @param array|int $params 数组lottery_config_id(可选), paid_s_count, paid_n_count, free_s_count, free_n_count或兼容旧版传 4 个 int 时视为 (paid_s_count, paid_n_count, free_s_count, free_n_count)
* @param int|null $adminId 执行人(旧版 4 参调用时第二参为 paid_n_count此处不传 adminId
* @param array|int $params 数组lottery_config_id(可选), paid_s_count, paid_n_count
* @param int|null $adminId 执行人
* @return int 记录 ID
* @throws ApiException
*/
public function createWeightTestRecord(array|int $params, mixed $adminIdOrFreeS = null, mixed $freeSOrFreeN = null, mixed $freeN = null): int
{
public function createWeightTestRecord(
array|int $params,
mixed $adminIdOrFreeS = null,
?array $adminInfo = null,
$requestDeptId = null
): int {
$adminId = null;
if (!is_array($params)) {
// 兼容旧版调用createWeightTestRecord(paid_s_count, paid_n_count, free_s_count, free_n_count)
// 兼容旧版调用createWeightTestRecord(paid_s_count, paid_n_count)
$params = [
'paid_s_count' => (int) $params,
'paid_n_count' => (int) $adminIdOrFreeS,
'free_s_count' => (int) $freeSOrFreeN,
'free_n_count' => (int) $freeN,
];
} else {
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
}
$deptId = $this->resolveWeightTestDeptId(
$adminInfo,
AdminScopeHelper::pickRequestDeptId($requestDeptId, is_array($params) ? $params : []),
is_array($params) ? $params : []
);
$allowed = [100, 500, 1000, 5000];
$ante = $this->resolveWeightTestAnte($params, $deptId);
$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;
@@ -259,19 +279,23 @@ class DiceRewardConfigRecordLogic extends BaseLogic
if ($freeConfigId <= 0 && $lotteryConfigId > 0) {
$freeConfigId = $lotteryConfigId;
}
$paidS = isset($params['paid_s_count']) ? (int) $params['paid_s_count'] : (int) ($params['s_count'] ?? 0);
$paidN = isset($params['paid_n_count']) ? (int) $params['paid_n_count'] : (int) ($params['n_count'] ?? 0);
$freeS = (int) ($params['free_s_count'] ?? 0);
$freeN = (int) ($params['free_n_count'] ?? 0);
$paidS = isset($params['paid_s_count']) ? (int) $params['paid_s_count'] : 0;
$paidN = isset($params['paid_n_count']) ? (int) $params['paid_n_count'] : 0;
$chainFreeMode = !empty($params['chain_free_mode']);
$killModeEnabled = !empty($params['kill_mode_enabled']);
$testSafetyLine = isset($params['test_safety_line']) ? (int) $params['test_safety_line'] : 5000;
if ($testSafetyLine < 0) {
throw new ApiException('test_safety_line must be greater than or equal to 0');
}
foreach ([$paidS, $paidN, $freeS, $freeN] as $c) {
foreach ([$paidS, $paidN] as $c) {
if ($c !== 0 && !in_array($c, $allowed, true)) {
throw new ApiException('Counts only support 0, 100, 500, 1000, 5000');
}
}
$total = $paidS + $paidN + $freeS + $freeN;
$total = $paidS + $paidN;
if ($total <= 0) {
throw new ApiException('Sum of paid/free direction counts must be greater than 0');
throw new ApiException('Sum of paid direction counts must be greater than 0');
}
$snapshot = [];
@@ -283,8 +307,8 @@ class DiceRewardConfigRecordLogic extends BaseLogic
$paidTierWeights = null;
$freeTierWeights = null;
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟
$instance = DiceReward::getCachedInstance();
// 来自当前渠道的 DiceReward 权重快照(按方向+点数),用于权重测试模拟
$instance = DiceReward::getCachedInstance($deptId);
$byTierDirection = $instance['by_tier_direction'] ?? [];
foreach ($byTierDirection as $tier => $byDir) {
foreach ($byDir as $dir => $rows) {
@@ -303,7 +327,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
// JSON 结构 {"grid_number": weight, ...}
$bigwinWeights = [];
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN');
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN', $deptId);
foreach ($bigwinConfigs as $cfg) {
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
if ($grid <= 0) {
@@ -314,10 +338,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
}
if ($paidConfigId > 0) {
$config = DiceLotteryPoolConfig::find($paidConfigId);
if (!$config) {
throw new ApiException('Paid pool config not found');
}
$config = $this->findPoolConfigInDept($paidConfigId, $deptId, 'Paid pool config not found');
$tierWeightsSnapshot['paid'] = [
'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0),
@@ -346,10 +367,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
}
if ($freeConfigId > 0) {
$config = DiceLotteryPoolConfig::find($freeConfigId);
if (!$config) {
throw new ApiException('Free pool config not found');
}
$config = $this->findPoolConfigInDept($freeConfigId, $deptId, 'Free pool config not found');
$tierWeightsSnapshot['free'] = [
'T1' => (int) ($config->t1_weight ?? 0),
'T2' => (int) ($config->t2_weight ?? 0),
@@ -384,33 +402,125 @@ class DiceRewardConfigRecordLogic extends BaseLogic
if (!is_array($tierWeightsSnapshot['free'])) {
$tierWeightsSnapshot['free'] = [];
}
if ($chainFreeMode) {
$tierWeightsSnapshot['chain_free_mode'] = true;
}
$record = new DiceRewardConfigRecord();
$record->test_count = $total;
$plannedPaidSpins = $paidS + $paidN;
$record->chain_free_mode = $chainFreeMode ? 1 : 0;
$record->kill_mode_enabled = $killModeEnabled ? 1 : 0;
$record->test_safety_line = $testSafetyLine;
$record->paid_planned_spins = $plannedPaidSpins;
// 总抽奖次数与 test_count 仅在任务成功结束时写入(见 WeightTestRunner::markSuccess
$record->test_count = 0;
$record->total_play_count = 0;
$record->weight_config_snapshot = $snapshot;
$record->tier_weights_snapshot = $tierWeightsSnapshot;
$record->lottery_config_id = $lotteryConfigId > 0 ? $lotteryConfigId : null;
$record->paid_lottery_config_id = $paidConfigId > 0 ? $paidConfigId : null;
$record->free_lottery_config_id = $freeConfigId > 0 ? $freeConfigId : null;
$record->total_play_count = $total;
$record->over_play_count = 0;
$record->status = DiceRewardConfigRecord::STATUS_RUNNING;
$record->remark = null;
$record->s_count = $paidS + $paidN;
$record->n_count = $freeS + $freeN;
$record->paid_s_count = $paidS;
$record->paid_n_count = $paidN;
$record->free_s_count = $freeS;
$record->free_n_count = $freeN;
$record->play_again_count = 0;
$record->paid_tier_weights = $paidTierWeights;
$record->free_tier_weights = $freeTierWeights;
$record->result_counts = [];
$record->tier_counts = null;
$record->bigwin_weight = $bigwinWeights ?: null;
$record->ante = $ante;
$record->admin_id = $adminId;
$record->dept_id = $deptId;
$record->create_time = date('Y-m-d H:i:s');
$record->save();
return (int) $record->id;
}
/**
* 解析一键测试所属渠道:请求 dept_id > 奖池配置 dept_id > 渠道管理员本渠道
*/
private function resolveWeightTestDeptId(?array $adminInfo, $requestDeptId, array $params): int
{
$deptId = AdminScopeHelper::resolveConfigDeptId($adminInfo, $requestDeptId);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
foreach (['paid_lottery_config_id', 'free_lottery_config_id', 'lottery_config_id'] as $key) {
$poolId = isset($params[$key]) ? (int) $params[$key] : 0;
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
return $poolDeptId;
}
}
$scopeDeptId = AdminScopeHelper::getDeptId($adminInfo);
if ($scopeDeptId !== null && $scopeDeptId > 0) {
return $scopeDeptId;
}
return $deptId;
}
/**
* 校验奖池配置属于当前渠道
*/
private function findPoolConfigInDept(int $poolId, int $deptId, string $notFoundMsg): DiceLotteryPoolConfig
{
$config = DiceLotteryPoolConfig::find($poolId);
if (!$config) {
throw new ApiException($notFoundMsg);
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($poolDeptId !== $deptId) {
throw new ApiException('POOL_CONFIG_NOT_IN_CHANNEL');
}
return $config;
}
/**
* 解析一键测试底注:优先 ante_config_id否则按 mult + 渠道校验
*/
private function resolveWeightTestAnte(array $params, int $deptId): int
{
$anteConfigId = isset($params['ante_config_id']) ? (int) $params['ante_config_id'] : 0;
if ($anteConfigId > 0) {
$config = DiceAnteConfig::find($anteConfigId);
if (! $config) {
throw new ApiException('ANTE_CONFIG_NOT_FOUND');
}
$configDeptId = AdminScopeHelper::normalizeRecordDeptId($config->dept_id ?? null);
if ($configDeptId !== $deptId) {
throw new ApiException('ANTE_CONFIG_NOT_IN_CHANNEL');
}
$mult = (int) ($config->mult ?? 0);
if ($mult <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
return $mult;
}
$ante = isset($params['ante']) ? (int) $params['ante'] : 0;
if ($ante <= 0) {
throw new ApiException('ANTE_MUST_POSITIVE');
}
$anteQuery = DiceAnteConfig::where('mult', $ante);
ConfigScopeEditHelper::applyDeptIdWhere($anteQuery, $deptId);
if ($anteQuery->count() <= 0) {
throw new ApiException(ApiLang::translateParams('ANTE_NOT_ALLOWED', [$ante]));
}
return $ante;
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\dice\logic\reward_config_record;
use app\api\logic\PlayStartLogic;
use app\dice\helper\AdminScopeHelper;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record_test\DicePlayRecordTest;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
@@ -14,15 +15,38 @@ use support\think\Db;
/**
* 一键测试权重:单进程后台执行模拟摇色子,写入 dice_play_record_test 并更新 dice_reward_config_record 进度
* 抽奖逻辑与 PlayStartLogic 一致:使用 name=default 的安全线、杀分开关;盈利<安全线时付费用玩家权重、免费用 killScore盈利>=安全线且杀分开启时付费/免费均用 killScore
* 支持测试内杀分:当模拟玩家累计盈利达到安全线后,付费抽奖切换到 killScore
*/
class WeightTestRunner
{
private const BATCH_SIZE = 10;
/** 本次测试所属渠道(与 dice_reward_config_record.dept_id 一致) */
private int $runDeptId = 0;
/** 测试记录写库白名单字段 */
private const PLAY_RECORD_TEST_COLUMNS = [
'reward_config_record_id',
'dept_id',
'admin_id',
'lottery_config_id',
'lottery_type',
'is_win',
'win_coin',
'super_win_coin',
'reward_win_coin',
'direction',
'reward_tier',
'ante',
'paid_amount',
'start_index',
'target_index',
'roll_array',
'roll_number',
'status',
];
/**
* 执行指定测试记录:按付费/免费、顺/逆方向交替模拟(付费顺→付费逆→免费顺→免费逆),每 10 条写入一次测试表并更新进度
* 使用与 playStart 相同的彩金池逻辑name=default 的安全线/kill_enabled付费用 paid_tier_weights玩家权重或 killScore免费用 killScore
* 执行指定测试记录:按付费次数模拟,若命中 T5 则链式插入免费局(同方向同底注)
* @param int $recordId dice_reward_config_record.id
*/
public function run(int $recordId): void
@@ -33,55 +57,67 @@ 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);
$freeN = (int) ($record->free_n_count ?? 0);
if ($paidS + $paidN + $freeS + $freeN <= 0) {
$sCount = (int) ($record->s_count ?? 0);
$nCount = (int) ($record->n_count ?? 0);
$total = $sCount + $nCount;
if ($total <= 0) {
$this->markFailed($recordId, '抽奖次数必须大于 0');
return;
}
$paidS = $sCount;
$paidN = $nCount;
} else {
$total = $paidS + $paidN + $freeS + $freeN;
$total = $paidS + $paidN;
if ($total <= 0) {
$this->markFailed($recordId, '抽奖次数必须大于 0');
return;
}
$configType0 = DiceLotteryPoolConfig::where('name', 'default')->find();
$configType1 = DiceLotteryPoolConfig::where('name', 'killScore')->find();
$this->runDeptId = $this->resolveRunDeptId($recordId, $record);
$deptId = $this->runDeptId;
DiceReward::setRequestDeptId($deptId);
DiceRewardConfig::clearRequestInstance();
$configType0 = DiceLotteryPoolConfig::findByNameForDept('default', $deptId);
$configType1 = DiceLotteryPoolConfig::findByNameForDept('killScore', $deptId);
if (!$configType0) {
$this->markFailed($recordId, '彩金池配置 name=default 不存在');
$this->markFailed($recordId, '彩金池配置 name=default 不存在(当前渠道)');
return;
}
$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 || AdminScopeHelper::normalizeRecordDeptId($paidPoolConfig->dept_id ?? null) !== $deptId) {
$paidPoolConfig = $configType0;
}
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
if (!$freePoolConfig || AdminScopeHelper::normalizeRecordDeptId($freePoolConfig->dept_id ?? null) !== $deptId) {
$freePoolConfig = $configType1 ?: $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;
$killModeEnabled = (int) ($record->kill_mode_enabled ?? 0) === 1;
$testSafetyLine = (int) ($record->test_safety_line ?? 5000);
if ($testSafetyLine < 0) {
$testSafetyLine = 0;
}
// 测试内“玩家累计盈利”:用于控制付费局是否切换杀分
$playerProfitTotal = 0.0;
$playLogic = new PlayStartLogic();
$resultCounts = [];
@@ -90,70 +126,162 @@ class WeightTestRunner
$done = 0;
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);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
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);
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeS; $i++) {
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, null);
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
for ($i = 0; $i < $freeN; $i++) {
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, null);
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId);
$done++;
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
}
$this->runChainFreeMode(
$recordId,
$deptId,
$playLogic,
$paidS,
$paidN,
$ante,
$paidPoolConfig,
$freePoolConfig,
$configType1,
$paidTierWeightsCustom,
$freeTierWeightsCustom,
$killModeEnabled,
$testSafetyLine,
$playerProfitTotal,
$resultCounts,
$tierCounts,
$buffer,
$done
);
if (!empty($buffer)) {
$this->insertBuffer($buffer);
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
// 链式/非链式:运行中均不写入 total_play_count仅在 markSuccess 落库实际总次数
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts, null);
}
// 平台赚取金额:通过关联 DicePlayRecordTestreward_config_record_id统计
$this->markSuccess($recordId, $resultCounts, $tierCounts);
} catch (\Throwable $e) {
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
$this->markFailed($recordId, $e->getMessage());
} finally {
DiceReward::clearRequestInstance();
DiceRewardConfig::clearRequestInstance();
}
}
/**
* 累加彩金池累计盈利,用于触发杀分,与 PlayStartLogic 一致
* @param int $lotteryType 0=付费券1=免费券
* @param object $usedConfig 本次使用的奖池配置(仅用于校验非空)
* @param object $configType0 name=default 的彩金池
* @param float $playerProfitTotal 实际为“彩金池累计盈利”滚动值
* 付费次数仅由配置决定;付费抽到「再来一次」则在队列末尾插入一条免费抽奖(同方向、同底注),可链式触发
*/
private function accumulateProfitForDefault(array $row, int $lotteryType, $usedConfig, $configType0, float &$playerProfitTotal): void
{
if (($lotteryType !== 0 && $lotteryType !== 1) || $usedConfig === null || $configType0 === null || !isset($row['win_coin'])) {
return;
private function runChainFreeMode(
int $recordId,
int $deptId,
PlayStartLogic $playLogic,
int $paidS,
int $paidN,
int $ante,
$paidPoolConfig,
$freePoolConfig,
$killPoolConfig,
?array $paidTierWeightsCustom,
?array $freeTierWeightsCustom,
bool $killModeEnabled,
int $testSafetyLine,
float &$playerProfitTotal,
array &$resultCounts,
array &$tierCounts,
array &$buffer,
int &$done
): void {
$queue = [];
for ($i = 0; $i < $paidS; $i++) {
$queue[] = ['paid', 0, $ante];
}
$winCoin = (float) $row['win_coin'];
$playerProfitTotal += $lotteryType === 0 ? ($winCoin - 100.0) : $winCoin;
for ($i = 0; $i < $paidN; $i++) {
$queue[] = ['paid', 1, $ante];
}
$qi = 0;
while ($qi < count($queue)) {
$item = $queue[$qi];
$isPaid = $item[0] === 'paid';
$dir = $item[1];
$playAnte = $item[2];
$lotteryType = $isPaid ? 0 : 1;
if ($isPaid) {
$useKillForPaid = $killModeEnabled && $playerProfitTotal >= $testSafetyLine && $killPoolConfig !== null;
if ($useKillForPaid) {
$cfg = $killPoolConfig;
$customWeights = null;
} else {
$cfg = $paidPoolConfig;
$customWeights = $paidTierWeightsCustom;
}
} else {
$cfg = $freePoolConfig;
$customWeights = $freeTierWeightsCustom;
}
$row = $playLogic->simulateOnePlay($cfg, $dir, $lotteryType, $playAnte, $customWeights, $deptId);
$winCoin = (float) ($row['win_coin'] ?? 0);
$paidAmount = (float) ($row['paid_amount'] ?? 0);
$playerProfitTotal += $winCoin - $paidAmount;
$this->aggregate($row, $resultCounts, $tierCounts);
$buffer[] = $this->rowForInsert($row, $recordId, $deptId);
$done++;
if (!empty($row['grants_free_ticket'])) {
$queue[] = ['free', $dir, $playAnte];
}
$this->flushIfNeeded($buffer, $recordId, $done, count($queue), $resultCounts, $tierCounts, null);
$qi++;
}
}
/**
* 解析本次测试渠道:优先读库字段,避免 ORM 字段缓存未含 dept_id 时读不到
*/
private function resolveRunDeptId(int $recordId, DiceRewardConfigRecord $record): int
{
$recordTable = (new DiceRewardConfigRecord())->getTable();
$fromDb = Db::table($recordTable)->where('id', $recordId)->value('dept_id');
$deptId = AdminScopeHelper::normalizeRecordDeptId($fromDb);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($deptId)) {
return $deptId;
}
return $this->resolveDeptIdFromRecordPools($record, $deptId);
}
/**
* 历史记录 dept_id=0 时,从关联奖池配置反推并回写
*/
private function resolveDeptIdFromRecordPools(DiceRewardConfigRecord $record, int $fallbackDeptId): int
{
foreach (
[
(int) ($record->paid_lottery_config_id ?? 0),
(int) ($record->free_lottery_config_id ?? 0),
(int) ($record->lottery_config_id ?? 0),
] as $poolId
) {
if ($poolId <= 0) {
continue;
}
$pool = DiceLotteryPoolConfig::find($poolId);
if (! $pool) {
continue;
}
$poolDeptId = AdminScopeHelper::normalizeRecordDeptId($pool->dept_id ?? null);
if (! AdminScopeHelper::isTemplateDeptId($poolDeptId)) {
if (AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null) !== $poolDeptId) {
$record->dept_id = $poolDeptId;
$record->save();
}
return $poolDeptId;
}
}
return $fallbackDeptId;
}
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
@@ -168,15 +296,20 @@ class WeightTestRunner
}
}
private function rowForInsert(array $row, int $rewardConfigRecordId): array
private function rowForInsert(array $row, int $rewardConfigRecordId, int $deptId): array
{
$bindDeptId = ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)
? $this->runDeptId
: $deptId;
$out = [
'reward_config_record_id' => $rewardConfigRecordId,
'dept_id' => $bindDeptId,
];
$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',
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
'super_win_coin', 'reward_win_coin', 'direction', 'reward_tier',
'ante', 'paid_amount',
'start_index', 'target_index', 'roll_array', 'roll_number', 'status',
];
foreach ($keys as $k) {
if (array_key_exists($k, $row)) {
@@ -186,14 +319,14 @@ class WeightTestRunner
return $out;
}
private function flushIfNeeded(array &$buffer, int $recordId, int $done, int $total, array $resultCounts, array $tierCounts): void
private function flushIfNeeded(array &$buffer, int $recordId, int $done, int $total, array $resultCounts, array $tierCounts, ?int $recordTotalPlayCount = null): void
{
if (count($buffer) < self::BATCH_SIZE) {
return;
}
$this->insertBuffer($buffer);
$buffer = [];
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
array_splice($buffer, 0, count($buffer));
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts, $recordTotalPlayCount);
}
private function insertBuffer(array $rows): void
@@ -201,16 +334,57 @@ class WeightTestRunner
if (empty($rows)) {
return;
}
$table = (new DicePlayRecordTest())->getTable();
foreach ($rows as $row) {
DicePlayRecordTest::create($row);
if (!is_array($row)) {
continue;
}
$payload = [];
foreach (self::PLAY_RECORD_TEST_COLUMNS as $column) {
if (array_key_exists($column, $row)) {
$payload[$column] = $row[$column];
}
}
if (! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$payload['dept_id'] = $this->runDeptId;
}
if (!array_key_exists('create_time', $payload) || $payload['create_time'] === null || $payload['create_time'] === '') {
$payload['create_time'] = date('Y-m-d H:i:s');
}
if (!array_key_exists('update_time', $payload) || $payload['update_time'] === null || $payload['update_time'] === '') {
$payload['update_time'] = $payload['create_time'];
}
if ($payload === []) {
continue;
}
// strict(false):表结构新增 dept_id 后,避免连接层字段缓存未刷新导致插入被丢弃
Db::table($table)->strict(false)->insert($payload);
}
}
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts): void
/**
* 将本批测试明细 dept_id 与主记录对齐(修复历史 worker 未写入 dept_id 的情况)
*/
private function syncPlayRecordTestDeptId(int $recordId, int $deptId): void
{
if (AdminScopeHelper::isTemplateDeptId($deptId)) {
return;
}
DicePlayRecordTest::where('reward_config_record_id', $recordId)
->where(function ($query) {
$query->whereNull('dept_id')->whereOr('dept_id', AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
})
->update(['dept_id' => $deptId]);
}
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts, ?int $totalPlayCount = null): void
{
$record = DiceRewardConfigRecord::find($recordId);
if ($record) {
$record->over_play_count = $overPlayCount;
if ($totalPlayCount !== null) {
$record->total_play_count = $totalPlayCount;
}
$record->result_counts = $resultCounts;
$record->tier_counts = $tierCounts;
$record->save();
@@ -219,12 +393,19 @@ 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
{
$record = DiceRewardConfigRecord::find($recordId);
if ($record) {
$deptId = AdminScopeHelper::normalizeRecordDeptId($record->dept_id ?? null);
if (AdminScopeHelper::isTemplateDeptId($deptId) && ! AdminScopeHelper::isTemplateDeptId($this->runDeptId)) {
$deptId = $this->runDeptId;
$record->dept_id = $deptId;
}
$this->syncPlayRecordTestDeptId($recordId, $deptId);
// 平台盈利通过关联测试记录统计
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空
@@ -235,6 +416,10 @@ class WeightTestRunner
$record->tier_counts = $tierCounts;
$record->remark = null;
$record->platform_profit = $platformProfit;
$record->play_again_count = DiceRewardConfigRecord::computePlayAgainCountFromRelated($recordId);
$actualCount = (int) DicePlayRecordTest::where('reward_config_record_id', $recordId)->count();
$record->total_play_count = $actualCount;
$record->test_count = $actualCount;
$record->save();
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace app\dice\model;
use plugin\saiadmin\basic\think\BaseModel as SaiBaseModel;
/**
* 大富翁模块模型基类:删除均为硬删除(物理删除)
*
* 注意:
* - 不要在此重写实例方法 delete(),否则与 trait/父类的 delete() 相互覆盖,
* 在调用 $this->force()->delete() 时会无限递归force() 返回 $this
* 导致内存爆栈、HTTP 500。
* - 物理删除一律通过静态 destroy() 入口(强制 $force=true完成
* SoftDelete::destroy() 内部会按硬删除分支执行。
*/
abstract class DiceModel extends SaiBaseModel
{
/**
* @param mixed $data
*/
public static function destroy($data, bool $force = true): bool
{
return parent::destroy($data, true);
}
}

View File

@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\model\ante_config;
use app\dice\model\DiceModel;
/**
* 底注配置模型
*
* @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 DiceModel
{
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

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\config;
use plugin\saiadmin\basic\eloquent\BaseModel;
use app\dice\model\DiceModel;
/**
* 摇色子配置模型
@@ -23,7 +23,7 @@ use plugin\saiadmin\basic\eloquent\BaseModel;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DiceConfig extends BaseModel
class DiceConfig extends DiceModel
{
/**
* 数据表主键

View File

@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\model\game;
use app\dice\model\DiceModel;
/**
* 游戏管理模型
*
* dice_game 游戏配置表
*/
class DiceGame extends DiceModel
{
protected $primaryKey = 'id';
protected $table = 'dice_game';
public $timestamps = true;
public function searchProviderCodeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('provider_code', '=', $value);
}
public function searchGameCodeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('game_code', 'like', '%' . $value . '%');
}
public function searchGameTypeAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('game_type', '=', $value);
}
public function searchStatusAttr($query, $value): void
{
if ($value === '' || $value === null) {
return;
}
$query->where('status', '=', $value);
}
}

View File

@@ -6,7 +6,9 @@
// +----------------------------------------------------------------------
namespace app\dice\model\lottery_pool_config;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
/**
* 色子奖池配置模型
@@ -25,9 +27,9 @@ 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
class DiceLotteryPoolConfig extends DiceModel
{
/**
* 数据表主键
@@ -41,6 +43,16 @@ class DiceLotteryPoolConfig extends BaseModel
*/
protected $table = 'dice_lottery_pool_config';
/**
* 按名称与渠道查找奖池配置(一键测试等场景,避免命中其他渠道同名配置)
*/
public static function findByNameForDept(string $name, int $deptId): ?self
{
$query = (new self())->where('name', $name);
ConfigScopeEditHelper::applyDeptIdWhere($query, AdminScopeHelper::normalizeRecordDeptId($deptId));
return $query->find();
}
/**
* 名称 搜索
*/

View File

@@ -9,7 +9,7 @@ namespace app\dice\model\play_record;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer;
use app\dice\model\reward\DiceRewardConfig;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\BelongsTo;
/**
@@ -22,12 +22,15 @@ 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*1免费局=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 $reward_tier 中奖档位T1,T2,T3,T4,T5,BIGWIN
* @property $lottery_id 奖池
* @property $start_index 起始索引
* @property $target_index 结束索引
@@ -38,7 +41,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayRecord extends BaseModel
class DicePlayRecord extends DiceModel
{
/**
* 数据表主键
@@ -61,15 +64,6 @@ class DicePlayRecord extends BaseModel
return $this->belongsTo(DicePlayer::class, 'player_id', 'id');
}
/**
* 中奖配置
* 关联模型 diceRewardConfig
*/
public function diceRewardConfig(): BelongsTo
{
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
}
/**
* 彩金池配置
* 关联模型 diceLotteryPoolConfig
@@ -249,24 +243,19 @@ class DicePlayRecord extends BaseModel
}
$ids = DiceRewardConfig::where('ui_text', 'like', '%' . $value . '%')->column('id');
if (!empty($ids)) {
$query->whereIn('reward_config_id', $ids);
$query->whereIn('target_index', $ids);
} else {
$query->whereRaw('1=0');
}
}
/** 按奖励档位(diceRewardConfig.tier中奖名 T1-T5 */
/** 按奖励档位(表字段 reward_tier中奖名 T1-T5/BIGWIN */
public function searchRewardTierAttr($query, $value)
{
if ($value === '' || $value === null) {
return;
}
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
if (!empty($ids)) {
$query->whereIn('reward_config_id', $ids);
} else {
$query->whereRaw('1=0');
}
$query->where('reward_tier', '=', $value);
}
/** 方向 0=顺时针 1=逆时针 */

View File

@@ -6,8 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\play_record_test;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\reward_config\DiceRewardConfig;
use app\dice\model\DiceModel;
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use think\model\relation\BelongsTo;
@@ -19,11 +18,13 @@ 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*1免费局=0
* @property $direction 方向:0=顺时针,1=逆时针
* @property $reward_config_id 奖励配置id
* @property $reward_tier 中奖档位T1,T2,T3,T4,T5,BIGWIN
* @property $create_time 创建时间
* @property $update_time 修改时间
* @property $start_index 起始索引
@@ -36,7 +37,7 @@ use think\model\relation\BelongsTo;
* @property $admin_id 所属管理员
* @property int|null $reward_config_record_id 关联 DiceRewardConfigRecord.id权重测试记录
*/
class DicePlayRecordTest extends BaseModel
class DicePlayRecordTest extends DiceModel
{
/**
* 数据表主键
@@ -50,6 +51,10 @@ class DicePlayRecordTest extends BaseModel
*/
protected $table = 'dice_play_record_test';
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
/**
* 彩金池配置
* 关联 lottery_config_id -> DiceLotteryPoolConfig.id
@@ -59,15 +64,6 @@ class DicePlayRecordTest extends BaseModel
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
}
/**
* 奖励配置(终点格 = target_index 对应 DiceRewardConfig.id表中为 reward_config_id
* 关联 reward_config_id -> DiceRewardConfig.id
*/
public function diceRewardConfig(): BelongsTo
{
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
}
/**
* 关联的权重测试记录
* reward_config_record_id -> DiceRewardConfigRecord.id
@@ -77,7 +73,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,18 +113,29 @@ class DicePlayRecordTest extends BaseModel
}
}
/** 中奖档位(按 reward_config_id 对应 DiceRewardConfig.tier */
/** 付费金额(付费局=ante*1免费局=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_tier */
public function searchRewardTierAttr($query, $value)
{
if ($value === '' || $value === null) {
return;
}
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
if (!empty($ids)) {
$query->whereIn('reward_config_id', $ids);
} else {
$query->whereRaw('1=0');
}
$query->where('reward_tier', '=', $value);
}
/** 点数和 roll_number摇取点数和 5-30 */
@@ -138,4 +145,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

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\player;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
/**
@@ -15,7 +15,8 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* dice_player 大富翁-玩家
*
* @property $id ID
* @property $username 用户名
* @property $dept_id 所属渠道ID
* @property $username 用户名(同渠道内唯一)
* @property $phone 手机
* @property $uid uid
* @property $name 昵称
@@ -32,11 +33,12 @@ use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
* @property $total_ticket_count 总抽奖次数
* @property $paid_ticket_count 购买抽奖次数
* @property $free_ticket_count 赠送抽奖次数
* @property array|null $free_ticket 免费抽奖券:{"ante":1,"count":1}
* @property $create_time 创建时间
* @property $update_time 更新时间
* @property $delete_time 删除时间
*/
class DicePlayer extends BaseModel
class DicePlayer extends DiceModel
{
/**
* 数据表主键
@@ -54,6 +56,10 @@ class DicePlayer extends BaseModel
protected $updateTime = 'update_time';
protected $json = ['free_ticket'];
protected $jsonAssoc = true;
/**
* 新增前:生成唯一 uid昵称 name 默认使用 uid
* 用 try-catch 避免表尚未含 uid 时 getAttr/getData 抛 InvalidArgumentException

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player_ticket_record;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\BelongsTo;
/**
@@ -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 赠送抽奖次数
@@ -26,7 +27,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayerTicketRecord extends BaseModel
class DicePlayerTicketRecord extends DiceModel
{
/**
* 数据表主键
@@ -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

@@ -7,7 +7,7 @@
namespace app\dice\model\player_wallet_record;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use plugin\saiadmin\app\model\system\SystemUser;
use think\model\relation\BelongsTo;
@@ -31,7 +31,7 @@ use think\model\relation\BelongsTo;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DicePlayerWalletRecord extends BaseModel
class DicePlayerWalletRecord extends DiceModel
{
/**
* 数据表主键

View File

@@ -4,7 +4,9 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\DiceModel;
use support\think\Cache;
/**
@@ -25,42 +27,70 @@ use support\think\Cache;
* @property $remark 备注(来自config)
* @property $type 奖励类型(来自config)
*/
class DiceReward extends BaseModel
class DiceReward extends DiceModel
{
/** 方向:顺时针 */
public const DIRECTION_CLOCKWISE = 0;
/** 方向:逆时针 */
public const DIRECTION_COUNTERCLOCKWISE = 1;
/** 缓存键:奖励对照实例 */
/** 缓存键前缀:奖励对照实例(按渠道分键) */
private const CACHE_KEY_INSTANCE = 'dice:reward:instance';
private const CACHE_TTL = 86400 * 30;
private static ?array $instance = null;
private static ?int $requestDeptId = null;
protected $table = 'dice_reward';
/** 主键 id 自增,唯一约束 (direction, grid_number) */
protected $pk = 'id';
private static function cacheKeyForDept(int $deptId): string
{
return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
private static function resolveDeptId(?int $deptId): int
{
if ($deptId !== null) {
return AdminScopeHelper::normalizeRecordDeptId($deptId);
}
if (self::$requestDeptId !== null) {
return self::$requestDeptId;
}
return AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
/**
* 请求级设置当前渠道(一键测试 worker 内调用 simulateOnePlay 前设置)
*/
public static function setRequestDeptId(?int $deptId): void
{
self::$requestDeptId = $deptId !== null
? AdminScopeHelper::normalizeRecordDeptId($deptId)
: null;
}
/**
* 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比)
* 优先从共享缓存读取,保证多进程(如一键测试 worker与数据库一致
* @return array{list: array, by_tier_direction: array}
*/
public static function getCachedInstance(): array
public static function getCachedInstance(?int $deptId = null): array
{
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
$deptId = self::resolveDeptId($deptId);
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) {
self::$instance = $instance;
return $instance;
}
if (self::$instance !== null) {
if (self::$instance !== null && self::$requestDeptId === $deptId) {
return self::$instance;
}
self::refreshCache();
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
self::refreshCache($deptId);
$instance = Cache::get($cacheKey);
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
return self::$instance;
}
@@ -69,9 +99,9 @@ class DiceReward extends BaseModel
* 按档位+方向取权重列表(用于抽奖:该档位该方向下 end_index => weight
* @return array<int, int> end_index => weight
*/
public static function getCachedByTierAndDirection(string $tier, int $direction): array
public static function getCachedByTierAndDirection(string $tier, int $direction, ?int $deptId = null): array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTierDirection = $inst['by_tier_direction'] ?? [];
$list = $byTierDirection[$tier][$direction] ?? [];
$result = [];
@@ -84,11 +114,14 @@ class DiceReward extends BaseModel
}
/**
* 重新从数据库加载并写入缓存;修改/新增/删除后需调用以实例化
* 按渠道从数据库加载并写入缓存
*/
public static function refreshCache(): void
public static function refreshCache(?int $deptId = null): void
{
$list = (new self())->order('tier')->order('direction')->order('end_index')->select()->toArray();
$deptId = self::resolveDeptId($deptId);
$query = (new self())->order('tier')->order('direction')->order('end_index');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTierDirection = [];
foreach ($list as $row) {
$tier = isset($row['tier']) ? (string) $row['tier'] : '';
@@ -103,11 +136,12 @@ class DiceReward extends BaseModel
$byTierDirection[$tier][$direction][] = $row;
}
}
self::$instance = [
$instance = [
'list' => $list,
'by_tier_direction' => $byTierDirection,
];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
self::$instance = $instance;
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
}
private static function buildEmptyInstance(): array
@@ -121,20 +155,29 @@ class DiceReward extends BaseModel
public static function clearRequestInstance(): void
{
self::$instance = null;
self::$requestDeptId = null;
}
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
}
public static function onAfterInsert($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterUpdate($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterDelete($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
}

View File

@@ -6,8 +6,10 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward_config;
use app\dice\helper\AdminScopeHelper;
use app\dice\helper\ConfigScopeEditHelper;
use app\dice\model\reward\DiceReward;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use support\think\Cache;
/**
@@ -27,7 +29,7 @@ use support\think\Cache;
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class DiceRewardConfig extends BaseModel
class DiceRewardConfig extends DiceModel
{
/** 缓存键:彩金池奖励列表实例 */
private const CACHE_KEY_INSTANCE = 'dice:reward_config:instance';
@@ -45,31 +47,35 @@ class DiceRewardConfig extends BaseModel
* 优先从共享缓存读取,保证多进程(如一键测试 worker能拿到最新配置与数据库一致
* @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float}
*/
public static function getCachedInstance(): array
public static function getCachedInstance(?int $deptId = null): array
{
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$cacheKey = self::cacheKeyForDept($deptId);
$instance = Cache::get($cacheKey);
if ($instance !== null && is_array($instance)) {
self::$instance = $instance;
return $instance;
}
if (self::$instance !== null) {
return self::$instance;
}
self::refreshCache();
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
return self::$instance;
self::refreshCache($deptId);
$instance = Cache::get($cacheKey);
return is_array($instance) ? $instance : self::buildEmptyInstance();
}
public static function getCachedList(): array
private static function cacheKeyForDept(int $deptId): string
{
$inst = self::getCachedInstance();
return self::CACHE_KEY_INSTANCE . ':' . $deptId;
}
public static function getCachedList(?int $deptId = null): array
{
$inst = self::getCachedInstance($deptId);
return $inst['list'] ?? [];
}
public static function getCachedById(int $id): ?array
public static function getCachedById(int $id, ?int $deptId = null): ?array
{
$list = self::getCachedList();
$list = self::getCachedList($deptId);
foreach ($list as $row) {
if (isset($row['id']) && (int) $row['id'] === $id) {
return $row;
@@ -79,11 +85,16 @@ class DiceRewardConfig extends BaseModel
}
/**
* 重新从数据库加载并写入缓存(按档位+权重抽 grid_number含 by_tier、by_tier_grid
* 按渠道从数据库加载并写入缓存(避免多渠道配置混在同一缓存键
*/
public static function refreshCache(): void
public static function refreshCache(?int $deptId = null): void
{
$list = (new self())->order('id', 'asc')->select()->toArray();
if ($deptId === null) {
$deptId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
}
$query = (new self())->order('id', 'asc');
ConfigScopeEditHelper::applyDeptIdWhere($query, $deptId);
$list = $query->select()->toArray();
$byTier = [];
$byTierGrid = [];
foreach ($list as $row) {
@@ -103,13 +114,16 @@ class DiceRewardConfig extends BaseModel
}
}
$minRealEv = empty($list) ? 0.0 : (float) min(array_column($list, 'real_ev'));
self::$instance = [
$instance = [
'list' => $list,
'by_tier' => $byTier,
'by_tier_grid' => $byTierGrid,
'min_real_ev' => $minRealEv,
];
Cache::set(self::CACHE_KEY_INSTANCE, self::$instance, self::CACHE_TTL);
Cache::set(self::cacheKeyForDept($deptId), $instance, self::CACHE_TTL);
if ($deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
self::$instance = $instance;
}
}
private static function buildEmptyInstance(): array
@@ -125,9 +139,9 @@ class DiceRewardConfig extends BaseModel
/**
* 按档位+色子点数取一条(用于 BIGWIN
*/
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber, ?int $deptId = null): ?array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTierGrid = $inst['by_tier_grid'] ?? [];
$tierData = $byTierGrid[$tier] ?? [];
$row = $tierData[$gridNumber] ?? null;
@@ -143,9 +157,9 @@ class DiceRewardConfig extends BaseModel
/**
* 从缓存按档位取奖励列表(不含权重,仅配置)
*/
public static function getCachedByTier(string $tier): array
public static function getCachedByTier(string $tier, ?int $deptId = null): array
{
$inst = self::getCachedInstance();
$inst = self::getCachedInstance($deptId);
$byTier = $inst['by_tier'] ?? [];
return $byTier[$tier] ?? [];
}
@@ -155,10 +169,10 @@ class DiceRewardConfig extends BaseModel
* @param int $direction 0=顺时针, 1=逆时针
* @return array 每行含 id, grid_number, real_ev, tier, weight 等
*/
public static function getCachedByTierForDirection(string $tier, int $direction): array
public static function getCachedByTierForDirection(string $tier, int $direction, ?int $deptId = null): array
{
$list = self::getCachedByTier($tier);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction);
$list = self::getCachedByTier($tier, $deptId);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction, $deptId);
foreach ($list as $i => $row) {
$id = isset($row['id']) ? (int) $row['id'] : 0;
$list[$i]['weight'] = $weightMap[$id] ?? 1;
@@ -171,19 +185,27 @@ class DiceRewardConfig extends BaseModel
self::$instance = null;
}
private static function refreshCacheForModel($model): void
{
$deptId = AdminScopeHelper::normalizeRecordDeptId(
is_array($model) ? ($model['dept_id'] ?? null) : ($model->dept_id ?? null)
);
self::refreshCache($deptId);
}
public static function onAfterInsert($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterUpdate($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public static function onAfterDelete($model): void
{
self::refreshCache();
self::refreshCacheForModel($model);
}
public function searchGridNumberMinAttr($query, $value)

View File

@@ -4,7 +4,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward_config;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
/**
* 权重配比测试记录模型
@@ -20,7 +20,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间
*/
class DiceRewardConfigRecord extends BaseModel
class DiceRewardConfigRecord extends DiceModel
{
protected $pk = 'id';

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\reward_config_record;
use app\dice\model\play_record_test\DicePlayRecordTest;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\DiceModel;
use think\model\relation\HasMany;
/**
@@ -22,26 +22,28 @@ use think\model\relation\HasMany;
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID兼容旧付费+免费共用)
* @property int|null $paid_lottery_config_id 付费抽奖奖池配置 ID默认 type=0
* @property int|null $free_lottery_config_id 免费抽奖奖池配置 ID默认 type=1
* @property int $total_play_count 总模拟次数s_count+n_count
* @property int $total_play_count 总模拟次数
* @property int $over_play_count 已完成次数
* @property int $status 状态 -1失败 0进行中 1成功
* @property string|null $remark 失败时记录原因
* @property int $s_count 顺时针模拟次数(兼容旧数据
* @property int $n_count 逆时针模拟次数(兼容旧数据)
* @property int|null $ante 底注/注数dice_ante_config.mult
* @property int $paid_s_count 付费抽奖顺时针次数
* @property int $paid_n_count 付费抽奖逆时针次数
* @property int $free_s_count 免费抽奖顺时针次数
* @property int $free_n_count 免费抽奖逆时针次数
* @property int $chain_free_mode 1=链式再来一次免费抽奖
* @property int $kill_mode_enabled 测试内杀分开关 1=开启
* @property int $test_safety_line 测试内安全线(模拟玩家累计盈利阈值)
* @property int $paid_planned_spins 计划付费抽奖次数(顺+逆)
* @property int $play_again_count 再来一次次数(T5触发次数)
* @property array|null $paid_tier_weights 付费自定义档位权重 T1-T5
* @property array|null $free_tier_weights 免费自定义档位权重 T1-T5
* @property array $result_counts 落点统计 grid_number=>出现次数
* @property array|null $tier_counts 档位出现次数 T1=>count
* @property float|null $platform_profit 平台赚取金额(付费抽取次数×100-玩家总收益)
* @property float|null $platform_profit 平台赚取金额(付费金额 paid_amount 求和-玩家总收益)
* @property array|null $bigwin_weight 测试时 BIGWIN 档位权重快照JSONgrid_number=>weight
* @property int|null $admin_id 执行测试的管理员ID
* @property string|null $create_time 创建时间
*/
class DiceRewardConfigRecord extends BaseModel
class DiceRewardConfigRecord extends DiceModel
{
/** 状态:失败 */
public const STATUS_FAIL = -1;
@@ -68,20 +70,48 @@ class DiceRewardConfigRecord extends BaseModel
return $this->hasMany(DicePlayRecordTest::class, 'reward_config_record_id', 'id');
}
/** 计划付费抽奖次数(顺+逆) */
public function searchPaidPlannedSpinsAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('paid_planned_spins', '=', $value);
}
}
/** 底注/注数dice_ante_config.mult */
public function searchAnteAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('ante', '=', $value);
}
}
/**
* 根据关联的 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);
}
/**
* 根据关联的 DicePlayRecordTest 统计再来一次次数reward_tier=T5
* @param int $recordId
* @return int
*/
public static function computePlayAgainCountFromRelated(int $recordId): int
{
return (int) DicePlayRecordTest::where('reward_config_record_id', $recordId)
->where('reward_tier', 'T5')
->count();
}
/**

View File

@@ -0,0 +1,497 @@
<?php
declare(strict_types=1);
namespace app\dice\service;
use app\dice\helper\AdminScopeHelper;
use app\dice\logic\reward\DiceRewardLogic;
use app\dice\model\reward\DiceReward;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道默认配置复制、补齐与关联删除
* 默认配置dept_id = 0与超管「默认配置模板」一致
*/
class DiceChannelConfigService
{
/** 需 (dept_id, id) 复合唯一的配置表 */
private const COMPOSITE_KEY_TABLES = [
'dice_config',
'dice_reward_config',
];
/** 从默认模板复制的配置表 */
private const CONFIG_TABLES = [
'dice_config',
'dice_ante_config',
'dice_lottery_pool_config',
'dice_reward_config',
'dice_game',
];
/** 复制时必须保留主键 id非自增或固定 0-25 */
private const TABLES_KEEP_ID = [
'dice_config',
'dice_reward_config',
];
/** 可关联删除的业务表 */
private const RELATION_TABLES = [
'dice_config' => ['label' => '游戏键值配置', 'group' => 'configs'],
'dice_ante_config' => ['label' => '底注配置', 'group' => 'configs'],
'dice_lottery_pool_config' => ['label' => '彩金池配置', 'group' => 'configs'],
'dice_reward_config' => ['label' => '奖励索引配置', 'group' => 'configs'],
'dice_reward' => ['label' => '中奖概率(奖励对照)', 'group' => 'configs'],
'dice_game' => ['label' => '游戏管理', 'group' => 'configs'],
'dice_player' => ['label' => '玩家', 'group' => 'players'],
'dice_play_record' => ['label' => '抽奖记录', 'group' => 'records'],
'dice_play_record_test' => ['label' => '测试抽奖记录', 'group' => 'records'],
'dice_player_wallet_record' => ['label' => '钱包流水', 'group' => 'records'],
'dice_player_ticket_record' => ['label' => '票券记录', 'group' => 'records'],
'dice_reward_config_record' => ['label' => '权重测试记录', 'group' => 'records'],
];
/**
* 默认模板 dept_id 统一为 0并为固定 id 的配置表建立 (dept_id, id) 唯一约束
*/
public function ensureConfigCompositeKeys(): void
{
foreach (array_merge(self::CONFIG_TABLES, ['dice_reward']) as $table) {
if ($this->tableHasColumn($table, 'dept_id')) {
Db::table($table)->whereNull('dept_id')->update(['dept_id' => AdminScopeHelper::DEFAULT_TEMPLATE_DEPT]);
}
}
foreach (self::COMPOSITE_KEY_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (!$this->tableHasColumn($table, 'row_id')) {
if ($table === 'dice_reward_config') {
Db::execute(
'ALTER TABLE `dice_reward_config`'
. ' MODIFY `id` int(11) NOT NULL COMMENT \'ID\','
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
} else {
Db::execute(
'ALTER TABLE `dice_config`'
. ' ADD COLUMN `row_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,'
. ' DROP PRIMARY KEY,'
. ' ADD PRIMARY KEY (`row_id`)'
);
}
}
$indexes = Db::query("SHOW INDEX FROM `{$table}` WHERE Key_name = 'uk_dept_config'");
if (empty($indexes)) {
Db::execute("ALTER TABLE `{$table}` ADD UNIQUE KEY `uk_dept_config` (`dept_id`, `id`)");
}
}
$this->ensureDeptScopedUniqueIndexes();
}
/**
* 将全局唯一键改为按渠道 (dept_id, 业务键) 唯一,便于复制默认模板
*/
private function ensureDeptScopedUniqueIndexes(): void
{
if ($this->tableHasColumn('dice_lottery_pool_config', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'dice_lottery_poll_config_unique'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` DROP INDEX `dice_lottery_poll_config_unique`');
}
$uk = Db::query("SHOW INDEX FROM `dice_lottery_pool_config` WHERE Key_name = 'uk_dept_name'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_lottery_pool_config` ADD UNIQUE KEY `uk_dept_name` (`dept_id`, `name`)');
}
}
if ($this->tableHasColumn('dice_game', 'dept_id')) {
foreach (['uk_dice_game_code', 'uk_dice_game_key'] as $idx) {
$exists = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = '{$idx}'");
if (!empty($exists)) {
Db::execute("ALTER TABLE `dice_game` DROP INDEX `{$idx}`");
}
}
$ukCode = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_code'");
if (empty($ukCode)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_code` (`dept_id`, `game_code`)');
}
$ukKey = Db::query("SHOW INDEX FROM `dice_game` WHERE Key_name = 'uk_dept_game_key'");
if (empty($ukKey)) {
Db::execute('ALTER TABLE `dice_game` ADD UNIQUE KEY `uk_dept_game_key` (`dept_id`, `game_key`)');
}
}
if ($this->tableHasColumn('dice_reward', 'dept_id')) {
$old = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_direction_grid_number'");
if (!empty($old)) {
Db::execute('ALTER TABLE `dice_reward` DROP INDEX `uk_direction_grid_number`');
}
$uk = Db::query("SHOW INDEX FROM `dice_reward` WHERE Key_name = 'uk_dept_direction_grid'");
if (empty($uk)) {
Db::execute('ALTER TABLE `dice_reward` ADD UNIQUE KEY `uk_dept_direction_grid` (`dept_id`, `direction`, `grid_number`)');
}
}
}
/**
* 将当前无 dept_id 的配置标记为默认模板(仅执行一次迁移)
*/
public function markLegacyConfigAsDefault(): int
{
$this->ensureConfigCompositeKeys();
$total = 0;
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$total += $this->countByDept($table, AdminScopeHelper::DEFAULT_TEMPLATE_DEPT);
}
return $total;
}
/**
* 为单个渠道从默认模板复制配置(已存在则跳过)
*/
public function copyDefaultConfigToDept(int $deptId): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$result = ['dept_id' => $deptId, 'copied' => [], 'skipped' => [], 'merged' => []];
foreach (self::CONFIG_TABLES as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
if (in_array($table, self::TABLES_KEEP_ID, true)) {
$merged = $this->syncCompositeIdTableFromDefault($table, $deptId);
if ($merged > 0) {
$result['merged'][$table] = $merged;
} elseif ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
}
continue;
}
if ($this->countByDept($table, $deptId) > 0) {
$result['skipped'][] = $table;
continue;
}
$rows = $this->defaultTemplateRows($table);
if (empty($rows)) {
continue;
}
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
}
$result['copied'][] = $table;
}
$this->ensureRewardReferenceForDept($deptId);
DiceRewardConfig::refreshCache($deptId);
return $result;
}
/**
* 按业务 id 从默认模板补齐配置dice_config / dice_reward_config
*/
private function syncCompositeIdTableFromDefault(string $table, int $deptId): int
{
$templateRows = $this->defaultTemplateRows($table);
if (empty($templateRows)) {
return 0;
}
$inserted = 0;
foreach ($templateRows as $row) {
$row = (array) $row;
if (!isset($row['id'])) {
continue;
}
$businessId = $row['id'];
$exists = Db::table($table)->where('dept_id', $deptId)->where('id', $businessId)->count();
if ($exists > 0) {
continue;
}
unset($row['row_id'], $row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table($table)->insert($row);
$inserted++;
}
return $inserted;
}
/**
* 渠道已有奖励索引时,自动生成 dice_reward 对照表
*/
public function ensureRewardReferenceForDept(int $deptId): void
{
if ($deptId <= 0 || !$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) <= 0) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
$logic = new DiceRewardLogic();
$logic->createRewardReferenceFromConfig($deptId);
}
/**
* 复制默认 dice_reward 到渠道
*/
public function copyDefaultRewardsToDept(int $deptId): void
{
$this->ensureRewardReferenceForDept($deptId);
if (!$this->tableHasColumn('dice_reward', 'dept_id')) {
return;
}
if ($this->countByDept('dice_reward', $deptId) > 0) {
return;
}
if ($this->countByDept('dice_reward_config', $deptId) > 0) {
return;
}
$rows = $this->defaultTemplateRows('dice_reward');
foreach ($rows as $row) {
$row = (array) $row;
unset($row['id'], $row['row_id']);
unset($row['create_time'], $row['update_time'], $row['delete_time']);
$row['dept_id'] = $deptId;
Db::table('dice_reward')->insert($row);
}
}
/**
* 为所有已有渠道补齐缺失配置
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::column('id');
$summary = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$summary[$deptId] = $this->copyDefaultConfigToDept($deptId);
}
return $summary;
}
/**
* 修复已删除渠道 ID、无管理员关联的遗留数据归并到首个顶级渠道
*/
public function repairOrphanDeptReferences(): array
{
$validDeptIds = array_map('intval', SystemDept::column('id') ?: []);
if (empty($validDeptIds)) {
return [];
}
$rootDeptId = min($validDeptIds);
$stats = [];
$inList = implode(',', $validDeptIds);
$stats['sa_system_user'] = Db::execute(
"UPDATE sa_system_user SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
$bizTables = [
'dice_player',
'dice_play_record',
'dice_play_record_test',
'dice_player_wallet_record',
'dice_player_ticket_record',
'dice_reward_config_record',
];
foreach ($bizTables as $table) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$stats[$table . '_invalid_dept'] = Db::execute(
"UPDATE `{$table}` SET dept_id = {$rootDeptId}
WHERE dept_id IS NOT NULL AND dept_id > 0 AND dept_id NOT IN ({$inList})"
);
}
return $stats;
}
/**
* 根据管理员/玩家回填 dept_id
*/
public function backfillDataDeptId(): array
{
$stats = $this->repairOrphanDeptReferences();
if ($this->tableHasColumn('dice_player', 'dept_id') && $this->tableHasColumn('dice_player', 'admin_id')) {
$stats['dice_player'] = Db::execute(
'UPDATE dice_player p INNER JOIN sa_system_user u ON p.admin_id = u.id
SET p.dept_id = u.dept_id WHERE (p.dept_id IS NULL OR p.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
$validDeptIds = SystemDept::column('id') ?: [];
if (!empty($validDeptIds) && $this->tableHasColumn('dice_player', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_player_legacy'] = Db::table('dice_player')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_wallet_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByPlayer('dice_player_ticket_record'));
$stats = array_merge($stats, $this->backfillRecordDeptIdByAdmin('dice_play_record_test'));
if (!empty($validDeptIds) && $this->tableHasColumn('dice_play_record_test', 'dept_id')) {
$rootDeptId = (int) min($validDeptIds);
$stats['dice_play_record_test_legacy'] = Db::table('dice_play_record_test')
->where(function ($q) {
$q->whereNull('dept_id')->whereOr('dept_id', 0);
})
->update(['dept_id' => $rootDeptId]);
}
if ($this->tableHasColumn('dice_reward_config_record', 'dept_id')) {
$stats['dice_reward_config_record'] = Db::execute(
'UPDATE dice_reward_config_record r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0'
);
}
return $stats;
}
/**
* 删除渠道前关联数据统计
*/
public function getDestroyPreview(array $deptIds): array
{
$items = [];
foreach ($deptIds as $deptId) {
$deptId = (int) $deptId;
if ($deptId <= 0) {
continue;
}
$dept = SystemDept::find($deptId);
$row = [
'dept_id' => $deptId,
'dept_name' => $dept ? $dept->name : '',
'user_count' => SystemUser::where('dept_id', $deptId)->count(),
'relations' => [],
];
foreach (self::RELATION_TABLES as $table => $meta) {
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
$count = $this->countByDept($table, $deptId);
if ($count > 0) {
$row['relations'][] = [
'table' => $table,
'label' => $meta['label'],
'group' => $meta['group'],
'count' => $count,
];
}
}
$items[] = $row;
}
return $items;
}
/**
* 删除渠道及勾选的关联数据
*
* @param array $deleteTables 要删除的表名列表
*/
public function destroyDeptWithRelations(int $deptId, array $deleteTables): void
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
$userCount = SystemUser::where('dept_id', $deptId)->count();
if ($userCount > 0) {
throw new ApiException('This channel has users, please delete or transfer them first');
}
$allowed = array_keys(self::RELATION_TABLES);
foreach ($deleteTables as $table) {
if (!in_array($table, $allowed, true)) {
continue;
}
if (!$this->tableHasColumn($table, 'dept_id')) {
continue;
}
Db::table($table)->where('dept_id', $deptId)->delete();
}
SystemDept::destroy($deptId, true);
DiceRewardConfig::refreshCache($deptId);
DiceReward::refreshCache($deptId);
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRows(string $table): array
{
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$rows = Db::table($table)->where('dept_id', $templateId)->select()->toArray();
if (!empty($rows)) {
return $rows;
}
return Db::table($table)->whereNull('dept_id')->select()->toArray();
}
private function backfillRecordDeptIdByPlayer(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'player_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN dice_player p ON r.player_id = p.id
SET r.dept_id = p.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND p.dept_id IS NOT NULL AND p.dept_id > 0"
),
];
}
private function backfillRecordDeptIdByAdmin(string $table): array
{
if (!$this->tableHasColumn($table, 'dept_id') || !$this->tableHasColumn($table, 'admin_id')) {
return [];
}
return [
$table => Db::execute(
"UPDATE `{$table}` r INNER JOIN sa_system_user u ON r.admin_id = u.id
SET r.dept_id = u.dept_id WHERE (r.dept_id IS NULL OR r.dept_id = 0) AND u.dept_id IS NOT NULL AND u.dept_id > 0"
),
];
}
private function countByDept(string $table, ?int $deptId): int
{
$query = Db::table($table);
if ($deptId === null || $deptId === AdminScopeHelper::DEFAULT_TEMPLATE_DEPT) {
$templateId = AdminScopeHelper::DEFAULT_TEMPLATE_DEPT;
$query->where(function ($q) use ($templateId) {
$q->where('dept_id', $templateId)->whereOr('dept_id', 'null');
});
} else {
$query->where('dept_id', $deptId);
}
return $query->count();
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

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

@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
namespace app\dice\validate\game;
use plugin\saiadmin\basic\BaseValidate;
/**
* 游戏管理验证器
*/
class DiceGameValidate extends BaseValidate
{
protected $rule = [
'provider' => 'require|max:64',
'provider_code' => 'require|max:32',
'game_code' => 'require|max:64',
'game_key' => 'require|max:64',
'game_name' => 'require|max:128',
'game_name_en' => 'max:128',
'game_type' => 'require|max:32',
'status' => 'require|in:0,1',
'sort' => 'number',
];
protected $message = [
'provider' => 'provider 必填',
'provider_code' => 'provider_code 必填',
'game_code' => 'game_code 必填',
'game_key' => 'game_key 必填',
'game_name' => 'game_name 必填',
'game_type' => 'game_type 必填',
'status' => 'status 仅支持 0 或 1',
'sort' => 'sort 必须为数字',
];
protected $scene = [
'save' => [
'provider',
'provider_code',
'game_code',
'game_key',
'game_name',
'game_name_en',
'game_type',
'status',
'sort',
],
'update' => [
'provider',
'provider_code',
'game_code',
'game_key',
'game_name',
'game_name_en',
'game_type',
'status',
'sort',
],
];
}

View File

@@ -22,7 +22,7 @@ class DicePlayRecordValidate extends BaseValidate
'lottery_type' => 'require',
'is_win' => 'require',
'win_coin' => 'require',
'reward_config_id' => 'require',
'reward_tier' => 'require',
'roll_array' => 'require|checkRollArray',
];
@@ -35,7 +35,7 @@ class DicePlayRecordValidate extends BaseValidate
'lottery_type' => '抽奖类型必须填写',
'is_win' => '中奖必须填写',
'win_coin' => '赢取平台币必须填写',
'reward_config_id' => '奖励配置必须填写',
'reward_tier' => '中奖档位必须填写',
'roll_array.require' => '摇取点数必须填写',
];
@@ -49,7 +49,7 @@ class DicePlayRecordValidate extends BaseValidate
'lottery_type',
'is_win',
'win_coin',
'reward_config_id',
'reward_tier',
'roll_array',
],
'update' => [
@@ -58,7 +58,7 @@ class DicePlayRecordValidate extends BaseValidate
'lottery_type',
'is_win',
'win_coin',
'reward_config_id',
'reward_tier',
'roll_array',
],
];

View File

@@ -21,7 +21,7 @@ class DicePlayRecordTestValidate extends BaseValidate
'lottery_type' => 'require',
'is_win' => 'require',
'direction' => 'require',
'reward_config_id' => 'require',
'reward_tier' => 'require',
'status' => 'require',
];
@@ -30,10 +30,10 @@ 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必须填写',
'reward_tier' => '中奖档位必须填写',
'status' => '状态:0=失败,1=成功必须填写',
];
@@ -46,7 +46,7 @@ class DicePlayRecordTestValidate extends BaseValidate
'lottery_type',
'is_win',
'direction',
'reward_config_id',
'reward_tier',
'status',
],
'update' => [
@@ -54,7 +54,7 @@ class DicePlayRecordTestValidate extends BaseValidate
'lottery_type',
'is_win',
'direction',
'reward_config_id',
'reward_tier',
'status',
],
];

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\validate\player;
use app\dice\model\player\DicePlayer;
use plugin\saiadmin\basic\BaseValidate;
/**
@@ -17,7 +18,7 @@ class DicePlayerValidate extends BaseValidate
* 定义验证规则
*/
protected $rule = [
'username' => 'require',
'username' => 'require|unique:' . DicePlayer::class . ',username^dept_id',
'name' => 'require',
'phone' => 'require',
'password' => 'require',
@@ -30,6 +31,7 @@ class DicePlayerValidate extends BaseValidate
*/
protected $message = [
'username' => '用户名必须填写',
'username.unique' => 'PLAYER_USERNAME_DEPT_UNIQUE',
'name' => '昵称必须填写',
'phone' => '手机号必须填写',
'password' => '密码必须填写',

15
server/app/view/404.html Normal file
View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $message ?></title>
<style>
body { font-family: system-ui, sans-serif; text-align: center; margin-top: 4rem; color: #333; }
h1 { font-size: 1.5rem; font-weight: 600; }
</style>
</head>
<body>
<h1><?= $message ?></h1>
</body>
</html>

View File

@@ -6,7 +6,7 @@ return [
// 登录成功返回的连接地址前缀,如 https://127.0.0.1:6777
'login_url_base' => env('API_LOGIN_URL_BASE', 'https://127.0.0.1:6777'),
// 游戏地址,用于 /api/v1/getGameUrl 返回拼接 token
'game_url' => env('GAME_URL', 'dice-game.yuliao666.top'),
'game_url' => env('GAME_URL', 'dice-v3-game.h55555game.top'),
// 按 username 存储的登录会话 Redis key 前缀,用于 token 中间件校验
'session_username_prefix' => env('API_SESSION_USERNAME_PREFIX', 'api:user:session:'),
// 登录会话过期时间(秒),默认 7 天
@@ -34,4 +34,7 @@ return [
// 玩家信息按 username 缓存Token 中间件用0 表示不缓存
'player_cache_ttl' => (int) env('API_PLAYER_CACHE_TTL', 300),
'player_cache_prefix' => env('API_PLAYER_CACHE_PREFIX', 'api:player:'),
// /api/v1/getPlayerInfo 返回体快照Redis0 表示不缓存;变更玩家数据时需 deletePlayerByUsername 失效
'player_info_snapshot_ttl' => (int) env('API_PLAYER_INFO_SNAPSHOT_TTL', 180),
'player_info_snapshot_prefix' => env('API_PLAYER_INFO_SNAPSHOT_PREFIX', 'api:v1:player_info:'),
];

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

@@ -13,16 +13,21 @@
*/
use Webman\Route;
use app\api\middleware\TokenMiddleware;
use app\api\middleware\ApiAccessLogMiddleware;
use app\api\middleware\AuthTokenMiddleware;
use app\api\middleware\TokenMiddleware;
// 平台鉴权接口:/api/v1/authToken请求头 signature/secret/time/agent_id返回 authtToken
Route::group('/api/v1', function () {
Route::any('/authToken', [app\api\controller\v1\AuthTokenController::class, 'index']);
})->middleware([]);
})->middleware([
ApiAccessLogMiddleware::class,
]);
// 平台 v1 接口:需在请求头携带 auth-token
Route::group('/api/v1', function () {
Route::any('/getGameList', [app\api\controller\v1\GameController::class, 'getGameList']);
Route::any('/getGameHall', [app\api\controller\v1\GameController::class, 'getGameHall']);
Route::any('/getGameUrl', [app\api\controller\v1\GameController::class, 'getGameUrl']);
Route::any('/getPlayerInfo', [app\api\controller\v1\GameController::class, 'getPlayerInfo']);
Route::any('/getPlayerGameRecord', [app\api\controller\v1\GameController::class, 'getPlayerGameRecord']);
@@ -30,13 +35,16 @@ Route::group('/api/v1', function () {
Route::any('/getPlayerTicketRecord', [app\api\controller\v1\GameController::class, 'getPlayerTicketRecord']);
Route::any('/setPlayerWallet', [app\api\controller\v1\GameController::class, 'setPlayerWallet']);
})->middleware([
ApiAccessLogMiddleware::class,
AuthTokenMiddleware::class,
]);
// 登录接口:无需 token提交 JSON 获取带 token 的连接地址
Route::group('/api', function () {
Route::any('/user/Login', [app\api\controller\UserController::class, 'Login']);
})->middleware([]);
})->middleware([
ApiAccessLogMiddleware::class,
]);
// 其余接口:仅经 token 中间件鉴权header: tokenbase64(username.-.time)
Route::group('/api', function () {
@@ -46,9 +54,14 @@ Route::group('/api', function () {
Route::any('/user/walletRecord', [app\api\controller\UserController::class, 'walletRecord']);
Route::any('/user/playGameRecord', [app\api\controller\UserController::class, 'playGameRecord']);
Route::any('/game/config', [app\api\controller\GameController::class, 'config']);
Route::any('/game/buyLotteryTickets', [app\api\controller\GameController::class, 'buyLotteryTickets']);
// 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([
ApiAccessLogMiddleware::class,
TokenMiddleware::class,
]);
// 关闭主应用默认路由(/controller/action 隐式映射),未在本文件显式注册的路径返回 404
Route::disableDefaultRoute('');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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 @@
ALTER TABLE `dice_config`
ADD COLUMN `title_en` varchar(255) NOT NULL DEFAULT '' COMMENT '标题(英文)' AFTER `title`,
ADD COLUMN `value_en` text NULL COMMENT '值(英文)' AFTER `value`;

51
server/db/dice_game.sql Normal file
View File

@@ -0,0 +1,51 @@
-- 游戏管理表
CREATE TABLE IF NOT EXISTS `dice_game` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`provider` varchar(64) NOT NULL DEFAULT 'Dicey Fun' COMMENT '供应商名称',
`provider_code` varchar(32) NOT NULL DEFAULT 'DF' COMMENT '供应商编码',
`game_code` varchar(64) NOT NULL COMMENT '游戏编号',
`game_key` varchar(64) NOT NULL COMMENT '游戏唯一值',
`game_name` varchar(128) NOT NULL COMMENT '游戏名称(中文)',
`game_name_en` varchar(128) NOT NULL DEFAULT '' COMMENT '游戏名称(英文)',
`game_type` varchar(32) NOT NULL DEFAULT 'slot' COMMENT '游戏类型',
`logo` varchar(255) NOT NULL DEFAULT '' COMMENT '游戏LOGO地址',
`game_url` varchar(255) NOT NULL DEFAULT '' COMMENT '游戏地址',
`hall_url` varchar(255) NOT NULL DEFAULT '' COMMENT '大厅地址',
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态1启用 0禁用',
`sort` int NOT NULL DEFAULT 100 COMMENT '排序值,越小越靠前',
`is_hot` tinyint NOT NULL DEFAULT 0 COMMENT '是否热门1是 0否',
`merchant_config_json` text COMMENT '商户可见扩展配置',
`sensitive_config_json` text COMMENT '敏感配置(不对大厅接口返回)',
`remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_dice_game_code` (`game_code`),
UNIQUE KEY `uk_dice_game_key` (`game_key`),
KEY `idx_provider_status_sort` (`provider_code`,`status`,`sort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='游戏管理表';
-- 初始化默认游戏(大富翁)
INSERT INTO `dice_game`
(`provider`,`provider_code`,`game_code`,`game_key`,`game_name`,`game_name_en`,`game_type`,`logo`,`game_url`,`hall_url`,`status`,`sort`,`is_hot`,`merchant_config_json`,`sensitive_config_json`,`remark`)
SELECT
'Dicey Fun',
'DF',
'dafuwen',
'dafuwen',
'大富翁',
'Dafuweng',
'slot',
'',
'https://dice-v3-game.h55555game.top/',
'https://dice-v3-game.h55555game.top/',
1,
1,
1,
NULL,
NULL,
'初始化默认游戏'
WHERE NOT EXISTS (
SELECT 1 FROM `dice_game` WHERE `game_code` = 'dafuwen'
);

View File

@@ -0,0 +1,44 @@
-- 游戏管理菜单与权限
-- 说明挂载到顶级菜单parent_id=0
SET @now = NOW();
-- 1) 创建游戏管理顶级菜单type=2parent_id=0
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, '游戏管理', 'Game', NULL, 2, 'game', '/plugin/dice/game/index/index', NULL, 'ri:apps-2-line', 91, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE NOT EXISTS (
SELECT 1 FROM `sa_system_menu` WHERE `path` = 'game' AND `component` = '/plugin/dice/game/index/index' AND `type` = 2
);
SET @game_menu_id = (
SELECT `id` FROM `sa_system_menu`
WHERE `path` = 'game' AND `component` = '/plugin/dice/game/index/index' AND `type` = 2
ORDER BY `id` ASC LIMIT 1
);
-- 2) 创建按钮权限
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 @game_menu_id, '数据列表', '', 'dice:game: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:game: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 @game_menu_id, '读取', '', 'dice:game: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:game: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 @game_menu_id, '添加', '', 'dice:game: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:game: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 @game_menu_id, '修改', '', 'dice:game: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:game: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 @game_menu_id, '删除', '', 'dice:game: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:game:index:destroy' AND `type` = 3);

View File

@@ -0,0 +1,3 @@
-- 彩金池累计盈利:每次抽奖成功后累加 (100 - DiceRewardConfig.real_ev),后台「当前彩金池」展示为 profit_amount
-- 若表已有 ev 字段可跳过本句
ALTER TABLE `dice_lottery_pool_config` ADD COLUMN `ev` decimal(14,2) NOT NULL DEFAULT 0.00 COMMENT '池子累计盈利(游戏结算时累加)' AFTER `t5_weight`;

View File

@@ -0,0 +1,5 @@
-- 杀分开关:是否启用杀分(达到安全线后是否使用 type=1 权重)
-- 若列已存在可跳过
ALTER TABLE `dice_lottery_pool_config`
ADD COLUMN `kill_enabled` tinyint NOT NULL DEFAULT 1 COMMENT '是否启用杀分0=关闭 1=开启' AFTER `safety_line`;

View File

@@ -0,0 +1,7 @@
-- 彩金池盈利字段:使用 profit_amount计算方式为每局抽奖累加付费=win_coin-paid_amount免费=win_coin
-- 1. 添加 profit_amount若已存在则报错可忽略
ALTER TABLE `dice_lottery_pool_config` ADD COLUMN `profit_amount` decimal(14,2) NOT NULL DEFAULT 0.00 COMMENT '池子累计盈利(每局抽奖累加:付费=win_coin-paid_amount免费=win_coin' AFTER `t5_weight`;
-- 2. 若表中原有 ev 字段,可将数据同步到 profit_amount若无 ev 可注释本行)
-- UPDATE `dice_lottery_pool_config` SET `profit_amount` = IFNULL(`ev`, 0) WHERE 1;
-- 3. 可选:删除旧字段 ev
-- ALTER TABLE `dice_lottery_pool_config` DROP COLUMN `ev`;

View File

@@ -0,0 +1,6 @@
-- [已废弃] dice_lottery_pool_config 不再使用 type 字段,改用 name 区分:
-- default=原 type=0killScore=原 type=1up=原 type=2
-- 如需移除 type 列,请执行:
-- ALTER TABLE `dice_lottery_pool_config` DROP COLUMN `type`;
-- ALTER TABLE `dice_lottery_pool_config` DROP COLUMN `type`;

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*1免费局=0' AFTER `ante`;

View File

@@ -0,0 +1,3 @@
-- DicePlayRecord 新增 roll_number 字段摇取点数和5 个色子点数之和5-30
ALTER TABLE `dice_play_record`
ADD COLUMN `roll_number` int unsigned NOT NULL DEFAULT 0 COMMENT '摇取点数和5个色子点数之和5-30' AFTER `roll_array`;

View File

@@ -0,0 +1,17 @@
-- 游玩记录表:新增 reward_tierT1,T2,T3,T4,T5,BIGWIN
-- 说明:
-- - 当前版本已不再使用/保留历史“奖励配置ID”字段
-- - 回填逻辑改为使用 target_index对应 dice_reward_config.id与 super_win_coin 判定 BIGWIN
ALTER TABLE `dice_play_record`
ADD COLUMN `reward_tier` varchar(10) NOT NULL DEFAULT '' COMMENT '中奖档位T1,T2,T3,T4,T5,BIGWIN' AFTER `direction`;
UPDATE `dice_play_record` r
SET r.`reward_tier` =
CASE
WHEN IFNULL(r.`super_win_coin`, 0) > 0 THEN 'BIGWIN'
WHEN IFNULL(r.`target_index`, 0) > 0 THEN IFNULL((SELECT c.`tier` FROM `dice_reward_config` c WHERE c.`id` = r.`target_index` LIMIT 1), '')
ELSE ''
END
WHERE IFNULL(r.`reward_tier`, '') = '';

View File

@@ -0,0 +1,5 @@
-- 测试用游玩记录表:结构与 dice_play_record 一致不关联真实玩家player_id 填 0
-- 用于一键测试权重时写入模拟数据,可一键清空
-- 若表已存在可跳过;执行前请确认 dice_play_record 表已存在
CREATE TABLE IF NOT EXISTS `dice_play_record_test` LIKE `dice_play_record`;

View File

@@ -0,0 +1,10 @@
-- 测试用游玩记录表:新增底注/注数 ante 与付费金额 paid_amount
-- 用于权重一键测试时按新口径计算 win_coin / paid_amount / 平台盈利
ALTER TABLE `dice_play_record_test`
ADD COLUMN `ante` int unsigned NOT NULL DEFAULT 1 COMMENT '底注/注数dice_ante_config.mult' AFTER `lottery_type`;
ALTER TABLE `dice_play_record_test`
ADD COLUMN `paid_amount` int unsigned NOT NULL DEFAULT 0 COMMENT '付费金额(付费局=ante*1免费局=0' AFTER `ante`;

View File

@@ -0,0 +1,5 @@
-- 测试抽奖记录关联权重测试记录:用于按 record 统计 platform_profit付费金额 paid_amount 求和 - win_coin 求和)
-- 若列已存在可跳过
ALTER TABLE `dice_play_record_test` ADD COLUMN `reward_config_record_id` int unsigned DEFAULT NULL COMMENT '关联 dice_reward_config_record.id' AFTER `admin_id`;
CREATE INDEX `idx_reward_config_record_id` ON `dice_play_record_test` (`reward_config_record_id`);

View File

@@ -0,0 +1,17 @@
-- 游玩记录测试表:新增 reward_tierT1,T2,T3,T4,T5,BIGWIN
-- 说明:
-- - 当前版本已不再使用/保留历史“奖励配置ID”字段
-- - 回填逻辑改为使用 target_index对应 dice_reward_config.id与 super_win_coin 判定 BIGWIN
ALTER TABLE `dice_play_record_test`
ADD COLUMN `reward_tier` varchar(10) NOT NULL DEFAULT '' COMMENT '中奖档位T1,T2,T3,T4,T5,BIGWIN' AFTER `direction`;
UPDATE `dice_play_record_test` r
SET r.`reward_tier` =
CASE
WHEN IFNULL(r.`super_win_coin`, 0) > 0 THEN 'BIGWIN'
WHEN IFNULL(r.`target_index`, 0) > 0 THEN IFNULL((SELECT c.`tier` FROM `dice_reward_config` c WHERE c.`id` = r.`target_index` LIMIT 1), '')
ELSE ''
END
WHERE IFNULL(r.`reward_tier`, '') = '';

View File

@@ -0,0 +1,14 @@
-- 修复测试记录时间字段为空:
-- 1) 先回填历史 NULL
-- 2) 再设置数据库默认值与自动更新时间,避免应用侧漏写导致 NULL
UPDATE `dice_play_record_test`
SET `create_time` = IFNULL(`create_time`, NOW()),
`update_time` = IFNULL(`update_time`, IFNULL(`create_time`, NOW()))
WHERE `create_time` IS NULL OR `update_time` IS NULL;
ALTER TABLE `dice_play_record_test`
MODIFY COLUMN `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';
ALTER TABLE `dice_play_record_test`
MODIFY COLUMN `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

View File

@@ -0,0 +1,5 @@
-- 为 dice_player 表新增 admin_id 字段
-- admin_id 关联 sa_system_user.id表示创建该玩家的后台管理员
ALTER TABLE `dice_player`
ADD COLUMN `admin_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '创建该玩家的后台管理员ID关联 sa_system_user.id';

View File

@@ -0,0 +1,6 @@
-- 玩家表新增 free_ticket 字段用于记录免费抽奖券JSON{"ante":1,"count":1}
-- 若已存在可跳过
ALTER TABLE `dice_player`
ADD COLUMN `free_ticket` json NULL COMMENT '免费抽奖券:{"ante":1,"count":1}' AFTER `free_ticket_count`;

View File

@@ -0,0 +1,28 @@
-- 玩家管理:新增“获取游戏链接”按钮权限
SET @now = NOW();
-- 优先使用已有“数据列表”按钮找到玩家菜单 ID
SET @player_menu_id = (
SELECT `parent_id` FROM `sa_system_menu`
WHERE `slug` = 'dice:player:index:index' AND `type` = 3
ORDER BY `id` ASC LIMIT 1
);
-- 兜底:按玩家菜单路径查找
SET @player_menu_id = IFNULL(
@player_menu_id,
(
SELECT `id` FROM `sa_system_menu`
WHERE `path` = 'player' AND `type` = 2
ORDER BY `id` ASC LIMIT 1
)
);
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 @player_menu_id, '获取游戏链接', '', 'dice:player:index:getGameUrl', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
WHERE @player_menu_id IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:player:index:getGameUrl' AND `type` = 3
);

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

@@ -0,0 +1,11 @@
-- 为 dice_play_record、dice_player_ticket_record、dice_player_wallet_record 表新增 admin_id 字段
-- admin_id 关联 DicePlayer.admin_id表示玩家所属管理员
ALTER TABLE `dice_play_record`
ADD COLUMN `admin_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '关联玩家所属管理员IDDicePlayer.admin_id';
ALTER TABLE `dice_player_ticket_record`
ADD COLUMN `admin_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '关联玩家所属管理员IDDicePlayer.admin_id';
ALTER TABLE `dice_player_wallet_record`
ADD COLUMN `admin_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '关联玩家所属管理员IDDicePlayer.admin_id';

12
server/db/dice_reward.sql Normal file
View File

@@ -0,0 +1,12 @@
-- 奖励对照表:按档位与方向(顺时针/逆时针)存储权重,无自增 ID
-- 与 dice_reward_config 通过 end_index(=DiceRewardConfig.id) 关联
CREATE TABLE IF NOT EXISTS `dice_reward` (
`tier` varchar(20) NOT NULL COMMENT '档位 T1-T5/BIGWIN',
`direction` tinyint NOT NULL COMMENT '0=顺时针,1=逆时针',
`end_index` int unsigned NOT NULL COMMENT '结束索引DiceRewardConfig.id',
`weight` int unsigned NOT NULL DEFAULT 1 COMMENT '权重 1-10000档位内按权重比抽取',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '软删除时间',
PRIMARY KEY (`tier`, `direction`, `end_index`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='奖励对照表-按档位与方向存储权重';

View File

@@ -0,0 +1,8 @@
-- dice_reward 表增加展示字段:创建时从 config 写入,便于列表直接显示
ALTER TABLE `dice_reward`
ADD COLUMN `grid_number` int unsigned NOT NULL DEFAULT 0 COMMENT '色子点数(摇取值)',
ADD COLUMN `start_index` int unsigned NOT NULL DEFAULT 0 COMMENT '起始索引(DiceRewardConfig.id)',
ADD COLUMN `ui_text` varchar(255) DEFAULT '' COMMENT '显示文本(来自config)',
ADD COLUMN `real_ev` decimal(12,2) DEFAULT NULL COMMENT '实际中奖金额(来自config)',
ADD COLUMN `remark` varchar(255) DEFAULT '' COMMENT '备注(来自config)',
ADD COLUMN `type` tinyint NOT NULL DEFAULT 0 COMMENT '奖励类型(来自config):-2=唯一惩罚,-1=抽水,0=回本,1=再来一次,2=小赚,3=大奖格';

View File

@@ -0,0 +1,4 @@
-- dice_reward 表增加自增主键 id原复合主键改为唯一索引以保证 (tier,direction,end_index) 不重复
ALTER TABLE `dice_reward` DROP PRIMARY KEY;
ALTER TABLE `dice_reward` ADD COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);
ALTER TABLE `dice_reward` ADD UNIQUE KEY `uk_tier_direction_end` (`tier`, `direction`, `end_index`);

View File

@@ -0,0 +1,6 @@
-- 奖励配置表增加 weight 字段:仅 tier=BIGWIN 时使用0-1000010000=100% 中大奖
-- 若之前执行过 dice_reward_config_drop_weight.sql 已删除该列,需执行本脚本恢复
-- 若表已有 weight 列会报错,可忽略
ALTER TABLE `dice_reward_config`
ADD COLUMN `weight` int unsigned NOT NULL DEFAULT 10000 COMMENT 'BIGWIN 大奖权重 0-1000010000=100%' AFTER `tier`;

View File

@@ -0,0 +1,4 @@
-- 奖励配置表新增 type 字段:奖励类型
-- -2=唯一惩罚, -1=抽水, 0=回本, 1=再来一次, 2=小赚, 3=大奖格
ALTER TABLE `dice_reward_config`
ADD COLUMN `type` tinyint NOT NULL DEFAULT 0 COMMENT '奖励类型:-2=唯一惩罚,-1=抽水,0=回本,1=再来一次,2=小赚,3=大奖格';

View File

@@ -0,0 +1,3 @@
ALTER TABLE `dice_reward_config`
ADD COLUMN `ui_text_en` varchar(255) NOT NULL DEFAULT '' COMMENT '前端显示文本(英文)' AFTER `ui_text`;

View File

@@ -0,0 +1,3 @@
-- DiceRewardConfig 新增 weight 字段:仅 tier=BIGWIN 时可设定0-100%
ALTER TABLE `dice_reward_config`
ADD COLUMN `weight` decimal(5,2) NOT NULL DEFAULT 0.00 COMMENT '权重%,仅 tier=BIGWIN 时可设定0-100' AFTER `tier`;

View File

@@ -0,0 +1,14 @@
-- dice_reward_config 表结构迁移:按 DiceRewardConfigTest 配置
-- 1. s_end_index 改为 n_start_index逆时针起始索引
-- 2. n_end_index 改为 s_start_index顺时针起始索引
-- 3. weight 改为 1-10000 整数(原为 0-100 小数则需先改类型再改范围)
-- 若表已有 s_end_index / n_end_index先重命名
ALTER TABLE `dice_reward_config`
CHANGE COLUMN `s_end_index` `n_start_index` int NOT NULL DEFAULT 0 COMMENT '逆时针起始索引';
ALTER TABLE `dice_reward_config`
CHANGE COLUMN `n_end_index` `s_start_index` int NOT NULL DEFAULT 0 COMMENT '顺时针起始索引';
-- weight 改为 1-10000 无符号整数(若原为 decimal(5,2),先改类型)
ALTER TABLE `dice_reward_config`
MODIFY COLUMN `weight` int unsigned NOT NULL DEFAULT 1 COMMENT '权重 1-10000档位内按权重比抽取 grid_number';

View File

@@ -0,0 +1,28 @@
[
{"id": 0, "grid_number": 20, "ui_text": "100", "ui_text_en": "100", "real_ev": 1, "tier": "T2", "remark": "完美回本"},
{"id": 1, "grid_number": 27, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -80, "tier": "T3", "remark": "抽水"},
{"id": 2, "grid_number": 24, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -85, "tier": "T3", "remark": "抽水"},
{"id": 3, "grid_number": 10, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -140, "tier": "T4", "remark": "惩罚"},
{"id": 4, "grid_number": 5, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -90, "tier": "T3", "remark": "抽水"},
{"id": 5, "grid_number": 15, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -88, "tier": "T3", "remark": "抽水"},
{"id": 6, "grid_number": 8, "ui_text": "300", "ui_text_en": "300", "real_ev": 250, "tier": "T1", "remark": "大奖格"},
{"id": 7, "grid_number": 22, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -120, "tier": "T4", "remark": "惩罚"},
{"id": 8, "grid_number": 30, "ui_text": "600", "ui_text_en": "600", "real_ev": 499, "tier": "T1", "remark": "大奖格"},
{"id": 9, "grid_number": 23, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -83, "tier": "T3", "remark": "抽水"},
{"id": 10, "grid_number": 16, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -82, "tier": "T3", "remark": "抽水"},
{"id": 11, "grid_number": 12, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -79, "tier": "T3", "remark": "抽水"},
{"id": 12, "grid_number": 13, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -77, "tier": "T3", "remark": "抽水"},
{"id": 13, "grid_number": 7, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -78, "tier": "T3", "remark": "抽水"},
{"id": 14, "grid_number": 17, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -76, "tier": "T3", "remark": "抽水"},
{"id": 15, "grid_number": 9, "ui_text": "500", "ui_text_en": "500", "real_ev": 400, "tier": "T1", "remark": "大奖格"},
{"id": 16, "grid_number": 21, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -84, "tier": "T3", "remark": "抽水"},
{"id": 17, "grid_number": 26, "ui_text": "400", "ui_text_en": "400", "real_ev": 350, "tier": "T1", "remark": "大奖格"},
{"id": 18, "grid_number": 6, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -86, "tier": "T3", "remark": "抽水"},
{"id": 19, "grid_number": 29, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -87, "tier": "T3", "remark": "抽水"},
{"id": 20, "grid_number": 19, "ui_text": "100", "ui_text_en": "100", "real_ev": 1, "tier": "T2", "remark": "完美回本"},
{"id": 21, "grid_number": 11, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -81, "tier": "T3", "remark": "抽水"},
{"id": 22, "grid_number": 25, "ui_text": "再来一次", "ui_text_en": "Once again", "real_ev": 0, "tier": "T5", "remark": "前端需要在播放一次动画(特殊)"},
{"id": 23, "grid_number": 14, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -89, "tier": "T3", "remark": "抽水"},
{"id": 24, "grid_number": 28, "ui_text": "-40", "ui_text_en": "-40", "real_ev": -75, "tier": "T3", "remark": "抽水"},
{"id": 25, "grid_number": 18, "ui_text": "50", "ui_text_en": "50", "real_ev": 50, "tier": "T2", "remark": "小赚"}
]

View File

@@ -0,0 +1,7 @@
-- 移除 DiceRewardConfig 表的 s_start_index、n_start_index 字段
-- 起始索引已迁移至 dice_reward.start_index开局逻辑与列表均不再依赖 config 的这两列
-- 执行前请确认:已运行「创建奖励对照」且 dice_reward 中 start_index 已正确写入
-- 若 MySQL < 8.0.23 不支持 DROP COLUMN IF EXISTS可改为 DROP COLUMN 并忽略“列不存在”错误
ALTER TABLE `dice_reward_config` DROP COLUMN IF EXISTS `s_start_index`;
ALTER TABLE `dice_reward_config` DROP COLUMN IF EXISTS `n_start_index`;

View File

@@ -0,0 +1,2 @@
-- 从奖励配置表移除权重字段,权重改由 dice_reward 表管理(区分顺时针/逆时针)
ALTER TABLE `dice_reward_config` DROP COLUMN IF EXISTS `weight`;

View File

@@ -0,0 +1,14 @@
-- 权重配比测试记录表:保存测试时的权重快照与落点统计,用于验证配比效果
-- weight_config_snapshot: 测试时使用的权重配比快照(按档位 T1-T5/BIGWIN 的 id, grid_number, tier, weight
-- result_counts: 落点统计 JSON键为 grid_number色子点数值为出现次数
CREATE TABLE IF NOT EXISTS `dice_reward_config_record` (
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
`test_count` int unsigned NOT NULL DEFAULT 100 COMMENT '测试次数100/500/1000',
`weight_config_snapshot` json DEFAULT NULL COMMENT '测试时权重配比快照:按档位保存 id,grid_number,tier,weight',
`result_counts` json DEFAULT NULL COMMENT '落点统计grid_number=>出现次数',
`admin_id` int unsigned DEFAULT NULL COMMENT '执行测试的管理员ID',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_create_time` (`create_time`),
KEY `idx_admin_id` (`admin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='奖励配置权重测试记录';

View File

@@ -0,0 +1,7 @@
-- 一键测试权重:新增底注/注数 ante 字段
-- 用于权重测试模拟时计算 win_coin / paid_amount / 平台盈利
-- 若列已存在可跳过该条
ALTER TABLE `dice_reward_config_record`
ADD COLUMN `ante` int unsigned NOT NULL DEFAULT 1 COMMENT '底注/注数(玩家每注下注倍数 mult' AFTER `free_n_count`;

View File

@@ -0,0 +1,5 @@
-- 奖励配置权重测试记录表新增 bigwin_weight测试时 BIGWIN 档位的权重快照
-- 若列已存在可跳过该条
ALTER TABLE `dice_reward_config_record` ADD COLUMN `bigwin_weight` json DEFAULT NULL COMMENT '测试时 BIGWIN 档位 weight 快照:{"grid_number": weight, ...}' AFTER `platform_profit`;

View File

@@ -0,0 +1,7 @@
-- 一键测试权重:链式再来一次模式显式落库,计划付费次数与再来一次次数用于展示
-- 执行前请确认表 `dice_reward_config_record` 已存在
ALTER TABLE `dice_reward_config_record`
ADD COLUMN `chain_free_mode` tinyint NOT NULL DEFAULT 0 COMMENT '1=链式再来一次(付费抽到T5后插入免费局)' AFTER `paid_n_count`,
ADD COLUMN `paid_planned_spins` int unsigned NOT NULL DEFAULT 0 COMMENT '计划付费抽奖次数(顺时针+逆时针)' AFTER `chain_free_mode`,
ADD COLUMN `play_again_count` int unsigned NOT NULL DEFAULT 0 COMMENT '再来一次次数(T5触发次数)' AFTER `paid_planned_spins`;

View File

@@ -0,0 +1,6 @@
-- 一键测试权重:新增测试内杀分开关与安全线
-- kill_mode_enabled=1 时,模拟玩家累计盈利达到 test_safety_line 后,付费抽奖切到 killScore
ALTER TABLE `dice_reward_config_record`
ADD COLUMN `kill_mode_enabled` tinyint NOT NULL DEFAULT 0 COMMENT '测试内杀分开关1=开启0=关闭' AFTER `chain_free_mode`,
ADD COLUMN `test_safety_line` int unsigned NOT NULL DEFAULT 5000 COMMENT '测试内安全线:模拟玩家累计盈利达到该值后,付费抽奖走杀分逻辑' AFTER `kill_mode_enabled`;

View File

@@ -0,0 +1,5 @@
-- 奖励配置权重测试记录:新增平台赚取金额(测试完成后写入)
-- 公式:关联 dice_play_record_test 中付费金额 paid_amount 求和 - 关联 win_coin 求和
-- 必须执行本脚本后,新完成的权重测试才会记录「平台赚取金额」;若某列已存在会报错,可跳过该条
ALTER TABLE `dice_reward_config_record` ADD COLUMN `platform_profit` decimal(14,2) DEFAULT NULL COMMENT '平台赚取金额(付费金额 paid_amount 求和-玩家总收益 win_coin 求和)' AFTER `tier_counts`;

View File

@@ -0,0 +1,16 @@
-- 一键测试权重:为 dice_reward_config_record 增加进度与结果字段
-- total_play_count: 总模拟次数s_count + n_count
-- over_play_count: 已完成次数,每完成 10 条写入 dice_play_record_test 后更新
-- status: -1 失败0 进行中1 成功
-- remark: 失败时记录原因
-- s_count / n_count: 顺时针、逆时针模拟次数
-- tier_counts: 档位出现次数 JSON如 {"T1":100,"T2":200,...},用于档位概率
-- 若某列已存在会报错,可跳过该条
ALTER TABLE `dice_reward_config_record` ADD COLUMN `total_play_count` int unsigned NOT NULL DEFAULT 0 COMMENT '总模拟次数' AFTER `lottery_config_id`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `over_play_count` int unsigned NOT NULL DEFAULT 0 COMMENT '已完成次数' AFTER `total_play_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `status` tinyint NOT NULL DEFAULT 0 COMMENT '状态 -1失败 0进行中 1成功' AFTER `over_play_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `remark` varchar(500) DEFAULT NULL COMMENT '失败时记录原因' AFTER `status`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `s_count` int unsigned NOT NULL DEFAULT 0 COMMENT '顺时针模拟次数' AFTER `remark`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `n_count` int unsigned NOT NULL DEFAULT 0 COMMENT '逆时针模拟次数' AFTER `s_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `tier_counts` json DEFAULT NULL COMMENT '档位出现次数 T1=>count' AFTER `result_counts`;

View File

@@ -0,0 +1,4 @@
-- 测试记录表:增加 T1-T5 档位权重快照与使用的奖池配置 ID
ALTER TABLE `dice_reward_config_record`
ADD COLUMN `tier_weights_snapshot` json DEFAULT NULL COMMENT '测试时使用的 T1-T5 档位权重快照:来自 DiceLotteryPoolConfig 的 t1_weightt5_weight' AFTER `weight_config_snapshot`,
ADD COLUMN `lottery_config_id` int unsigned DEFAULT NULL COMMENT '测试时使用的奖池配置 IDDiceLotteryPoolConfig.id' AFTER `tier_weights_snapshot`;

View File

@@ -0,0 +1,8 @@
-- 移除 dice_reward_config_record 冗余旧计数字段(已由 paid_s_count/paid_n_count + 链式逻辑替代)
-- 执行前请确认相关代码已升级,不再依赖以下字段
ALTER TABLE `dice_reward_config_record`
DROP COLUMN `s_count`,
DROP COLUMN `n_count`,
DROP COLUMN `free_s_count`,
DROP COLUMN `free_n_count`;

View File

@@ -0,0 +1,7 @@
-- 一键测试权重:付费/免费可分别选择奖池配置type=0 / type=1
-- paid_lottery_config_id: 付费抽奖使用的奖池配置,默认 type=0
-- free_lottery_config_id: 免费抽奖使用的奖池配置,默认 type=1
-- 若某列已存在会报错,可跳过该条
ALTER TABLE `dice_reward_config_record` ADD COLUMN `paid_lottery_config_id` int unsigned DEFAULT NULL COMMENT '付费抽奖奖池配置ID' AFTER `lottery_config_id`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `free_lottery_config_id` int unsigned DEFAULT NULL COMMENT '免费抽奖奖池配置ID' AFTER `paid_lottery_config_id`;

View File

@@ -0,0 +1,12 @@
-- 一键测试权重:支持付费/免费分页配置与自定义档位概率
-- paid_s_count / paid_n_count: 付费抽奖 顺时针/逆时针 次数
-- free_s_count / free_n_count: 免费抽奖 顺时针/逆时针 次数
-- paid_tier_weights / free_tier_weights: 自定义档位概率 JSON {T1:x, T2:x, ...},不选奖池配置时使用
-- 若某列已存在会报错,可跳过该条
ALTER TABLE `dice_reward_config_record` ADD COLUMN `paid_s_count` int unsigned NOT NULL DEFAULT 0 COMMENT '付费抽奖顺时针次数' AFTER `n_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `paid_n_count` int unsigned NOT NULL DEFAULT 0 COMMENT '付费抽奖逆时针次数' AFTER `paid_s_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `free_s_count` int unsigned NOT NULL DEFAULT 0 COMMENT '免费抽奖顺时针次数' AFTER `paid_n_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `free_n_count` int unsigned NOT NULL DEFAULT 0 COMMENT '免费抽奖逆时针次数' AFTER `free_s_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `paid_tier_weights` json DEFAULT NULL COMMENT '付费自定义档位权重 T1-T5' AFTER `free_n_count`;
ALTER TABLE `dice_reward_config_record` ADD COLUMN `free_tier_weights` json DEFAULT NULL COMMENT '免费自定义档位权重 T1-T5' AFTER `paid_tier_weights`;

View File

@@ -0,0 +1,236 @@
[
{
"id": 0,
"grid_number": 20,
"ui_text": "100",
"ui_text_en": "100",
"real_ev": 0,
"tier": "T2",
"remark": "完美回本(豹子格位仅 T1/T2/T3"
},
{
"id": 1,
"grid_number": 27,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -80,
"tier": "T3",
"remark": "抽水"
},
{
"id": 2,
"grid_number": 24,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -85,
"tier": "T3",
"remark": "抽水"
},
{
"id": 3,
"grid_number": 10,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -75,
"tier": "T3",
"remark": "抽水"
},
{
"id": 4,
"grid_number": 5,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -90,
"tier": "T3",
"remark": "抽水"
},
{
"id": 5,
"grid_number": 15,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -88,
"tier": "T3",
"remark": "抽水"
},
{
"id": 6,
"grid_number": 8,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -82,
"tier": "T3",
"remark": "抽水"
},
{
"id": 7,
"grid_number": 22,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -78,
"tier": "T3",
"remark": "抽水"
},
{
"id": 8,
"grid_number": 30,
"ui_text": "600",
"ui_text_en": "600",
"real_ev": 499,
"tier": "T1",
"remark": "大奖格"
},
{
"id": 9,
"grid_number": 23,
"ui_text": "再来一次",
"ui_text_en": "Once again",
"real_ev": 0,
"tier": "T5",
"remark": "前端需要在播放一次动画(特殊)"
},
{
"id": 10,
"grid_number": 16,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -83,
"tier": "T3",
"remark": "抽水"
},
{
"id": 11,
"grid_number": 12,
"ui_text": "150",
"ui_text_en": "150",
"real_ev": 150,
"tier": "T1",
"remark": "大奖格"
},
{
"id": 12,
"grid_number": 13,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -140,
"tier": "T4",
"remark": "惩罚"
},
{
"id": 13,
"grid_number": 7,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -79,
"tier": "T3",
"remark": "抽水"
},
{
"id": 14,
"grid_number": 17,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -77,
"tier": "T3",
"remark": "抽水"
},
{
"id": 15,
"grid_number": 9,
"ui_text": "500",
"ui_text_en": "500",
"real_ev": 400,
"tier": "T1",
"remark": "大奖格"
},
{
"id": 16,
"grid_number": 21,
"ui_text": "100",
"ui_text_en": "100",
"real_ev": 0,
"tier": "T2",
"remark": "完美回本"
},
{
"id": 17,
"grid_number": 26,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -76,
"tier": "T3",
"remark": "抽水"
},
{
"id": 18,
"grid_number": 6,
"ui_text": "200",
"ui_text_en": "200",
"real_ev": 200,
"tier": "T1",
"remark": "大奖格"
},
{
"id": 19,
"grid_number": 29,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -120,
"tier": "T4",
"remark": "惩罚"
},
{
"id": 20,
"grid_number": 19,
"ui_text": "100",
"ui_text_en": "100",
"real_ev": 0,
"tier": "T2",
"remark": "完美回本"
},
{
"id": 21,
"grid_number": 11,
"ui_text": "120",
"ui_text_en": "120",
"real_ev": 120,
"tier": "T1",
"remark": "大奖格"
},
{
"id": 22,
"grid_number": 25,
"ui_text": "-40",
"ui_text_en": "-40",
"real_ev": -81,
"tier": "T3",
"remark": "抽水"
},
{
"id": 23,
"grid_number": 14,
"ui_text": "150",
"ui_text_en": "150",
"real_ev": 50,
"tier": "T2",
"remark": "小赚"
},
{
"id": 24,
"grid_number": 28,
"ui_text": "100",
"ui_text_en": "100",
"real_ev": 0,
"tier": "T2",
"remark": "完美回本"
},
{
"id": 25,
"grid_number": 18,
"ui_text": "30",
"ui_text_en": "30",
"real_ev": 30,
"tier": "T2",
"remark": "小赚"
}
]

View File

@@ -0,0 +1,20 @@
-- DiceRewardConfigTest 新表奖励配置T1-T5 按档位+权重直接抽取 grid_number
-- 字段s_end_index 改为 n_start_index逆时针起始索引n_end_index 改为 s_start_index顺时针起始索引
-- weight 取值范围 1-10000各档位权重和不限制
CREATE TABLE IF NOT EXISTS `dice_reward_config_test` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`grid_number` int NOT NULL DEFAULT 0 COMMENT '色子点数',
`ui_text` varchar(64) NOT NULL DEFAULT '' COMMENT '前端显示文本',
`real_ev` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '真实资金结算',
`tier` varchar(16) NOT NULL DEFAULT '' COMMENT '所属档位 T1-T5|BIGWIN',
`weight` int unsigned NOT NULL DEFAULT 1 COMMENT '权重 1-10000按档位内权重比抽取 grid_number',
`n_start_index` int NOT NULL DEFAULT 0 COMMENT '逆时针起始索引',
`s_start_index` int NOT NULL DEFAULT 0 COMMENT '顺时针起始索引',
`remark` varchar(255) NOT NULL DEFAULT '',
`type` tinyint NOT NULL DEFAULT 1,
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_tier` (`tier`),
KEY `idx_grid_number` (`grid_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='奖励配置Test按档位权重抽 grid_numberweight 1-10000';

View File

@@ -0,0 +1,3 @@
-- 保证每个点数(direction, grid_number)唯一一条记录,避免多点数算出相同 end_index 时互相覆盖
ALTER TABLE `dice_reward` DROP INDEX `uk_tier_direction_end`;
ALTER TABLE `dice_reward` ADD UNIQUE KEY `uk_direction_grid_number` (`direction`, `grid_number`);

View File

@@ -0,0 +1,10 @@
-- 移除 Dice_* 表的 channel_id 和 department_id 字段
-- 需 MySQL 8.0.23+ 支持 DROP COLUMN IF EXISTS若版本较低请逐条执行并忽略报错
ALTER TABLE `dice_config` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_player` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_play_record` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_player_ticket_record` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_player_wallet_record` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_reward_config` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;
ALTER TABLE `dice_lottery_pool_config` DROP COLUMN IF EXISTS `channel_id`, DROP COLUMN IF EXISTS `department_id`;

View File

@@ -0,0 +1,9 @@
-- 为 sa_system_user 表新增 agent_id 字段
-- agent_id = md5(id),保证唯一,用于外部系统标识用户
ALTER TABLE `sa_system_user`
ADD COLUMN `agent_id` varchar(32) NULL DEFAULT NULL COMMENT '代理标识md5(id)唯一' AFTER `id`,
ADD UNIQUE INDEX `uk_agent_id`(`agent_id`) USING BTREE;
-- 为已有数据回填 agent_id
UPDATE `sa_system_user` SET `agent_id` = MD5(id) WHERE `agent_id` IS NULL OR `agent_id` = '';

View File

@@ -0,0 +1,614 @@
# Dicey Fun 第三方接入文档(基于现有项目接口)
## 1. 基础信息
- provider: `Dicey Fun`
- provider_code: `DF`
- game_type: `slot`
- game_list: `["dafuwen"]`
- provider_logo: ``
- 获取大厅地址: `https://dice-v3-lobby.h55555game.top`
- 后台管理地址: `https://dice-v3.h55555game.top/`
- agent_token: `[后台菜单查看:系统管理-用户管理-代理ID]`
- agent_id: `5ef059938ba799aaa845e1c2e8a762bd`
## 2. 接口域名与协议
- 协议: `HTTP/HTTPS`(建议生产使用 `HTTPS`
- Base URL: `https://{your-domain}`(由部署方提供)
- 数据格式: `application/json`
- 字符编码: `UTF-8`
### 2.1 调用规范(建议第三方按此统一实现)
- `/api/v1/authToken` 使用 `GET + Query 参数`
- 其他 `/api/v1/*` 接口使用 `POST + JSON Body`(本项目路由为 `Route::any`,但建议第三方统一按 `POST` 接入)
- 请求头统一:
- `Content-Type: application/json`
- `Accept: application/json`
- `auth-token: {authtoken}`(除 `/api/v1/authToken` 外必传)
- 时间相关参数统一使用 Unix 时间戳(秒)
- 建议所有请求设置超时:连接超时 `3s`,读取超时 `10s`
- 生产环境建议增加调用方 IP 白名单和重试退避机制(避免瞬时重试风暴)
---
## 3. 通用返回格式
所有接口统一返回:
```json
{
"code": 200,
"message": "success",
"data": {}
}
```
说明:
- `code=200` 表示成功
- 失败时通常返回:`400/401/402/403/404/422/500`
常见错误码:
- `400` 参数错误
- `401` 未携带 token
- `402` token 无效或过期
- `403` 签名或鉴权失败
- `404` 资源不存在
- `422` 业务错误(如余额不足)
- `500` 服务端异常
---
## 4. 鉴权流程(平台级)
`/api/v1/*` 接口调用前,先获取 `auth-token`
### 4.1 获取 auth-token
- 路径: `GET /api/v1/authToken`
- 鉴权参数Query
- `agent_id`:代理标识(商户标识)
- `secret`:双方约定密钥
- `time`Unix 时间戳(秒)
- `signature`:签名
签名规则:
```text
signature = md5(agent_id + secret + time)
```
签名示例(原串与结果):
```text
agent_id = 9f86d081884c7d659a2feaa0c55ad015
secret = xF75oK91TQj13s0UmNIr1NBWMWGfflNO
time = 1713753600
sign_src = 9f86d081884c7d659a2feaa0c55ad015xF75oK91TQj13s0UmNIr1NBWMWGfflNO1713753600
signature= md5(sign_src)
```
PHP 生成签名示例:
```php
$agentId = '9f86d081884c7d659a2feaa0c55ad015';
$secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
$time = (string) time();
$signature = md5($agentId . $secret . $time);
```
JavaScript 生成签名示例Node.js
```javascript
const crypto = require('crypto');
const agentId = '9f86d081884c7d659a2feaa0c55ad015';
const secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
const time = Math.floor(Date.now() / 1000).toString();
const signature = crypto.createHash('md5').update(agentId + secret + time).digest('hex');
```
服务端校验逻辑(关键点):
- `agent_id/secret/time/signature` 任一缺失即失败(`400`
- `secret` 不匹配即失败(`403`
- `time` 超出容差窗口即失败(`403`,默认容差 `300s`
- `signature` 校验失败即失败(`403`
- 校验通过后颁发 `authtoken`,后续请求必须放在 Header `auth-token`
防重放与时间同步建议:
- 调用方服务器必须启用 NTP 时间同步
- `time` 使用发起请求时的当前秒级时间戳,不要复用旧值
- 遇到 “Timestamp expired or invalid” 时优先检查服务器时间偏差
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"authtoken": "xxx.yyy.zzz"
}
}
```
后续调用 `/api/v1/*` 时,请在 Header 携带:
```text
auth-token: {authtoken}
```
### 4.2 完整调用链(推荐)
1. 计算 `signature = md5(agent_id + secret + time)`
2. 调用 `GET /api/v1/authToken` 获取 `authtoken`
3. 在 Header 添加 `auth-token: {authtoken}`
4. 调用业务接口(如 `getPlayerInfo``setPlayerWallet``getGameUrl``getPlayerGameRecord``getPlayerWalletRecord``getPlayerTicketRecord`
5. 若返回 `402`,重新获取 `authtoken` 后重试一次
---
## 5. 游戏相关接口
以下接口均需 Header: `auth-token`
## 5.1 获取游戏列表(已支持)
- 路径: `POST /api/v1/getGameList`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `lang`(可选):`zh`/`en`,默认 `zh`
- 返回说明:
-`dice_game` 表读取启用状态(`status=1`)的游戏
- 当前默认仅返回一个游戏:`dafuwen`
-`lang` 返回中英文 `game_name`
- 已做字段脱敏:不会返回敏感配置(如 `sensitive_config_json`
返回字段(`data.game_list[]`
- `provider`:供应商名称
- `provider_code`:供应商编码
- `game_code`:游戏编号
- `game_key`:游戏唯一值
- `game_type`:游戏类型
- `logo`:游戏 Logo 地址
- `game_url`:游戏地址
- `hall_url`:大厅地址
- `status`:状态(`1` 启用)
- `sort`:排序值
- `game_name`:游戏名称(跟随 `lang` 返回中文或英文)
成功返回示例(`lang=zh`
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
成功返回示例(`lang=en`
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.2 获取游戏大厅信息(已支持,脱敏)
- 路径: `POST /api/v1/getGameHall`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `lang`(可选):`zh`/`en`,默认 `zh`
- 返回说明:
- 返回大厅地址 `hall_url`
- 返回游戏列表(来自 `dice_game`
- 不返回敏感信息字段
返回字段:
- `data.provider`:供应商名称
- `data.provider_code`:供应商编码
- `data.hall_url`:大厅地址
- `data.game_list`:游戏列表(字段结构同 `/api/v1/getGameList`
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.h55555game.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
成功返回示例(`lang=en`
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.h55555game.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.3 获取某个游戏地址(已支持)
- 路径: `POST /api/v1/getGameUrl`
- Body 参数:
- `username`(必填):玩家账号(不存在会自动创建)
- `password`(可选):默认 `123456`
- `time`(可选):不传则服务端取当前时间戳
- `lang`(可选):`zh`/`en`,默认 `zh`
成功返回示例:
```json
{
"code": 200,
"message": "success",
"data": {
"url": "https://{game-domain}/?token=...&lang=zh"
}
}
```
### 5.4 获取大厅地址(当前项目建议)
当前项目以 `getGameUrl` 作为主要入场方式,`game_list` 仅有 `dafuwen`
- 若第三方需要独立大厅地址,可使用你方配置值:`[代填]`
- 若第三方可直接跳游戏,可直接调用 `getGameUrl`
### 5.5 获取游戏列表 API当前项目状态
已提供独立接口:`POST /api/v1/getGameList`,支持中英文格式,且数据来自 `dice_game` 表。
## 5.6 获取玩家游戏记录(已支持)
- 路径: `POST /api/v1/getPlayerGameRecord`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `username`(可选):玩家账号;不传则**不按玩家筛选**(返回库内符合条件的记录,请谨慎使用)
- `start_create_time`(可选)、`end_create_time`(可选):与表字段 `create_time` 比较;**仅允许落在「当前时间起向前 7 天」内**,且两者跨度**不得超过 7 天**;均不传时服务端默认查询该 7 天窗口。`end_create_time` 晚于当前时间时按当前时间截断;不满足规则时返回参数错误。
- `limit`(可选):返回条数上限,默认 `20`;若小于 `1` 或大于 `2000` 则按 `20` 处理
- 返回说明:
- 成功时 `data` 为**数组**(按 `id` 倒序,最多 `limit` 条),每条为 `dice_play_record` 行数据,并附带 `dice_player``{ id, username, phone }`(若批量关联不到则为 `null`
- 若传了 `username` 且玩家不存在:`data` 为空数组 `[]`
记录主要字段(与库表一致,节选):`id``player_id``admin_id``lottery_config_id``lottery_type``ante``paid_amount``is_win``win_coin``super_win_coin``reward_win_coin``use_coins``direction``reward_tier``lottery_id``start_index``target_index``roll_array``roll_number``lottery_name``status``create_time``update_time` 等。
---
## 6. 游戏管理后台(新增)
本次已新增游戏管理数据表与菜单,用于统一管理游戏基础信息。
### 6.1 数据表
- 建表 SQL`server/db/dice_game.sql`
- 表名:`dice_game`
- 关键字段:
- `logo`:游戏 logo
- `game_url`:游戏地址
- `hall_url`:大厅地址
- `game_code`:游戏编号
- `game_key`:游戏唯一值
- `status`状态1 启用 / 0 禁用)
- `game_type`:游戏类型
- `merchant_config_json`:商户可见扩展
- `sensitive_config_json`:敏感配置(大厅接口不返回)
### 6.2 菜单与权限
- 菜单 SQL`server/db/dice_game_menu.sql`
- 菜单路径:`/dice/game/index`
- 权限标识:
- `dice:game:index:index`
- `dice:game:index:read`
- `dice:game:index:save`
- `dice:game:index:update`
- `dice:game:index:destroy`
---
## 7. 钱包相关接口
以下接口均需 Header: `auth-token`
### 7.1 查询余额(已支持)
方式 1推荐`POST /api/v1/getPlayerInfo`
- 请求参数:
- `username`(必填)
- 余额字段:
- `data.coin`
### 7.2 额度转入 / 额度转出(已支持)
接口:`POST /api/v1/setPlayerWallet`
- 请求参数:
- `username`(必填)
- `coin`(必填)
- `coin > 0`:额度转入(充值)
- `coin < 0`:额度转出(提现)
- `coin = 0`:非法
成功返回 `wallet record`,包含转账前后余额等信息。
### 7.3 获取大厅地址(钱包侧)
如接入方钱包流程要求“转账后返回大厅地址”,可在完成 `setPlayerWallet` 后再调用:
- `POST /api/v1/getGameUrl`
### 7.4 获取钱包流水(已支持)
- 路径: `POST /api/v1/getPlayerWalletRecord`
- Header:
- `auth-token: {authtoken}`
- Body 参数:
- `username`(可选):玩家账号;不传则**不按玩家筛选**
- `start_create_time``end_create_time`(可选):同 `getPlayerGameRecord`,作用于 `create_time`
- `limit`(可选):条数规则同 `getPlayerGameRecord`
- 返回说明:
- 成功时 `data` 为数组;每条为 `dice_player_wallet_record` 数据,并含关联 `dice_player``id, username, phone`
- 若传了 `username` 且玩家不存在:`data` 为空数组 `[]`
`type` 含义:`0` 充值、`1` 提现、`2` 购买抽奖次数(与业务写入一致)。
### 7.5 获取抽奖券获取记录(已支持)
- 路径: `POST /api/v1/getPlayerTicketRecord`
- Header:
- `auth-token: {authtoken}`
- Body 参数:与 **7.4** 相同(`username``start_create_time``end_create_time``limit`
- 返回说明:
- 成功时 `data``dice_player_ticket_record` 列表,含关联 `dice_player`
- 若传了 `username` 且玩家不存在:`data` 为空数组 `[]`
主要字段(节选):`id``player_id``admin_id``use_coins``ante``total_ticket_count``paid_ticket_count``free_ticket_count``remark``create_time``update_time` 等。
---
## 8. 商户(代理)可配置字段
建议在对接参数表中配置以下字段:
- `provider``Dicey Fun`
- `provider_code``DF`
- `agent_id``5ef059938ba799aaa845e1c2e8a762bd`
- `secret`:签名密钥(双方约定)
- `agent_token``[我来填]`(如需额外业务层 token
- `game_url`:游戏前端域名/地址
- `lobby_url`:大厅地址(可选)
- `lang`:默认语言(`zh`/`en`
- `callback_url`:业务回调地址(如后续扩展)
- `ip_whitelist`:调用白名单(建议)
---
## 9. 后台管理信息
- 后台管理地址:`https://dice-v3.h55555game.top/`
- 后台账号:`zhuguan`
- 后台密码:`qwer1234`
---
## 10. 对接时序(建议)
1. 平台分配 `agent_id``secret`
2. 第三方调用 `/api/v1/authToken` 获取 `authtoken`
3. 第三方调用 `/api/v1/getGameHall``/api/v1/getGameList` 获取大厅/游戏信息
4. 第三方调用 `/api/v1/getPlayerInfo`(可选,检查用户与余额)
5. 第三方调用 `/api/v1/setPlayerWallet` 进行额度转入(如有)
6. 第三方调用 `/api/v1/getGameUrl` 获取游戏地址并跳转
7. 结束后调用 `/api/v1/setPlayerWallet` 执行额度转出(如有)
8. (可选)对账或客服:调用 `/api/v1/getPlayerWalletRecord``/api/v1/getPlayerGameRecord``/api/v1/getPlayerTicketRecord` 拉取流水
---
## 11. Postman 调用示例
### 11.1 获取 auth-token
```bash
curl --location --request GET 'https://{your-domain}/api/v1/authToken?agent_id={agent_id}&secret={secret}&time={time}&signature={signature}'
```
建议在接入测试时,先本地打印以下值再发请求,便于排查:
- `agent_id`
- `time`
- `sign_src`(拼接前字符串)
- `signature`
- 最终请求 URL
### 11.2 获取游戏地址
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameUrl' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"lang":"zh"
}'
```
### 11.3 获取游戏列表(中文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.4 获取游戏列表(英文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"en"
}'
```
### 11.5 获取游戏大厅(中文)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameHall' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.6 额度转入
```bash
curl --location --request POST 'https://{your-domain}/api/v1/setPlayerWallet' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"coin":100
}'
```
### 11.7 查询余额
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerInfo' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001"
}'
```
### 11.8 获取玩家游戏记录
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerGameRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```
### 11.9 获取钱包流水
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerWalletRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```
### 11.10 获取抽奖券获取记录
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerTicketRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```

View File

@@ -0,0 +1,614 @@
# Dicey Fun Third-Party Integration Guide (Based on Existing Project APIs)
## 1. Basic Information
- provider: `Dicey Fun`
- provider_code: `DF`
- game_type: `slot`
- game_list: `["dafuwen"]`
- provider_logo: ``
- Lobby URL (reference): `https://dice-v3-lobby.h55555game.top`
- Admin console URL: `https://dice-v3.h55555game.top/`
- agent_token: `[View in admin console menu: System Management -> User Management -> Agent ID]`
- agent_id: `5ef059938ba799aaa845e1c2e8a762bd`
## 2. API Domain and Protocol
- Protocol: `HTTP/HTTPS` (Production is recommended to use `HTTPS`)
- Base URL: `https://{your-domain}` (Provided by the deployment party)
- Content-Type: `application/json`
- Charset: `UTF-8`
### 2.1 Calling Conventions (Recommended for Third Parties)
- `/api/v1/authToken` uses `GET + Query parameters`
- Other `/api/v1/*` endpoints use `POST + JSON Body` (In this project the route is `Route::any`, but third parties are recommended to standardize on `POST`)
- Unified headers:
- `Content-Type: application/json`
- `Accept: application/json`
- `auth-token: {authtoken}` (Required for all endpoints except `/api/v1/authToken`)
- All time-related parameters use Unix timestamps (seconds)
- Recommended timeouts: connect timeout `3s`, read timeout `10s`
- Production recommendation: add caller IP whitelist and retry backoff (to avoid burst retry storms)
---
## 3. Common Response Format
All endpoints return the following structure:
```json
{
"code": 200,
"message": "success",
"data": {}
}
```
Notes:
- `code=200` indicates success
- Failures typically return: `400/401/402/403/404/422/500`
Common error codes:
- `400` Invalid parameters
- `401` Missing token
- `402` Token invalid or expired
- `403` Signature or authentication failed
- `404` Resource not found
- `422` Business error (e.g., insufficient balance)
- `500` Server exception
---
## 4. Authentication Flow (Platform Level)
Before calling any `/api/v1/*` endpoint, obtain an `auth-token` first.
### 4.1 Get auth-token
- Path: `GET /api/v1/authToken`
- Auth parameters (Query):
- `agent_id`: Agent identifier (merchant identifier)
- `secret`: Shared secret agreed by both parties
- `time`: Unix timestamp (seconds)
- `signature`: Signature
Signature rule:
```text
signature = md5(agent_id + secret + time)
```
Signature example (source string and result):
```text
agent_id = 9f86d081884c7d659a2feaa0c55ad015
secret = xF75oK91TQj13s0UmNIr1NBWMWGfflNO
time = 1713753600
sign_src = 9f86d081884c7d659a2feaa0c55ad015xF75oK91TQj13s0UmNIr1NBWMWGfflNO1713753600
signature= md5(sign_src)
```
PHP signature example:
```php
$agentId = '9f86d081884c7d659a2feaa0c55ad015';
$secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
$time = (string) time();
$signature = md5($agentId . $secret . $time);
```
JavaScript signature example (Node.js):
```javascript
const crypto = require('crypto');
const agentId = '9f86d081884c7d659a2feaa0c55ad015';
const secret = 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
const time = Math.floor(Date.now() / 1000).toString();
const signature = crypto.createHash('md5').update(agentId + secret + time).digest('hex');
```
Server-side validation logic (key points):
- Missing any of `agent_id/secret/time/signature` => fail (`400`)
- `secret` mismatch => fail (`403`)
- `time` outside tolerance window => fail (`403`, default tolerance `300s`)
- `signature` mismatch => fail (`403`)
- If validated, the server issues `authtoken`; subsequent requests must include it in the `auth-token` header
Anti-replay and time sync recommendations:
- Caller server must enable NTP time synchronization
- `time` should be the current seconds timestamp at request time; do not reuse old values
- If you see “Timestamp expired or invalid”, first check server clock drift
Success response example:
```json
{
"code": 200,
"message": "success",
"data": {
"authtoken": "xxx.yyy.zzz"
}
}
```
For subsequent calls to `/api/v1/*`, include the following header:
```text
auth-token: {authtoken}
```
### 4.2 Full Call Chain (Recommended)
1. Compute `signature = md5(agent_id + secret + time)`
2. Call `GET /api/v1/authToken` to obtain `authtoken`
3. Add header `auth-token: {authtoken}`
4. Call business endpoints (e.g., `getPlayerInfo`, `setPlayerWallet`, `getGameUrl`, `getPlayerGameRecord`, `getPlayerWalletRecord`, `getPlayerTicketRecord`)
5. If `402` is returned, re-fetch `authtoken` and retry once
---
## 5. Game APIs
All endpoints below require the `auth-token` header.
## 5.1 Get Game List (Supported)
- Path: `POST /api/v1/getGameList`
- Header:
- `auth-token: {authtoken}`
- Body parameters:
- `lang` (optional): `zh`/`en`, default `zh`
- Response notes:
- Reads enabled games (`status=1`) from the `dice_game` table
- Currently returns only one game by default: `dafuwen`
- Returns `game_name` in Chinese/English according to `lang`
- Fields are desensitized: sensitive configs (e.g., `sensitive_config_json`) will not be returned
Response fields (`data.game_list[]`):
- `provider`: Provider name
- `provider_code`: Provider code
- `game_code`: Game code
- `game_key`: Unique game key
- `game_type`: Game type
- `logo`: Game logo URL
- `game_url`: Game URL
- `hall_url`: Lobby URL
- `status`: Status (`1` enabled)
- `sort`: Sort value
- `game_name`: Game name (Chinese/English based on `lang`)
Success example (`lang=zh`):
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
Success example (`lang=en`):
```json
{
"code": 200,
"message": "success",
"data": {
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.2 Get Game Hall Info (Supported, Desensitized)
- Path: `POST /api/v1/getGameHall`
- Header:
- `auth-token: {authtoken}`
- Body parameters:
- `lang` (optional): `zh`/`en`, default `zh`
- Response notes:
- Returns lobby URL `hall_url`
- Returns game list (from `dice_game`)
- Does not return sensitive information fields
Response fields:
- `data.provider`: Provider name
- `data.provider_code`: Provider code
- `data.hall_url`: Lobby URL
- `data.game_list`: Game list (same structure as `/api/v1/getGameList`)
Success example:
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.h55555game.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "大富翁"
}
]
}
}
```
Success example (`lang=en`):
```json
{
"code": 200,
"message": "success",
"data": {
"provider": "Dicey Fun",
"provider_code": "DF",
"hall_url": "https://dice-v3-game.h55555game.top/",
"game_list": [
{
"provider": "Dicey Fun",
"provider_code": "DF",
"game_code": "dafuwen",
"game_key": "dafuwen",
"game_type": "slot",
"logo": "",
"game_url": "https://dice-v3-game.h55555game.top/",
"hall_url": "https://dice-v3-game.h55555game.top/",
"status": 1,
"sort": 1,
"game_name": "Dafuweng"
}
]
}
}
```
## 5.3 Get Game URL (Supported)
- Path: `POST /api/v1/getGameUrl`
- Body parameters:
- `username` (required): Player username (auto-created if not exists)
- `password` (optional): default `123456`
- `time` (optional): if omitted, server uses current timestamp
- `lang` (optional): `zh`/`en`, default `zh`
Success example:
```json
{
"code": 200,
"message": "success",
"data": {
"url": "https://{game-domain}/?token=...&lang=zh"
}
}
```
### 5.4 Lobby URL (Recommendation for This Project)
This project uses `getGameUrl` as the primary entry method, and `game_list` currently contains only `dafuwen`.
- If the third party needs a standalone lobby URL, use your configured value: `[to be filled]`
- If the third party can jump directly into the game, call `getGameUrl` directly
### 5.5 Game List API (Current Project Status)
An independent endpoint is provided: `POST /api/v1/getGameList`, supporting both Chinese and English, with data from the `dice_game` table.
## 5.6 Get Player Game Records (Supported)
- Path: `POST /api/v1/getPlayerGameRecord`
- Header:
- `auth-token: {authtoken}`
- Body parameters:
- `username` (optional): Player username; if omitted, **no player filter** is applied (returns matching rows from the database—use with care)
- `start_create_time` (optional), `end_create_time` (optional): Filter on `create_time`. Queries are **restricted to the rolling 7-day window ending at server “now”**, and the span between the two bounds **must not exceed 7 days**. If both are omitted, the server defaults to that full 7-day window. If `end_create_time` is after “now”, it is truncated to “now”. Invalid ranges return a parameter error.
- `limit` (optional): Maximum number of rows to return, default `20`; if less than `1` or greater than `2000`, it is treated as `20`
- Response notes:
- On success, `data` is an **array** (ordered by `id` descending, at most `limit` rows). Each item is a `dice_play_record` row plus `dice_player`: `{ id, username, phone }` (or `null` if the player cannot be resolved)
- If `username` is provided but the player does not exist: `data` is an empty array `[]`
Main fields (same as table columns, partial list): `id`, `player_id`, `admin_id`, `lottery_config_id`, `lottery_type`, `ante`, `paid_amount`, `is_win`, `win_coin`, `super_win_coin`, `reward_win_coin`, `use_coins`, `direction`, `reward_tier`, `lottery_id`, `start_index`, `target_index`, `roll_array`, `roll_number`, `lottery_name`, `status`, `create_time`, `update_time`, etc.
---
## 6. Game Management Admin (Added)
This update introduces a game management table and menu to centrally manage basic game information.
### 6.1 Database Table
- Table creation SQL: `server/db/dice_game.sql`
- Table name: `dice_game`
- Key fields:
- `logo`: Game logo
- `game_url`: Game URL
- `hall_url`: Lobby URL
- `game_code`: Game code
- `game_key`: Unique game key
- `status`: Status (1 enabled / 0 disabled)
- `game_type`: Game type
- `merchant_config_json`: Merchant-visible extensions
- `sensitive_config_json`: Sensitive configuration (not returned by hall APIs)
### 6.2 Menu and Permissions
- Menu SQL: `server/db/dice_game_menu.sql`
- Menu path: `/dice/game/index`
- Permission identifiers:
- `dice:game:index:index`
- `dice:game:index:read`
- `dice:game:index:save`
- `dice:game:index:update`
- `dice:game:index:destroy`
---
## 7. Wallet APIs
All endpoints below require the `auth-token` header.
### 7.1 Query Balance (Supported)
Method 1 (recommended): `POST /api/v1/getPlayerInfo`
- Request parameters:
- `username` (required)
- Balance field:
- `data.coin`
### 7.2 Credit In / Credit Out (Supported)
Endpoint: `POST /api/v1/setPlayerWallet`
- Request parameters:
- `username` (required)
- `coin` (required)
- `coin > 0`: Credit in (deposit)
- `coin < 0`: Credit out (withdraw)
- `coin = 0`: Invalid
On success, returns a `wallet record` including balances before/after transfer.
### 7.3 Get Lobby URL (Wallet-side)
If the integrators wallet flow requires “return lobby URL after transfer”, call the following after `setPlayerWallet`:
- `POST /api/v1/getGameUrl`
### 7.4 Get Player Wallet Records (Supported)
- Path: `POST /api/v1/getPlayerWalletRecord`
- Header:
- `auth-token: {authtoken}`
- Body parameters:
- `username` (optional): Player username; if omitted, **no player filter** is applied
- `start_create_time`, `end_create_time` (optional): Same as `getPlayerGameRecord`, applied to `create_time`
- `limit` (optional): Same rules as `getPlayerGameRecord`
- Response notes:
- On success, `data` is an array of `dice_player_wallet_record` rows with related `dice_player` (`id`, `username`, `phone`)
- If `username` is provided but the player does not exist: `data` is an empty array `[]`
`type` meaning: `0` deposit, `1` withdraw, `2` purchase draw chances (consistent with how records are written in business logic).
### 7.5 Get Player Ticket Acquisition Records (Supported)
- Path: `POST /api/v1/getPlayerTicketRecord`
- Header:
- `auth-token: {authtoken}`
- Body parameters: Same as **7.4** (`username`, `start_create_time`, `end_create_time`, `limit`)
- Response notes:
- On success, `data` is a list of `dice_player_ticket_record` rows with related `dice_player`
- If `username` is provided but the player does not exist: `data` is an empty array `[]`
Main fields (partial list): `id`, `player_id`, `admin_id`, `use_coins`, `ante`, `total_ticket_count`, `paid_ticket_count`, `free_ticket_count`, `remark`, `create_time`, `update_time`, etc.
---
## 8. Merchant (Agent) Configurable Fields
It is recommended to configure the following fields in the integration parameter table:
- `provider`: `Dicey Fun`
- `provider_code`: `DF`
- `agent_id`: `5ef059938ba799aaa845e1c2e8a762bd`
- `secret`: Signature secret (shared by both parties)
- `agent_token`: `[to be filled by us]` (if an additional business-layer token is needed)
- `game_url`: Game frontend domain/URL
- `lobby_url`: Lobby URL (optional)
- `lang`: Default language (`zh`/`en`)
- `callback_url`: Business callback URL (for future extension)
- `ip_whitelist`: Caller IP whitelist (recommended)
---
## 9. Admin Console Information
- Admin console URL: `https://dice-v3.h55555game.top/`
- Username: `zhuguan`
- Password: `qwer1234`
---
## 10. Integration Sequence (Recommended)
1. Platform assigns `agent_id` and `secret`
2. Third party calls `/api/v1/authToken` to obtain `authtoken`
3. Third party calls `/api/v1/getGameHall` or `/api/v1/getGameList` to obtain lobby/game info
4. Third party calls `/api/v1/getPlayerInfo` (optional, check user and balance)
5. Third party calls `/api/v1/setPlayerWallet` to credit in (if applicable)
6. Third party calls `/api/v1/getGameUrl` to get the game URL and redirect
7. After the session, call `/api/v1/setPlayerWallet` to credit out (if applicable)
8. (Optional) Reconciliation or support: call `/api/v1/getPlayerWalletRecord`, `/api/v1/getPlayerGameRecord`, `/api/v1/getPlayerTicketRecord` to pull history
---
## 11. Postman / cURL Examples
### 11.1 Get auth-token
```bash
curl --location --request GET 'https://{your-domain}/api/v1/authToken?agent_id={agent_id}&secret={secret}&time={time}&signature={signature}'
```
During integration testing, it is recommended to print the following values locally before sending the request to ease troubleshooting:
- `agent_id`
- `time`
- `sign_src` (concatenated source string before hashing)
- `signature`
- Final request URL
### 11.2 Get Game URL
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameUrl' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"lang":"zh"
}'
```
### 11.3 Get Game List (Chinese)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.4 Get Game List (English)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameList' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"en"
}'
```
### 11.5 Get Game Hall (Chinese)
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getGameHall' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"lang":"zh"
}'
```
### 11.6 Credit In
```bash
curl --location --request POST 'https://{your-domain}/api/v1/setPlayerWallet' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"coin":100
}'
```
### 11.7 Query Balance
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerInfo' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001"
}'
```
### 11.8 Get Player Game Records
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerGameRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```
### 11.9 Get Player Wallet Records
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerWalletRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```
### 11.10 Get Player Ticket Records
```bash
curl --location --request POST 'https://{your-domain}/api/v1/getPlayerTicketRecord' \
--header 'Content-Type: application/json' \
--header 'auth-token: {authtoken}' \
--data-raw '{
"username":"test_player_001",
"limit":20
}'
```

View File

@@ -142,7 +142,7 @@ Endpoints like "get player game record" or wallet histories can easily trigger N
- Use `whereIn('player_id', $playerIds)` instead of one query per player.
- Use eager loading (`with(['dicePlayer'])`) for related player info.
- Keep page size (`limit`) moderate (for example, 100 rows or less per page).
- Keep `limit` reasonable for load (default `20`, maximum `2000`; records are always scoped to a rolling 7-day window).
### 4.4 Redis vs DB coordination

View File

@@ -145,7 +145,7 @@
- 使用 `whereIn('player_id', $playerIds)` 做批量查询;
- 使用 `with(['dicePlayer'])` 或 join 预加载关联的玩家信息;
- 控制单页 `limit`,例如不超过 100 条
- 控制 `limit` 以兼顾负载(默认 `20`,上限 `2000`;接口已固定为「最近 7 天」时间窗)
### 4.4 Redis 与 DB 的整体协同

View File

@@ -0,0 +1,20 @@
# 后端 dice-api.h55555game.top 正确配置说明
# 问题:当前 Nginx 用 root 当静态站,而 /core、/dice 等接口由 Webman(6688) 处理,必须反代到 6688
# 在 server { ... } 内、在现有 location 之前,添加下面这一块(或替换掉仅用 root 的方式):
# 将请求转发到 Webman端口 6688
location / {
proxy_pass http://127.0.0.1:6688;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 若 public 目录下有需要直接由 Nginx 提供的静态文件,可再单独加 location例如
# location /assets/ {
# alias /www/wwwroot/dafuweng-api/server/public/;
# }

View File

@@ -27,7 +27,6 @@ class UserInfoCache
'expire' => 60 * 60 * 4,
'dept' => 'saiadmin:user_cache:dept_',
'role' => 'saiadmin:user_cache:role_',
'post' => 'saiadmin:user_cache:post_',
]);
}
@@ -73,11 +72,6 @@ class UserInfoCache
$tags[] = $cache['role'] . $role['id'];
}
}
if (!empty($data['postList'])) {
foreach ($data['postList'] as $post) {
$tags[] = $cache['post'] . $post['id'];
}
}
Cache::tag($tags)->set($cache['prefix'] . $uid, $data, $cache['expire']);
return $data;
}
@@ -125,21 +119,4 @@ class UserInfoCache
return Cache::tag($tags)->clear();
}
/**
* 清理岗位下所有用户缓存
*/
public static function clearUserInfoByPostId($post_id): bool
{
$cache = static::cacheConfig();
if (is_array($post_id)) {
$tags = [];
foreach ($post_id as $id) {
$tags[] = $cache['post'] . $id;
}
} else {
$tags = $cache['post'] . $post_id;
}
return Cache::tag($tags)->clear();
}
}

View File

@@ -14,7 +14,7 @@ use support\Request;
use support\Response;
/**
* 部门控制器
* 渠道控制器
*/
class SystemDeptController extends BaseController
{
@@ -33,7 +33,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据列表', 'core:dept:index')]
#[Permission('渠道数据列表', 'core:dept:index')]
public function index(Request $request) : Response
{
$where = $request->more([
@@ -50,7 +50,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据读取', 'core:dept:read')]
#[Permission('渠道数据读取', 'core:dept:read')]
public function read(Request $request) : Response
{
$id = $request->input('id', '');
@@ -68,7 +68,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据添加', 'core:dept:save')]
#[Permission('渠道数据添加', 'core:dept:save')]
public function save(Request $request): Response
{
$data = $request->post();
@@ -86,7 +86,7 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据修改','core:dept:update')]
#[Permission('渠道数据修改','core:dept:update')]
public function update(Request $request): Response
{
$data = $request->post();
@@ -104,23 +104,58 @@ class SystemDeptController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('部门数据删除','core:dept:destroy')]
#[Permission('渠道数据删除','core:dept:destroy')]
public function destroy(Request $request) : Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$deleteTables = $request->post('delete_tables', []);
if (!is_array($deleteTables)) {
$deleteTables = [];
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
if (!empty($deleteTables)) {
foreach ($idList as $deptId) {
$this->logic->destroyWithRelations((int) $deptId, $deleteTables);
}
return $this->success('delete success');
}
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
return $this->fail('delete failed');
}
/**
* 可操作部门
* 删除渠道前关联数据预览
*/
#[Permission('渠道数据删除', 'core:dept:destroy')]
public function destroyPreview(Request $request): Response
{
$ids = $request->input('ids', '');
if ($ids === '' || $ids === null) {
return $this->fail('please select data');
}
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
$data = $this->logic->getDestroyPreview($idList);
return $this->success($data);
}
/**
* 为所有渠道补齐默认配置
*/
#[Permission('渠道数据修改', 'core:dept:update')]
public function syncChannelConfigs(Request $request): Response
{
$data = $this->logic->syncAllChannelConfigs();
return $this->success($data, 'sync success');
}
/**
* 可操作渠道
* @param Request $request
* @return Response
*/

View File

@@ -1,177 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\logic\system\SystemPostLogic;
use plugin\saiadmin\app\validate\system\SystemPostValidate;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 岗位信息控制器
*/
class SystemPostController extends BaseController
{
/**
* 构造
*/
public function __construct()
{
$this->logic = new SystemPostLogic();
$this->validate = new SystemPostValidate;
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('岗位数据列表', 'core:post:index')]
public function index(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据读取', 'core:post:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
if ($model) {
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
} else {
return $this->fail('not found');
}
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据添加', 'core:post:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
} else {
return $this->fail('add failed');
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据修改', 'core:post:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据删除', 'core:post: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);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
}
/**
* 导入数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导入', 'core:post:import')]
public function import(Request $request): Response
{
$file = current($request->file());
if (!$file || !$file->isValid()) {
return $this->fail('uploaded file not found');
}
$this->logic->import($file);
return $this->success('import success');
}
/**
* 导出数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导出', 'core:post:export')]
public function export(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
return $this->logic->export($where);
}
/**
* 下载导入模板
* @return Response
*/
public function downloadTemplate(): Response
{
$file_name = "template.xlsx";
return downloadFile($file_name);
}
/**
* 可操作岗位
* @param Request $request
* @return Response
*/
public function accessPost(Request $request): Response
{
$where = ['status' => 1];
$data = $this->logic->accessPost($where);
return $this->success($data);
}
}

View File

@@ -6,10 +6,8 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\app\model\system\SystemUserRole;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\cache\UserInfoCache;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\app\validate\system\SystemRoleValidate;
use plugin\saiadmin\app\logic\system\SystemRoleLogic;
use plugin\saiadmin\service\Permission;
@@ -17,13 +15,10 @@ use support\Request;
use support\Response;
/**
* 角色控制器
* 角色控制器(按渠道隔离)
*/
class SystemRoleController extends BaseController
{
/**
* 构造
*/
public function __construct()
{
$this->logic = new SystemRoleLogic();
@@ -31,11 +26,6 @@ class SystemRoleController extends BaseController
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')]
public function index(Request $request): Response
{
@@ -44,19 +34,14 @@ class SystemRoleController extends BaseController
['code', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
$data = $this->logic->getList($query);
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$data = $this->logic->indexList($where, $requestDeptId);
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据读取', 'core:role:read')]
public function read(Request $request): Response
{
@@ -64,53 +49,49 @@ class SystemRoleController extends BaseController
$model = $this->logic->read($id);
if ($model) {
$data = is_array($model) ? $model : $model->toArray();
$role = $this->logic->model->find($id);
if ($role) {
$this->logic->assertRoleWritable($role);
}
return $this->success($data);
} else {
return $this->fail('not found');
}
return $this->fail('not found');
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据添加', 'core:role:save')]
public function save(Request $request): Response
{
$data = $request->post();
$data['dept_id'] = $this->logic->resolveRequestDeptId(
AdminScopeHelper::pickRequestDeptId($data['dept_id'] ?? null, $data)
);
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
} else {
return $this->fail('add failed');
}
return $this->fail('add failed');
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据修改', 'core:role:update')]
public function update(Request $request): Response
{
$data = $request->post();
$role = $this->logic->model->find($data['id'] ?? 0);
if ($role) {
$this->logic->assertRoleWritable($role);
if (!isset($data['dept_id']) || $data['dept_id'] === '' || $data['dept_id'] === null) {
$data['dept_id'] = $role->dept_id;
}
}
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
return $this->fail('update failed');
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('角色数据删除', 'core:role:destroy')]
public function destroy(Request $request): Response
{
@@ -121,16 +102,10 @@ class SystemRoleController extends BaseController
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
return $this->fail('delete failed');
}
/**
* 根据角色获取菜单
* @param Request $request
* @return Response
*/
#[Permission('角色数据列表', 'core:role:index')]
public function getMenuByRole(Request $request): Response
{
@@ -139,11 +114,6 @@ class SystemRoleController extends BaseController
return $this->success($data);
}
/**
* 菜单权限
* @param Request $request
* @return Response
*/
#[Permission('角色菜单权限', 'core:role:menu')]
public function menuPermission(Request $request): Response
{
@@ -153,16 +123,14 @@ class SystemRoleController extends BaseController
return $this->success('operation success');
}
/**
* 可操作角色
* @param Request $request
* @return Response
*/
public function accessRole(Request $request): Response
{
$where = ['status' => 1];
$data = $this->logic->accessRole($where);
$requestDeptId = AdminScopeHelper::pickRequestDeptId(
$request->input('dept_id'),
$request->all()
);
$data = $this->logic->accessRole($where, $requestDeptId);
return $this->success($data);
}
}

View File

@@ -182,7 +182,6 @@ class SystemUserController extends BaseController
{
$data = $request->post();
unset($data['deptList']);
unset($data['postList']);
unset($data['roleList']);
$result = $this->logic->updateInfo($this->adminId, $data);
if ($result) {

View File

@@ -2,129 +2,123 @@
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use app\dice\service\DiceChannelConfigService;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemUser;
use plugin\saiadmin\utils\Helper;
use plugin\saiadmin\utils\Arr;
/**
* 部门逻辑层
* 渠道逻辑层(表 sa_system_dept
*/
class SystemDeptLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemDept();
}
/**
* 添加数据
*/
public function add($data): mixed
{
$data = $this->handleData($data);
$this->model->save($data);
return $this->model->getKey();
$deptId = (int) $this->model->getKey();
if ($deptId > 0) {
(new DiceChannelConfigService())->copyDefaultConfigToDept($deptId);
(new SystemRoleChannelService())->copyDefaultRolesToDept($deptId, false);
}
return $deptId;
}
/**
* 修改数据
*/
public function edit($id, $data): mixed
{
$oldLevel = $data['level'] . $id . ',';
$data = $this->handleData($data);
if ($data['parent_id'] == $id) {
throw new ApiException('Parent department cannot be the same as current department');
}
if (in_array($id, explode(',', $data['level']))) {
throw new ApiException('Cannot set parent department to a child of current department');
}
$newLevel = $data['level'] . $id . ',';
$deptIds = $this->model->where('level', 'like', $oldLevel . '%')->column('id');
return $this->transaction(function () use ($deptIds, $oldLevel, $newLevel, $data, $id) {
$this->model->whereIn('id', $deptIds)->exp('level', "REPLACE(level, '$oldLevel', '$newLevel')")->update([]);
return $this->model->update($data, ['id' => $id]);
});
return $this->model->update($data, ['id' => $id]);
}
/**
* 数据删除
*/
public function destroy($ids): bool
{
$num = $this->model->where('parent_id', 'in', $ids)->count();
if ($num > 0) {
throw new ApiException('This department has sub-departments, please delete them first');
} else {
$count = SystemUser::where('dept_id', 'in', $ids)->count();
if ($count > 0) {
throw new ApiException('This department has users, please delete or transfer them first');
}
return $this->model->destroy($ids);
$count = SystemUser::where('dept_id', 'in', $ids)->count();
if ($count > 0) {
throw new ApiException('This channel has users, please delete or transfer them first');
}
return $this->model->destroy($ids);
}
/**
* 数据处理
* 带关联选项删除渠道
*/
public function destroyWithRelations(int $deptId, array $deleteTables): bool
{
(new SystemRoleChannelService())->deleteRolesByDept($deptId);
(new DiceChannelConfigService())->destroyDeptWithRelations($deptId, $deleteTables);
return true;
}
public function getDestroyPreview(array $deptIds): array
{
return (new DiceChannelConfigService())->getDestroyPreview($deptIds);
}
public function syncAllChannelConfigs(): array
{
$config = (new DiceChannelConfigService())->syncAllChannelsFromDefault();
$roles = (new SystemRoleChannelService())->syncAllChannelsFromDefault();
return ['config' => $config, 'roles' => $roles];
}
protected function handleData($data)
{
// 处理上级部门
if (empty($data['parent_id']) || $data['parent_id'] == 0) {
$data['level'] = '0';
$data['parent_id'] = 0;
} else {
$parentMenu = SystemDept::findOrEmpty($data['parent_id']);
$data['level'] = $parentMenu['level'] . $parentMenu['id'] . ',';
}
$data['level'] = '0';
$data['parent_id'] = 0;
return $data;
}
/**
* 数据树形化
* @param array $where
* @return array
*/
public function tree(array $where = []): array
{
$query = $this->search($where);
$request = request();
if ($request && $request->input('tree', 'false') === 'true') {
$query->field('id, id as value, name as label, parent_id');
}
$query->order('sort', 'desc');
$query->with(['leader']);
$data = $this->getAll($query);
return Helper::makeTree($data);
return $this->getAll($query);
}
/**
* 可操作部门
* @param array $where
* @return array
*/
public function accessDept(array $where = []): array
{
$query = $this->search($where);
// 超级管理员(id=1)可查看全部部门,普通管理员按部门权限过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$query->auth($this->adminInfo['deptList'] ?? []);
$deptId = $this->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('id', $deptId);
} else {
return [];
}
}
$query->field('id, id as value, name as label, parent_id');
$query->field('id, id as value, name as label');
$query->order('sort', 'desc');
$data = $this->getAll($query);
return Helper::makeTree($data);
return $this->getAll($query);
}
/**
* 当前管理员可操作的渠道 IDdeptList 缺失时回退 dept_id
*/
public function resolveAccessibleDeptId(?array $adminInfo = null): int
{
$adminInfo = $adminInfo ?? $this->adminInfo ?? [];
if (empty($adminInfo['id']) || (int) $adminInfo['id'] <= 1) {
return 0;
}
$deptList = $adminInfo['deptList'] ?? [];
if (is_array($deptList) && isset($deptList['id']) && (int) $deptList['id'] > 0) {
return (int) $deptList['id'];
}
$deptId = $adminInfo['dept_id'] ?? null;
if ($deptId !== null && $deptId !== '' && (int) $deptId > 0) {
return (int) $deptId;
}
return 0;
}
}

View File

@@ -1,95 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use plugin\saiadmin\app\model\system\SystemPost;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\service\OpenSpoutWriter;
use OpenSpout\Reader\XLSX\Reader;
/**
* 岗位管理逻辑层
*/
class SystemPostLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemPost();
}
/**
* 可操作岗位
* @param array $where
* @return array
*/
public function accessPost(array $where = []): array
{
$query = $this->search($where);
$query->field('id, id as value, name as label, name, code');
return $this->getAll($query);
}
/**
* 导入数据
*/
public function import($file)
{
$path = $this->getImport($file);
$reader = new Reader();
try {
$reader->open($path);
$data = [];
foreach ($reader->getSheetIterator() as $sheet) {
$isHeader = true;
foreach ($sheet->getRowIterator() as $row) {
if ($isHeader) {
$isHeader = false;
continue;
}
$cells = $row->getCells();
$data[] = [
'name' => $cells[0]->getValue(),
'code' => $cells[1]->getValue(),
'sort' => $cells[2]->getValue(),
'status' => $cells[3]->getValue(),
];
}
}
$this->saveAll($data);
} catch (\Exception $e) {
throw new ApiException('Import file error, please upload correct xlsx file');
}
}
/**
* 导出数据
*/
public function export($where = [])
{
$query = $this->search($where)->field('id,name,code,sort,status,create_time');
$data = $this->getAll($query);
$file_name = '岗位数据.xlsx';
$header = ['编号', '岗位名称', '岗位标识', '排序', '状态', '创建时间'];
$filter = [
'status' => [
['value' => 1, 'label' => '正常'],
['value' => 2, 'label' => '禁用']
]
];
$writer = new OpenSpoutWriter($file_name);
$writer->setWidth([15, 15, 20, 15, 15, 25]);
$writer->setHeader($header);
$writer->setData($data, null, $filter);
$file_path = $writer->returnFile();
return response()->download($file_path, urlencode($file_name));
}
}

View File

@@ -6,121 +6,133 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use app\dice\helper\AdminScopeHelper;
use plugin\saiadmin\app\cache\UserMenuCache;
use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\app\service\SystemRoleChannelService;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use support\think\Cache;
use support\think\Db;
/**
* 角色逻辑层
* 角色逻辑层(按渠道 dept_id 隔离)
*/
class SystemRoleLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemRole();
}
/**
* 添加数据
* 分页列表(按渠道过滤)
*/
public function indexList(array $where, $requestDeptId = null): array
{
$query = $this->search($where);
$this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
return $this->getList($query);
}
public function add($data): bool
{
$data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, null);
return $this->model->save($data);
}
/**
* 修改数据
*/
public function edit($id, $data): bool
{
$model = $this->model->findOrEmpty($id);
if ($model->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($model);
$data = $this->handleData($data);
$deptId = AdminScopeHelper::normalizeRecordDeptId($model->dept_id ?? $data['dept_id'] ?? null);
$data['dept_id'] = $deptId;
$this->assertCodeUniqueInDept($data['code'] ?? '', $deptId, (int) $id);
return $model->save($data);
}
/**
* 删除数据
*/
public function destroy($ids): bool
{
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
$maxLevel = !empty($levelArr) ? max($levelArr) : 100;
$num = SystemRole::where('level', '>=', $maxLevel)->whereIn('id', $ids)->count();
if ($num > 0) {
throw new ApiException('Cannot operate roles with higher level than current account');
} else {
return $this->model->destroy($ids);
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
foreach ($idList as $roleId) {
$roleId = (int) $roleId;
if ($roleId === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot delete super admin role');
}
$role = $this->model->find($roleId);
if (!$role) {
continue;
}
$this->assertRoleWritable($role);
if ((int) ($role->level ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
}
}
return $this->model->destroy($ids);
}
/**
* 数据处理
*/
protected function handleData($data)
{
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
if ($data['level'] >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
if (($data['level'] ?? 0) >= $maxLevel) {
throw new ApiException('Cannot operate roles with higher level than current account');
}
}
return $data;
}
/**
* 可操作角色
* @param array $where
* @return array
*/
public function accessRole(array $where = []): array
public function accessRole(array $where = [], $requestDeptId = null): array
{
$query = $this->search($where);
// 越权保护
$levelArr = array_column($this->adminInfo['roleList'], 'level');
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
$this->applyDeptScope($query, $requestDeptId);
$levelArr = array_column($this->adminInfo['roleList'] ?? [], 'level');
if (!empty($levelArr)) {
$maxLevel = max($levelArr);
$query->where('level', '<', $maxLevel);
}
$query->where('id', '<>', SystemRoleChannelService::SUPER_ADMIN_ROLE_ID);
$query->order('sort', 'desc');
return $this->getAll($query);
}
/**
* 根据角色数组获取菜单
* @param $ids
* @return array
*/
public function getMenuIdsByRoleIds($ids): array
{
if (empty($ids))
if (empty($ids)) {
return [];
}
return $this->model->where('id', 'in', $ids)->with([
'menus' => function ($query) {
$query->where('status', 1)->order('sort', 'desc');
}
])->select()->toArray();
}
/**
* 根据角色获取菜单
* @param $id
* @return array
*/
public function getMenuByRole($id): array
{
$role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
$menus = $role->menus ?: [];
return [
'id' => $id,
@@ -128,14 +140,14 @@ class SystemRoleLogic extends BaseLogic
];
}
/**
* 保存菜单权限
* @param $id
* @param $menu_ids
* @return mixed
*/
public function saveMenuPermission($id, $menu_ids): mixed
{
$role = $this->model->findOrEmpty($id);
if ($role->isEmpty()) {
throw new ApiException('Data not found');
}
$this->assertRoleWritable($role);
return $this->transaction(function () use ($id, $menu_ids) {
$role = $this->model->findOrEmpty($id);
if ($role) {
@@ -147,10 +159,90 @@ class SystemRoleLogic extends BaseLogic
}
$cache = config('plugin.saiadmin.saithink.button_cache');
$tag = $cache['role'] . $id;
Cache::tag($tag)->clear(); // 清理权限缓存-角色TAG
UserMenuCache::clearMenuCache(); // 清理菜单缓存
Cache::tag($tag)->clear();
UserMenuCache::clearMenuCache();
return true;
});
}
/**
* 解析并校验当前请求应操作的渠道 ID
*/
public function resolveRequestDeptId($requestDeptId): int
{
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
return $deptLogic->resolveAccessibleDeptId();
}
/**
* 列表/下拉按渠道过滤
*/
protected function applyDeptScope($query, $requestDeptId = null): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
$deptId = AdminScopeHelper::resolveConfigDeptId($this->adminInfo, $requestDeptId);
$query->where('dept_id', $deptId);
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
}
}
/**
* 校验角色属于当前可操作渠道
*/
public function assertRoleWritable($role): void
{
if (!$this->tableHasDeptIdColumn()) {
return;
}
$roleDeptId = AdminScopeHelper::normalizeRecordDeptId($role->dept_id ?? null);
if ((int) ($role->id ?? 0) === SystemRoleChannelService::SUPER_ADMIN_ROLE_ID) {
throw new ApiException('Cannot operate super admin role');
}
if ((int) ($this->adminInfo['id'] ?? 0) === 1) {
return;
}
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$scopeDeptId = $deptLogic->resolveAccessibleDeptId();
if ($scopeDeptId > 0 && $roleDeptId !== $scopeDeptId) {
throw new ApiException('No permission to operate this channel role');
}
}
protected function assertCodeUniqueInDept(string $code, int $deptId, ?int $excludeId): void
{
if ($code === '') {
return;
}
$query = SystemRole::where('code', $code)->where('dept_id', $deptId);
if ($excludeId !== null && $excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
if ($query->count() > 0) {
throw new ApiException('Role code already exists in this channel');
}
}
protected function tableHasDeptIdColumn(): bool
{
try {
$fields = Db::getFields((new SystemRole())->getTable());
return isset($fields['dept_id']);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -40,9 +40,16 @@ class SystemUserLogic extends BaseLogic
{
$query = $this->search($where);
$query->with(['depts']);
// 超级管理员(id=1)可查看全部用户,普通管理员按部门权限过滤
// 超级管理员(id=1)可查看全部用户,渠道管理员按本渠道过滤
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
$query->auth($this->adminInfo['deptList'] ?? []);
$deptLogic = new SystemDeptLogic();
$deptLogic->init($this->adminInfo);
$deptId = $deptLogic->resolveAccessibleDeptId();
if ($deptId > 0) {
$query->where('dept_id', $deptId);
} else {
$query->auth($this->adminInfo['deptList'] ?? []);
}
}
return $this->getList($query);
}
@@ -69,8 +76,13 @@ class SystemUserLogic extends BaseLogic
$admin = $this->model->findOrEmpty($id);
$data = $admin->hidden(['password'])->toArray();
$data['roleList'] = $admin->roles->toArray() ?: [];
$data['postList'] = $admin->posts->toArray() ?: [];
$data['deptList'] = $admin->depts ? $admin->depts->toArray() : [];
if (empty($data['deptList']) && ! empty($admin->dept_id)) {
$dept = SystemDept::find($admin->dept_id);
if ($dept && ! $dept->isEmpty()) {
$data['deptList'] = $dept->toArray();
}
}
return $data;
}
@@ -101,7 +113,6 @@ class SystemUserLogic extends BaseLogic
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
return $this->transaction(function () use ($data) {
$role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
if ($this->adminInfo['id'] > 1) {
// 部门保护
if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) {
@@ -114,11 +125,7 @@ class SystemUserLogic extends BaseLogic
}
$user = SystemUser::create($data);
$user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
return $user;
});
}
@@ -134,7 +141,6 @@ class SystemUserLogic extends BaseLogic
unset($data['password']);
return $this->transaction(function () use ($data, $id) {
$role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
// 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户
$query = $this->model->where('id', $id);
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
@@ -157,11 +163,7 @@ class SystemUserLogic extends BaseLogic
$result = parent::edit($id, $data);
if ($result) {
$user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
UserInfoCache::clearUserInfo($id);
UserAuthCache::clearUserAuth($id);
UserMenuCache::clearUserMenu($id);

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

@@ -9,15 +9,15 @@ namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 部门模型
* 渠道模型
*
* sa_system_dept 部门
* sa_system_dept 渠道
*
* @property $id 编号
* @property $parent_id 父级ID0为根节点
* @property $name 部门名称
* @property $code 部门编码
* @property $leader_id 部门负责人ID
* @property $parent_id 父级ID扁平渠道固定为0
* @property $name 渠道名称
* @property $code 渠道编码
* @property $leader_id 渠道负责人ID
* @property $level 祖级列表,格式: 0,1,5,
* @property $sort 排序,数字越小越靠前
* @property $status 状态: 1启用, 0禁用
@@ -38,24 +38,21 @@ class SystemDept extends BaseModel
protected $table = 'sa_system_dept';
/**
* 权限范围
* 权限范围(扁平渠道,仅本渠道)
*/
public function scopeAuth($query, $value)
{
if (!empty($value) && isset($value['id'])) {
$deptIds = [$value['id']];
$level = $value['level'] ?? '';
if ($level !== '' && $level !== null) {
$deptLevel = $level . $value['id'] . ',';
$ids = static::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $ids);
}
$query->whereIn('id', $deptIds);
if (is_array($value) && isset($value['id']) && (int) $value['id'] > 0) {
$query->where('id', $value['id']);
return;
}
if (is_numeric($value) && (int) $value > 0) {
$query->where('id', (int) $value);
}
}
/**
* 部门领导
* 渠道负责人
*/
public function leader()
{

View File

@@ -1,37 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 岗位模型
*
* sa_system_post 岗位信息表
*
* @property $id 主键
* @property $name 岗位名称
* @property $code 岗位代码
* @property $sort 排序
* @property $status 状态
* @property $remark 备注
* @property $created_by 创建者
* @property $updated_by 更新者
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class SystemPost extends BaseModel
{
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
protected $table = 'sa_system_post';
}

View File

@@ -13,7 +13,8 @@ use plugin\saiadmin\basic\think\BaseModel;
*
* sa_system_role 角色表
*
* @property $id
* @property $id
* @property int $dept_id 所属渠道ID0=默认模板
* @property $name 角色名称
* @property $code 角色标识,如: hr_manager
* @property $level 角色级别:用于行政控制,不可操作级别大于自己的角色
@@ -41,6 +42,14 @@ class SystemRole extends BaseModel
*/
protected $table = 'sa_system_role';
/** 按渠道筛选 */
public function searchDeptIdAttr($query, $value): void
{
if ($value !== '' && $value !== null) {
$query->where('dept_id', '=', $value);
}
}
/**
* 权限范围
*/

View File

@@ -24,7 +24,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $phone 手机号
* @property $signed 个性签名
* @property $dashboard 工作台
* @property $dept_id 主归属部门
* @property $dept_id 主归属渠道
* @property $is_super 是否超级管理员: 1是
* @property $status 状态: 1启用, 2禁用
* @property $remark 备注
@@ -82,16 +82,12 @@ class SystemUser extends BaseModel
}
/**
* 权限范围 - 过滤部门用户
* 权限范围 - 过滤同渠道用户
*/
public function scopeAuth($query, $value)
{
if (!empty($value)) {
$deptIds = [$value['id']];
$deptLevel = $value['level'] . $value['id'] . ',';
$dept_ids = SystemDept::whereLike('level', $deptLevel . '%')->column('id');
$deptIds = array_merge($deptIds, $dept_ids);
$query->whereIn('dept_id', $deptIds);
if (!empty($value) && isset($value['id'])) {
$query->where('dept_id', $value['id']);
}
}
@@ -104,15 +100,7 @@ class SystemUser extends BaseModel
}
/**
* 通过中间表关联岗位
*/
public function posts()
{
return $this->belongsToMany(SystemPost::class, SystemUserPost::class, 'post_id', 'user_id');
}
/**
* 通过中间表关联部门
* 关联渠道
*/
public function depts()
{

View File

@@ -1,25 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use think\model\Pivot;
/**
* 用户岗位关联模型
*
* sa_system_user_post 用户与岗位关联表
*
* @property $id 主键
* @property $user_id 用户主键
* @property $post_id 岗位主键
*/
class SystemUserPost extends Pivot
{
protected $pk = 'id';
protected $table = 'sa_system_user_post';
}

View File

@@ -0,0 +1,257 @@
<?php
declare(strict_types=1);
namespace plugin\saiadmin\app\service;
use plugin\saiadmin\app\model\system\SystemDept;
use plugin\saiadmin\app\model\system\SystemRole;
use plugin\saiadmin\exception\ApiException;
use support\think\Db;
/**
* 渠道角色:从默认模板复制指定角色、同步与删除
*/
class SystemRoleChannelService
{
/** 全局超级管理员角色,不参与渠道复制 */
public const SUPER_ADMIN_ROLE_ID = 1;
/**
* 为渠道从默认模板复制三个代理角色(缺失则补齐,不整包跳过)
*/
public function copyDefaultRolesToDept(int $deptId, bool $pruneExtra = false): array
{
if ($deptId <= 0) {
throw new ApiException('Invalid channel id');
}
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'dept_id column missing'];
}
$templates = $this->defaultTemplateRoles();
if (empty($templates)) {
return ['dept_id' => $deptId, 'copied' => 0, 'skipped' => 0, 'pruned' => 0, 'message' => 'no template roles'];
}
$copied = 0;
$skipped = 0;
foreach ($templates as $template) {
$template = (array) $template;
$templateId = (int) ($template['id'] ?? 0);
$code = (string) ($template['code'] ?? '');
if ($templateId <= 0 || $code === '') {
continue;
}
if ($this->roleExists($deptId, $code)) {
$skipped++;
continue;
}
$newId = $this->insertRoleFromTemplate($template, $deptId);
if ($newId > 0) {
$this->copyRoleMenus($templateId, $newId);
$copied++;
}
}
$pruned = 0;
if ($pruneExtra) {
$pruned = $this->pruneExtraChannelRoles($deptId);
}
return ['dept_id' => $deptId, 'copied' => $copied, 'skipped' => $skipped, 'pruned' => $pruned];
}
/**
* 为所有已启用渠道补齐三个默认角色,并移除多余历史角色
*/
public function syncAllChannelsFromDefault(): array
{
$deptIds = SystemDept::where('status', 1)->where('id', '>', 0)->column('id');
$result = [];
foreach ($deptIds as $deptId) {
$result[(int) $deptId] = $this->copyDefaultRolesToDept((int) $deptId, true);
}
return $result;
}
/**
* 删除渠道下全部角色及菜单关联
*/
public function deleteRolesByDept(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$roleIds = SystemRole::where('dept_id', $deptId)->column('id');
if (empty($roleIds)) {
return 0;
}
Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_menu')->whereIn('role_id', $roleIds)->delete();
Db::name('sa_system_role_dept')->whereIn('role_id', $roleIds)->delete();
return SystemRole::destroy($roleIds);
}
/**
* 将用户已绑定的模板角色映射到其渠道对应角色(仅三个默认 code
*/
public function remapUserRolesToChannelRoles(): int
{
if (!$this->tableHasColumn('sa_system_role', 'dept_id')) {
return 0;
}
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return 0;
}
$codeList = "'" . implode("','", array_map('addslashes', $codes)) . "'";
return Db::execute(
'UPDATE `sa_system_user_role` ur
INNER JOIN `sa_system_user` u ON ur.user_id = u.id
INNER JOIN `sa_system_role` r_old ON ur.role_id = r_old.id
INNER JOIN `sa_system_role` r_new ON r_new.dept_id = u.dept_id AND r_new.code = r_old.code
SET ur.role_id = r_new.id
WHERE u.dept_id > 0
AND r_old.dept_id = 0
AND r_old.code IN (' . $codeList . ')
AND r_old.id <> ' . self::SUPER_ADMIN_ROLE_ID
);
}
/**
* @return string[]
*/
public function getDefaultChannelRoleCodes(): array
{
$codes = config('plugin.saiadmin.saithink.channel_default_role_codes', []);
if (!is_array($codes) || $codes === []) {
return ['yijidaili', 'erjidaili', 'sanjidaili'];
}
$out = [];
foreach ($codes as $code) {
$code = trim((string) $code);
if ($code !== '') {
$out[] = $code;
}
}
return $out;
}
/**
* 删除渠道下不在默认三个 code 内、且未被用户绑定的角色
*/
public function pruneExtraChannelRoles(int $deptId): int
{
if ($deptId <= 0) {
return 0;
}
$allowed = $this->getDefaultChannelRoleCodes();
if (empty($allowed)) {
return 0;
}
$query = SystemRole::where('dept_id', $deptId)->whereNotIn('code', $allowed);
$roleIds = $query->column('id');
if (empty($roleIds)) {
return 0;
}
$usedIds = Db::name('sa_system_user_role')->whereIn('role_id', $roleIds)->column('role_id');
$usedMap = array_flip($usedIds ?: []);
$pruned = 0;
foreach ($roleIds as $roleId) {
if (isset($usedMap[$roleId])) {
continue;
}
Db::name('sa_system_role_menu')->where('role_id', $roleId)->delete();
Db::name('sa_system_role_dept')->where('role_id', $roleId)->delete();
SystemRole::destroy($roleId);
$pruned++;
}
return $pruned;
}
/**
* @return array<int, array<string, mixed>>
*/
private function defaultTemplateRoles(): array
{
$codes = $this->getDefaultChannelRoleCodes();
if (empty($codes)) {
return [];
}
$query = Db::table('sa_system_role')
->where('id', '<>', self::SUPER_ADMIN_ROLE_ID)
->whereIn('code', $codes);
if ($this->tableHasColumn('sa_system_role', 'dept_id')) {
$query->where('dept_id', 0);
}
$rows = $query->order('sort', 'desc')->select()->toArray();
if (count($rows) === count($codes)) {
return $rows;
}
// 按配置顺序返回,缺失的 code 跳过
$byCode = [];
foreach ($rows as $row) {
$byCode[(string) ($row['code'] ?? '')] = $row;
}
$ordered = [];
foreach ($codes as $code) {
if (isset($byCode[$code])) {
$ordered[] = $byCode[$code];
}
}
return $ordered;
}
private function insertRoleFromTemplate(array $template, int $deptId): int
{
unset(
$template['id'],
$template['create_time'],
$template['update_time'],
$template['delete_time']
);
$template['dept_id'] = $deptId;
$now = date('Y-m-d H:i:s');
if (!isset($template['create_time'])) {
$template['create_time'] = $now;
}
if (!isset($template['update_time'])) {
$template['update_time'] = $now;
}
return (int) Db::table('sa_system_role')->insertGetId($template);
}
private function copyRoleMenus(int $fromRoleId, int $toRoleId): void
{
$menuIds = Db::name('sa_system_role_menu')->where('role_id', $fromRoleId)->column('menu_id');
if (empty($menuIds)) {
return;
}
$rows = [];
foreach ($menuIds as $menuId) {
$rows[] = ['role_id' => $toRoleId, 'menu_id' => $menuId];
}
Db::name('sa_system_role_menu')->limit(100)->insertAll($rows);
}
private function roleExists(int $deptId, string $code): bool
{
return SystemRole::where('dept_id', $deptId)->where('code', $code)->count() > 0;
}
private function tableHasColumn(string $table, string $column): bool
{
try {
$fields = Db::getFields($table);
return isset($fields[$column]);
} catch (\Throwable $e) {
return false;
}
}
}

View File

@@ -9,7 +9,7 @@ namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate;
/**
* 部门验证器
* 渠道验证器
*/
class SystemDeptValidate extends BaseValidate
{
@@ -25,7 +25,7 @@ class SystemDeptValidate extends BaseValidate
* 定义错误信息
*/
protected $message = [
'name' => '部门名称必须填写',
'name' => '渠道名称必须填写',
'status' => '状态必须填写',
];

View File

@@ -1,50 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate;
/**
* 用户角色验证器
*/
class SystemPostValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected $rule = [
'name' => 'require',
'code' => 'require',
'status' => 'require',
];
/**
* 定义错误信息
*/
protected $message = [
'name' => '岗位名称必须填写',
'code' => '岗位标识必须填写',
'status' => '状态必须填写',
];
/**
* 定义场景
*/
protected $scene = [
'save' => [
'name',
'code',
'status',
],
'update' => [
'name',
'code',
'status',
],
];
}

View File

@@ -19,7 +19,7 @@ class SystemRoleValidate extends BaseValidate
*/
protected $rule = [
'name' => 'require|max:16',
'code' => 'require|alphaDash|unique:' . SystemRole::class,
'code' => 'require|alphaDash|unique:' . SystemRole::class . ',code^dept_id',
'status' => 'require',
];

View File

@@ -6,6 +6,7 @@
// +----------------------------------------------------------------------
namespace plugin\saiadmin\basic;
use app\api\util\ApiLang;
use support\Request;
use support\Response;
@@ -36,6 +37,7 @@ class OpenController
if (is_string($data)) {
$msg = $data;
}
$msg = ApiLang::translate($msg, request());
return json(['code' => 200, 'message' => $msg, 'data' => $data], $option);
}
@@ -47,6 +49,7 @@ class OpenController
*/
public function fail(string $msg = 'fail', int $code = 400): Response
{
$msg = ApiLang::translate($msg, request());
return json(['code' => $code, 'message' => $msg]);
}

View File

@@ -12,10 +12,18 @@ use plugin\saiadmin\basic\contracts\ModelInterface;
/**
* ThinkORM 模型基类
*
* 全局策略:所有删除一律为硬删除(物理删除)。
* - 保留 SoftDelete trait 仅是为了兼容历史字段(如 delete_time与查询作用域
* 实际删除方法delete/destroy均通过 trait 别名重写为强制 force=true。
* - 项目中不使用 withTrashed/onlyTrashed/restore() 等软删除恢复接口。
*/
class BaseModel extends Model implements ModelInterface
{
use SoftDelete;
use SoftDelete {
delete as protected softDeleteCascadeOriginal;
destroy as protected softDeleteDestroyOriginal;
}
/**
* 删除时间字段
@@ -99,6 +107,25 @@ class BaseModel extends Model implements ModelInterface
}
}
/**
* 删除记录(静态入口):一律强制硬删除(物理删除)。
* @param mixed $data 主键、闭包或条件
* @param bool $force 兼容签名,内部一律按 true 处理
*/
public static function destroy($data, bool $force = true): bool
{
return static::softDeleteDestroyOriginal($data, true);
}
/**
* 删除记录(实例方法):一律强制硬删除。
*/
public function delete(): bool
{
$this->force(true);
return $this->softDeleteCascadeOriginal();
}
/**
* 新增前事件:自动写入 create_time有后台登录信息时写入 created_by
* @param Model $model

View File

@@ -23,6 +23,7 @@ Route::group('/core', function () {
Route::get('/dice/dashboard/rechargeBarChart', [\app\dice\controller\DiceDashboardController::class, 'rechargeBarChart']);
Route::get('/dice/dashboard/walletRecordList', [\app\dice\controller\DiceDashboardController::class, 'walletRecordList']);
Route::get('/dice/dashboard/newPlayerList', [\app\dice\controller\DiceDashboardController::class, 'newPlayerList']);
Route::get('/dice/dashboard/playRecordList', [\app\dice\controller\DiceDashboardController::class, 'playRecordList']);
Route::get('/system/clearAllCache', [plugin\saiadmin\app\controller\SystemController::class, 'clearAllCache']);
Route::get("/system/getResourceCategory", [plugin\saiadmin\app\controller\SystemController::class, 'getResourceCategory']);
@@ -49,14 +50,11 @@ Route::group('/core', function () {
Route::get("/role/getMenuByRole", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'getMenuByRole']);
Route::post("/role/menuPermission", [\plugin\saiadmin\app\controller\system\SystemRoleController::class, 'menuPermission']);
// 部门管理
// 渠道管理
fastRoute("dept", \plugin\saiadmin\app\controller\system\SystemDeptController::class);
Route::get("/dept/accessDept", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'accessDept']);
// 岗位管理
fastRoute('post', \plugin\saiadmin\app\controller\system\SystemPostController::class);
Route::get("/post/accessPost", [\plugin\saiadmin\app\controller\system\SystemPostController::class, 'accessPost']);
Route::post("/post/downloadTemplate", [plugin\saiadmin\app\controller\system\SystemPostController::class, 'downloadTemplate']);
Route::get("/dept/destroyPreview", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'destroyPreview']);
Route::post("/dept/syncChannelConfigs", [\plugin\saiadmin\app\controller\system\SystemDeptController::class, 'syncChannelConfigs']);
// 菜单管理
fastRoute('menu', \plugin\saiadmin\app\controller\system\SystemMenuController::class);
@@ -94,10 +92,11 @@ Route::group('/core', function () {
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
Route::get('/dice/player/DicePlayer/getSystemUserTreeOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserTreeOptions']);
Route::get('/dice/player/DicePlayer/getGameUrl', [\app\dice\controller\player\DicePlayerController::class, 'getGameUrl']);
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class);
Route::get('/dice/play_record/DicePlayRecord/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
Route::get('/dice/play_record/DicePlayRecord/getLotteryConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getLotteryConfigOptions']);
Route::get('/dice/play_record/DicePlayRecord/getRewardConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getRewardConfigOptions']);
fastRoute('dice/player_wallet_record/DicePlayerWalletRecord', \app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class);
Route::get('/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerOptions', [\app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class, 'getPlayerOptions']);
Route::get('/dice/player_wallet_record/DicePlayerWalletRecord/getPlayerWalletBefore', [\app\dice\controller\player_wallet_record\DicePlayerWalletRecordController::class, 'getPlayerWalletBefore']);
@@ -118,6 +117,9 @@ 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/game/DiceGame', \app\dice\controller\game\DiceGameController::class);
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
Route::get('/dice/ante_config/DiceAnteConfig/getOptions', [\app\dice\controller\ante_config\DiceAnteConfigController::class, 'getOptions']);
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

@@ -33,7 +33,6 @@ return [
'expire' => 60 * 60 * 4,
'dept' => 'saiadmin:user_cache:dept_',
'role' => 'saiadmin:user_cache:role_',
'post' => 'saiadmin:user_cache:post_',
],
// 用户权限缓存
@@ -73,4 +72,13 @@ return [
'attr' => 'saiadmin:reflection_cache:attr_',
],
/**
* 新建渠道时从默认模板复制的角色 code须存在于 dept_id=0 的模板角色)
*/
'channel_default_role_codes' => [
'yijidaili',
'erjidaili',
'sanjidaili',
],
];

View File

@@ -391,7 +391,6 @@ INSERT INTO `sa_system_menu` VALUES (3, 0, '系统管理', 'System', NULL, 1, '/
INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (7, 3, '岗位管理', 'Post', '', 2, 'post', '/system/post', NULL, 'ri:signpost-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -423,13 +422,6 @@ INSERT INTO `sa_system_menu` VALUES (36, 6, '修改', '', 'core:role:update', 3,
INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (41, 7, '数据列表', '', 'core:post:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (42, 7, '添加', '', 'core:post:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (43, 7, '修改', '', 'core:post:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (44, 7, '读取', '', 'core:post:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (45, 7, '删除', '', 'core:post:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (46, 7, '导入', '', 'core:post:import', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (47, 7, '导出', '', 'core:post:export', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -501,31 +493,6 @@ CREATE TABLE `sa_system_oper_log` (
-- Records of sa_system_oper_log
-- ----------------------------
-- ----------------------------
-- Table structure for sa_system_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_post`;
CREATE TABLE `sa_system_post` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(50) NULL DEFAULT NULL COMMENT '岗位名称',
`code` varchar(100) NULL DEFAULT NULL COMMENT '岗位代码',
`sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序',
`status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)',
`remark` varchar(255) NULL DEFAULT NULL COMMENT '备注',
`created_by` int(11) NULL DEFAULT NULL COMMENT '创建者',
`updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
`delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 87 COMMENT = '岗位信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_post
-- ----------------------------
INSERT INTO `sa_system_post` VALUES (1, '司机岗', 'driver', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_post` VALUES (2, '保安岗', 'security', 100, 1, '', 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ----------------------------
-- Table structure for sa_system_role
-- ----------------------------
@@ -635,23 +602,6 @@ INSERT INTO `sa_system_user` VALUES (10, 'timi_boss', '$2y$10$sY/4StKVV.N/8Ock8J
INSERT INTO `sa_system_user` VALUES (100, 'dev_wang', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '王程序员', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_user` VALUES (101, 'dev_li', '$2y$10$sY/4StKVV.N/8Ock8J8kdeIOK4jS4tAUoYjkzvB8Tzy0fLh.wA2KS', '李策划', NULL, 'https://image.saithink.top/saiadmin/avatar.jpg', NULL, '15888888888', NULL, 'work', 1111, 0, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ----------------------------
-- Table structure for sa_system_user_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_user_post`;
CREATE TABLE `sa_system_user_post` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户主键',
`post_id` bigint(20) UNSIGNED NOT NULL COMMENT '岗位主键',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_user_id`(`user_id`) USING BTREE,
INDEX `idx_post_id`(`post_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '用户与岗位关联表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_user_post
-- ----------------------------
-- ----------------------------
-- Table structure for sa_system_user_role
-- ----------------------------

View File

@@ -380,7 +380,6 @@ INSERT INTO `sa_system_menu` VALUES (3, 0, '系统管理', 'System', NULL, 1, '/
INSERT INTO `sa_system_menu` VALUES (4, 3, '用户管理', 'User', NULL, 2, 'user', '/system/user', NULL, 'ri:user-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (5, 3, '部门管理', 'Dept', NULL, 2, 'dept', '/system/dept', NULL, 'ri:node-tree', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (6, 3, '角色管理', 'Role', NULL, 2, 'role', '/system/role', NULL, 'ri:admin-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (7, 3, '岗位管理', 'Post', '', 2, 'post', '/system/post', NULL, 'ri:signpost-line', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (8, 3, '菜单管理', 'Menu', NULL, 2, 'menu', '/system/menu', NULL, 'ri:menu-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (10, 0, '运维管理', 'Safeguard', NULL, 1, '/safeguard', '', NULL, 'ri:shield-check-line', 100, NULL, 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (11, 10, '缓存管理', 'Cache', '', 2, 'cache', '/safeguard/cache', NULL, 'ri:keyboard-box-line', 80, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -412,13 +411,6 @@ INSERT INTO `sa_system_menu` VALUES (36, 6, '修改', '', 'core:role:update', 3,
INSERT INTO `sa_system_menu` VALUES (37, 6, '读取', '', 'core:role:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (38, 6, '删除', '', 'core:role:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (39, 6, '菜单权限', '', 'core:role:menu', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (41, 7, '数据列表', '', 'core:post:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (42, 7, '添加', '', 'core:post:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (43, 7, '修改', '', 'core:post:update', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (44, 7, '读取', '', 'core:post:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (45, 7, '删除', '', 'core:post:destroy', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (46, 7, '导入', '', 'core:post:import', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (47, 7, '导出', '', 'core:post:export', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (48, 8, '数据列表', '', 'core:menu:index', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (49, 8, '读取', '', 'core:menu:read', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
INSERT INTO `sa_system_menu` VALUES (50, 8, '添加', '', 'core:menu:save', 3, '', '', NULL, '', 100, '', 2, 2, 2, 2, 2, 0, NULL, 1, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
@@ -490,25 +482,6 @@ CREATE TABLE `sa_system_oper_log` (
-- Records of sa_system_oper_log
-- ----------------------------
-- ----------------------------
-- Table structure for sa_system_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_post`;
CREATE TABLE `sa_system_post` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(50) NULL DEFAULT NULL COMMENT '岗位名称',
`code` varchar(100) NULL DEFAULT NULL COMMENT '岗位代码',
`sort` smallint(5) UNSIGNED NULL DEFAULT 0 COMMENT '排序',
`status` smallint(6) NULL DEFAULT 1 COMMENT '状态 (1正常 2停用)',
`remark` varchar(255) NULL DEFAULT NULL COMMENT '备注',
`created_by` int(11) NULL DEFAULT NULL COMMENT '创建者',
`updated_by` int(11) NULL DEFAULT NULL COMMENT '更新者',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
`delete_time` datetime(0) NULL DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 87 COMMENT = '岗位信息表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for sa_system_role
-- ----------------------------
@@ -606,23 +579,6 @@ CREATE TABLE `sa_system_user` (
-- ----------------------------
INSERT INTO `sa_system_user` VALUES (1, 'admin', '$2y$10$wnixh48uDnaW/6D9EygDd.OHJK0vQY/4nHaTjMKBCVDBP2NiTatqS', '祭道之上', '2', 'https://image.saithink.top/saiadmin/avatar.jpg', 'saiadmin@admin.com', '15888888888', 'SaiAdmin是兼具设计美学与高效开发的后台系统!', 'statistics', 1, 1, 1, NULL, NULL, NULL, 1, 1, '2026-01-01 00:00:00', '2026-01-01 00:00:00', NULL);
-- ----------------------------
-- Table structure for sa_system_user_post
-- ----------------------------
DROP TABLE IF EXISTS `sa_system_user_post`;
CREATE TABLE `sa_system_user_post` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户主键',
`post_id` bigint(20) UNSIGNED NOT NULL COMMENT '岗位主键',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_user_id`(`user_id`) USING BTREE,
INDEX `idx_post_id`(`post_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 COMMENT = '用户与岗位关联表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sa_system_user_post
-- ----------------------------
-- ----------------------------
-- Table structure for sa_system_user_role
-- ----------------------------

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);

View File

@@ -12,3 +12,5 @@ Route::group('/tool/install', function () {
Route::get('/online/storeAppVersions', [plugin\saipackage\app\controller\InstallController::class, 'storeAppVersions']);
Route::post('/online/storeDownloadApp', [plugin\saipackage\app\controller\InstallController::class, 'storeDownloadApp']);
});
Route::disableDefaultRoute('saipackage');

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => 'This category has sub-categories, please delete them first',
'This department has sub-departments, please delete them first' => 'This department has sub-departments, please delete them first',
'This department has users, please delete or transfer them first' => 'This department has users, please delete or transfer them first',
'This channel has users, please delete or transfer them first' => 'This channel has users, please delete or transfer them first',
'This dict code already exists' => 'This dict code already exists',
'This menu has sub-menus, please delete them first' => 'This menu has sub-menus, please delete them first',
'Timestamp expired or invalid, please sync time' => 'Timestamp expired or invalid, please sync time',

View File

@@ -254,6 +254,7 @@ return [
'This category has sub-categories, please delete them first' => '该部门下存在子分类,请先删除子分类',
'This department has sub-departments, please delete them first' => '该部门下存在子部门,请先删除子部门',
'This department has users, please delete or transfer them first' => '该部门下存在用户,请先删除或者转移用户',
'This channel has users, please delete or transfer them first' => '该渠道下存在用户,请先删除或者转移用户',
'This dict code already exists' => '该字典标识已存在',
'This menu has sub-menus, please delete them first' => '该菜单下存在子菜单,请先删除子菜单',
'Timestamp expired or invalid, please sync time' => '时间戳已过期或无效,请同步时间',

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
/**
* 生成 /api/v1/authToken或 /api/v1/authtoken所需 signature
*
* 用法:
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret
* php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret --time=1713772800
*/
$options = getopt('', ['agent_id:', 'secret:', 'time::']);
$agentId = $options['agent_id'] ?? '5ef059938ba799aaa845e1c2e8a762bd';
$secret = $options['secret'] ?? 'xF75oK91TQj13s0UmNIr1NBWMWGfflNO';
$time = $options['time'] ?? (string) time();
if ($agentId === '' || $secret === '' || $time === '') {
echo "缺少参数。\n";
echo "用法: php scripts/gen_auth_token_signature.php --agent_id=1001 --secret=your_secret [--time=unix_timestamp]\n";
exit(1);
}
if (ctype_digit($time) === false) {
echo "time 必须是 unix 时间戳(纯数字字符串)。\n";
exit(1);
}
$signature = md5($agentId . $secret . $time);
$query = http_build_query([
'agent_id' => $agentId,
'secret' => $secret,
'time' => $time,
'signature' => $signature,
]);
echo "agent_id: {$agentId}\n";
echo "secret: {$secret}\n";
echo "time: {$time}\n";
echo "signature: {$signature}\n";
echo "query: {$query}\n";

View File

@@ -43,7 +43,6 @@ $fallbackCn = [
'添加失败' => 'add failed',
'修改失败' => 'update failed',
'删除失败' => 'delete failed',
'请选择要删除的数据' => 'please select data to delete',
'参数错误,请检查' => 'invalid parameters, please check',
'参数错误,请检查参数' => 'invalid parameters, please check',
'操作失败' => 'operation failed',