- Added new section in AGENTS.md detailing learned workspace facts for better understanding of settlement processes. - Updated AgentNodeDestroyController to remove unnecessary checks for admin users. - Enhanced AgentSettlement controllers to assert permissions for finance adjustments and bill operations. - Improved query scopes in AgentSettlement services to ensure proper data access based on admin roles. - Refactored methods in SettlementPartyEnrichment for better bill row enrichment and data handling. - Introduced new methods in AdminAgentSettlementScope for managing agent node visibility and finance adjustments.
62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\AgentSettlement;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\AdminAgentSettlementScope;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class AgentSettlementPaymentIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$admin = $request->lotteryAdmin();
|
|
abort_if($admin === null, 401);
|
|
|
|
$periodId = (int) $request->query('settlement_period_id', 0);
|
|
$adminSiteId = (int) $request->query('admin_site_id', 0);
|
|
|
|
$query = DB::table('payment_records as pr')
|
|
->join('settlement_bills as sb', 'sb.id', '=', 'pr.settlement_bill_id')
|
|
->join('settlement_periods as sp', 'sp.id', '=', 'sb.settlement_period_id')
|
|
->select([
|
|
'pr.*',
|
|
'sb.bill_type',
|
|
'sb.owner_type',
|
|
'sb.owner_id',
|
|
'sb.counterparty_type',
|
|
'sb.counterparty_id',
|
|
'sp.period_start',
|
|
'sp.period_end',
|
|
'sp.admin_site_id',
|
|
])
|
|
->orderByDesc('pr.id');
|
|
|
|
if ($periodId > 0) {
|
|
$query->where('sb.settlement_period_id', $periodId);
|
|
}
|
|
|
|
if ($adminSiteId > 0) {
|
|
$query->where('sp.admin_site_id', $adminSiteId);
|
|
}
|
|
|
|
$siteIds = $admin->accessibleAdminSiteIds();
|
|
if ($siteIds !== null) {
|
|
if ($siteIds === []) {
|
|
$query->whereRaw('0 = 1');
|
|
} else {
|
|
$query->whereIn('sp.admin_site_id', $siteIds);
|
|
}
|
|
}
|
|
|
|
AdminAgentSettlementScope::applyDirectEdgeScopeToBillsQuery($query, $admin, 'sb');
|
|
|
|
return ApiResponse::success([
|
|
'items' => $query->limit(200)->get(),
|
|
]);
|
|
}
|
|
}
|