diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index b0e9c258..0acc8414 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -66,17 +66,6 @@ use Throwable; class Pages extends Controller { - /** @var list 快递签署页当前可选的合作方名称 */ - private const AGREEMENT_COURIER_NAMES = [ - '新北中通', - '新北中通其他', - '新德邦快递', - '睢宁中通', - '武进极兔', - '沭阳德邦', - '常州圆通其他', - ]; - private const EDGE_BANDING_SOURCE = 'jiansun'; private const INVENTORY_SOURCE = 'jiansun'; @@ -390,6 +379,8 @@ class Pages extends Controller $tabValue = null; $tabColumn = null; $upstreamError = null; + $agreementCourierNames = $this->agreementCourierNames($page['slug'] ?? null); + $agreementCourierAccounts = $this->agreementCourierAccounts($page['slug'] ?? null, $agreementCourierNames); if (($section['slug'] ?? null) === 'product-inventory' && ($page['slug'] ?? null) === 'inventory-report') { [$rows, $upstreamError] = $this->inventoryReportRows(); @@ -437,7 +428,8 @@ class Pages extends Controller 'agreementTasks' => $this->agreementTasks($page['slug']), 'agreementQuoteSignatures' => $this->agreementQuoteSignatures($page['slug']), 'agreementSubjects' => $this->agreementSubjects($page['slug']), - 'agreementCourierAccounts' => $this->agreementCourierAccounts($page['slug']), + 'agreementCourierNames' => $agreementCourierNames, + 'agreementCourierAccounts' => $agreementCourierAccounts, 'agreementQuoteVersions' => $this->agreementQuoteVersions($page['slug']), ]; } @@ -494,7 +486,8 @@ class Pages extends Controller 'agreementTasks' => $this->agreementTasks($page['slug'] ?? null), 'agreementQuoteSignatures' => $this->agreementQuoteSignatures($page['slug'] ?? null), 'agreementSubjects' => $this->agreementSubjects($page['slug'] ?? null), - 'agreementCourierAccounts' => $this->agreementCourierAccounts($page['slug'] ?? null), + 'agreementCourierNames' => $agreementCourierNames, + 'agreementCourierAccounts' => $agreementCourierAccounts, 'agreementQuoteVersions' => $this->agreementQuoteVersions($page['slug'] ?? null), ]; } @@ -607,15 +600,32 @@ class Pages extends Controller ); } + protected function agreementCourierNames(?string $page): Collection + { + if ($page !== 'agreement-signing') { + return collect(); + } + + try { + return collect($this->courierInformation->names()); + } catch (Throwable $exception) { + // 快递镜像不可用时仍允许打开签署页,并明确展示暂无可选资料。 + report($exception); + return collect(); + } + } + /** @return array */ - protected function agreementCourierAccounts(?string $page): array + protected function agreementCourierAccounts(?string $page, ?Collection $courierNames = null): array { if ($page !== 'agreement-signing') { return []; } try { - return $this->courierInformation->signingAccountsByName(self::AGREEMENT_COURIER_NAMES); + return $this->courierInformation->signingAccountsByName( + ($courierNames ?? $this->agreementCourierNames($page))->values()->all(), + ); } catch (Throwable $exception) { // 快递镜像不可用时仍可手工填写 E 签宝账号,不能阻断签署页。 report($exception); diff --git a/modules/EcommerceFinance/Repositories/CourierInformationMirrorRepository.php b/modules/EcommerceFinance/Repositories/CourierInformationMirrorRepository.php index 068afcf2..4d14024b 100644 --- a/modules/EcommerceFinance/Repositories/CourierInformationMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/CourierInformationMirrorRepository.php @@ -112,6 +112,30 @@ class CourierInformationMirrorRepository return ['data' => $rows, 'total' => $total]; } + /** + * 快递资料中的去重快递公司名称,按资料 Id 的首次出现顺序返回。 + * + * @return list + */ + public function names(): array + { + if (! $this->ready()) { + throw new RuntimeException('business_mirror_dataset_not_ready'); + } + + return $this->connection + ->table($this->dataset()->targetTable()) + ->select(['Id', 'expname']) + ->whereNotNull('expname') + ->orderBy('Id') + ->get() + ->map(static fn ($row): string => trim((string) ($row->expname ?? ''))) + ->filter(static fn (string $name): bool => $name !== '') + ->unique() + ->values() + ->all(); + } + /** * @param array $filters * @return \Generator diff --git a/resources/views/business/pages/courier-payables/agreement-signing.blade.php b/resources/views/business/pages/courier-payables/agreement-signing.blade.php index 1bd3aabe..219c2dc9 100644 --- a/resources/views/business/pages/courier-payables/agreement-signing.blade.php +++ b/resources/views/business/pages/courier-payables/agreement-signing.blade.php @@ -1,9 +1,9 @@ @php($agreementTasks = $agreementTasks ?? collect()) @php($agreementQuoteSignatures = $agreementQuoteSignatures ?? collect()) @php($agreementSubjects = $agreementSubjects ?? collect()) +@php($agreementCourierNames = collect($agreementCourierNames ?? [])) @php($agreementCourierAccounts = $agreementCourierAccounts ?? []) @php($agreementQuoteVersions = $agreementQuoteVersions ?? collect()) -@php($agreementCourierNames = collect(['新北中通', '新北中通其他', '新德邦快递', '睢宁中通', '武进极兔', '沭阳德邦', '常州圆通其他'])->merge($agreementQuoteVersions->pluck('carrier_name'))->filter()->unique()->values()) @php($agreementCooperationSecondaryEsignAccount = '18052733960') @php($agreementDefaultSubject = $agreementSubjects->firstWhere('is_default', true) ?: $agreementSubjects->first()) @php($agreementCompanyName = $agreementDefaultSubject?->name ?: company()?->name ?: '当前公司') @@ -1370,6 +1370,9 @@