feat: 增强代理结算和账单管理功能
- 在多个控制器中引入 SettlementPartyEnrichment 服务,以优化代理结算和账单的处理逻辑。 - 更新 AgentSettlementBillIndexController 和 AgentSettlementBillShowController,支持根据账单 ID 和关键字进行查询。 - 在 AgentSettlementPeriodCloseController 中添加对站点管理权限的验证,确保只有具备相应权限的管理员能够关闭账期。 - 在 AgentSettlementPeriodIndexController 中更新账期数据的返回格式,提升数据的完整性和可用性。 - 引入对相对占成比例的支持,增强代理资料的管理能力,确保数据一致性。
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Services\AgentSettlement;
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use App\Support\AdminAgentSettlementScope;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@@ -10,19 +12,26 @@ final class AgentSettlementPeriodSummaryService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AgentSettlementPeriodPipelineService $pipelineService,
|
||||
private readonly ShareLedgerScopedProfitAggregator $scopedProfitAggregator,
|
||||
) {}
|
||||
/**
|
||||
* @param list<int> $periodIds
|
||||
* @return array<int, array<string, int>>
|
||||
*/
|
||||
public function summariesForPeriodIds(array $periodIds): array
|
||||
public function summariesForPeriodIds(array $periodIds, ?AdminUser $admin = null): array
|
||||
{
|
||||
if ($periodIds === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = DB::table('settlement_bills')
|
||||
->whereIn('settlement_period_id', $periodIds)
|
||||
$query = DB::table('settlement_bills')
|
||||
->whereIn('settlement_period_id', $periodIds);
|
||||
|
||||
if ($admin !== null) {
|
||||
AdminAgentSettlementScope::applySubtreeToBillsQuery($query, $admin);
|
||||
}
|
||||
|
||||
$rows = $query
|
||||
->groupBy('settlement_period_id')
|
||||
->selectRaw('settlement_period_id')
|
||||
->selectRaw("SUM(CASE WHEN bill_type = 'player' THEN 1 ELSE 0 END) as player_bills")
|
||||
@@ -32,6 +41,7 @@ final class AgentSettlementPeriodSummaryService
|
||||
->selectRaw("SUM(CASE WHEN status IN ('confirmed', 'partial_paid', 'overdue') AND unpaid_amount > 0 THEN 1 ELSE 0 END) as awaiting_payment")
|
||||
->selectRaw("SUM(CASE WHEN status = 'settled' THEN 1 ELSE 0 END) as settled")
|
||||
->selectRaw('COALESCE(SUM(unpaid_amount), 0) as total_unpaid')
|
||||
->selectRaw('COALESCE(SUM(net_amount), 0) as total_net')
|
||||
->get();
|
||||
|
||||
$out = [];
|
||||
@@ -45,6 +55,7 @@ final class AgentSettlementPeriodSummaryService
|
||||
'awaiting_payment' => (int) $row->awaiting_payment,
|
||||
'settled' => (int) $row->settled,
|
||||
'total_unpaid' => (int) $row->total_unpaid,
|
||||
'total_net' => (int) $row->total_net,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,11 +66,11 @@ final class AgentSettlementPeriodSummaryService
|
||||
* @param Collection<int, object> $periods
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function attachToPeriodRows(Collection $periods): array
|
||||
public function attachToPeriodRows(Collection $periods, ?AdminUser $admin = null): array
|
||||
{
|
||||
$ids = $periods->pluck('id')->map(static fn ($id): int => (int) $id)->all();
|
||||
$summaries = $this->summariesForPeriodIds($ids);
|
||||
$pipelines = $this->pipelineService->countsForPeriods($periods);
|
||||
$summaries = $this->summariesForPeriodIds($ids, $admin);
|
||||
$pipelines = $this->pipelineService->countsForPeriods($periods, $admin);
|
||||
$empty = [
|
||||
'player_bills' => 0,
|
||||
'agent_bills' => 0,
|
||||
@@ -68,8 +79,17 @@ final class AgentSettlementPeriodSummaryService
|
||||
'awaiting_payment' => 0,
|
||||
'settled' => 0,
|
||||
'total_unpaid' => 0,
|
||||
'total_net' => 0,
|
||||
];
|
||||
$viewerScope = $this->scopedProfitAggregator->resolveViewer($admin)['scope'];
|
||||
$emptyPipeline = [
|
||||
'credit_ledger_count' => 0,
|
||||
'share_ledger_count' => 0,
|
||||
'game_win_loss_total' => 0,
|
||||
'win_loss_scope' => $viewerScope,
|
||||
'basic_rebate_total' => 0,
|
||||
'unsettled_ticket_count' => 0,
|
||||
];
|
||||
$emptyPipeline = ['credit_ledger_count' => 0, 'share_ledger_count' => 0];
|
||||
|
||||
$items = [];
|
||||
foreach ($periods as $period) {
|
||||
|
||||
Reference in New Issue
Block a user