优化一键测试权重
This commit is contained in:
@@ -69,10 +69,12 @@ class DiceRewardController extends BaseController
|
||||
/**
|
||||
* 权重编辑弹窗:按档位分组获取配置+顺时针/逆时针权重(dice_reward 双方向)
|
||||
* 返回与 reward_config 权重配比一致结构,供奖励对照页弹窗同时编辑 direction=0/1
|
||||
* 拉取前先刷新缓存,保证与列表页(直查 DB)数据一致,避免表格与弹窗权重不一致
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function weightRatioListWithDirection(Request $request): Response
|
||||
{
|
||||
DiceReward::refreshCache();
|
||||
$logic = new DiceRewardLogic();
|
||||
$data = $logic->getListGroupedByTierWithDirection();
|
||||
return $this->success($data);
|
||||
|
||||
@@ -195,12 +195,19 @@ class DiceRewardLogic
|
||||
continue;
|
||||
}
|
||||
$id = isset($item['id']) ? (int) $item['id'] : 0;
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
if ($id <= 0) {
|
||||
$id = isset($item['reward_id']) ? (int) $item['reward_id'] : 0;
|
||||
}
|
||||
if ($id <= 0) {
|
||||
throw new ApiException('存在无效的 DiceReward id');
|
||||
}
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : self::WEIGHT_MIN;
|
||||
$weight = max(self::WEIGHT_MIN, min(self::WEIGHT_MAX, $weight));
|
||||
DiceReward::where('id', $id)->update(['weight' => $weight]);
|
||||
$model = DiceReward::find($id);
|
||||
if ($model !== null) {
|
||||
$model->weight = $weight;
|
||||
$model->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
}
|
||||
DiceRewardConfig::refreshCache();
|
||||
}
|
||||
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
|
||||
@@ -7,6 +7,8 @@ use app\api\logic\PlayStartLogic;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
@@ -82,6 +84,10 @@ class WeightTestRunner
|
||||
}
|
||||
}
|
||||
|
||||
// 每次测试开始前清空进程内静态缓存,强制从共享缓存读取最新 BIGWIN/奖励配置,与数据库一致
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
DiceReward::clearRequestInstance();
|
||||
|
||||
$playLogic = new PlayStartLogic();
|
||||
$resultCounts = [];
|
||||
$tierCounts = [];
|
||||
|
||||
@@ -46,18 +46,19 @@ class DiceReward extends BaseModel
|
||||
|
||||
/**
|
||||
* 获取奖励对照实例(按档位+方向索引,用于抽奖与权重配比)
|
||||
* 优先从共享缓存读取,保证多进程(如一键测试 worker)与数据库一致
|
||||
* @return array{list: array, by_tier_direction: array}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
if ($instance !== null && is_array($instance)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
|
||||
@@ -42,18 +42,19 @@ class DiceRewardConfig extends BaseModel
|
||||
|
||||
/**
|
||||
* 获取彩金池实例(含 list / by_tier / by_tier_grid),无则从库加载并写入缓存
|
||||
* 优先从共享缓存读取,保证多进程(如一键测试 worker)能拿到最新配置,与数据库一致
|
||||
* @return array{list: array, by_tier: array, by_tier_grid: array, min_real_ev: float}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
if ($instance !== null && is_array($instance)) {
|
||||
self::$instance = $instance;
|
||||
return $instance;
|
||||
}
|
||||
if (self::$instance !== null) {
|
||||
return self::$instance;
|
||||
}
|
||||
self::refreshCache();
|
||||
$instance = Cache::get(self::CACHE_KEY_INSTANCE);
|
||||
self::$instance = is_array($instance) ? $instance : self::buildEmptyInstance();
|
||||
|
||||
Reference in New Issue
Block a user