feat: 扩展奖池、风控与报表能力,新增对账补偿、广播和人工操作接口
This commit is contained in:
@@ -10,12 +10,17 @@ use App\Models\PlayConfigItem;
|
||||
use App\Models\PlayConfigVersion;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Lottery\ConfigVersionStatus;
|
||||
use App\Services\Draw\LotteryHallRealtimeBroadcaster;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
/** 后台:玩法配置版本({@see play_config_versions} / {@see play_config_items}) */
|
||||
final class PlayConfigStreamService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LotteryHallRealtimeBroadcaster $hallRealtime,
|
||||
) {}
|
||||
|
||||
/** @return LengthAwarePaginator<int, PlayConfigVersion> */
|
||||
public function paginate(?string $status, int $perPage, int $page = 1): LengthAwarePaginator
|
||||
{
|
||||
@@ -140,6 +145,12 @@ final class PlayConfigStreamService
|
||||
{
|
||||
$this->validatePublishableDraft($draft);
|
||||
$before = $this->snapshotVersion($draft);
|
||||
$currentItems = PlayConfigItem::query()
|
||||
->whereIn('version_id', PlayConfigVersion::query()
|
||||
->select('id')
|
||||
->where('status', ConfigVersionStatus::Active->value))
|
||||
->get()
|
||||
->keyBy('play_code');
|
||||
|
||||
DB::transaction(function () use ($draft, $admin): void {
|
||||
/** @var PlayConfigVersion|null $current */
|
||||
@@ -160,6 +171,7 @@ final class PlayConfigStreamService
|
||||
});
|
||||
|
||||
$after = $this->snapshotVersion($draft->fresh(['items']));
|
||||
$this->broadcastToggleDiffs($currentItems, $draft->items()->get());
|
||||
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
@@ -173,6 +185,26 @@ final class PlayConfigStreamService
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Support\Collection<string, PlayConfigItem> $currentItems
|
||||
* @param \Illuminate\Support\Collection<int, PlayConfigItem> $nextItems
|
||||
*/
|
||||
private function broadcastToggleDiffs(\Illuminate\Support\Collection $currentItems, \Illuminate\Support\Collection $nextItems): void
|
||||
{
|
||||
foreach ($nextItems as $next) {
|
||||
$current = $currentItems->get($next->play_code);
|
||||
if ($current === null || (bool) $current->is_enabled === (bool) $next->is_enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->hallRealtime->notifyPlayToggle(
|
||||
(string) $next->play_code,
|
||||
(bool) $next->is_enabled,
|
||||
'play config version published',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteVersion(PlayConfigVersion $version, AdminUser $admin, ?Request $request = null): void
|
||||
{
|
||||
$before = $this->snapshotVersion($version);
|
||||
|
||||
Reference in New Issue
Block a user