feat: 拆分开奖与结算审核流程,新增手动结果录入、重开和派彩审批接口
This commit is contained in:
51
app/Services/Draw/DrawAdminActionService.php
Normal file
51
app/Services/Draw/DrawAdminActionService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Lottery\DrawStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class DrawAdminActionService
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
$locked->forceFill(['status' => DrawStatus::Cancelled->value])->save();
|
||||
|
||||
return $locked->refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user