From 48220ec13e65352a54b4ed3c66d2212c15c1d989 Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Tue, 24 Nov 2026 16:59:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=A5=E4=BB=B7=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=B8=A4=E7=BA=A7=E5=AE=A1=E6=A0=B8=E5=B9=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=AF=8F=E9=98=B6=E6=AE=B5=E4=BB=BB=E4=B8=80=E4=BA=BA=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/CourierOnboardings.php | 2 +- .../Business/CourierQuoteChanges.php | 33 +++- .../SystemSettings/WorkflowReviewers.php | 8 +- app/Models/Business/CourierQuoteChange.php | 2 + .../Business/CourierQuoteChangeEvent.php | 1 + app/Support/CourierQuoteChangeService.php | 31 +++- .../CourierQuoteWorkflowPermissions.php | 37 ++++- app/Support/CourierRequoteService.php | 4 +- docs/报价历史批量审核.md | 4 +- .../partials/stock-quote-review.blade.php | 4 +- .../quote-change-history.blade.php | 8 +- .../quote-change-show.blade.php | 13 +- .../quote-workflow-permissions.blade.php | 15 +- .../CourierQuoteWorkflowPermissionsTest.php | 156 ++++++++++++++++++ 14 files changed, 271 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/Business/CourierOnboardings.php b/app/Http/Controllers/Business/CourierOnboardings.php index edcb781b..487795bf 100644 --- a/app/Http/Controllers/Business/CourierOnboardings.php +++ b/app/Http/Controllers/Business/CourierOnboardings.php @@ -101,7 +101,7 @@ class CourierOnboardings extends Controller } $requotes = $this->requotes(); $open = $requotes->openChange($onboarding); - if ($open !== null && ($open->status === \App\Models\Business\CourierQuoteChange::STATUS_PENDING_REVIEW || $open->created_by !== user_id())) { + if ($open !== null && (in_array($open->status, [\App\Models\Business\CourierQuoteChange::STATUS_PENDING_REVIEW, \App\Models\Business\CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true) || $open->created_by !== user_id())) { return redirect()->route('business.courier-quote-changes.show', $open) ->with('success', "已有未完成的变价单 {$open->number},请先查看该单;待审核单可由发起人撤回修改。"); } diff --git a/app/Http/Controllers/Business/CourierQuoteChanges.php b/app/Http/Controllers/Business/CourierQuoteChanges.php index f5b6631c..63040157 100644 --- a/app/Http/Controllers/Business/CourierQuoteChanges.php +++ b/app/Http/Controllers/Business/CourierQuoteChanges.php @@ -48,20 +48,28 @@ class CourierQuoteChanges extends Controller $quoteReviewer = $this->canReview(); $admin = $this->canAdminister(); - $selfReview = app(CourierQuoteWorkflowPermissions::class)->allowsSelfReview((int) user_id()); - $reviewableIds = $changes->filter(fn ($change) => ($change->isStockQuote() ? $admin : $quoteReviewer) - && ($change->created_by !== user_id() || ($change->isStockQuote() ? config('courier_onboarding.allow_same_reviewer') : $selfReview)))->pluck('id')->all(); + $permissions = app(CourierQuoteWorkflowPermissions::class); + $workflow = $permissions->settings(); + $stageAccess = []; + $reviewableIds = $changes->filter(function ($change) use ($permissions, &$stageAccess) { + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) return false; + // 本页同环节和同自审条件仅核验一次;下个请求重新读取权限和花名册。 + $key = $change->status . ':' . (int) $change->isStockQuote() . ':' . (int) ($change->created_by === user_id()); + return $stageAccess[$key] ??= $permissions->canReviewChange($change, (int) user_id()); + })->pluck('id')->all(); return view('business.pages.courier-payables.quote-change-history', [ 'changes' => $changes, 'canReview' => $quoteReviewer || $admin, 'reviewableChangeIds' => $reviewableIds, 'filters' => $filters, + 'quoteWorkflow' => $workflow, 'carrierOptions' => CourierQuoteChange::query()->whereNotNull('carrier_name')->distinct()->orderBy('carrier_name')->pluck('carrier_name')->all(), 'changeTypeOptions' => CourierQuoteChange::query()->whereNotNull('change_type')->distinct()->orderBy('change_type')->pluck('change_type')->all(), 'statusOptions' => [ CourierQuoteChange::STATUS_DRAFT => '草稿', - CourierQuoteChange::STATUS_PENDING_REVIEW => '待审核', + CourierQuoteChange::STATUS_PENDING_REVIEW => $workflow['staged'] ? '待初审' : '待审核', + CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW => '待复审', CourierQuoteChange::STATUS_RETURNED => '已退回', CourierQuoteChange::STATUS_APPROVED => '已审核', ], @@ -72,7 +80,7 @@ class CourierQuoteChanges extends Controller private function historyFilters(Request $request): array { $status = (string) $request->input('status', ''); - $allowed = [CourierQuoteChange::STATUS_DRAFT, CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_RETURNED, CourierQuoteChange::STATUS_APPROVED]; + $allowed = [CourierQuoteChange::STATUS_DRAFT, CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW, CourierQuoteChange::STATUS_RETURNED, CourierQuoteChange::STATUS_APPROVED]; return [ 'carrier' => mb_substr(trim((string) $request->input('carrier', '')), 0, 100), @@ -130,10 +138,8 @@ class CourierQuoteChanges extends Controller ? $this->requotes->reviewWarnings($quoteChange, $requoteDiff) : [], 'voidedBy' => $quoteChange->version?->voided_by ? user_model_class()::query()->find($quoteChange->version->voided_by)?->name : null, - 'canReview' => $reviewAllowed && ($quoteChange->created_by !== user_id() - || ($quoteChange->isStockQuote() ? config('courier_onboarding.allow_same_reviewer') - : app(CourierQuoteWorkflowPermissions::class)->allowsSelfReview((int) user_id()))), - 'canWithdraw' => ! $quoteChange->isStockQuote() && $quoteChange->status === CourierQuoteChange::STATUS_PENDING_REVIEW + 'canReview' => app(CourierQuoteWorkflowPermissions::class)->canReviewChange($quoteChange, (int) user_id()), + 'canWithdraw' => ! $quoteChange->isStockQuote() && in_array($quoteChange->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true) && $quoteChange->created_by === user_id() && app(CourierQuoteWorkflowPermissions::class)->can('initiators', (int) user_id()), 'canManageSignature' => $canManageSignature, 'canCorrectPeriods' => $reviewAllowed && !$quoteChange->isStockQuote() @@ -250,6 +256,11 @@ class CourierQuoteChanges extends Controller } $change = $this->service->approve($quoteChange, user_id(), $request->boolean('stock_signature_verified')); + if ($change->status === CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW) { + return redirect()->route('business.courier-quote-changes.show', $change) + ->with('success', '初审通过,已转复审。任意一名指定复审人员通过后才生成生效报价版本。'); + } + $message = "审核完成,已生成新报价版本 {$change->version->version_code}。"; if ($change->isStockQuote()) { @@ -490,6 +501,10 @@ class CourierQuoteChanges extends Controller private function canReview(?CourierQuoteChange $change = null): bool { + if ($change && (app(CourierQuoteWorkflowPermissions::class)->settings()['staged'] + || $change->status === CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW)) { + return app(CourierQuoteWorkflowPermissions::class)->canReviewChange($change, (int) user_id()); + } return $change?->isStockQuote() ? $this->canAdminister() : app(CourierQuoteWorkflowPermissions::class)->can('reviewers', (int) user_id()); } diff --git a/app/Http/Controllers/SystemSettings/WorkflowReviewers.php b/app/Http/Controllers/SystemSettings/WorkflowReviewers.php index 51daa349..94698caa 100644 --- a/app/Http/Controllers/SystemSettings/WorkflowReviewers.php +++ b/app/Http/Controllers/SystemSettings/WorkflowReviewers.php @@ -58,11 +58,15 @@ class WorkflowReviewers extends Controller $data = $request->validate([ 'initiators' => ['required', 'array', 'min:1', 'max:10'], 'initiators.*' => ['required', 'string', 'max:100', 'distinct'], - 'reviewers' => ['required', 'array', 'min:1', 'max:10'], + 'reviewers' => ['required_without:first_reviewers', 'array', 'min:1', 'max:10'], 'reviewers.*' => ['required', 'string', 'max:100', 'distinct'], + 'first_reviewers' => ['required_with:final_reviewers', 'array', 'min:1', 'max:10'], + 'first_reviewers.*' => ['required', 'string', 'max:100', 'distinct'], + 'final_reviewers' => ['required_with:first_reviewers', 'array', 'min:1', 'max:10'], + 'final_reviewers.*' => ['required', 'string', 'max:100', 'distinct'], ]); app(CourierQuoteWorkflowPermissions::class)->save($data, user()->name, (int) user_id()); - return redirect()->route('system-settings.workflow-reviewers.index')->with('success', '报价变价发起和审核人员已保存,立即对未完成变价生效。'); + return redirect()->route('system-settings.workflow-reviewers.index')->with('success', '报价发起和审核人员已保存,立即对未完成报价生效。'); } } diff --git a/app/Models/Business/CourierQuoteChange.php b/app/Models/Business/CourierQuoteChange.php index 16f37d1c..6fb7d8a5 100644 --- a/app/Models/Business/CourierQuoteChange.php +++ b/app/Models/Business/CourierQuoteChange.php @@ -10,6 +10,7 @@ class CourierQuoteChange extends Model { public const STATUS_DRAFT = 'draft'; public const STATUS_PENDING_REVIEW = 'pending_review'; + public const STATUS_PENDING_FINAL_REVIEW = 'pending_final_review'; public const STATUS_RETURNED = 'returned'; public const STATUS_APPROVED = 'approved'; @@ -104,6 +105,7 @@ class CourierQuoteChange extends Model return match ($this->status) { self::STATUS_DRAFT => '草稿', self::STATUS_PENDING_REVIEW => '待审核', + self::STATUS_PENDING_FINAL_REVIEW => '待复审', self::STATUS_RETURNED => '已退回', self::STATUS_APPROVED => '已审核', default => $this->status, diff --git a/app/Models/Business/CourierQuoteChangeEvent.php b/app/Models/Business/CourierQuoteChangeEvent.php index 77c940c5..428c0a6a 100644 --- a/app/Models/Business/CourierQuoteChangeEvent.php +++ b/app/Models/Business/CourierQuoteChangeEvent.php @@ -34,6 +34,7 @@ class CourierQuoteChangeEvent extends Model 'withdrawn' => '撤回修改', 'returned' => '退回修改', 'approved' => '审核通过', + 'first_approved' => '初审通过', 'voided' => '版本作废', 'period_end_updated' => '设置执行截止日期', 'periods_corrected' => '更正执行区间', diff --git a/app/Support/CourierQuoteChangeService.php b/app/Support/CourierQuoteChangeService.php index 2ebd3e0f..c28f04ea 100644 --- a/app/Support/CourierQuoteChangeService.php +++ b/app/Support/CourierQuoteChangeService.php @@ -139,11 +139,12 @@ final class CourierQuoteChangeService return DB::transaction(function () use ($change, $userId): CourierQuoteChange { $change = CourierQuoteChange::query()->lockForUpdate()->findOrFail($change->id); abort_unless(! $change->isStockQuote() && $change->created_by === $userId, 403, '只有变价发起人可以撤回自己的待审核单。'); - if ($change->status !== CourierQuoteChange::STATUS_PENDING_REVIEW || $change->version()->exists()) { + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true) || $change->version()->exists()) { throw ValidationException::withMessages(['status' => '只有尚未审核通过的待审核变价单可以撤回,请刷新状态。']); } + $from = $change->status; $change->update(['status' => CourierQuoteChange::STATUS_DRAFT, 'submitted_by' => null, 'submitted_at' => null]); - $this->recordEvent($change, 'withdrawn', CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_DRAFT, + $this->recordEvent($change, 'withdrawn', $from, CourierQuoteChange::STATUS_DRAFT, '发起人撤回审核,修改后需重新提交。', $userId); return $change->fresh(['items', 'events']); @@ -153,17 +154,19 @@ final class CourierQuoteChangeService public function returnForChanges(CourierQuoteChange $change, string $note, int $userId): CourierQuoteChange { app(CourierQuoteWorkflowPermissions::class)->assertReviewer($change, $userId); - if ($change->status !== CourierQuoteChange::STATUS_PENDING_REVIEW) { + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) { throw ValidationException::withMessages(['status' => '只有待审核的变更单可以退回。']); } return DB::transaction(function () use ($change, $note, $userId): CourierQuoteChange { $change = CourierQuoteChange::query()->lockForUpdate()->findOrFail($change->id); - if ($change->status !== CourierQuoteChange::STATUS_PENDING_REVIEW) { + app(CourierQuoteWorkflowPermissions::class)->assertReviewer($change, $userId); + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) { throw ValidationException::withMessages(['status' => '只有待审核的变更单可以退回,请刷新状态。']); } + $from = $change->status; $change->update(['status' => CourierQuoteChange::STATUS_RETURNED]); - $this->recordEvent($change, 'returned', CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_RETURNED, $note, $userId); + $this->recordEvent($change, 'returned', $from, CourierQuoteChange::STATUS_RETURNED, $note, $userId); return $change->fresh(['items', 'events']); }); @@ -172,11 +175,11 @@ final class CourierQuoteChangeService public function approve(CourierQuoteChange $change, int $userId, bool $historicalDocumentsConfirmed = false): CourierQuoteChange { app(CourierQuoteWorkflowPermissions::class)->assertReviewer($change, $userId); - if ($change->status !== CourierQuoteChange::STATUS_PENDING_REVIEW) { + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) { throw ValidationException::withMessages(['status' => '只有待审核的变更单可以审核通过。']); } - $allowsSelfReview = $change->isStockQuote() ? config('courier_onboarding.allow_same_reviewer') + $allowsSelfReview = $change->isStockQuote() && !app(CourierQuoteWorkflowPermissions::class)->settings()['staged'] ? config('courier_onboarding.allow_same_reviewer') : app(CourierQuoteWorkflowPermissions::class)->allowsSelfReview($userId); if ($change->created_by === $userId && ! $allowsSelfReview) { throw ValidationException::withMessages(['approval' => '发起人不能审核自己提交的报价变更。']); @@ -186,9 +189,11 @@ final class CourierQuoteChangeService return DB::transaction(function () use ($change, $source, $userId, $historicalDocumentsConfirmed): CourierQuoteChange { $change = CourierQuoteChange::query()->lockForUpdate()->findOrFail($change->id); - if ($change->status !== CourierQuoteChange::STATUS_PENDING_REVIEW) { + app(CourierQuoteWorkflowPermissions::class)->assertReviewer($change, $userId); + if (!in_array($change->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) { throw ValidationException::withMessages(['status' => '只有待审核的变更单可以审核通过,请刷新状态。']); } + $from = $change->status; if ($change->isStockQuote()) { \App\Models\Common\Company::whereKey(company_id())->lockForUpdate()->firstOrFail(); $entry = CourierStockQuoteEntry::findOrFail(data_get($change->quote_payload, 'stock_quote_entry_id')); @@ -200,6 +205,14 @@ final class CourierQuoteChangeService throw ValidationException::withMessages(['stock_signature_verified' => '尚未上传历史签署资料,请补充资料或取消历史资料核验;不影响存量报价审核生效。']); } $historicalSigned = $hasHistoricalFiles && $historicalDocumentsConfirmed; + $workflow = app(CourierQuoteWorkflowPermissions::class)->settings(); + if ($workflow['staged'] && $change->status === CourierQuoteChange::STATUS_PENDING_REVIEW) { + $change->update(['status' => CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW]); + $this->recordEvent($change, 'first_approved', $from, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW, + '初审通过,等待任意一名指定复审人员审核;尚未生成生效报价版本。', $userId, + ['first_reviewers' => $workflow['first_reviewers'], 'final_reviewers' => $workflow['final_reviewers']]); + return $change->fresh(['items', 'events', 'version']); + } $source = CourierQuoteNotes::apply($source, $change->quote_payload['quote_notes'] ?? []); $values = $source['values']; $formulas = $source['formulas']; @@ -265,7 +278,7 @@ final class CourierQuoteChangeService $eventNote .= ' 该报价为历史生效;补差明细尚未生成,原运费保持不变。'; } - $this->recordEvent($change, 'approved', CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_APPROVED, $eventNote, $userId, [ + $this->recordEvent($change, 'approved', $from, CourierQuoteChange::STATUS_APPROVED, $eventNote, $userId, [ ...$this->changeDetails($change), 'version_code' => $version->version_code, 'historical_documents_confirmed' => $historicalSigned, diff --git a/app/Support/CourierQuoteWorkflowPermissions.php b/app/Support/CourierQuoteWorkflowPermissions.php index 57344e56..6decb3b0 100644 --- a/app/Support/CourierQuoteWorkflowPermissions.php +++ b/app/Support/CourierQuoteWorkflowPermissions.php @@ -28,7 +28,9 @@ final class CourierQuoteWorkflowPermissions $settings = json_decode($value ?? '', true); $settings = is_array($settings) ? $settings : []; - return ['configured' => $value !== null] + $settings + ['initiators' => [], 'reviewers' => [], 'self_reviewers' => []]; + return ['configured' => $value !== null, + 'staged' => !empty($settings['first_reviewers']) && !empty($settings['final_reviewers'])] + + $settings + ['initiators' => [], 'reviewers' => [], 'self_reviewers' => [], 'first_reviewers' => [], 'final_reviewers' => []]; } public function history(): array @@ -39,7 +41,11 @@ final class CourierQuoteWorkflowPermissions public function save(array $data, string $actor, ?int $actorId): void { - $next = ['initiators' => [], 'reviewers' => []]; + $staged = array_key_exists('first_reviewers', $data) || array_key_exists('final_reviewers', $data); + if (!$staged && $this->settings()['staged']) { + throw ValidationException::withMessages(['first_reviewers' => '请同时设置报价初审、复审人员。']); + } + $next = $staged ? ['initiators' => [], 'first_reviewers' => [], 'final_reviewers' => []] : ['initiators' => [], 'reviewers' => []]; foreach (array_keys($next) as $stage) { $ids = $data[$stage] ?? []; if (! is_array($ids) || count($ids) < 1 || count($ids) > 10 || count(array_unique($ids)) !== count($ids)) { @@ -54,6 +60,13 @@ final class CourierQuoteWorkflowPermissions $next[$stage][] = ['dingtalk_user_id' => (string) $id, 'display_name' => $person['display_name']]; } } + if ($staged) { + if (array_intersect($data['first_reviewers'], $data['final_reviewers'])) { + throw ValidationException::withMessages(['final_reviewers' => '初审和复审请选择不同人员。']); + } + $next['reviewers'] = [...$next['first_reviewers'], ...$next['final_reviewers']]; + $data['reviewers'] = array_column($next['reviewers'], 'dingtalk_user_id'); + } // 未指定时保留已授权的本人单据审核权限;移出审核名单时同步撤销。 $selfIds = $data['self_reviewers'] ?? array_intersect( array_column($this->settings()['self_reviewers'], 'dingtalk_user_id'), $data['reviewers'] @@ -130,15 +143,29 @@ final class CourierQuoteWorkflowPermissions public function assertReviewer(CourierQuoteChange $change, int $userId): void { abort_unless((int) $change->company_id === (int) company_id(), 403); - $allowed = $change->isStockQuote() + $settings = $this->settings(); + $staged = $settings['staged'] || $change->status === CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW; + $allowed = $staged ? ($settings['staged'] && $this->can($change->status === CourierQuoteChange::STATUS_PENDING_REVIEW ? 'first_reviewers' : 'final_reviewers', $userId)) + : ($change->isStockQuote() ? in_array(SystemAccess::roleName(User::find($userId)), [SystemAccess::ADMIN, SystemAccess::SUPER_ADMIN], true) - : $this->can('reviewers', $userId); + : $this->can('reviewers', $userId)); abort_unless($allowed, 403, '你不是该报价变价的指定审核人员。'); - if (! $change->isStockQuote() && $change->created_by === $userId && ! $this->allowsSelfReview($userId)) { + if (($staged || !$change->isStockQuote()) && $change->created_by === $userId && ! $this->allowsSelfReview($userId)) { throw ValidationException::withMessages(['approval' => '发起人不能审核自己提交的报价变更。']); } } + public function canReviewChange(CourierQuoteChange $change, int $userId): bool + { + try { + $this->assertReviewer($change, $userId); + return $change->created_by !== $userId || $this->allowsSelfReview($userId) + || (!$this->settings()['staged'] && $change->isStockQuote() && config('courier_onboarding.allow_same_reviewer')); + } catch (ValidationException | \Symfony\Component\HttpKernel\Exception\HttpException) { + return false; + } + } + private function account(string $id): ?User { $identities = DingTalkIdentity::query()->where('dingtalk_user_id', $id)->with('user')->limit(2)->get(); diff --git a/app/Support/CourierRequoteService.php b/app/Support/CourierRequoteService.php index 4692d547..85c3b97c 100644 --- a/app/Support/CourierRequoteService.php +++ b/app/Support/CourierRequoteService.php @@ -92,7 +92,7 @@ final class CourierRequoteService { return CourierQuoteChange::query() ->where('carrier_name', $onboarding->courier_name) - ->whereIn('status', [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_RETURNED, CourierQuoteChange::STATUS_DRAFT]) + ->whereIn('status', [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW, CourierQuoteChange::STATUS_RETURNED, CourierQuoteChange::STATUS_DRAFT]) ->whereNotNull('quote_payload') ->where('change_type', '!=', '存量报价') ->latest('id') @@ -170,7 +170,7 @@ final class CourierRequoteService $open = $this->openChange($onboarding); abort_if($open !== null && $open->created_by !== $userId, 403, '只有变价发起人可以修改或重新提交该变价单。'); - if ($open !== null && $open->status === CourierQuoteChange::STATUS_PENDING_REVIEW) { + if ($open !== null && in_array($open->status, [CourierQuoteChange::STATUS_PENDING_REVIEW, CourierQuoteChange::STATUS_PENDING_FINAL_REVIEW], true)) { throw ValidationException::withMessages(['status' => "已有待审核的变价单 {$open->number},审核完成后再发起新的变价。"]); } diff --git a/docs/报价历史批量审核.md b/docs/报价历史批量审核.md index 8d63e272..48316d43 100644 --- a/docs/报价历史批量审核.md +++ b/docs/报价历史批量审核.md @@ -2,7 +2,9 @@ 报价管理 → 报价历史中,有报价审核权限的账号可勾选本页待审核记录,或用表头勾选框全选本页可审核项,点击“批量审核通过”。确认窗口列出变更单号、快递、变更类型和执行期间;核对原报价、计费规则及实际执行日期后提交。已审核和受自审限制的记录不显示勾选框。 -批量接口沿用当前公司和报价管理页级权限,同时检查管理员/超级管理员审核身份;仅处理明确提交的记录ID,最多100条,不隐式选择其他页或其他公司。逐条调用现有单条审核入口,保留自审限制、报价期间冲突校验、版本生成、审核日志和原签署后续流程。单条失败不撤销其他成功项;完成后显示成功/未通过数量及每条结果,返回原页码。 +批量接口沿用当前公司和报价管理页级权限,按配置检查当前环节指定人员;仅处理明确提交的记录ID,最多100条,不隐式选择其他页或其他公司。逐条调用现有单条审核入口,保留自审限制、报价期间冲突校验、版本生成、审核日志和原签署后续流程。单条失败不撤销其他成功项;完成后显示成功/未通过数量及每条结果,返回原页码。 + +在系统设置 → 流程审核权限设置中配置报价初审、复审名单后,所有未完成存量报价和变价统一两级审核。每环节任意一人通过即可;初审只转为待复审,复审通过才生成版本并执行原签署后续流程。管理员身份不能越过指定名单。退回或撤回后重新提交必须重走初审;待复审的后台变价仍视为未完成,不能再次发起同一快递变价。既有已完成报价和审计记录保留。 存量报价仍按既有规则审核生效,不自动发起签署;历史签署资料必须逐份核对,不接受批量标记为已经核验。非存量变价沿用原单条审核的签署准备与推送流程。 diff --git a/resources/views/business/pages/courier-payables/partials/stock-quote-review.blade.php b/resources/views/business/pages/courier-payables/partials/stock-quote-review.blade.php index 7ae666d2..bc5c9bf5 100644 --- a/resources/views/business/pages/courier-payables/partials/stock-quote-review.blade.php +++ b/resources/views/business/pages/courier-payables/partials/stock-quote-review.blade.php @@ -16,13 +16,13 @@ @if(collect($stockEntry->files)->contains('source', 'workbook_embedded'))

工作表内嵌图片已按原始字节独立留存,未裁剪、未压缩。提取成功不代表已核对一致;后续调价仍保留本版原件。

@endif - @if($canReview && $change->status === 'pending_review') + @if($canReview && in_array($change->status, ['pending_review', 'pending_final_review']))
@if(collect($stockEntry->files)->contains('kind', 'signed'))

@endif -

存量报价审核通过后按实际执行日期生效,无需签章。历史签署资料可另行核验归档,不影响报价生效。

+

存量报价最终审核通过后按实际执行日期生效,无需签章。历史签署资料可另行核验归档,不影响报价生效。

@endif diff --git a/resources/views/business/pages/courier-payables/quote-change-history.blade.php b/resources/views/business/pages/courier-payables/quote-change-history.blade.php index 06b50aae..f85dedc3 100644 --- a/resources/views/business/pages/courier-payables/quote-change-history.blade.php +++ b/resources/views/business/pages/courier-payables/quote-change-history.blade.php @@ -68,16 +68,16 @@ @endif
@if($canReview)@endif @foreach($changes as $change) - @php($badge = match($change->status){'pending_review'=>'pending','approved'=>'approved','returned'=>'returned',default=>''}) - @if($canReview)@endif + @php($badge = match($change->status){'pending_review','pending_final_review'=>'pending','approved'=>'approved','returned'=>'returned',default=>''}) + @if($canReview)@endif @endforeach
变更单号原报价快递公司变更类型明细生效日期生效方式追溯核算状态新版本更新时间操作
@if(in_array($change->id, $reviewableChangeIds, true) && $change->status === 'pending_review')@else—@endif{{ $change->number }}{{ $change->source_quote_id }}{{ $change->carrier_name }}{{ $change->change_type }}{{ $change->items->count() }} 项{{ $change->effective_date->toDateString() }}{{ $change->isRetrospective() ? '追溯变价' : '正常生效' }}{{ $change->recalculationStatusLabel() }}{{ $change->statusLabel() }}{{ $change->version?->version_code ?? '—' }}{{ $change->updated_at?->format('Y-m-d H:i') }}查看@if($change->isEditable() && $change->created_by===user_id()) · 编辑@endif
@if(in_array($change->id, $reviewableChangeIds, true) && in_array($change->status, ['pending_review', 'pending_final_review']))@else—@endif{{ $change->number }}{{ $change->source_quote_id }}{{ $change->carrier_name }}{{ $change->change_type }}{{ $change->items->count() }} 项{{ $change->effective_date->toDateString() }}{{ $change->isRetrospective() ? '追溯变价' : '正常生效' }}{{ $change->recalculationStatusLabel() }}{{ ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}{{ $change->version?->version_code ?? '—' }}{{ $change->updated_at?->format('Y-m-d H:i') }}查看@if($change->isEditable() && $change->created_by===user_id()) · 编辑@endif
@if($canReview)

确认批量审核通过

-

将审核下列报价,并按现有流程生成新版本。请先核对原报价、计费规则与实际执行日期。

+

将处理下列报价的当前审核环节。初审通过后转复审,复审通过后生成新版本;请先核对原报价、计费规则与实际执行日期。

-

存量报价审核后生效,不自动发起签署;其他变价沿用单条审核的签署准备和推送流程。历史签署资料不会在此批量标记为已核验。

+

存量报价最终审核后生效,不自动发起签署;其他变价复审通过后沿用单条审核的签署准备和推送流程。历史签署资料不会在此批量标记为已核验。

diff --git a/resources/views/business/pages/courier-payables/quote-change-show.blade.php b/resources/views/business/pages/courier-payables/quote-change-show.blade.php index 88fa8a32..08beb1f1 100644 --- a/resources/views/business/pages/courier-payables/quote-change-show.blade.php +++ b/resources/views/business/pages/courier-payables/quote-change-show.blade.php @@ -75,12 +75,15 @@ 编辑草稿
@csrf
@endif - @if($canReview && $change->status==='pending_review') -
@csrf
+ @if($canReview && in_array($change->status, ['pending_review', 'pending_final_review'])) + @php($firstReview = ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review') +
@csrf
@endif - @if(!$change->isStockQuote() && ($quoteWorkflow['configured'] ?? false)) + @if($quoteWorkflow['staged'] ?? false) +
初审:{{ implode('、', array_column($quoteWorkflow['first_reviewers'], 'display_name')) }}(任意一人通过);复审:{{ implode('、', array_column($quoteWorkflow['final_reviewers'], 'display_name')) }}(任意一人通过)。复审通过后才生成生效报价版本,退回修改后需重新初审。当前:{{ $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}。
+ @elseif(!$change->isStockQuote() && ($quoteWorkflow['configured'] ?? false))
变价发起:{{ implode('、', array_column($quoteWorkflow['initiators'], 'display_name')) }};指定审核:{{ implode('、', array_column($quoteWorkflow['reviewers'], 'display_name')) }}。@if($quoteWorkflow['self_reviewers'] ?? []){{ implode('、', array_column($quoteWorkflow['self_reviewers'], 'display_name')) }}可审核本人发起的变价。@else 发起人不能自审。@endif 待审核单可由发起人撤回修改后重提。
@endif @if(is_string(session('success')))
{{ session('success') }}
@endif @@ -88,7 +91,7 @@ @if($reviewWarnings)@endif @if($change->isRetrospective())
追溯变价 · {{ $change->recalculationStatusLabel() }}
执行期间:{{ $change->periodLabel() }}。{{ $change->recalculation_note ?: '审核完成后应按执行期间生成补款或扣款明细,原运费和原始 Excel 保持不变。' }}
@endif
-
{{ $change->number }} · {{ $change->statusLabel() }}
+
{{ $change->number }} · {{ ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}
原报价版本
{{ $change->source_quote_id }}
@@ -248,7 +251,7 @@
@endif
状态与审计记录
@foreach($change->events as $event)
{{ $event->eventLabel() }}
{{ $event->note }}
操作人:{{ $event->actor?->name ?? ('用户 #' . $event->created_by) }}
@endforeach
- @if($canReview && $change->status==='pending_review')
@csrf
@endif + @if($canReview && in_array($change->status, ['pending_review', 'pending_final_review']))
@csrf
@endif
diff --git a/resources/views/system_settings/partials/quote-workflow-permissions.blade.php b/resources/views/system_settings/partials/quote-workflow-permissions.blade.php index 317f02c0..7ee53bdd 100644 --- a/resources/views/system_settings/partials/quote-workflow-permissions.blade.php +++ b/resources/views/system_settings/partials/quote-workflow-permissions.blade.php @@ -1,8 +1,8 @@

报价变价发起和审核人员

-

指定人员发起变价,由任意一名指定审核人通过即可。@if($quotePermissions['self_reviewers'] ?? []){{ implode('、', array_column($quotePermissions['self_reviewers'], 'display_name')) }}已获授权,可审核本人发起的变价;移出审核名单时同步撤销该授权。@else 发起人不能审核自己的变价。@endif 该设置不改变快递入驻和存量报价补录流程。

+

指定人员发起变价。所有存量报价、变价统一两级审核:初审、复审各任意一名指定人员通过即可,复审通过后生成生效版本。@if($quotePermissions['self_reviewers'] ?? []){{ implode('、', array_column($quotePermissions['self_reviewers'], 'display_name')) }}已获授权,可审核本人发起的变价;移出审核名单时同步撤销该授权。@else 发起人不能审核自己的变价。@endif 快递入驻沿用上方初审、复审设置。

@if(!$quotePermissions['configured'])

尚未单独配置报价变价人员,当前沿用原有权限;保存后按下方名单执行。

@endif -
+ @csrf @method('PATCH')
@@ -12,8 +12,8 @@

人员须在职、已绑定启用账号并有报价管理页面权限,无需管理员身份。每类最多 10 人。

-
- @foreach(['initiators' => '变价发起人员', 'reviewers' => '变价审核人员'] as $stage => $label) +
+ @foreach(['initiators' => '变价发起人员', 'first_reviewers' => '报价初审人员', 'final_reviewers' => '报价复审人员'] as $stage => $label)

{{ $label }}

    @@ -26,13 +26,13 @@ @endforeach
-

{{ $stage === 'reviewers' ? '任意一人通过即可,其余人无需重复审核。' : '可创建、保存和提交本人发起的报价变价。' }}

+

{{ $stage !== 'initiators' ? '任意一人通过即可,其余人无需重复审核。' : '可创建、保存和提交本人发起的报价变价。' }}

@endforeach
- - 保存后立即对未完成变价生效,已完成的审核记录保持不变。 + + 保存后立即对所有未完成报价和以后新提交报价生效;已完成审核记录保留。

变价权限变更记录(最近 10 次)

@@ -40,6 +40,7 @@

{{ $entry['actor'] }} · {{ \Illuminate\Support\Carbon::parse($entry['at'])->format('Y-m-d H:i') }}

发起:{{ implode('、', array_column($entry['after']['initiators'], 'display_name')) }};审核:{{ implode('、', array_column($entry['after']['reviewers'], 'display_name')) }}

+ @if(!empty($entry['after']['first_reviewers']))

初审:{{ implode('、', array_column($entry['after']['first_reviewers'], 'display_name')) }};复审:{{ implode('、', array_column($entry['after']['final_reviewers'], 'display_name')) }}

@endif @if($entry['after']['self_reviewers'] ?? [])

可审核本人单据:{{ implode('、', array_column($entry['after']['self_reviewers'], 'display_name')) }}

@endif
@empty diff --git a/tests/Feature/Business/CourierQuoteWorkflowPermissionsTest.php b/tests/Feature/Business/CourierQuoteWorkflowPermissionsTest.php index 835a1106..55e2cfaf 100644 --- a/tests/Feature/Business/CourierQuoteWorkflowPermissionsTest.php +++ b/tests/Feature/Business/CourierQuoteWorkflowPermissionsTest.php @@ -60,6 +60,162 @@ class CourierQuoteWorkflowPermissionsTest extends FeatureTestCase return ['initiators' => ['init-one', 'init-two'], 'reviewers' => ['review-one', 'review-two']]; } + private function stagedGroups(): array + { + return ['initiators' => ['init-one', 'init-two'], 'first_reviewers' => ['review-one', 'review-two'], + 'final_reviewers' => ['init-one', 'init-two']]; + } + + public function test_two_stage_review_accepts_either_person_at_each_stage_and_only_final_creates_a_version(): void + { + app(CourierQuoteWorkflowPermissions::class)->save($this->stagedGroups(), '负责人指定两级审核', null); + foreach ([['review-one', 'init-two', 'init-one'], ['review-two', 'init-one', 'init-two']] as [$first, $final, $creator]) { + $change = $this->pending($creator); + $this->withExceptionHandling()->loginAs($this->people[$final], $this->company) + ->post(route('business.courier-quote-changes.approve', $change))->assertForbidden(); + $this->loginAs($this->people[$first], $this->company) + ->get(route('business.courier-quote-changes.show', $change))->assertOk()->assertSeeText('初审通过,转复审'); + $before = \App\Models\Business\CourierQuoteVersion::count(); + $this->post(route('business.courier-quote-changes.approve', $change))->assertRedirect()->assertSessionHasNoErrors(); + $this->assertSame('pending_final_review', $change->fresh()->status); + $this->assertSame($before, \App\Models\Business\CourierQuoteVersion::count()); + $this->assertDatabaseHas('business_courier_quote_change_events', ['quote_change_id' => $change->id, 'event_type' => 'first_approved', 'created_by' => $this->people[$first]->id]); + $this->withExceptionHandling()->post(route('business.courier-quote-changes.approve', $change))->assertForbidden(); + $this->loginAs()->post(route('business.courier-quote-changes.approve', $change))->assertForbidden(); + $this->loginAs($this->people[$final], $this->company) + ->get(route('business.courier-quote-changes.index', ['status' => 'pending_final_review']))->assertOk()->assertSeeText('待复审')->assertSee('name="ids[]"', false); + $this->get(route('business.courier-quote-changes.show', $change))->assertOk()->assertSeeText('复审通过'); + $this->post(route('business.courier-quote-changes.approve', $change))->assertRedirect()->assertSessionHasNoErrors(); + $this->assertSame('approved', $change->fresh()->status); + $this->assertSame($this->people[$final]->id, $change->fresh()->approved_by); + $this->assertSame($before + 1, \App\Models\Business\CourierQuoteVersion::count()); + $this->withExceptionHandling()->post(route('business.courier-quote-changes.approve', $change))->assertSessionHasErrors('status'); + } + } + + public function test_stock_quote_batch_review_uses_named_stages_without_administrator_bypass(): void + { + $groups = $this->stagedGroups(); + app(CourierQuoteWorkflowPermissions::class)->save($groups, '负责人指定两级审核', null); + $entry = \App\Models\Business\CourierStockQuoteEntry::create([ + 'company_id' => $this->company->id, 'courier_name' => '存量阶段测试', 'quote_type' => '标准快递报价', + 'sheet_name' => '存量阶段测试', 'source_range' => 'A1:B2', 'values_json' => json_encode([['省份','价格'],['江苏',5]]), + 'formulas_json' => '[]', 'files' => [], 'created_by' => $this->people['init-one']->id, + 'effective_date' => '2026-10-01', + ]); + $this->loginAs($this->people['init-one'], $this->company); + $change = app(\App\Support\CourierQuoteChangeService::class)->create([ + 'source_quote_id' => 'STOCK-'.$entry->id, 'change_type' => '存量报价', 'effective_date' => '2026-10-01', + 'summary' => '核对存量报价期间及计费规则', 'quote_payload' => ['stock_quote_entry_id' => $entry->id, 'billing_rules' => '按原报价计费'], + 'proposed_values_json' => $entry->values_json, + ], $this->people['init-one']->id); + $entry->update(['source_change_id' => $change->id]); + $this->post(route('business.courier-quote-changes.submit', $change))->assertRedirect(); + $request = ['ids' => [$change->id], 'stock_rules_confirmed' => 1]; + $this->withExceptionHandling()->loginAs()->post(route('business.courier-quote-changes.approve', $change), ['stock_rules_confirmed'=>1])->assertForbidden(); + $this->loginAs($this->people['review-one'], $this->company)->post(route('business.courier-quote-changes.batch-approve'), $request)->assertRedirect(); + $this->assertSame('pending_final_review', $change->fresh()->status); + $this->assertDatabaseCount('business_courier_quote_versions', 0); + $this->post(route('business.courier-quote-changes.batch-approve'), $request)->assertRedirect(); + $this->assertSame('pending_final_review', $change->fresh()->status); + $this->loginAs($this->people['init-two'], $this->company)->get(route('business.courier-quote-changes.show', $change)) + ->assertOk()->assertSee('name="stock_rules_confirmed"', false)->assertSeeText('复审通过'); + $this->post(route('business.courier-quote-changes.batch-approve'), $request)->assertRedirect(); + $this->assertSame('approved', $change->fresh()->status); + $this->assertDatabaseCount('business_courier_quote_versions', 1); + $this->assertSame('存量报价,审核生效(无需签章)', $change->fresh()->version->signature_status); + } + + public function test_final_reviewer_return_requires_a_new_first_review_after_resubmission(): void + { + app(CourierQuoteWorkflowPermissions::class)->save($this->stagedGroups(), 'test', null); + $change = $this->pending(); + $this->loginAs($this->people['review-two'], $this->company)->post(route('business.courier-quote-changes.approve', $change))->assertRedirect(); + $this->loginAs($this->people['init-two'], $this->company)->post(route('business.courier-quote-changes.return', $change), ['review_note' => '请补充报价依据'])->assertRedirect(); + $this->assertSame('returned', $change->fresh()->status); + $this->loginAs($this->people['init-one'], $this->company)->post(route('business.courier-quote-changes.submit', $change))->assertRedirect(); + $this->assertSame('pending_review', $change->fresh()->status); + $this->withExceptionHandling()->loginAs($this->people['init-two'], $this->company)->post(route('business.courier-quote-changes.approve', $change))->assertForbidden(); + $this->assertDatabaseCount('business_courier_quote_versions', 0); + } + + public function test_stale_first_review_and_permission_revocation_cannot_skip_a_stage(): void + { + $permissions = app(CourierQuoteWorkflowPermissions::class); + $permissions->save($this->stagedGroups(), 'test', null); + $change = $this->pending(); + $stale = $change->fresh(); + app(\App\Support\CourierQuoteChangeService::class)->approve($change, $this->people['review-one']->id); + try { + app(\App\Support\CourierQuoteChangeService::class)->approve($stale, $this->people['review-two']->id); + $this->fail('过期初审请求不能执行复审'); + } catch (\Symfony\Component\HttpKernel\Exception\HttpException $e) { + $this->assertSame(403, $e->getStatusCode()); + } + $this->assertSame('pending_final_review', $change->fresh()->status); + $this->assertDatabaseCount('business_courier_quote_versions', 0); + $this->eligible = false; + $this->assertFalse($permissions->canReviewChange($change->fresh(), $this->people['init-two']->id)); + $this->eligible = true; + $this->people['init-two']->update(['enabled' => false]); + $this->assertFalse($permissions->canReviewChange($change->fresh(), $this->people['init-two']->id)); + } + + public function test_stage_settings_reject_overlap_partial_groups_and_silent_single_stage_downgrade(): void + { + $permissions = app(CourierQuoteWorkflowPermissions::class); + $this->withExceptionHandling()->loginAs()->patch(route('system-settings.workflow-reviewers.quote.update'), + [...$this->stagedGroups(), 'final_reviewers' => ['review-one']])->assertSessionHasErrors('final_reviewers'); + $this->patch(route('system-settings.workflow-reviewers.quote.update'), $this->stagedGroups())->assertRedirect()->assertSessionHasNoErrors(); + $this->assertTrue($permissions->settings()['staged']); + $this->get(route('system-settings.workflow-reviewers.index'))->assertOk()->assertSeeText('报价初审人员')->assertSeeText('报价复审人员'); + $this->patch(route('system-settings.workflow-reviewers.quote.update'), $this->permissionGroups())->assertSessionHasErrors('first_reviewers'); + $this->assertTrue($permissions->settings()['staged']); + } + + public function test_onboarded_requote_waiting_final_review_cannot_be_overwritten_or_duplicated(): void + { + app(CourierQuoteWorkflowPermissions::class)->save($this->stagedGroups(), 'test', null); + $quote = ['quote_mode' => 'waybill_rate', 'volumetric_rule' => '计泡', 'volumetric_divisor' => 6000, + 'quote_effective_date' => now()->addDay()->toDateString(), + 'quote_rows' => [['region' => '江苏', 'base' => '3.2', 'rates' => ['0.8']]]]; + $onboarding = CourierOnboarding::create([ + 'company_id' => $this->company->id, 'number' => 'RZ-TWO-STAGE', 'token' => str_repeat('z', 40), + 'status' => CourierOnboarding::STATUS_ACTIVATED, 'courier_name' => '两级变价测试快递', + ...app(CourierOnboardingService::class)->quoteAttributes($quote), + ]); + $baseChange = CourierQuoteChange::create([ + 'company_id' => $this->company->id, 'number' => 'BG-STAGE-BASE', 'source_quote_id' => 'RZ-'.$onboarding->id, + 'source_sheet_name' => '两级变价测试快递报价', 'carrier_name' => $onboarding->courier_name, + 'quote_type' => '快递报价', 'change_type' => '新快递入驻', 'status' => 'approved', + 'effective_date' => now()->subDay(), 'summary' => '已完成入驻审核的首版报价', 'created_by' => $this->people['init-one']->id, + ]); + \App\Models\Business\CourierQuoteVersion::create([ + 'company_id' => $this->company->id, 'version_code' => 'QB-STAGE-BASE', + 'source_change_id' => $baseChange->id, + 'source_quote_id' => 'RZ-'.$onboarding->id, 'sheet_name' => '两级变价测试快递报价', + 'company_name' => $onboarding->courier_name, 'carrier_name' => $onboarding->courier_name, + 'quote_type' => '快递报价', 'effective_date' => now()->subDay(), 'status' => 'approved', + 'signature_status' => '已签署并归档', 'values_json' => json_encode([['省份','价格'],['江苏',3.2]]), + 'formulas_json' => '[]', 'created_by' => $this->people['init-one']->id, 'approved_by' => $this->people['init-two']->id, + ]); + $quote['quote_rows'][0]['base'] = '3.5'; + $quote['summary'] = '两级审核变价测试'; + $this->loginAs($this->people['init-one'], $this->company) + ->post(route('business.courier-onboardings.requote.store', $onboarding), $quote)->assertRedirect()->assertSessionHasNoErrors(); + $change = CourierQuoteChange::latest('id')->firstOrFail(); + $this->loginAs($this->people['review-one'], $this->company) + ->post(route('business.courier-quote-changes.approve', $change))->assertRedirect()->assertSessionHasNoErrors(); + $this->assertSame('pending_final_review', $change->fresh()->status); + $this->assertDatabaseCount('business_courier_quote_versions', 1); + $this->loginAs($this->people['init-one'], $this->company) + ->get(route('business.courier-onboardings.requote', $onboarding))->assertRedirect(route('business.courier-quote-changes.show', $change)); + $quote['quote_rows'][0]['base'] = '4'; + $this->withExceptionHandling()->post(route('business.courier-onboardings.requote.store', $onboarding), $quote)->assertSessionHasErrors('status'); + $this->assertDatabaseCount('business_courier_quote_changes', 2); + $this->assertSame('pending_final_review', $change->fresh()->status); + } + private function payload(): array { return ['source_quote_id' => 'QB-001', 'change_type' => '费率调整', 'effective_date' => now()->addDay()->toDateString(), -- 2.47.2