- 在多个控制器中引入 SettlementPartyEnrichment 服务,以优化代理结算和账单的处理逻辑。 - 更新 AgentSettlementBillIndexController 和 AgentSettlementBillShowController,支持根据账单 ID 和关键字进行查询。 - 在 AgentSettlementPeriodCloseController 中添加对站点管理权限的验证,确保只有具备相应权限的管理员能够关闭账期。 - 在 AgentSettlementPeriodIndexController 中更新账期数据的返回格式,提升数据的完整性和可用性。 - 引入对相对占成比例的支持,增强代理资料的管理能力,确保数据一致性。
68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\AgentSettlement;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
final class AgentSettlementBillGuard
|
|
{
|
|
private const LOCKED_STATUSES = ['confirmed', 'partial_paid', 'settled', 'overdue', 'reversed'];
|
|
|
|
private const PAYABLE_STATUSES = ['confirmed', 'partial_paid', 'overdue'];
|
|
|
|
public function __construct(
|
|
private readonly AgentSettlementPeriodCompletionService $periodCompletion,
|
|
) {}
|
|
|
|
public function assertPeriodMutable(int $billId): void
|
|
{
|
|
$periodId = (int) DB::table('settlement_bills')->where('id', $billId)->value('settlement_period_id');
|
|
if ($this->periodCompletion->isPeriodReadOnly($periodId)) {
|
|
throw ValidationException::withMessages([
|
|
'period' => ['completed'],
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function assertNetAmountMutable(int $billId): void
|
|
{
|
|
$bill = DB::table('settlement_bills')->where('id', $billId)->first();
|
|
if ($bill === null) {
|
|
return;
|
|
}
|
|
|
|
if (in_array((string) $bill->status, self::LOCKED_STATUSES, true) || $bill->locked_at !== null) {
|
|
throw ValidationException::withMessages([
|
|
'bill' => ['locked'],
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function assertPayable(int $billId): void
|
|
{
|
|
$bill = DB::table('settlement_bills')->where('id', $billId)->first();
|
|
if ($bill === null) {
|
|
throw new \InvalidArgumentException('bill_not_found');
|
|
}
|
|
|
|
if (! in_array((string) $bill->status, self::PAYABLE_STATUSES, true)) {
|
|
throw ValidationException::withMessages([
|
|
'bill' => ['not_payable'],
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function markConfirmed(int $billId): void
|
|
{
|
|
$this->assertPeriodMutable($billId);
|
|
|
|
DB::table('settlement_bills')->where('id', $billId)->update([
|
|
'status' => 'confirmed',
|
|
'locked_at' => now(),
|
|
'confirmed_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|