fix: 增强配置发布校验与关闭玩法清理提示
1. 发布赔率、玩法配置和风控封顶草稿前校验空配置、重复项、金额范围和合法性 2. 限制赔率返水与佣金比例在 0 到 1 之间 3. 投注预览和下单遇到已关闭玩法时返回需清理注项明细
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Services\AuditLogger;
|
||||
use App\Models\RiskCapVersion;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Lottery\ConfigVersionStatus;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
/** 后台:风控封顶版本({@see risk_cap_versions} / {@see risk_cap_items}) */
|
||||
@@ -97,6 +98,7 @@ final class RiskCapStreamService
|
||||
|
||||
public function publish(RiskCapVersion $draft, AdminUser $admin, ?Request $request = null): void
|
||||
{
|
||||
$this->validatePublishableDraft($draft);
|
||||
$before = $this->snapshotVersion($draft);
|
||||
|
||||
DB::transaction(function () use ($draft, $admin): void {
|
||||
@@ -162,4 +164,39 @@ final class RiskCapStreamService
|
||||
'items_count' => $v->items()->count(),
|
||||
];
|
||||
}
|
||||
|
||||
private function validatePublishableDraft(RiskCapVersion $draft): void
|
||||
{
|
||||
$items = $draft->items()->orderBy('draw_id')->orderBy('normalized_number')->get();
|
||||
$errors = [];
|
||||
$seenKeys = [];
|
||||
|
||||
if ($items->isEmpty()) {
|
||||
$errors['items'][] = '草稿至少需要一条封顶配置';
|
||||
}
|
||||
|
||||
foreach ($items as $index => $row) {
|
||||
$normalizedNumber = (string) $row->normalized_number;
|
||||
$capAmount = (int) $row->cap_amount;
|
||||
$drawId = $row->draw_id === null ? '__null__' : (string) $row->draw_id;
|
||||
$key = $drawId.'|'.$normalizedNumber;
|
||||
|
||||
if (! preg_match('/^[0-9]{4}$/', $normalizedNumber)) {
|
||||
$errors["items.$index.normalized_number"][] = '号码必须是 4 位数字';
|
||||
}
|
||||
|
||||
if ($capAmount <= 0) {
|
||||
$errors["items.$index.cap_amount"][] = '封顶金额必须大于 0';
|
||||
}
|
||||
|
||||
if (isset($seenKeys[$key])) {
|
||||
$errors["items.$index"][] = '同一期号与号码存在重复封顶配置';
|
||||
}
|
||||
$seenKeys[$key] = true;
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
throw ValidationException::withMessages($errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user