[色子游戏]抽奖记录(测试权重)-优化
[API]记录抽奖券DicePlayerTicketRecord
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
namespace app\dice\logic\reward_config_record;
|
||||
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\reward\DiceRewardConfig;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
@@ -250,6 +251,15 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$adminId = $adminIdOrFreeS !== null && $adminIdOrFreeS !== '' ? (int) $adminIdOrFreeS : null;
|
||||
}
|
||||
$allowed = [100, 500, 1000, 5000];
|
||||
$ante = isset($params['ante']) ? intval($params['ante']) : 1;
|
||||
if ($ante <= 0) {
|
||||
throw new ApiException('ante must be greater than 0');
|
||||
}
|
||||
$anteExists = DiceAnteConfig::where('mult', $ante)->count();
|
||||
if ($anteExists <= 0) {
|
||||
throw new ApiException('ante not allowed: ' . $ante);
|
||||
}
|
||||
|
||||
$lotteryConfigId = isset($params['lottery_config_id']) ? (int) $params['lottery_config_id'] : 0;
|
||||
$paidConfigId = isset($params['paid_lottery_config_id']) ? (int) $params['paid_lottery_config_id'] : 0;
|
||||
$freeConfigId = isset($params['free_lottery_config_id']) ? (int) $params['free_lottery_config_id'] : 0;
|
||||
@@ -407,6 +417,7 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
$record->result_counts = [];
|
||||
$record->tier_counts = null;
|
||||
$record->bigwin_weight = $bigwinWeights ?: null;
|
||||
$record->ante = $ante;
|
||||
$record->admin_id = $adminId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
|
||||
@@ -33,6 +33,7 @@ class WeightTestRunner
|
||||
return;
|
||||
}
|
||||
|
||||
$ante = is_numeric($record->ante ?? null) ? intval($record->ante) : 1;
|
||||
$paidS = (int) ($record->paid_s_count ?? 0);
|
||||
$paidN = (int) ($record->paid_n_count ?? 0);
|
||||
$freeS = (int) ($record->free_s_count ?? 0);
|
||||
@@ -60,28 +61,40 @@ class WeightTestRunner
|
||||
$safetyLine = (int) ($configType0->safety_line ?? 0);
|
||||
$killEnabled = ((int) ($configType0->kill_enabled ?? 1)) === 1;
|
||||
|
||||
$paidTierWeights = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
|
||||
$paidTierWeightsCustom = (is_array($record->paid_tier_weights ?? null) && $record->paid_tier_weights !== [])
|
||||
? $record->paid_tier_weights
|
||||
: [
|
||||
'T1' => (int) ($configType0->t1_weight ?? 0),
|
||||
'T2' => (int) ($configType0->t2_weight ?? 0),
|
||||
'T3' => (int) ($configType0->t3_weight ?? 0),
|
||||
'T4' => (int) ($configType0->t4_weight ?? 0),
|
||||
'T5' => (int) ($configType0->t5_weight ?? 0),
|
||||
];
|
||||
if (array_sum($paidTierWeights) <= 0) {
|
||||
$this->markFailed($recordId, '需提供 paid_tier_weights(玩家权重,盈利未达安全线时付费抽奖使用)或选择 default 奖池');
|
||||
return;
|
||||
: null;
|
||||
$freeTierWeightsCustom = (is_array($record->free_tier_weights ?? null) && $record->free_tier_weights !== [])
|
||||
? $record->free_tier_weights
|
||||
: null;
|
||||
|
||||
$paidPoolConfigId = (int) ($record->paid_lottery_config_id ?? 0);
|
||||
$freePoolConfigId = (int) ($record->free_lottery_config_id ?? 0);
|
||||
|
||||
$paidPoolConfig = $paidPoolConfigId > 0 ? DiceLotteryPoolConfig::find($paidPoolConfigId) : $configType0;
|
||||
if (!$paidPoolConfig) {
|
||||
$paidPoolConfig = $configType0;
|
||||
}
|
||||
$freePoolConfig = $freePoolConfigId > 0 ? DiceLotteryPoolConfig::find($freePoolConfigId) : $configType1;
|
||||
if (!$freePoolConfig) {
|
||||
$freePoolConfig = $configType0;
|
||||
}
|
||||
|
||||
$freeConfig = $configType1 !== null ? $configType1 : $configType0;
|
||||
if ($paidTierWeightsCustom !== null && array_sum($paidTierWeightsCustom) <= 0) {
|
||||
$this->markFailed($recordId, 'paid_tier_weights(玩家权重)之和必须大于 0');
|
||||
return;
|
||||
}
|
||||
if ($freeTierWeightsCustom !== null && array_sum($freeTierWeightsCustom) <= 0) {
|
||||
$this->markFailed($recordId, 'free_tier_weights(免费玩家权重)之和必须大于 0');
|
||||
return;
|
||||
}
|
||||
|
||||
// 每次测试开始前清空进程内静态缓存,强制从共享缓存读取最新 BIGWIN/奖励配置,与数据库一致
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
DiceReward::clearRequestInstance();
|
||||
|
||||
// 彩金池累计盈利:用于判断是否触发杀分(不再依赖单个玩家累计盈利)
|
||||
$poolProfitTotal = $configType0->profit_amount ?? 0;
|
||||
$poolProfitTotal = floatval($configType0->profit_amount ?? 0);
|
||||
|
||||
$playLogic = new PlayStartLogic();
|
||||
$resultCounts = [];
|
||||
@@ -92,9 +105,9 @@ class WeightTestRunner
|
||||
try {
|
||||
for ($i = 0; $i < $paidS; $i++) {
|
||||
$usePoolWeights = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
|
||||
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $customWeights);
|
||||
$paidConfig = $usePoolWeights ? $configType1 : $paidPoolConfig;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeightsCustom;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 0, 0, $ante, $customWeights);
|
||||
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
@@ -103,9 +116,9 @@ class WeightTestRunner
|
||||
}
|
||||
for ($i = 0; $i < $paidN; $i++) {
|
||||
$usePoolWeights = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
|
||||
$paidConfig = $usePoolWeights ? $configType1 : $configType0;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeights;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $customWeights);
|
||||
$paidConfig = $usePoolWeights ? $configType1 : $paidPoolConfig;
|
||||
$customWeights = $usePoolWeights ? null : $paidTierWeightsCustom;
|
||||
$row = $playLogic->simulateOnePlay($paidConfig, 1, 0, $ante, $customWeights);
|
||||
$this->accumulateProfitForDefault($row, 0, $paidConfig, $configType0, $poolProfitTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
@@ -113,7 +126,10 @@ class WeightTestRunner
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $freeS; $i++) {
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, null);
|
||||
$useKillMode = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
|
||||
$freeConfig = $useKillMode ? $configType1 : $freePoolConfig;
|
||||
$customWeights = $useKillMode ? null : $freeTierWeightsCustom;
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 0, 1, $ante, $customWeights);
|
||||
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
@@ -121,7 +137,10 @@ class WeightTestRunner
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $freeN; $i++) {
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, null);
|
||||
$useKillMode = $killEnabled && $poolProfitTotal >= $safetyLine && $configType1 !== null;
|
||||
$freeConfig = $useKillMode ? $configType1 : $freePoolConfig;
|
||||
$customWeights = $useKillMode ? null : $freeTierWeightsCustom;
|
||||
$row = $playLogic->simulateOnePlay($freeConfig, 1, 1, $ante, $customWeights);
|
||||
$this->accumulateProfitForDefault($row, 1, $freeConfig, $configType0, $poolProfitTotal);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row, $recordId);
|
||||
@@ -153,7 +172,8 @@ class WeightTestRunner
|
||||
return;
|
||||
}
|
||||
$winCoin = (float) $row['win_coin'];
|
||||
$playerProfitTotal += $lotteryType === 0 ? ($winCoin - 100.0) : $winCoin;
|
||||
$paidAmount = (float) ($row['paid_amount'] ?? 0);
|
||||
$playerProfitTotal += $lotteryType === 0 ? ($winCoin - $paidAmount) : $winCoin;
|
||||
}
|
||||
|
||||
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
|
||||
@@ -176,6 +196,7 @@ class WeightTestRunner
|
||||
$keys = [
|
||||
'player_id', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
'super_win_coin', 'reward_win_coin', 'use_coins', 'direction', 'reward_config_id',
|
||||
'ante', 'paid_amount',
|
||||
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
|
||||
];
|
||||
foreach ($keys as $k) {
|
||||
@@ -219,7 +240,7 @@ class WeightTestRunner
|
||||
|
||||
/**
|
||||
* 标记测试成功并记录平台总盈利 platform_profit
|
||||
* 通过关联 DicePlayRecordTest(reward_config_record_id)统计:付费(lottery_type=0)次数×100 - win_coin 求和
|
||||
* 通过关联 DicePlayRecordTest(reward_config_record_id)统计:付费金额 paid_amount 求和 - win_coin 求和
|
||||
*/
|
||||
private function markSuccess(int $recordId, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user