feat: 添加结算功能,更新 TicketItem 模型以支持最新结算详情,增强 DrawTickService 以自动处理结算,更新 TicketWalletService 以支持派彩入账,扩展 API 路由以管理结算批次和奖池
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SettlementBatch;
|
||||
use App\Models\TicketSettlementDetail;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/settlement-batches/{batch}/details — 该批次下注单结算明细分页。
|
||||
*/
|
||||
final class AdminSettlementBatchDetailsController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, SettlementBatch $batch): JsonResponse
|
||||
{
|
||||
$perPage = min(max((int) $request->integer('per_page', 25), 1), 100);
|
||||
$page = max((int) $request->integer('page', 1), 1);
|
||||
|
||||
$paginator = TicketSettlementDetail::query()
|
||||
->where('settlement_batch_id', $batch->id)
|
||||
->with([
|
||||
'ticketItem:id,ticket_no,play_code,player_id',
|
||||
'ticketItem.player:id,username,site_player_id',
|
||||
])
|
||||
->orderBy('id')
|
||||
->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
return ApiResponse::success([
|
||||
'batch_id' => (int) $batch->id,
|
||||
'items' => collect($paginator->items())->map(function ($row) {
|
||||
/** @var TicketSettlementDetail $row */
|
||||
$item = $row->ticketItem;
|
||||
$player = $item?->player;
|
||||
|
||||
return [
|
||||
'id' => (int) $row->id,
|
||||
'ticket_item_id' => (int) $row->ticket_item_id,
|
||||
'ticket_no' => $item?->ticket_no,
|
||||
'play_code' => $item?->play_code,
|
||||
'player_id' => $item?->player_id,
|
||||
'player_username' => $player?->username,
|
||||
'site_player_id' => $player?->site_player_id,
|
||||
'matched_prize_tier' => $row->matched_prize_tier,
|
||||
'win_amount' => (int) $row->win_amount,
|
||||
'jackpot_allocation_amount' => (int) $row->jackpot_allocation_amount,
|
||||
'match_detail_json' => $row->match_detail_json,
|
||||
'created_at' => $row->created_at?->toIso8601String(),
|
||||
];
|
||||
})->all(),
|
||||
'meta' => [
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'total' => $paginator->total(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/settlement-batches/{batch} — 单批次摘要。
|
||||
*/
|
||||
final class AdminSettlementBatchShowController extends Controller
|
||||
{
|
||||
public function __invoke(SettlementBatch $batch): JsonResponse
|
||||
{
|
||||
$batch->load(['draw:id,draw_no,business_date,status', 'resultBatch:id,result_version,status']);
|
||||
|
||||
return ApiResponse::success([
|
||||
'id' => (int) $batch->id,
|
||||
'draw_id' => (int) $batch->draw_id,
|
||||
'draw_no' => $batch->draw?->draw_no,
|
||||
'draw_status' => $batch->draw?->status,
|
||||
'result_batch_id' => (int) $batch->result_batch_id,
|
||||
'result_batch_version' => $batch->resultBatch?->result_version,
|
||||
'result_batch_status' => $batch->resultBatch?->status,
|
||||
'settle_version' => (int) $batch->settle_version,
|
||||
'status' => $batch->status,
|
||||
'total_ticket_count' => (int) $batch->total_ticket_count,
|
||||
'total_win_count' => (int) $batch->total_win_count,
|
||||
'total_payout_amount' => (int) $batch->total_payout_amount,
|
||||
'total_jackpot_payout_amount' => (int) $batch->total_jackpot_payout_amount,
|
||||
'started_at' => $batch->started_at?->toIso8601String(),
|
||||
'finished_at' => $batch->finished_at?->toIso8601String(),
|
||||
'created_at' => $batch->created_at?->toIso8601String(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user