DicePlayRecord添加字段super_win_coin和reward_win_coin记录不同的中奖金额类型

This commit is contained in:
2026-03-07 11:09:41 +08:00
parent fe1ceeb4fb
commit e312154b0f
15 changed files with 280 additions and 60 deletions

View File

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

View File

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

View File

@@ -22,7 +22,7 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
* @property $password 密码
* @property $status 状态
* @property $coin 平台币
* @property $is_up 倍率
* @property $lottery_config_id 彩金池配置ID0或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');
}
}

View File

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