feat(risk): 支持按开注商隔离风险池并新增经营报表
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
lotterLaravel E2E / e2e-api (push) Has been cancelled

This commit is contained in:
2026-07-10 10:23:30 +08:00
parent d4779660c8
commit 2ea3e810a0
31 changed files with 610 additions and 58 deletions

View File

@@ -54,6 +54,7 @@ final class EffectivePlayCatalogService
$riskItems = RiskCapItem::query()
->where('version_id', $riskVersion->id)
->whereIn('provider_code', ['GLOBAL', $providerCode])
->orderBy('normalized_number')
->get();
@@ -92,7 +93,9 @@ final class EffectivePlayCatalogService
'risk_cap' => $this->serializeVersionHead($riskVersion),
],
'plays' => $plays,
'risk_cap_items' => $riskItems->map(fn (RiskCapItem $r) => $this->serializeRiskItem($r))->all(),
'risk_cap_items' => $this->resolveProviderRiskItems($riskItems, $providerCode)
->map(fn (RiskCapItem $r) => $this->serializeRiskItem($r))
->all(),
];
}
@@ -120,6 +123,29 @@ final class EffectivePlayCatalogService
return collect(array_values($selected));
}
/**
* @param Collection<int, RiskCapItem> $items
* @return Collection<int, RiskCapItem>
*/
private function resolveProviderRiskItems(Collection $items, string $providerCode): Collection
{
$selected = [];
foreach ($items->sortBy(fn (RiskCapItem $row): int => (string) ($row->provider_code ?? 'GLOBAL') === $providerCode ? 0 : 1) as $row) {
$key = implode('|', [
$row->draw_id === null ? 'null' : (string) $row->draw_id,
(string) $row->normalized_number,
(string) $row->cap_type,
]);
if (! isset($selected[$key])) {
$selected[$key] = $row;
}
}
return collect(array_values($selected));
}
/**
* 大厅列表展示单档赔率:优先头奖档 {@see first},兼容历史 {@see default}
*
@@ -210,6 +236,7 @@ final class EffectivePlayCatalogService
private function serializeRiskItem(RiskCapItem $r): array
{
return [
'provider_code' => $r->provider_code ?? 'GLOBAL',
'draw_id' => $r->draw_id,
'normalized_number' => $r->normalized_number,
'cap_amount' => (int) $r->cap_amount,

View File

@@ -58,6 +58,7 @@ final class RiskCapStreamService
foreach ($source->items()->orderBy('normalized_number')->get() as $row) {
RiskCapItem::query()->create([
'version_id' => $draft->id,
'provider_code' => $row->provider_code ?? 'GLOBAL',
'draw_id' => $row->draw_id,
'normalized_number' => $row->normalized_number,
'cap_amount' => $row->cap_amount,
@@ -67,6 +68,7 @@ final class RiskCapStreamService
} else {
RiskCapItem::query()->create([
'version_id' => $draft->id,
'provider_code' => 'GLOBAL',
'draw_id' => null,
'normalized_number' => '0000',
'cap_amount' => 50_000_000_000,
@@ -89,6 +91,7 @@ final class RiskCapStreamService
foreach ($items as $row) {
RiskCapItem::query()->create([
'version_id' => $draft->id,
'provider_code' => strtoupper((string) ($row['provider_code'] ?? 'GLOBAL')),
'draw_id' => isset($row['draw_id']) ? (int) $row['draw_id'] : null,
'normalized_number' => (string) $row['normalized_number'],
'cap_amount' => (int) $row['cap_amount'],
@@ -192,9 +195,10 @@ final class RiskCapStreamService
$capAmount = (int) $row->cap_amount;
$drawId = $row->draw_id === null ? '__null__' : (string) $row->draw_id;
$capType = (string) $row->cap_type;
$providerCode = strtoupper((string) ($row->provider_code ?? 'GLOBAL'));
$key = $capType === 'default'
? 'default|'.$drawId
: $drawId.'|'.$normalizedNumber;
? 'default|'.$providerCode.'|'.$drawId
: $providerCode.'|'.$drawId.'|'.$normalizedNumber;
if (! preg_match('/^[0-9]{4}$/', $normalizedNumber)) {
$errors["items.$index.normalized_number"][] = '号码必须是 4 位数字';
@@ -204,6 +208,10 @@ final class RiskCapStreamService
$errors["items.$index.cap_amount"][] = '封顶金额必须大于 0';
}
if (! preg_match('/^[A-Z0-9_-]{2,32}$/', $providerCode)) {
$errors["items.$index.provider_code"][] = '开注商编码格式不正确';
}
if ($capType === 'default' && $row->draw_id !== null) {
$errors["items.$index.cap_type"][] = '默认封顶不能绑定具体期号';
}