feat: 更新玩法配置管理,简化字段并增强功能

- 将玩法相关的显示名称字段统一为 `display_name`,移除多语言字段。
- 在 `PlayTypePatchController` 中新增即时切换玩法开关的功能,并推送大厅更新。
- 优化多个控制器和服务中的权限检查与数据处理逻辑,提升代码可读性与维护性。
This commit is contained in:
2026-05-25 14:34:24 +08:00
parent 270d2e9af1
commit e27a00f260
74 changed files with 4469 additions and 280 deletions

View File

@@ -11,6 +11,7 @@ use App\Models\PlayConfigVersion;
use Illuminate\Support\Facades\DB;
use App\Lottery\ConfigVersionStatus;
use App\Services\Draw\LotteryHallRealtimeBroadcaster;
use App\Http\Middleware\RecordAdminApiAudit;
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
@@ -62,9 +63,7 @@ final class PlayConfigStreamService
'category' => $row->category,
'dimension' => $row->dimension,
'bet_mode' => $row->bet_mode,
'display_name_zh' => $row->display_name_zh,
'display_name_en' => $row->display_name_en,
'display_name_ne' => $row->display_name_ne,
'display_name' => $row->display_name,
'is_enabled' => $row->is_enabled,
'min_bet_amount' => $row->min_bet_amount,
'max_bet_amount' => $row->max_bet_amount,
@@ -85,9 +84,7 @@ final class PlayConfigStreamService
'category' => $pt->category,
'dimension' => $pt->dimension,
'bet_mode' => $pt->bet_mode,
'display_name_zh' => $pt->display_name_zh,
'display_name_en' => $pt->display_name_en,
'display_name_ne' => $pt->display_name_ne,
'display_name' => $pt->display_name,
'is_enabled' => (bool) $pt->is_enabled,
'min_bet_amount' => 100,
'max_bet_amount' => 500_000_000,
@@ -109,6 +106,53 @@ final class PlayConfigStreamService
/**
* @param array<int, array<string, mixed>> $items
*/
/**
* 即时切换当前生效玩法开关(无需发布草稿),并推送大厅 WS。
*/
public function patchActivePlayToggle(AdminUser $admin, string $playCode, bool $enabled, ?Request $request = null): PlayConfigItem
{
/** @var PlayConfigVersion $active */
$active = PlayConfigVersion::query()
->where('status', ConfigVersionStatus::Active->value)
->firstOrFail();
/** @var PlayConfigItem $item */
$item = PlayConfigItem::query()
->where('version_id', $active->id)
->where('play_code', $playCode)
->firstOrFail();
$before = ['is_enabled' => (bool) $item->is_enabled];
if ($before['is_enabled'] === $enabled) {
return $item;
}
DB::transaction(function () use ($item, $enabled, $active, $admin, $playCode): void {
$item->forceFill(['is_enabled' => $enabled])->save();
$active->forceFill(['updated_by' => $admin->id])->save();
PlayType::query()
->where('play_code', $playCode)
->update(['is_enabled' => $enabled]);
});
$this->hallRealtime->notifyPlayToggle($playCode, $enabled, 'play toggle applied to active config');
AuditLogger::recordForAdmin(
$admin,
$request,
moduleCode: 'play_config',
actionCode: 'toggle_active',
targetType: 'play_config_item',
targetId: $playCode,
beforeJson: $before,
afterJson: ['is_enabled' => $enabled, 'active_version_id' => $active->id],
);
$request?->attributes->set(RecordAdminApiAudit::ATTRIBUTE_AUDIT_RECORDED, true);
return $item->refresh();
}
public function replaceItems(PlayConfigVersion $draft, array $items, AdminUser $admin): void
{
DB::transaction(function () use ($draft, $items, $admin): void {
@@ -121,9 +165,7 @@ final class PlayConfigStreamService
'category' => $row['category'] ?? null,
'dimension' => $row['dimension'] ?? null,
'bet_mode' => $row['bet_mode'] ?? null,
'display_name_zh' => $row['display_name_zh'] ?? null,
'display_name_en' => $row['display_name_en'] ?? null,
'display_name_ne' => $row['display_name_ne'] ?? null,
'display_name' => $row['display_name'] ?? null,
'is_enabled' => (bool) ($row['is_enabled'] ?? true),
'min_bet_amount' => (int) ($row['min_bet_amount'] ?? 0),
'max_bet_amount' => (int) ($row['max_bet_amount'] ?? 0),
@@ -183,6 +225,7 @@ final class PlayConfigStreamService
beforeJson: $before,
afterJson: $after,
);
$request?->attributes->set(RecordAdminApiAudit::ATTRIBUTE_AUDIT_RECORDED, true);
}
/**
@@ -223,6 +266,7 @@ final class PlayConfigStreamService
beforeJson: $before,
afterJson: null,
);
$request?->attributes->set(RecordAdminApiAudit::ATTRIBUTE_AUDIT_RECORDED, true);
}
/** @return array<string, mixed> */
@@ -278,8 +322,8 @@ final class PlayConfigStreamService
$errors["items.$index.max_bet_amount"][] = '最大下注额不能小于最小下注额';
}
if ($row->display_name_zh === null || $row->display_name_zh === '') {
$errors["items.$index.display_name_zh"][] = '显示名称不能为空';
if ($row->display_name === null || $row->display_name === '') {
$errors["items.$index.display_name"][] = '显示名称不能为空';
}
if ($row->display_order === null) {