[接口]优化新增购买抽奖券时记录DicePlayerTicketRecord
This commit is contained in:
@@ -53,8 +53,14 @@ class GameController extends OpenController
|
|||||||
$logic = new GameLogic();
|
$logic = new GameLogic();
|
||||||
$data = $logic->buyLotteryTickets($userId, $count);
|
$data = $logic->buyLotteryTickets($userId, $count);
|
||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
return $this->fail($e->getMessage(), ReturnCode::EMPTY_PARAMS);
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace app\api\logic;
|
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\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 plugin\saiadmin\exception\ApiException;
|
||||||
use support\think\Db;
|
use support\think\Db;
|
||||||
|
|
||||||
@@ -74,6 +75,7 @@ class GameLogic
|
|||||||
$player->free_draw_count = $freeBefore + $addFree;
|
$player->free_draw_count = $freeBefore + $addFree;
|
||||||
$player->save();
|
$player->save();
|
||||||
|
|
||||||
|
// 钱包流水记录
|
||||||
DicePlayerWalletRecord::create([
|
DicePlayerWalletRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
'coin' => -$cost,
|
'coin' => -$cost,
|
||||||
@@ -85,6 +87,16 @@ class GameLogic
|
|||||||
'free_draw_count' => $addFree,
|
'free_draw_count' => $addFree,
|
||||||
'remark' => "购买抽奖券{$addTotal}次(付费{$addPaid}次+赠送{$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);
|
$updated = DicePlayer::find($playerId);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use app\api\service\LotteryService;
|
|||||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||||
use app\dice\model\play_record\DicePlayRecord;
|
use app\dice\model\play_record\DicePlayRecord;
|
||||||
use app\dice\model\player\DicePlayer;
|
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\player_wallet_record\DicePlayerWalletRecord;
|
||||||
use app\dice\model\reward_config\DiceRewardConfig;
|
use app\dice\model\reward_config\DiceRewardConfig;
|
||||||
use plugin\saiadmin\exception\ApiException;
|
use plugin\saiadmin\exception\ApiException;
|
||||||
@@ -86,6 +87,7 @@ class PlayStartLogic
|
|||||||
$configId = (int) $config->id;
|
$configId = (int) $config->id;
|
||||||
$rewardId = (int) $reward->id;
|
$rewardId = (int) $reward->id;
|
||||||
$configName = (string) ($config->name ?? '');
|
$configName = (string) ($config->name ?? '');
|
||||||
|
$isTierT5 = (string) ($reward->tier ?? '') === 'T5';
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use (
|
Db::transaction(function () use (
|
||||||
$playerId,
|
$playerId,
|
||||||
@@ -99,6 +101,7 @@ class PlayStartLogic
|
|||||||
$startIndex,
|
$startIndex,
|
||||||
$targetIndex,
|
$targetIndex,
|
||||||
$rollArray,
|
$rollArray,
|
||||||
|
$isTierT5,
|
||||||
&$record
|
&$record
|
||||||
) {
|
) {
|
||||||
$record = DicePlayRecord::create([
|
$record = DicePlayRecord::create([
|
||||||
@@ -128,6 +131,19 @@ class PlayStartLogic
|
|||||||
} else {
|
} else {
|
||||||
$p->free_draw_count = max(0, (int) $p->free_draw_count - 1);
|
$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();
|
$p->save();
|
||||||
|
|
||||||
// 累加彩金池盈利额度(累加值为 -real_ev)。若 dice_lottery_config 表有 ev 字段则执行
|
// 累加彩金池盈利额度(累加值为 -real_ev)。若 dice_lottery_config 表有 ev 字段则执行
|
||||||
|
|||||||
Reference in New Issue
Block a user