feat: 添加结算功能,更新 TicketItem 模型以支持最新结算详情,增强 DrawTickService 以自动处理结算,更新 TicketWalletService 以支持派彩入账,扩展 API 路由以管理结算批次和奖池
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SettlementBatch;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/settlement-batches — 结算批次分页列表。
|
||||
*/
|
||||
final class AdminSettlementBatchIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
|
||||
$page = max((int) $request->integer('page', 1), 1);
|
||||
$drawNo = trim((string) $request->query('draw_no', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
|
||||
$q = SettlementBatch::query()
|
||||
->with(['draw:id,draw_no'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($drawNo !== '') {
|
||||
$q->whereHas('draw', fn ($d) => $d->where('draw_no', 'like', '%'.$drawNo.'%'));
|
||||
}
|
||||
|
||||
if ($status !== '') {
|
||||
$q->where('status', $status);
|
||||
}
|
||||
|
||||
$paginator = $q->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
return ApiResponse::success([
|
||||
'items' => collect($paginator->items())->map(fn (SettlementBatch $b) => $this->row($b))->all(),
|
||||
'meta' => [
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'total' => $paginator->total(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function row(SettlementBatch $b): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $b->id,
|
||||
'draw_id' => (int) $b->draw_id,
|
||||
'draw_no' => $b->draw?->draw_no,
|
||||
'result_batch_id' => (int) $b->result_batch_id,
|
||||
'settle_version' => (int) $b->settle_version,
|
||||
'status' => $b->status,
|
||||
'total_ticket_count' => (int) $b->total_ticket_count,
|
||||
'total_win_count' => (int) $b->total_win_count,
|
||||
'total_payout_amount' => (int) $b->total_payout_amount,
|
||||
'total_jackpot_payout_amount' => (int) $b->total_jackpot_payout_amount,
|
||||
'started_at' => $b->started_at?->toIso8601String(),
|
||||
'finished_at' => $b->finished_at?->toIso8601String(),
|
||||
'created_at' => $b->created_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user