feat: 增强代理结算和账单管理功能

- 在多个控制器中引入 SettlementPartyEnrichment 服务,以优化代理结算和账单的处理逻辑。
- 更新 AgentSettlementBillIndexController 和 AgentSettlementBillShowController,支持根据账单 ID 和关键字进行查询。
- 在 AgentSettlementPeriodCloseController 中添加对站点管理权限的验证,确保只有具备相应权限的管理员能够关闭账期。
- 在 AgentSettlementPeriodIndexController 中更新账期数据的返回格式,提升数据的完整性和可用性。
- 引入对相对占成比例的支持,增强代理资料的管理能力,确保数据一致性。
This commit is contained in:
2026-06-05 18:00:56 +08:00
parent a44679665d
commit 2d32f006c5
63 changed files with 4893 additions and 288 deletions

View File

@@ -2,22 +2,35 @@
namespace App\Services\AgentSettlement;
use App\Support\AgentSettlementPeriodWindow;
use Illuminate\Support\Facades\DB;
final class UnsettledTicketPeriodWarning
{
/**
* 未结算注单优先按游戏结算落账时间settled_at归属账期未开奖仍按下注时间created_at
*
* @return array{count: int, ticket_item_ids: list<int>}
*/
public function countForSite(int $adminSiteId, string $periodStart, string $periodEnd): array
{
$siteCode = (string) DB::table('admin_sites')->where('id', $adminSiteId)->value('code');
[$start, $end] = AgentSettlementPeriodWindow::boundStrings($periodStart, $periodEnd);
$rows = DB::table('ticket_items as ti')
->join('players as p', 'p.id', '=', 'ti.player_id')
->where('p.site_code', $siteCode)
->whereIn('ti.status', ['pending_draw', 'pending_confirm', 'pending_payout'])
->whereBetween('ti.created_at', [$periodStart, $periodEnd])
->whereNull('ti.agent_settled_at')
->where(function ($query) use ($start, $end): void {
$query->where(function ($settled) use ($start, $end): void {
$settled->whereNotNull('ti.settled_at')
->whereBetween('ti.settled_at', [$start, $end]);
})->orWhere(function ($pending) use ($start, $end): void {
$pending->whereNull('ti.settled_at')
->whereBetween('ti.created_at', [$start, $end]);
});
})
->pluck('ti.id')
->map(fn ($id): int => (int) $id)
->all();