Files
lotteryLaravel/app/Services/Draw/DrawAdminActionService.php
kang c8c90e3e94 feat: 增强奖池与钱包管理功能
更新 AdminJackpotPoolUpdateController 校验规则,禁止传入 current_amount。
优化 AdminRiskPoolManualStatusController:更新奖池状态后同步 Redis 状态。
在 TransferOrderReconcileController 中新增 completeCredit 方法,用于处理卡住的转账订单对账。
调整 TransferOrderListController:优化转账订单处理条件。
在 TicketItemsIndexController 中实现支持时区的日期筛选,提升日期处理准确性。
扩展 JackpotPool 模型,新增 adjustments 关联关系。
改进票据与钱包相关服务中的错误处理和事务管理。
2026-05-26 14:58:41 +08:00

58 lines
1.8 KiB
PHP

<?php
namespace App\Services\Draw;
use App\Models\Draw;
use App\Lottery\DrawStatus;
use Illuminate\Support\Facades\DB;
final class DrawAdminActionService
{
public function __construct(
private readonly DrawCancelBetRefundService $cancelBetRefund,
) {}
public function manualClose(Draw $draw): Draw
{
return DB::transaction(function () use ($draw): Draw {
/** @var Draw $locked */
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
if (! in_array($locked->status, [DrawStatus::Open->value, DrawStatus::Pending->value], true)) {
throw new \RuntimeException('draw_not_closeable');
}
$locked->forceFill([
'status' => DrawStatus::Closing->value,
'close_time' => now(),
])->save();
return $locked->refresh();
});
}
public function cancelBeforeResult(Draw $draw): Draw
{
return DB::transaction(function () use ($draw): Draw {
/** @var Draw $locked */
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
if (! in_array($locked->status, [
DrawStatus::Pending->value,
DrawStatus::Open->value,
DrawStatus::Closing->value,
DrawStatus::Closed->value,
], true)) {
throw new \RuntimeException('draw_not_cancelable');
}
if ($locked->resultBatches()->exists()) {
throw new \RuntimeException('draw_result_exists');
}
$this->cancelBetRefund->refundOpenBetsForDraw($locked);
$locked->forceFill(['status' => DrawStatus::Cancelled->value])->save();
return $locked->refresh();
});
}
}