- 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.
77 lines
2.7 KiB
PHP
77 lines
2.7 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\Database\Query\Builder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class AgentSettlementAdjustmentIndexController 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);
|
|
$adjustmentType = trim((string) $request->query('adjustment_type', ''));
|
|
|
|
$query = DB::table('settlement_adjustments as sa')
|
|
->leftJoin('settlement_periods as sp', 'sp.id', '=', 'sa.settlement_period_id')
|
|
->leftJoin('settlement_bills as sb', 'sb.id', '=', 'sa.original_bill_id')
|
|
->select([
|
|
'sa.*',
|
|
'sp.period_start',
|
|
'sp.period_end',
|
|
'sp.admin_site_id',
|
|
'sb.bill_type as original_bill_type',
|
|
'sb.owner_type as original_owner_type',
|
|
'sb.owner_id as original_owner_id',
|
|
])
|
|
->orderByDesc('sa.id');
|
|
|
|
if ($periodId > 0) {
|
|
$query->where('sa.settlement_period_id', $periodId);
|
|
}
|
|
|
|
if ($adminSiteId > 0) {
|
|
$query->where('sp.admin_site_id', $adminSiteId);
|
|
}
|
|
|
|
if ($adjustmentType !== '') {
|
|
$query->where('sa.adjustment_type', $adjustmentType);
|
|
}
|
|
|
|
$siteIds = $admin->accessibleAdminSiteIds();
|
|
if ($siteIds !== null) {
|
|
if ($siteIds === []) {
|
|
$query->whereRaw('0 = 1');
|
|
} else {
|
|
$query->whereIn('sp.admin_site_id', $siteIds);
|
|
}
|
|
}
|
|
|
|
$actorId = AdminAgentSettlementScope::boundAgentNodeId($admin);
|
|
if ($actorId !== null) {
|
|
$query->where(function (Builder $outer) use ($admin): void {
|
|
$outer->whereNull('sa.original_bill_id')
|
|
->orWhereExists(function (Builder $exists) use ($admin): void {
|
|
$exists->selectRaw('1')
|
|
->from('settlement_bills as sb')
|
|
->whereColumn('sb.id', 'sa.original_bill_id');
|
|
AdminAgentSettlementScope::applyDirectEdgeScopeToBillsQuery($exists, $admin, 'sb');
|
|
});
|
|
});
|
|
}
|
|
|
|
return ApiResponse::success([
|
|
'items' => $query->limit(200)->get(),
|
|
]);
|
|
}
|
|
}
|