优化中奖权重计算方式

This commit is contained in:
2026-03-12 17:17:00 +08:00
parent 064ce06393
commit 7e4ba86afa
25 changed files with 2344 additions and 403 deletions

View File

@@ -6,24 +6,23 @@
// +----------------------------------------------------------------------
namespace app\dice\model\reward_config;
use app\dice\model\reward\DiceReward;
use plugin\saiadmin\basic\think\BaseModel;
use support\think\Cache;
/**
* 奖励配置模型
*
* dice_reward_config 奖励配置
* 按档位 T1-T5 直接权重抽取 grid_numberweight 1-10000起始索引 s_start_index / n_start_index
* dice_reward_config 奖励配置BIGWIN 档位使用本表 weight0-1000010000=100% 中大奖)
*
* @property $id ID
* @property $grid_number 色子点数
* @property $ui_text 前端显示文本
* @property $real_ev 真实资金结算
* @property $tier 所属档位
* @property $weight 权重 1-10000档位内按权重比抽取
* @property $n_start_index 逆时针起始索引
* @property $s_start_index 顺时针起始索引
* @property $weight 权重(仅 BIGWIN 使用0-10000
* @property $remark 备注
* @property $type 奖励类型 -2=唯一惩罚,-1=抽水,0=回本,1=再来一次,2=小赚,3=大奖格
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
@@ -129,7 +128,7 @@ class DiceRewardConfig extends BaseModel
}
/**
* 从缓存按档位取奖励列表(含 weight用于按权重抽 grid_number
* 从缓存按档位取奖励列表(不含权重,仅配置
*/
public static function getCachedByTier(string $tier): array
{
@@ -138,6 +137,22 @@ class DiceRewardConfig extends BaseModel
return $byTier[$tier] ?? [];
}
/**
* 按档位+方向取奖励列表(合并 dice_reward 权重,用于抽奖)
* @param int $direction 0=顺时针, 1=逆时针
* @return array 每行含 id, grid_number, real_ev, tier, weight 等
*/
public static function getCachedByTierForDirection(string $tier, int $direction): array
{
$list = self::getCachedByTier($tier);
$weightMap = DiceReward::getCachedByTierAndDirection($tier, $direction);
foreach ($list as $i => $row) {
$id = isset($row['id']) ? (int) $row['id'] : 0;
$list[$i]['weight'] = $weightMap[$id] ?? 1;
}
return $list;
}
public static function clearRequestInstance(): void
{
self::$instance = null;
@@ -199,18 +214,4 @@ class DiceRewardConfig extends BaseModel
$query->where('tier', '=', $value);
}
}
public function searchWeightMinAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('weight', '>=', $value);
}
}
public function searchWeightMaxAttr($query, $value)
{
if ($value !== '' && $value !== null) {
$query->where('weight', '<=', $value);
}
}
}