From bc034727b08427a71a731540f12808a5f49c827c Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Tue, 10 Mar 2026 16:41:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E7=9C=8B=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=AE=9E=E6=97=B6=E5=BD=A9=E9=87=91=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/dice/api/lottery_config/index.ts | 36 +++++++++ .../dice/lottery_config/index/index.vue | 59 +++++--------- .../DiceLotteryConfigController.php | 21 +++++ .../lottery_config/DiceLotteryConfigLogic.php | 79 ++++++++++++++++++- .../lottery_config/DiceLotteryConfig.php | 1 + server/plugin/saiadmin/config/route.php | 2 + 6 files changed, 159 insertions(+), 39 deletions(-) diff --git a/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts b/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts index cfb4d82..2718950 100644 --- a/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts +++ b/saiadmin-artd/src/views/plugin/dice/api/lottery_config/index.ts @@ -75,5 +75,41 @@ export default { url: '/dice/lottery_config/DiceLotteryConfig/destroy', data: params }) + }, + + /** + * 获取当前彩金池(Redis 实例化,无则按 type=0 创建),含 profit_amount 实时值 + */ + getCurrentPool() { + return request.get<{ + id: number + name: string + safety_line: number + t1_weight: number + t2_weight: number + t3_weight: number + t4_weight: number + t5_weight: number + profit_amount: number + }>({ + url: '/dice/lottery_config/DiceLotteryConfig/getCurrentPool' + }) + }, + + /** + * 更新当前彩金池:仅 safety_line、t1_weight~t5_weight,不可改 profit_amount + */ + updateCurrentPool(params: { + safety_line?: number + t1_weight?: number + t2_weight?: number + t3_weight?: number + t4_weight?: number + t5_weight?: number + }) { + return request.post({ + url: '/dice/lottery_config/DiceLotteryConfig/updateCurrentPool', + data: params + }) } } diff --git a/saiadmin-artd/src/views/plugin/dice/lottery_config/index/index.vue b/saiadmin-artd/src/views/plugin/dice/lottery_config/index/index.vue index 377ea9a..a8771d9 100644 --- a/saiadmin-artd/src/views/plugin/dice/lottery_config/index/index.vue +++ b/saiadmin-artd/src/views/plugin/dice/lottery_config/index/index.vue @@ -7,29 +7,13 @@ @@ -54,11 +38,11 @@ type="secondary" @click="showDialog('edit', row)" /> - - - - - + + + + + @@ -71,6 +55,8 @@ :data="dialogData" @success="refreshData" /> + + @@ -80,6 +66,7 @@ import api from '../../api/lottery_config/index' import TableSearch from './modules/table-search.vue' import EditDialog from './modules/edit-dialog.vue' + import CurrentPoolDialog from './modules/current-pool-dialog.vue' // 搜索表单 const searchForm = ref({ @@ -172,14 +159,10 @@ }) // 编辑配置 - const { - dialogType, - dialogVisible, - dialogData, - showDialog, - // deleteRow, - // deleteSelectedRows, - handleSelectionChange - // selectedRows - } = useSaiAdmin() + const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange } = useSaiAdmin() + + const currentPoolVisible = ref(false) + function showCurrentPoolDialog() { + currentPoolVisible.value = true + } diff --git a/server/app/dice/controller/lottery_config/DiceLotteryConfigController.php b/server/app/dice/controller/lottery_config/DiceLotteryConfigController.php index 7adbac3..f6fad5e 100644 --- a/server/app/dice/controller/lottery_config/DiceLotteryConfigController.php +++ b/server/app/dice/controller/lottery_config/DiceLotteryConfigController.php @@ -135,4 +135,25 @@ class DiceLotteryConfigController extends BaseController } } + /** + * 获取当前彩金池(Redis 实例化,无则按 type=0 创建) + * 返回含 profit_amount 实时值,供前端轮询展示 + */ + #[Permission('色子奖池配置列表', 'dice:lottery_config:index:index')] + public function getCurrentPool(Request $request): Response + { + $data = $this->logic->getCurrentPool(); + return $this->success($data); + } + + /** + * 更新当前彩金池:仅可修改 safety_line、t1_weight~t5_weight,不可修改 profit_amount + */ + #[Permission('色子奖池配置修改', 'dice:lottery_config:index:update')] + public function updateCurrentPool(Request $request): Response + { + $data = $request->post(); + $this->logic->updateCurrentPool($data); + return $this->success('保存成功'); + } } diff --git a/server/app/dice/logic/lottery_config/DiceLotteryConfigLogic.php b/server/app/dice/logic/lottery_config/DiceLotteryConfigLogic.php index ff608bb..72a5bd6 100644 --- a/server/app/dice/logic/lottery_config/DiceLotteryConfigLogic.php +++ b/server/app/dice/logic/lottery_config/DiceLotteryConfigLogic.php @@ -6,16 +6,22 @@ // +---------------------------------------------------------------------- namespace app\dice\logic\lottery_config; +use app\dice\model\lottery_config\DiceLotteryConfig; use plugin\saiadmin\basic\think\BaseLogic; use plugin\saiadmin\exception\ApiException; use plugin\saiadmin\utils\Helper; -use app\dice\model\lottery_config\DiceLotteryConfig; +use support\think\Cache; /** * 色子奖池配置逻辑层 */ class DiceLotteryConfigLogic extends BaseLogic { + /** Redis 当前彩金池(type=0 实例)key,无则按 type=0 创建 */ + private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default'; + + private const EXPIRE = 86400 * 7; + /** * 构造函数 */ @@ -24,4 +30,75 @@ class DiceLotteryConfigLogic extends BaseLogic $this->model = new DiceLotteryConfig(); } + /** + * 获取当前彩金池:从 Redis 读取,若无则按 type=0 配置创建并写入 Redis,返回含 profit_amount(ev) 的完整数据 + * + * @return array{id:int,name:string,safety_line:int,t1_weight:int,t2_weight:int,t3_weight:int,t4_weight:int,t5_weight:int,profit_amount:float} + */ + public function getCurrentPool(): array + { + $cached = Cache::get(self::REDIS_KEY_CURRENT_POOL); + if ($cached && is_string($cached)) { + $data = json_decode($cached, true); + if (is_array($data)) { + $config = DiceLotteryConfig::find($data['id'] ?? 0); + $ev = $config && isset($config->ev) ? (float) $config->ev : (float) ($data['profit_amount'] ?? 0); + $data['profit_amount'] = $ev; + return $data; + } + } + $config = DiceLotteryConfig::where('type', 0)->find(); + if (!$config) { + throw new ApiException('未找到 type=0 的奖池配置,请先创建'); + } + $row = $config->toArray(); + $pool = [ + 'id' => (int) $row['id'], + 'name' => (string) ($row['name'] ?? ''), + 'safety_line' => (int) ($row['safety_line'] ?? 0), + 't1_weight' => (int) ($row['t1_weight'] ?? 0), + 't2_weight' => (int) ($row['t2_weight'] ?? 0), + 't3_weight' => (int) ($row['t3_weight'] ?? 0), + 't4_weight' => (int) ($row['t4_weight'] ?? 0), + 't5_weight' => (int) ($row['t5_weight'] ?? 0), + 'profit_amount' => isset($row['ev']) ? (float) $row['ev'] : 0.0, + ]; + Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE); + return $pool; + } + + /** + * 更新当前彩金池:仅允许修改 safety_line、t1_weight~t5_weight,不同步 profit_amount(ev) + * 同时更新 Redis 与 DB 中 type=0 的记录 + * + * @param array{safety_line?:int,t1_weight?:int,t2_weight?:int,t3_weight?:int,t4_weight?:int,t5_weight?:int} $data + */ + public function updateCurrentPool(array $data): void + { + $pool = $this->getCurrentPool(); + $id = (int) $pool['id']; + $config = DiceLotteryConfig::find($id); + if (!$config) { + throw new ApiException('奖池配置不存在'); + } + $allow = ['safety_line', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight']; + $update = []; + foreach ($allow as $k) { + if (array_key_exists($k, $data)) { + if ($k === 'safety_line') { + $update[$k] = (int) $data[$k]; + } else { + $update[$k] = max(0, min(100, (int) $data[$k])); + } + } + } + if (empty($update)) { + return; + } + DiceLotteryConfig::where('id', $id)->update($update); + $pool = array_merge($pool, $update); + $refreshed = DiceLotteryConfig::find($id); + $pool['profit_amount'] = $refreshed && isset($refreshed->ev) ? (float) $refreshed->ev : (float) ($pool['profit_amount'] ?? 0); + Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE); + } } diff --git a/server/app/dice/model/lottery_config/DiceLotteryConfig.php b/server/app/dice/model/lottery_config/DiceLotteryConfig.php index 91f91bc..0189574 100644 --- a/server/app/dice/model/lottery_config/DiceLotteryConfig.php +++ b/server/app/dice/model/lottery_config/DiceLotteryConfig.php @@ -25,6 +25,7 @@ use plugin\saiadmin\basic\think\BaseModel; * @property $t3_weight T3池权重 * @property $t4_weight T4池权重 * @property $t5_weight T5池权重 + * @property $ev 池子累计盈利(游戏结算时累加,仅展示不可编辑) */ class DiceLotteryConfig extends BaseModel { diff --git a/server/plugin/saiadmin/config/route.php b/server/plugin/saiadmin/config/route.php index c6410ec..6d8be5e 100644 --- a/server/plugin/saiadmin/config/route.php +++ b/server/plugin/saiadmin/config/route.php @@ -107,6 +107,8 @@ Route::group('/core', function () { Route::post('/dice/reward_config/DiceRewardConfig/batchUpdateWeights', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdateWeights']); fastRoute('dice/lottery_config/DiceLotteryConfig', \app\dice\controller\lottery_config\DiceLotteryConfigController::class); Route::get('/dice/lottery_config/DiceLotteryConfig/getOptions', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'getOptions']); + Route::get('/dice/lottery_config/DiceLotteryConfig/getCurrentPool', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'getCurrentPool']); + Route::post('/dice/lottery_config/DiceLotteryConfig/updateCurrentPool', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'updateCurrentPool']); // 数据表维护 Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']);