feat: 拆分开奖与结算审核流程,新增手动结果录入、重开和派彩审批接口
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Lottery\DrawStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Draw\DrawRngRunner;
|
||||
|
||||
final class DrawRngRunController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DrawRngRunner $rng,
|
||||
) {}
|
||||
|
||||
public function __invoke(Draw $draw): JsonResponse
|
||||
{
|
||||
try {
|
||||
$batch = DB::transaction(function () use ($draw) {
|
||||
/** @var Draw $locked */
|
||||
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
|
||||
if ($locked->status !== DrawStatus::Closed->value || $locked->resultBatches()->exists()) {
|
||||
throw new \RuntimeException('draw_not_runnable');
|
||||
}
|
||||
|
||||
return $this->rng->executeLocked($locked);
|
||||
});
|
||||
} catch (\RuntimeException) {
|
||||
return ApiResponse::error(trans('api.client_error'), ErrorCode::ClientHttpError->value, null, 409);
|
||||
}
|
||||
|
||||
$draw->refresh();
|
||||
|
||||
return ApiResponse::success([
|
||||
'draw_no' => $draw->draw_no,
|
||||
'status' => $draw->status,
|
||||
'batch' => [
|
||||
'id' => (int) $batch->id,
|
||||
'result_version' => (int) $batch->result_version,
|
||||
'source_type' => $batch->source_type,
|
||||
'status' => $batch->status,
|
||||
'items_count' => $batch->items()->count(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user