CaiWuXiTong/modules/EcommerceFinance/Services/SupplierStatementUploadEligibility.php
苏木 bb2082730b feat(供应商对账): 按结算方式排除无需上传厂家
结算方式为订单合同或现结的厂家不再计入未上传进度,也不发送群催办。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-12-04 17:13:51 +08:00

77 lines
2.8 KiB
PHP

<?php
namespace Modules\EcommerceFinance\Services;
use Modules\EcommerceFinance\Repositories\SupplierStatementSettlementRepository;
class SupplierStatementUploadEligibility
{
public function __construct(
private readonly SupplierStatementSettlementRepository $settlements,
) {
}
/**
* 将厂家分为需要上传对账单和无需上传两组。
*
* 结算方式为“订单合同”或“现结”的厂家无需上传;结算资料尚未覆盖的
* 已知厂家由配置兜底,避免历史数据缺失导致误催办。
*
* @param list<string> $suppliers
* @return array{
* required:list<string>,
* exempt:list<string>,
* exempt_reasons:array<string,string>,
* settlement_methods:array<string,string>
* }
*/
public function classify(array $suppliers, string $month): array
{
$suppliers = array_values(array_unique(array_filter(
array_map(static fn (mixed $supplier): string => trim((string) $supplier), $suppliers),
static fn (string $supplier): bool => $supplier !== '',
)));
$knownExempt = array_fill_keys(array_values(array_filter(array_map(
static fn (mixed $supplier): string => trim((string) $supplier),
(array) config('supplier_reconciliation.statement_upload_exempt_suppliers', []),
))), true);
$exemptMethods = array_fill_keys(array_values(array_filter(array_map(
static fn (mixed $method): string => trim((string) $method),
(array) config('supplier_reconciliation.statement_upload_exempt_settlement_methods', []),
))), true);
$settlements = $this->settlements->latestMethods($suppliers, $month);
$required = [];
$exempt = [];
$exemptReasons = [];
$settlementMethods = [];
foreach ($suppliers as $supplier) {
$settlement = $settlements[$supplier] ?? [];
$method = trim((string) ($settlement['settlement_method'] ?? ''));
if ($method !== '') {
$settlementMethods[$supplier] = $method;
}
if (isset($knownExempt[$supplier])) {
$exempt[] = $supplier;
$exemptReasons[$supplier] = '已知无需上传对账单';
} elseif ($method !== '' && isset($exemptMethods[$method])) {
$exempt[] = $supplier;
$exemptReasons[$supplier] = $method;
} else {
$required[] = $supplier;
}
}
sort($required, SORT_NATURAL | SORT_FLAG_CASE);
sort($exempt, SORT_NATURAL | SORT_FLAG_CASE);
return [
'required' => $required,
'exempt' => $exempt,
'exempt_reasons' => $exemptReasons,
'settlement_methods' => $settlementMethods,
];
}
}