feat: 协议签署归档列表按合作方类型筛选

This commit is contained in:
limeng 2026-11-24 18:38:29 +08:00
parent f75481633d
commit cd8c0511f2
4 changed files with 157 additions and 6 deletions

View File

@ -5245,6 +5245,16 @@ class Pages extends Controller
$query->where('document_type', $type);
}
$partnerType = $this->agreementFilterPartnerType();
if ($partnerType !== null) {
// Partner type is encrypted in the signing snapshot. Filter all
// candidates before pagination, reading only the fields needed.
$matchingIds = (clone $query)->select(['id', 'payload'])->lazyById(200)
->filter(static fn (CourierAgreementSignature $task): bool => $task->partnerType() === $partnerType)
->pluck('id')->all();
$query->whereIn('id', $matchingIds);
}
return $query
->latest('id')
->paginate(50, ['*'], 'agreement_task_page')->withQueryString();
@ -5295,6 +5305,17 @@ class Pages extends Controller
return in_array($scope, ['active', 'archived', 'all'], true) ? $scope : 'active';
}
protected function agreementFilterPartnerType(): ?string
{
if ($this->agreementFilterScope() !== 'archived') {
return null;
}
$partnerType = trim((string) request('agreement_partner_type', ''));
return in_array($partnerType, ['courier', 'supplier'], true) ? $partnerType : null;
}
protected function agreementSubjects(?string $page): Collection
{
if ($page !== 'agreement-signing') {
@ -5321,7 +5342,7 @@ class Pages extends Controller
try {
$type = $this->agreementFilterType();
if ($type !== null && $type !== 'quote-confirmation') {
if (($type !== null && $type !== 'quote-confirmation') || $this->agreementFilterPartnerType() === 'supplier') {
return collect();
}

View File

@ -87,7 +87,7 @@ class CourierAgreementSignature extends Model
'operator_account' => 'encrypted',
];
public function partnerTypeLabel(): string
public function partnerType(): string
{
// Records created before partner types were introduced are courier tasks.
try {
@ -97,7 +97,12 @@ class CourierAgreementSignature extends Model
$partnerType = 'courier';
}
return $partnerType === 'supplier' ? '供应商' : '快递公司';
return $partnerType === 'supplier' ? 'supplier' : 'courier';
}
public function partnerTypeLabel(): string
{
return $this->partnerType() === 'supplier' ? '供应商' : '快递公司';
}
/** Only completed archives with a readable courier snapshot belong to contract management. */

View File

@ -19,8 +19,10 @@
@php($agreementType = trim((string) request('agreement_type', '')))
@php($agreementScope = trim((string) request('agreement_scope', $agreementStatus === 'archived' ? 'archived' : 'active')))
@php($agreementScope = in_array($agreementScope, ['active', 'archived', 'all'], true) ? $agreementScope : 'active')
@php($agreementPartnerType = trim((string) request('agreement_partner_type', '')))
@php($agreementPartnerType = $agreementScope === 'archived' && in_array($agreementPartnerType, ['courier', 'supplier'], true) ? $agreementPartnerType : '')
@php($agreementPaymentPrefill = \App\Business\CourierProfileData::agreementPrefill(request('payment_account')))
@php($agreementFiltersActive = $agreementSearch !== '' || $agreementStatus !== '' || $agreementType !== '')
@php($agreementFiltersActive = $agreementSearch !== '' || $agreementStatus !== '' || $agreementType !== '' || $agreementPartnerType !== '')
<section class="agreement-workspace" aria-label="协议签署" data-agreement-signing>
<style>
@ -218,6 +220,10 @@
border-bottom: 1px solid var(--agreement-border);
}
.agreement-filter-bar--archived {
grid-template-columns: minmax(14rem, 1.4fr) repeat(3, minmax(8rem, 0.65fr)) auto auto;
}
.agreement-scope-bar {
display: flex;
flex-wrap: wrap;
@ -1360,7 +1366,7 @@
@endforeach
</nav>
<p class="agreement-form-error agreement-task-error" role="alert" data-task-load-error></p>
<form class="agreement-filter-bar" method="GET" action="{{ url()->current() }}" data-task-filter-form>
<form class="agreement-filter-bar{{ $agreementScope === 'archived' ? ' agreement-filter-bar--archived' : '' }}" method="GET" action="{{ url()->current() }}" data-task-filter-form>
<input type="hidden" name="agreement_view" value="tasks">
<input type="hidden" name="agreement_scope" value="{{ $agreementScope }}">
<div class="agreement-field">
@ -1390,6 +1396,16 @@
@endif
</select>
</div>
@if ($agreementScope === 'archived')
<div class="agreement-field">
<label for="agreement-task-partner-type">合作方类型</label>
<select class="agreement-control" id="agreement-task-partner-type" name="agreement_partner_type" data-task-filter data-task-partner-filter>
<option value="">全部合作方</option>
<option value="courier" @selected($agreementPartnerType === 'courier')>快递公司</option>
<option value="supplier" @selected($agreementPartnerType === 'supplier')>供应商</option>
</select>
</div>
@endif
<div class="agreement-field">
<label for="agreement-task-type">业务类型</label>
<select class="agreement-control" id="agreement-task-type" name="agreement_type" data-task-filter>
@ -2539,7 +2555,7 @@
}
if (event.target.closest('[data-task-reset]')) {
var resetUrl = new URL(window.location.href);
['agreement_search', 'agreement_status', 'agreement_type', 'agreement_task_page', 'agreement_quote_page', 'agreement_page'].forEach(function (key) {
['agreement_search', 'agreement_status', 'agreement_type', 'agreement_partner_type', 'agreement_task_page', 'agreement_quote_page', 'agreement_page'].forEach(function (key) {
resetUrl.searchParams.delete(key);
});
resetUrl.searchParams.set('agreement_view', 'tasks');
@ -2547,6 +2563,12 @@
}
});
root.addEventListener('change', function (event) {
if (event.target.matches('[data-task-partner-filter]')) {
event.target.form.requestSubmit();
}
});
root.addEventListener('submit', function (event) {
if (!event.target.matches('[data-task-filter-form]')) {
return;

View File

@ -300,6 +300,109 @@ class AgreementSigningPageTest extends FeatureTestCase
->assertDontSeeText('AGR-ACTIVE')->assertDontSee('<td>QB-ACTIVE</td>', false);
}
public function testArchivedTasksFilterPartnerTypesAcrossAgreementAndQuoteSources(): void
{
$this->grantWorkspaceAccess();
$archived = ['status' => CourierAgreementSignature::STATUS_ARCHIVED];
$courier = $this->createAgreementTask($archived + [
'business_no' => 'ARCHIVE-COURIER', 'payload' => ['partner_type' => 'courier'],
]);
$legacy = $this->createAgreementTask($archived + ['business_no' => 'ARCHIVE-LEGACY']);
$unreadable = $this->createAgreementTask($archived + ['business_no' => 'ARCHIVE-UNREADABLE']);
DB::table('business_courier_agreement_signatures')->where('id', $unreadable->id)->update(['payload' => 'legacy-ciphertext']);
$supplier = $this->createAgreementTask($archived + [
'business_no' => 'ARCHIVE-SUPPLIER', 'payload' => ['partner_type' => 'supplier'],
]);
$this->createAgreementTask(['business_no' => 'ACTIVE-SUPPLIER', 'payload' => ['partner_type' => 'supplier']]);
$this->createAgreementTask($archived + [
'business_no' => 'OTHER-COMPANY-SUPPLIER', 'company_id' => $this->company->id + 1000,
'payload' => ['partner_type' => 'supplier'],
]);
$deleted = $this->createAgreementTask($archived + [
'business_no' => 'DELETED-SUPPLIER', 'payload' => ['partner_type' => 'supplier'],
]);
$deleted->delete();
$quote = $this->createQuoteSignature('ARCHIVE-QUOTE', CourierQuoteSignature::STATUS_ARCHIVED, '测试快递');
$this->createQuoteSignature('ACTIVE-QUOTE', CourierQuoteSignature::STATUS_SIGNING, '测试快递');
$this->loginAs();
$url = route('business.pages.show', [
'section' => 'courier-payables', 'page' => 'agreement-signing', 'agreement_scope' => 'archived',
]);
$response = $this->get($url . '&agreement_partner_type=courier')->assertOk()
->assertSeeText('ARCHIVE-COURIER')->assertSeeText('ARCHIVE-LEGACY')
->assertSeeText('ARCHIVE-UNREADABLE')->assertSeeText('ARCHIVE-QUOTE')
->assertDontSeeText('ARCHIVE-SUPPLIER')->assertDontSee('<td>ACTIVE-QUOTE</td>', false)
->assertSee('id="agreement-task-partner-type"', false)
->assertSee('value="courier" selected', false);
$this->assertSame([$unreadable->id, $legacy->id, $courier->id], $response->viewData('agreementTasks')->pluck('id')->all());
$this->assertSame([$quote->id], $response->viewData('agreementQuoteSignatures')->pluck('id')->all());
$response = $this->get($url . '&agreement_partner_type=supplier')->assertOk()
->assertSeeText('ARCHIVE-SUPPLIER')->assertDontSeeText('ARCHIVE-COURIER')
->assertDontSeeText('ARCHIVE-LEGACY')->assertDontSeeText('ARCHIVE-UNREADABLE')
->assertDontSee('<td>ARCHIVE-QUOTE</td>', false)->assertDontSeeText('ACTIVE-SUPPLIER')
->assertDontSeeText('OTHER-COMPANY-SUPPLIER')->assertDontSeeText('DELETED-SUPPLIER')
->assertSee('value="supplier" selected', false);
$this->assertSame([$supplier->id], $response->viewData('agreementTasks')->pluck('id')->all());
$this->assertCount(0, $response->viewData('agreementQuoteSignatures'));
$response = $this->get($url)->assertOk();
$this->assertSame(4, $response->viewData('agreementTasks')->total());
$this->assertSame(1, $response->viewData('agreementQuoteSignatures')->total());
}
public function testArchivedPartnerFilterRunsBeforePaginationAndCombinesWithOtherFilters(): void
{
$this->grantWorkspaceAccess();
for ($i = 1; $i <= 205; $i++) {
$this->createAgreementTask([
'business_no' => 'ARCHIVE-PAGED-' . str_pad((string) $i, 3, '0', STR_PAD_LEFT),
'status' => CourierAgreementSignature::STATUS_ARCHIVED,
'payload' => ['partner_type' => $i > 150 ? 'supplier' : 'courier'],
]);
}
$this->createAgreementTask([
'business_no' => 'ARCHIVE-PAGED-OTHER-TYPE', 'document_type' => 'account-change',
'status' => CourierAgreementSignature::STATUS_ARCHIVED, 'payload' => ['partner_type' => 'supplier'],
]);
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'courier-payables', 'page' => 'agreement-signing', 'agreement_scope' => 'archived',
'agreement_partner_type' => 'supplier', 'agreement_search' => 'ARCHIVE-PAGED-',
'agreement_type' => 'account-proof', 'agreement_status' => 'archived', 'agreement_task_page' => 2,
]))->assertOk()->assertSeeText('ARCHIVE-PAGED-151')->assertSeeText('ARCHIVE-PAGED-155')
->assertDontSeeText('ARCHIVE-PAGED-150')->assertDontSeeText('ARCHIVE-PAGED-205')
->assertDontSeeText('ARCHIVE-PAGED-OTHER-TYPE');
$tasks = $response->viewData('agreementTasks');
$this->assertSame(55, $tasks->total());
$this->assertCount(5, $tasks->items());
foreach (['agreement_scope=archived', 'agreement_partner_type=supplier', 'agreement_search=ARCHIVE-PAGED-',
'agreement_type=account-proof', 'agreement_status=archived'] as $filter) {
$this->assertStringContainsString($filter, $tasks->url(1));
}
}
public function testArchivedPartnerFilterHandlesInvalidValuesEmptyResultsAndLeavingArchivedScope(): void
{
$this->grantWorkspaceAccess();
$this->createAgreementTask(['business_no' => 'ACTIVE-COURIER']);
$this->createAgreementTask([
'business_no' => 'ARCHIVE-COURIER', 'status' => CourierAgreementSignature::STATUS_ARCHIVED,
]);
$this->createQuoteSignature('ARCHIVE-QUOTE', CourierQuoteSignature::STATUS_ARCHIVED, '测试快递');
$this->loginAs();
$url = route('business.pages.show', ['section' => 'courier-payables', 'page' => 'agreement-signing']);
$this->get($url . '?agreement_scope=archived&agreement_partner_type=invalid')->assertOk()
->assertSeeText('ARCHIVE-COURIER')->assertSeeText('ARCHIVE-QUOTE');
$response = $this->get($url . '?agreement_scope=archived&agreement_partner_type=supplier')->assertOk()
->assertSeeText('没有匹配的签署任务');
$this->assertSame(0, $response->viewData('agreementTasks')->total());
$this->assertCount(0, $response->viewData('agreementQuoteSignatures'));
$this->get($url . '?agreement_scope=active&agreement_partner_type=supplier')->assertOk()
->assertSeeText('ACTIVE-COURIER')->assertDontSeeText('ARCHIVE-COURIER')
->assertDontSee('id="agreement-task-partner-type"', false);
}
public function testArchivedTaskShowsMetadataAndAllAvailableFilesWithoutReadingLegacyPayload(): void
{
$this->grantWorkspaceAccess();