From 2dcc9f479a051f0b907b3ea7c2dbd07dcf26a313 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Wed, 4 Mar 2026 17:36:52 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8E=A5=E5=8F=A3]=E4=BC=98=E5=8C=96=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=B4=AD=E4=B9=B0=E6=8A=BD=E5=A5=96=E5=88=B8=E6=97=B6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95DicePlayerTicketRecord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/api/controller/GameController.php | 10 ++++++++-- server/app/api/logic/GameLogic.php | 16 ++++++++++++++-- server/app/api/logic/PlayStartLogic.php | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/server/app/api/controller/GameController.php b/server/app/api/controller/GameController.php index dcd31ff..2d5e265 100644 --- a/server/app/api/controller/GameController.php +++ b/server/app/api/controller/GameController.php @@ -53,8 +53,14 @@ class GameController extends OpenController $logic = new GameLogic(); $data = $logic->buyLotteryTickets($userId, $count); return $this->success($data); - } catch (\plugin\saiadmin\exception\ApiException $e) { - return $this->fail($e->getMessage(), ReturnCode::EMPTY_PARAMS); + } 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::EMPTY_PARAMS); } } diff --git a/server/app/api/logic/GameLogic.php b/server/app/api/logic/GameLogic.php index a9082aa..13b9c66 100644 --- a/server/app/api/logic/GameLogic.php +++ b/server/app/api/logic/GameLogic.php @@ -3,9 +3,10 @@ declare(strict_types=1); namespace app\api\logic; -use app\dice\model\player\DicePlayer; -use app\dice\model\player_wallet_record\DicePlayerWalletRecord; use app\api\cache\UserCache; +use app\dice\model\player\DicePlayer; +use app\dice\model\player_ticket_record\DicePlayerTicketRecord; +use app\dice\model\player_wallet_record\DicePlayerWalletRecord; use plugin\saiadmin\exception\ApiException; use support\think\Db; @@ -74,6 +75,7 @@ class GameLogic $player->free_draw_count = $freeBefore + $addFree; $player->save(); + // 钱包流水记录 DicePlayerWalletRecord::create([ 'player_id' => $playerId, 'coin' => -$cost, @@ -85,6 +87,16 @@ class GameLogic 'free_draw_count' => $addFree, 'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)", ]); + + // 抽奖券获取记录 + DicePlayerTicketRecord::create([ + 'player_id' => $playerId, + 'use_coins' => $cost, + 'total_draw_count' => $addTotal, + 'paid_draw_count' => $addPaid, + 'free_draw_count' => $addFree, + 'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$addFree}次)", + ]); }); $updated = DicePlayer::find($playerId); diff --git a/server/app/api/logic/PlayStartLogic.php b/server/app/api/logic/PlayStartLogic.php index 0c13b59..c70b3f6 100644 --- a/server/app/api/logic/PlayStartLogic.php +++ b/server/app/api/logic/PlayStartLogic.php @@ -8,6 +8,7 @@ use app\api\service\LotteryService; use app\dice\model\lottery_config\DiceLotteryConfig; use app\dice\model\play_record\DicePlayRecord; use app\dice\model\player\DicePlayer; +use app\dice\model\player_ticket_record\DicePlayerTicketRecord; use app\dice\model\player_wallet_record\DicePlayerWalletRecord; use app\dice\model\reward_config\DiceRewardConfig; use plugin\saiadmin\exception\ApiException; @@ -86,6 +87,7 @@ class PlayStartLogic $configId = (int) $config->id; $rewardId = (int) $reward->id; $configName = (string) ($config->name ?? ''); + $isTierT5 = (string) ($reward->tier ?? '') === 'T5'; try { Db::transaction(function () use ( $playerId, @@ -99,6 +101,7 @@ class PlayStartLogic $startIndex, $targetIndex, $rollArray, + $isTierT5, &$record ) { $record = DicePlayRecord::create([ @@ -128,6 +131,19 @@ class PlayStartLogic } else { $p->free_draw_count = max(0, (int) $p->free_draw_count - 1); } + + // 若本局中奖档位为 T5,则额外赠送 1 次免费抽奖次数(总次数也 +1),并记录抽奖券获取记录 + if ($isTierT5) { + $p->free_draw_count = (int) $p->free_draw_count + 1; + $p->total_draw_count = (int) $p->total_draw_count + 1; + + DicePlayerTicketRecord::create([ + 'player_id' => $playerId, + 'free_draw_count' => 1, + 'remark' => '中奖结果为T5', + ]); + } + $p->save(); // 累加彩金池盈利额度(累加值为 -real_ev)。若 dice_lottery_config 表有 ev 字段则执行