From d9469d2d9a4ada98870e8038deaf1ddeb91a3c8b Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Sat, 24 Oct 2026 17:22:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=B2=E9=80=80=E5=9B=9E=E5=AD=98?= =?UTF-8?q?=E9=87=8F=E6=8A=A5=E4=BB=B7=E4=B8=8D=E5=86=8D=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=8C=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/CourierQuoteChangeService.php | 6 +++ app/Support/CourierStockQuoteEntryService.php | 6 ++- .../Business/CourierStockQuoteBatchTest.php | 32 +++++++++++++++ .../Business/CourierStockQuoteEntryTest.php | 39 +++++++++++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/app/Support/CourierQuoteChangeService.php b/app/Support/CourierQuoteChangeService.php index b30c0970..30fcbfb6 100644 --- a/app/Support/CourierQuoteChangeService.php +++ b/app/Support/CourierQuoteChangeService.php @@ -95,6 +95,12 @@ final class CourierQuoteChangeService } return DB::transaction(function () use ($change, $userId): CourierQuoteChange { + if ($change->isStockQuote() && $change->status === CourierQuoteChange::STATUS_RETURNED) { + // 退回期间可能已重新录入,恢复待审核前重新取得日期占用。 + \App\Models\Common\Company::whereKey(company_id())->lockForUpdate()->firstOrFail(); + $entry = CourierStockQuoteEntry::findOrFail(data_get($change->quote_payload, 'stock_quote_entry_id')); + app(CourierStockQuoteEntryService::class)->assertPeriod(['code' => $entry->courier_expcode, 'name' => $entry->courier_name], $entry->quote_type, $change->effective_date->toDateString(), $change->end_date?->toDateString(), $entry->id); + } $from = $change->status; $retrospective = ! $change->isStockQuote() && $this->isRetrospectiveDate($change->effective_date); $change->update([ diff --git a/app/Support/CourierStockQuoteEntryService.php b/app/Support/CourierStockQuoteEntryService.php index f6cdafc9..68c1e6cd 100644 --- a/app/Support/CourierStockQuoteEntryService.php +++ b/app/Support/CourierStockQuoteEntryService.php @@ -3,6 +3,7 @@ namespace App\Support; use App\Models\Business\CourierOnboarding; +use App\Models\Business\CourierQuoteChange; use App\Models\Business\CourierStockQuoteEntry; use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Http\UploadedFile; @@ -73,8 +74,9 @@ final class CourierStockQuoteEntryService public function existingIdentities(?int $exceptId = null): array { - return CourierStockQuoteEntry::withTrashed()->with(['change:id,company_id', 'change.version:id,company_id,source_change_id,status'])->when($exceptId !== null, fn ($query) => $query->where('id', '!=', $exceptId)) - ->get(['id', 'company_id', 'source_change_id', 'courier_expcode', 'courier_name', 'quote_type', 'effective_date', 'end_date'])->filter(fn ($entry) => !$entry->change?->version?->isVoided()) + return CourierStockQuoteEntry::withTrashed()->with(['change:id,company_id,status', 'change.version:id,company_id,source_change_id,status'])->when($exceptId !== null, fn ($query) => $query->where('id', '!=', $exceptId)) + ->get(['id', 'company_id', 'source_change_id', 'courier_expcode', 'courier_name', 'quote_type', 'effective_date', 'end_date']) + ->filter(fn ($entry) => $entry->change?->status !== CourierQuoteChange::STATUS_RETURNED && !$entry->change?->version?->isVoided()) ->map(fn ($entry) => ['code' => $entry->courier_expcode, 'name' => $entry->courier_name, 'quote_type' => $entry->quote_type, 'effective_date' => $entry->effective_date?->toDateString(), 'end_date' => $entry->end_date?->toDateString()])->all(); } diff --git a/tests/Feature/Business/CourierStockQuoteBatchTest.php b/tests/Feature/Business/CourierStockQuoteBatchTest.php index 741569fe..15178853 100644 --- a/tests/Feature/Business/CourierStockQuoteBatchTest.php +++ b/tests/Feature/Business/CourierStockQuoteBatchTest.php @@ -83,6 +83,38 @@ class CourierStockQuoteBatchTest extends FeatureTestCase $this->assertSame('2026-10-01', $entries[1]->change->effective_date->toDateString()); } + public function test_returned_open_ended_quote_does_not_block_four_new_batch_periods(): void + { + $oldBatch = $this->preview(['EXP-001']); + $this->postJson(route('business.courier-stock-quotes.batch-save', $oldBatch), $this->selection(['EXP-001']))->assertOk(); + $old = CourierStockQuoteEntry::firstOrFail(); + $files = $old->files; + $changes = app(CourierQuoteChangeService::class); + $changes->submit($old->change, (int) $this->user->id); + $changes->returnForChanges($old->change->fresh(), '退回后按实际区间重新录入', (int) $this->user->id); + + $batch = $this->preview(['EXP-001']); + $service = app(CourierStockQuoteBatchService::class); + $rows = $service->rows($service->load($batch, (int) $this->user->id), app(\App\Support\CourierStockQuoteEntryService::class)->courierOptions()); + $this->assertFalse($rows[0]['duplicate']); + $this->get(route('business.courier-stock-quotes.batch', $batch))->assertOk()->assertDontSeeText('已录入,默认跳过'); + $selection = $this->selection(['EXP-001']); + $selection['submit_for_review'] = $selection['confirmed'] = true; + $selection['entries'][0]['periods'] = [ + ['effective_date' => '2026-10-01', 'end_date' => '2026-10-04'], + ['effective_date' => '2026-10-11', 'end_date' => '2026-10-14'], + ['effective_date' => '2026-10-21', 'end_date' => '2026-10-24'], + ['effective_date' => '2026-11-01', 'end_date' => '2026-11-04'], + ]; + $this->postJson(route('business.courier-stock-quotes.batch-save', $batch), $selection)->assertOk(); + $this->assertDatabaseCount('business_courier_stock_quote_entries', 5); + $this->assertSame(4, CourierQuoteChange::where('status', CourierQuoteChange::STATUS_PENDING_REVIEW)->count()); + $this->assertSame(CourierQuoteChange::STATUS_RETURNED, $old->change->fresh()->status); + $this->assertSame($files, $old->fresh()->files); + Storage::disk('uploads')->assertExists($files[0]['path']); + $this->assertDatabaseCount('business_courier_quote_versions', 0); + } + public function test_bulk_save_reuses_rule_groups_overrides_dates_and_preserves_separate_prices(): void { $batch = $this->preview(['EXP-001', 'EXP-002', '说明']); diff --git a/tests/Feature/Business/CourierStockQuoteEntryTest.php b/tests/Feature/Business/CourierStockQuoteEntryTest.php index 80fff17d..bc5e383f 100644 --- a/tests/Feature/Business/CourierStockQuoteEntryTest.php +++ b/tests/Feature/Business/CourierStockQuoteEntryTest.php @@ -185,6 +185,45 @@ class CourierStockQuoteEntryTest extends FeatureTestCase ->assertSessionHasErrors('courier_expcode'); } + public function test_returned_quote_releases_period_and_replacement_preserves_review_overlap_protection(): void + { + $old = $this->createEntry(); + $files = $old->files; + $changes = app(CourierQuoteChangeService::class); + $changes->submit($old->change, (int) $this->user->id); + $reviewer = $this->reviewer(); + $changes->returnForChanges($old->change->fresh(), '原报价执行日期需重新录入', (int) $reviewer->id); + + $replacement = $this->createEntry(); + $this->assertNotSame($old->id, $replacement->id); + $this->assertSame(CourierQuoteChange::STATUS_RETURNED, $old->change->fresh()->status); + $this->assertSame($files, $old->fresh()->files); + Storage::disk('uploads')->assertExists($files[0]['path']); + $this->withExceptionHandling()->loginAs()->post(route('business.courier-quote-changes.submit', $old->change)) + ->assertSessionHasErrors('courier_name'); + $this->assertSame(CourierQuoteChange::STATUS_RETURNED, $old->change->fresh()->status); + + $changes->submit($replacement->change, (int) $this->user->id); + $this->post(route('business.courier-stock-quotes.store'), $this->payload())->assertSessionHasErrors('courier_name'); + $changes->approve($replacement->change->fresh(), (int) $reviewer->id); + $this->post(route('business.courier-stock-quotes.store'), $this->payload())->assertSessionHasErrors('courier_name'); + $this->assertDatabaseCount('business_courier_stock_quote_entries', 2); + $this->assertDatabaseCount('business_courier_quote_versions', 1); + } + + public function test_returned_quote_can_be_resubmitted_when_its_period_is_still_available(): void + { + $entry = $this->createEntry(); + $changes = app(CourierQuoteChangeService::class); + $changes->submit($entry->change, (int) $this->user->id); + $changes->returnForChanges($entry->change->fresh(), '重新核对后提交', (int) $this->reviewer()->id); + $this->loginAs()->post(route('business.courier-quote-changes.submit', $entry->change->fresh())) + ->assertSessionHasNoErrors()->assertRedirect(); + $this->assertSame(CourierQuoteChange::STATUS_PENDING_REVIEW, $entry->change->fresh()->status); + $this->assertDatabaseCount('business_courier_stock_quote_entries', 1); + $this->assertDatabaseCount('business_courier_quote_versions', 0); + } + public function test_multi_sheet_upload_requires_exact_sheet_and_invalid_workbooks_leave_no_record(): void { $this->withExceptionHandling()->loginAs()->post(route('business.courier-stock-quotes.store'), [...$this->payload(), 'source_quote' => $this->workbook(true)]) -- 2.47.2