feat: 增强代理结算和账单管理功能
- 在多个控制器中引入 SettlementPartyEnrichment 服务,以优化代理结算和账单的处理逻辑。 - 更新 AgentSettlementBillIndexController 和 AgentSettlementBillShowController,支持根据账单 ID 和关键字进行查询。 - 在 AgentSettlementPeriodCloseController 中添加对站点管理权限的验证,确保只有具备相应权限的管理员能够关闭账期。 - 在 AgentSettlementPeriodIndexController 中更新账期数据的返回格式,提升数据的完整性和可用性。 - 引入对相对占成比例的支持,增强代理资料的管理能力,确保数据一致性。
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin\AgentSettlement;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\AgentSettlement\SettlementPartyEnrichment;
|
||||
use App\Support\AdminAgentSettlementScope;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -11,6 +12,10 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class AgentSettlementBillShowController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SettlementPartyEnrichment $partyEnrichment,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request, int $settlement_bill): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
@@ -30,6 +35,35 @@ final class AgentSettlementBillShowController extends Controller
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
$agentIds = $rebateAllocations
|
||||
->filter(static fn (object $row): bool => (string) $row->participant_type === 'agent')
|
||||
->pluck('participant_id')
|
||||
->map(static fn ($id): int => (int) $id)
|
||||
->filter(static fn (int $id): bool => $id > 0)
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
$agents = $this->partyEnrichment->loadAgents($agentIds);
|
||||
$rebateAllocations = $rebateAllocations
|
||||
->map(function (object $row) use ($agents): array {
|
||||
$type = (string) $row->participant_type;
|
||||
$id = (int) $row->participant_id;
|
||||
|
||||
return [
|
||||
'id' => (int) $row->id,
|
||||
'rebate_record_id' => (int) $row->rebate_record_id,
|
||||
'settlement_bill_id' => (int) $row->settlement_bill_id,
|
||||
'participant_type' => $type,
|
||||
'participant_id' => $id,
|
||||
'participant_label' => $this->partyEnrichment->formatCounterpartyLabel($type, $id, $agents),
|
||||
'actual_share_rate' => (float) $row->actual_share_rate,
|
||||
'allocated_amount' => (int) $row->allocated_amount,
|
||||
'allocation_rule' => (string) $row->allocation_rule,
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$adjustments = DB::table('settlement_adjustments')
|
||||
->where('original_bill_id', $settlement_bill)
|
||||
->orderByDesc('id')
|
||||
|
||||
Reference in New Issue
Block a user