DicePlayRecord添加字段super_win_coin和reward_win_coin记录不同的中奖金额类型
This commit is contained in:
@@ -137,7 +137,10 @@ class GameController extends OpenController
|
||||
'player_id' => $userId,
|
||||
'lottery_config_id' => 0,
|
||||
'lottery_type' => 0,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
|
||||
@@ -34,6 +34,8 @@ class PlayStartLogic
|
||||
|
||||
/** 开启对局最低余额 = |DiceRewardConfig 最小 real_ev + 100| */
|
||||
private const MIN_COIN_EXTRA = 100;
|
||||
/** 豹子号中大奖额外平台币(可从 dice_config 等配置读取) */
|
||||
private const SUPER_WIN_BONUS = 500;
|
||||
|
||||
/**
|
||||
* 执行一局游戏
|
||||
@@ -120,13 +122,24 @@ class PlayStartLogic
|
||||
$targetIndex
|
||||
));
|
||||
$realEv = (float) ($chosen['real_ev'] ?? 0);
|
||||
$winCoin = 100 + $realEv; // 赢取平台币 = 100 + DiceRewardConfig.real_ev
|
||||
$rewardWinCoin = 100 + $realEv; // 摇色子中奖平台币 = 100 + DiceRewardConfig.real_ev
|
||||
$isSuperWin = DicePlayRecord::isSuperWin($rollArray);
|
||||
// 豹子中大奖时从缓存查 tier=BIGWIN 且 grid_number=roll_number 的奖励配置,取 real_ev 计算中大奖平台币
|
||||
$superWinCoin = 0;
|
||||
if ($isSuperWin) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$superWinCoin = $bigWinConfig !== null
|
||||
? 100 + (float) ($bigWinConfig['real_ev'] ?? 0)
|
||||
: self::SUPER_WIN_BONUS;
|
||||
}
|
||||
$winCoin = $superWinCoin + $rewardWinCoin; // 赢取平台币 = 中大奖 + 摇色子中奖
|
||||
|
||||
$record = null;
|
||||
$configId = (int) $config->id;
|
||||
$rewardId = $chosenId;
|
||||
$configName = (string) ($config->name ?? '');
|
||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||
$isWin = $isSuperWin ? 1 : 0;
|
||||
try {
|
||||
Db::transaction(function () use (
|
||||
$playerId,
|
||||
@@ -135,6 +148,9 @@ class PlayStartLogic
|
||||
$configName,
|
||||
$ticketType,
|
||||
$winCoin,
|
||||
$superWinCoin,
|
||||
$rewardWinCoin,
|
||||
$isWin,
|
||||
$realEv,
|
||||
$direction,
|
||||
$startIndex,
|
||||
@@ -147,7 +163,10 @@ class PlayStartLogic
|
||||
'player_id' => $playerId,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
'reward_win_coin' => $rewardWinCoin,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => $rewardId,
|
||||
@@ -210,7 +229,10 @@ class PlayStartLogic
|
||||
'player_id' => $playerId,
|
||||
'lottery_config_id' => $configId ?? 0,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
|
||||
@@ -82,7 +82,7 @@ class UserLogic
|
||||
$token = $tokenResult['access_token'];
|
||||
UserCache::setSessionByUsername($username, $token);
|
||||
|
||||
$userArr = $player->hidden(['password', 'is_up', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
|
||||
$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);
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ class DicePlayerController extends BaseController
|
||||
['phone', ''],
|
||||
['status', ''],
|
||||
['coin', ''],
|
||||
['is_up', ''],
|
||||
['lottery_config_id', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with(['diceLotteryConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -48,4 +48,13 @@ class DiceLotteryConfig extends BaseModel
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖池类型 搜索(type=0/1/2 等)
|
||||
*/
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('type', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,10 @@ use think\model\relation\BelongsTo;
|
||||
* @property $player_id 玩家id
|
||||
* @property $lottery_config_id 彩金池配置
|
||||
* @property $lottery_type 抽奖类型
|
||||
* @property $is_win 中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[5,5,5,5,5]为1,否则0
|
||||
* @property $win_coin 赢取平台币(= super_win_coin + reward_win_coin)
|
||||
* @property $super_win_coin 中大奖平台币(豹子时发放)
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $lottery_id 奖池
|
||||
@@ -111,7 +113,25 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖 */
|
||||
/**
|
||||
* 是否豹子号(中大奖):5 个点数相同且为 1~5 之一
|
||||
* @param int[] $rollArray 摇取点数数组,如 [1,1,1,1,1]
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSuperWin(array $rollArray): bool
|
||||
{
|
||||
if (count($rollArray) !== 5) {
|
||||
return false;
|
||||
}
|
||||
$unique = array_unique($rollArray);
|
||||
if (count($unique) !== 1) {
|
||||
return false;
|
||||
}
|
||||
$value = reset($unique);
|
||||
return in_array($value, [1, 2, 3, 4, 5], true);
|
||||
}
|
||||
|
||||
/** 是否中大奖 */
|
||||
public function searchIsWinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -135,6 +155,38 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币下限 */
|
||||
public function searchSuperWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币上限 */
|
||||
public function searchSuperWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币下限 */
|
||||
public function searchRewardWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币上限 */
|
||||
public function searchRewardWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 按奖励配置前端显示文本模糊(diceRewardConfig.ui_text) */
|
||||
public function searchRewardUiTextAttr($query, $value)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
* @property $password 密码
|
||||
* @property $status 状态
|
||||
* @property $coin 平台币
|
||||
* @property $is_up 倍率
|
||||
* @property $lottery_config_id 彩金池配置ID(0或null时使用自定义权重*_weight)
|
||||
* @property $t1_weight T1池权重
|
||||
* @property $t2_weight T2池权重
|
||||
* @property $t3_weight T3池权重
|
||||
@@ -162,13 +162,20 @@ class DicePlayer extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 倍率 搜索
|
||||
* 彩金池配置ID 搜索
|
||||
*/
|
||||
public function searchIs_upAttr($query, $value)
|
||||
public function searchLottery_config_idAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_up', '=', $value);
|
||||
$query->where('lottery_config_id', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联彩金池配置
|
||||
*/
|
||||
public function diceLotteryConfig()
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class DiceRewardConfig extends BaseModel
|
||||
|
||||
/**
|
||||
* 获取彩金池实例(含 list / 索引),无则从库加载并写入缓存;同请求内复用
|
||||
* @return array{list: array, by_tier: array, by_s_end_index: array, by_n_end_index: array, min_real_ev: float}
|
||||
* @return array{list: array, by_tier: array, by_tier_grid: array, by_s_end_index: array, by_n_end_index: array, min_real_ev: float}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
@@ -86,6 +86,7 @@ class DiceRewardConfig extends BaseModel
|
||||
{
|
||||
$list = (new self())->order('id', 'asc')->select()->toArray();
|
||||
$byTier = [];
|
||||
$byTierGrid = [];
|
||||
$bySEndIndex = [];
|
||||
$byNEndIndex = [];
|
||||
foreach ($list as $row) {
|
||||
@@ -95,6 +96,13 @@ class DiceRewardConfig extends BaseModel
|
||||
$byTier[$tier] = [];
|
||||
}
|
||||
$byTier[$tier][] = $row;
|
||||
$gridNum = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
if (!isset($byTierGrid[$tier])) {
|
||||
$byTierGrid[$tier] = [];
|
||||
}
|
||||
if (!isset($byTierGrid[$tier][$gridNum])) {
|
||||
$byTierGrid[$tier][$gridNum] = $row;
|
||||
}
|
||||
}
|
||||
$sEnd = isset($row['s_end_index']) ? (int) $row['s_end_index'] : 0;
|
||||
if ($sEnd !== 0) {
|
||||
@@ -115,6 +123,7 @@ class DiceRewardConfig extends BaseModel
|
||||
self::$instance = [
|
||||
'list' => $list,
|
||||
'by_tier' => $byTier,
|
||||
'by_tier_grid' => $byTierGrid,
|
||||
'by_s_end_index' => $bySEndIndex,
|
||||
'by_n_end_index' => $byNEndIndex,
|
||||
'min_real_ev' => $minRealEv,
|
||||
@@ -128,12 +137,28 @@ class DiceRewardConfig extends BaseModel
|
||||
return [
|
||||
'list' => [],
|
||||
'by_tier' => [],
|
||||
'by_tier_grid' => [],
|
||||
'by_s_end_index' => [],
|
||||
'by_n_end_index' => [],
|
||||
'min_real_ev' => 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存按档位 + 色子点数取一条奖励配置(用于超级大奖 tier=BIGWIN + grid_number=roll_number)
|
||||
* @param string $tier 档位,如 BIGWIN
|
||||
* @param int $gridNumber 色子点数(如摇出总和)
|
||||
* @return array|null 配置行或 null
|
||||
*/
|
||||
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
$byTierGrid = $inst['by_tier_grid'] ?? [];
|
||||
$tierData = $byTierGrid[$tier] ?? [];
|
||||
$row = $tierData[$gridNumber] ?? null;
|
||||
return is_array($row) ? $row : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存取最小 real_ev
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user