优化导入权重测试数据
This commit is contained in:
@@ -354,9 +354,13 @@ class DiceRewardLogic
|
||||
if ($configCw !== null) {
|
||||
$tier = isset($configCw['tier']) ? trim((string) $configCw['tier']) : '';
|
||||
if ($tier !== '') {
|
||||
// 使用对应奖励配置的 weight 作为格子权重(若未配置则退回最小权重)
|
||||
$weightCw = isset($configCw['weight']) && $configCw['weight'] !== null
|
||||
? $configCw['weight']
|
||||
: self::WEIGHT_MIN;
|
||||
$payloadCw = [
|
||||
'tier' => $tier,
|
||||
'weight' => self::WEIGHT_MIN,
|
||||
'weight' => $weightCw,
|
||||
'grid_number' => $gridNumber,
|
||||
'start_index' => $startId,
|
||||
'end_index' => $endIdCw,
|
||||
@@ -374,7 +378,7 @@ class DiceRewardLogic
|
||||
$m->tier = $tier;
|
||||
$m->direction = DiceReward::DIRECTION_CLOCKWISE;
|
||||
$m->end_index = $endIdCw;
|
||||
$m->weight = self::WEIGHT_MIN;
|
||||
$m->weight = $weightCw;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->start_index = $startId;
|
||||
$m->ui_text = $configCw['ui_text'] ?? '';
|
||||
@@ -390,9 +394,13 @@ class DiceRewardLogic
|
||||
if ($configCcw !== null) {
|
||||
$tier = isset($configCcw['tier']) ? trim((string) $configCcw['tier']) : '';
|
||||
if ($tier !== '') {
|
||||
// 使用对应奖励配置的 weight 作为格子权重(若未配置则退回最小权重)
|
||||
$weightCcw = isset($configCcw['weight']) && $configCcw['weight'] !== null
|
||||
? $configCcw['weight']
|
||||
: self::WEIGHT_MIN;
|
||||
$payloadCcw = [
|
||||
'tier' => $tier,
|
||||
'weight' => self::WEIGHT_MIN,
|
||||
'weight' => $weightCcw,
|
||||
'grid_number' => $gridNumber,
|
||||
'start_index' => $startId,
|
||||
'end_index' => $endIdCcw,
|
||||
@@ -410,7 +418,7 @@ class DiceRewardLogic
|
||||
$m->tier = $tier;
|
||||
$m->direction = DiceReward::DIRECTION_COUNTERCLOCKWISE;
|
||||
$m->end_index = $endIdCcw;
|
||||
$m->weight = self::WEIGHT_MIN;
|
||||
$m->weight = $weightCcw;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->start_index = $startId;
|
||||
$m->ui_text = $configCcw['ui_text'] ?? '';
|
||||
|
||||
@@ -91,40 +91,69 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
}
|
||||
if (is_array($snapshot) && !empty($snapshot)) {
|
||||
foreach ($snapshot as $item) {
|
||||
$id = isset($item['id']) ? (int) $item['id'] : 0;
|
||||
$direction = isset($item['direction']) ? (int) $item['direction'] : null;
|
||||
$gridNumber = isset($item['grid_number']) ? (int) $item['grid_number'] : 0;
|
||||
$weight = isset($item['weight']) ? (int) $item['weight'] : 1;
|
||||
$weight = max(1, min(10000, $weight));
|
||||
if ($id <= 0) {
|
||||
if (!in_array($direction, [DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE], true)) {
|
||||
continue;
|
||||
}
|
||||
if ($gridNumber <= 0) {
|
||||
continue;
|
||||
}
|
||||
$tier = isset($item['tier']) ? (string) $item['tier'] : '';
|
||||
if ($tier === '') {
|
||||
$tier = DiceRewardConfig::where('id', $id)->value('tier');
|
||||
$tier = $tier !== null && $tier !== '' ? (string) $tier : '';
|
||||
// 若快照中未带 tier,则尝试按方向+点数从现有配置中取
|
||||
$tierFromDb = DiceReward::where('direction', $direction)->where('grid_number', $gridNumber)->value('tier');
|
||||
$tier = $tierFromDb !== null ? (string) $tierFromDb : '';
|
||||
}
|
||||
if ($tier === '') {
|
||||
continue;
|
||||
}
|
||||
// 写入 DiceReward(顺/逆时针同值)
|
||||
foreach ([DiceReward::DIRECTION_CLOCKWISE, DiceReward::DIRECTION_COUNTERCLOCKWISE] as $direction) {
|
||||
$affected = DiceReward::where('tier', $tier)->where('direction', $direction)->where('end_index', $id)->update(['weight' => $weight]);
|
||||
if ($affected === 0) {
|
||||
$m = new DiceReward();
|
||||
$m->tier = $tier;
|
||||
$m->direction = $direction;
|
||||
$m->end_index = $id;
|
||||
$m->weight = $weight;
|
||||
$m->save();
|
||||
// 仅按方向 + 点数更新 DiceReward(若存在则更新,不存在才插入,避免唯一键冲突)
|
||||
$reward = DiceReward::where('direction', $direction)
|
||||
->where('grid_number', $gridNumber)
|
||||
->find();
|
||||
if ($reward) {
|
||||
$reward->weight = $weight;
|
||||
// 若快照中有 tier,补齐 tier 信息
|
||||
if ($tier !== '' && (string) $reward->tier !== $tier) {
|
||||
$reward->tier = $tier;
|
||||
}
|
||||
}
|
||||
// BIGWIN:同步写入 DiceRewardConfig.weight
|
||||
if (strtoupper($tier) === 'BIGWIN') {
|
||||
DiceRewardConfig::where('id', $id)->update(['weight' => $weight]);
|
||||
$reward->save();
|
||||
} else {
|
||||
$m = new DiceReward();
|
||||
if ($tier !== '') {
|
||||
$m->tier = $tier;
|
||||
}
|
||||
$m->direction = $direction;
|
||||
$m->grid_number = $gridNumber;
|
||||
$m->weight = $weight;
|
||||
$m->save();
|
||||
}
|
||||
}
|
||||
DiceReward::refreshCache();
|
||||
}
|
||||
|
||||
// 使用记录中的 bigwin_weight JSON 将 BIGWIN 概率导入到 DiceRewardConfig
|
||||
$recordBigwinWeight = $record['bigwin_weight'] ?? null;
|
||||
if (is_string($recordBigwinWeight)) {
|
||||
$decoded = json_decode($recordBigwinWeight, true);
|
||||
$recordBigwinWeight = is_array($decoded) ? $decoded : null;
|
||||
}
|
||||
if (is_array($recordBigwinWeight) && !empty($recordBigwinWeight)) {
|
||||
foreach ($recordBigwinWeight as $grid => $w) {
|
||||
$gridNumber = (int) $grid;
|
||||
$weight = (int) $w;
|
||||
if ($gridNumber <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($weight < 0) {
|
||||
$weight = 0;
|
||||
}
|
||||
DiceRewardConfig::where('tier', 'BIGWIN')
|
||||
->where('grid_number', $gridNumber)
|
||||
->update(['weight' => $weight]);
|
||||
}
|
||||
}
|
||||
|
||||
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||
$tierSnapshot = $record['tier_weights_snapshot'] ?? null;
|
||||
if (is_string($tierSnapshot)) {
|
||||
@@ -251,13 +280,15 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$paidTierWeights = null;
|
||||
$freeTierWeights = null;
|
||||
|
||||
// 来自 DiceReward 的当前权重快照(按方向+点数),用于权重测试模拟
|
||||
$instance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $instance['by_tier_direction'] ?? [];
|
||||
foreach ($byTierDirection as $tier => $byDir) {
|
||||
foreach ($byDir as $dir => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
$snapshot[] = [
|
||||
'id' => (int) ($row['id'] ?? 0),
|
||||
// 不再记录 DiceReward.id,只记录方向、点数和、档位与权重
|
||||
'direction' => (int) $dir,
|
||||
'grid_number' => (int) ($row['grid_number'] ?? 0),
|
||||
'tier' => (string) ($tier ?? ''),
|
||||
'weight' => (int) ($row['weight'] ?? 0),
|
||||
@@ -266,6 +297,19 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
// BIGWIN 概率快照从 DiceRewardConfig 读取(例如豹子号配置)
|
||||
// JSON 结构 {"grid_number": weight, ...}
|
||||
$bigwinWeights = [];
|
||||
$bigwinConfigs = DiceRewardConfig::getCachedByTier('BIGWIN');
|
||||
foreach ($bigwinConfigs as $cfg) {
|
||||
$grid = isset($cfg['grid_number']) ? (int) $cfg['grid_number'] : 0;
|
||||
if ($grid <= 0) {
|
||||
continue;
|
||||
}
|
||||
$w = isset($cfg['weight']) ? (int) $cfg['weight'] : 0;
|
||||
$bigwinWeights[$grid] = $w;
|
||||
}
|
||||
|
||||
if ($paidConfigId > 0) {
|
||||
$config = DiceLotteryPoolConfig::find($paidConfigId);
|
||||
if (!$config) {
|
||||
@@ -359,6 +403,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$record->free_tier_weights = $freeTierWeights;
|
||||
$record->result_counts = [];
|
||||
$record->tier_counts = null;
|
||||
$record->bigwin_weight = $bigwinWeights ?: null;
|
||||
$record->admin_id = $adminId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
|
||||
@@ -196,11 +196,15 @@ class WeightTestRunner
|
||||
*/
|
||||
private function markSuccess(int $recordId, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if ($record) {
|
||||
// 平台盈利通过关联测试记录统计
|
||||
$platformProfit = DiceRewardConfigRecord::computePlatformProfitFromRelated($recordId);
|
||||
// 落点统计也通过关联测试记录重新统计,避免模拟过程异常导致为空
|
||||
$dbResultCounts = DiceRewardConfigRecord::computeResultCountsFromRelated($recordId);
|
||||
|
||||
$record->status = DiceRewardConfigRecord::STATUS_SUCCESS;
|
||||
$record->result_counts = $resultCounts;
|
||||
$record->result_counts = !empty($dbResultCounts) ? $dbResultCounts : $resultCounts;
|
||||
$record->tier_counts = $tierCounts;
|
||||
$record->remark = null;
|
||||
$record->platform_profit = $platformProfit;
|
||||
|
||||
Reference in New Issue
Block a user