fix: use courier information names for agreement signing

This commit is contained in:
limeng 2026-09-23 16:16:28 +08:00
parent cdff51bd7a
commit d413c762b4
5 changed files with 92 additions and 16 deletions

View File

@ -66,17 +66,6 @@ use Throwable;
class Pages extends Controller
{
/** @var list<string> 快递签署页当前可选的合作方名称 */
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<string,string> */
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);

View File

@ -112,6 +112,30 @@ class CourierInformationMirrorRepository
return ['data' => $rows, 'total' => $total];
}
/**
* 快递资料中的去重快递公司名称,按资料 Id 的首次出现顺序返回。
*
* @return list<string>
*/
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<string,string> $filters
* @return \Generator<int,object>

View File

@ -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 @@
<label for="agreement-courier">快递公司 <span class="agreement-required" aria-hidden="true">*</span></label>
<select class="agreement-control" id="agreement-courier" name="courier_name" data-courier-select required>
<option value="">请选择</option>
@if ($agreementCourierNames->isEmpty())
<option value="" disabled>暂无可选快递资料</option>
@endif
@foreach ($agreementCourierNames as $courierName)
<option value="{{ $courierName }}" data-esign-account="{{ $agreementCourierAccounts[$courierName] ?? '' }}">{{ $courierName }}</option>
@endforeach

View File

@ -9,6 +9,8 @@ use App\Models\Business\CourierQuoteSignature;
use App\Models\Business\CourierQuoteVersion;
use App\Services\Esign\EsignClient;
use Illuminate\Support\Facades\DB;
use Mockery;
use Modules\EcommerceFinance\Repositories\CourierInformationMirrorRepository;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tests\Feature\FeatureTestCase;
@ -95,6 +97,32 @@ class AgreementSigningPageTest extends FeatureTestCase
->assertSeeText('收款帐户资料证明');
}
public function testAgreementSigningPageUsesCourierNamesFromCourierInformation(): void
{
$this->grantWorkspaceAccess();
$courierInformation = Mockery::mock(CourierInformationMirrorRepository::class);
$courierInformation->shouldReceive('names')
->once()
->andReturn(['顺丰', '韵达']);
$courierInformation->shouldReceive('signingAccountsByName')
->once()
->with(['顺丰', '韵达'])
->andReturn(['顺丰' => '13800000001']);
$this->app->instance(CourierInformationMirrorRepository::class, $courierInformation);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'courier-payables',
'page' => 'agreement-signing',
'agreement_view' => 'create',
]))
->assertOk()
->assertSee('<option value="顺丰" data-esign-account="13800000001">顺丰</option>', false)
->assertSee('<option value="韵达" data-esign-account="">韵达</option>', false)
->assertDontSee('<option value="新北中通"', false);
}
public function testAgreementSigningPageShowsOurCompanyAsInitiator(): void
{
$this->grantWorkspaceAccess();

View File

@ -125,6 +125,17 @@ class CourierInformationMirrorRepositoryTest extends TestCase
$this->assertSame(['常州圆通其他' => '13800000001'], $accounts);
}
public function test_it_returns_distinct_non_empty_courier_names_from_mirror_data(): void
{
$this->markReady(4);
$this->insertExpress(1, ['expname' => '顺丰']);
$this->insertExpress(2, ['expname' => '']);
$this->insertExpress(3, ['expname' => '顺丰']);
$this->insertExpress(4, ['expname' => '韵达']);
$this->assertSame(['顺丰', '韵达'], $this->repository->names());
}
private function createExpressTable(): void
{
Schema::connection('business_mirror')->create('js_wp_express', function (Blueprint $table): void {