feat: 增强管理员权限管理,添加 RBAC 支持,更新 AdminUser 模型以处理角色和权限,更新登录接口返回权限信息,扩展数据库填充器以同步角色权限
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Draw;
|
||||
use App\Models\SettlementBatch;
|
||||
use App\Models\TicketItem;
|
||||
use App\Models\TicketOrder;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/draws/{draw}/finance-summary — 单期投注/派彩汇总(客服/财务视角,PRD §15.4)。
|
||||
*
|
||||
* 口径:以订单实扣汇总为「当期投注」;以注项中奖+Jackpot 为「当期派彩」;差额为近似毛损益(不含回水等细项)。
|
||||
*/
|
||||
final class AdminDrawFinanceSummaryController extends Controller
|
||||
{
|
||||
public function __invoke(Draw $draw): JsonResponse
|
||||
{
|
||||
$drawId = (int) $draw->id;
|
||||
|
||||
$totalBetMinor = (int) TicketOrder::query()->where('draw_id', $drawId)->sum('total_actual_deduct');
|
||||
$orderCount = (int) TicketOrder::query()->where('draw_id', $drawId)->count();
|
||||
$itemCount = (int) TicketItem::query()->where('draw_id', $drawId)->count();
|
||||
|
||||
$currencyCode = (string) (TicketOrder::query()
|
||||
->where('draw_id', $drawId)
|
||||
->value('currency_code') ?? '');
|
||||
|
||||
$totalWinMinor = (int) TicketItem::query()->where('draw_id', $drawId)->sum('win_amount');
|
||||
$totalJackpotWinMinor = (int) TicketItem::query()->where('draw_id', $drawId)->sum('jackpot_win_amount');
|
||||
$totalPayoutMinor = $totalWinMinor + $totalJackpotWinMinor;
|
||||
$approxHouseGrossMinor = $totalBetMinor - $totalPayoutMinor;
|
||||
|
||||
$batches = SettlementBatch::query()
|
||||
->where('draw_id', $drawId)
|
||||
->orderByDesc('id')
|
||||
->limit(30)
|
||||
->get(['id', 'status', 'total_ticket_count', 'total_win_count', 'total_payout_amount', 'total_jackpot_payout_amount', 'finished_at']);
|
||||
|
||||
$batchRows = $batches->map(static function (SettlementBatch $b): array {
|
||||
return [
|
||||
'id' => (int) $b->id,
|
||||
'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,
|
||||
'finished_at' => $b->finished_at?->toIso8601String(),
|
||||
];
|
||||
})->values()->all();
|
||||
|
||||
return ApiResponse::success([
|
||||
'draw_id' => $drawId,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'draw_status' => $draw->status,
|
||||
'currency_code' => $currencyCode !== '' ? $currencyCode : null,
|
||||
'order_count' => $orderCount,
|
||||
'ticket_item_count' => $itemCount,
|
||||
'total_bet_minor' => $totalBetMinor,
|
||||
'total_win_payout_minor' => $totalWinMinor,
|
||||
'total_jackpot_win_minor' => $totalJackpotWinMinor,
|
||||
'total_payout_minor' => $totalPayoutMinor,
|
||||
'approx_house_gross_minor' => $approxHouseGrossMinor,
|
||||
'settlement_batches' => $batchRows,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user