feat: 报价统一初审复审并支持每阶段任一人通过 #1375

Open
limeng wants to merge 1 commits from feature/limeng-quote-two-stage-review into main
14 changed files with 271 additions and 47 deletions

View File

@ -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},请先查看该单;待审核单可由发起人撤回修改。");
}

View File

@ -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());
}

View File

@ -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', '报价发起和审核人员已保存,立即对未完成报价生效。');
}
}

View File

@ -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,

View File

@ -34,6 +34,7 @@ class CourierQuoteChangeEvent extends Model
'withdrawn' => '撤回修改',
'returned' => '退回修改',
'approved' => '审核通过',
'first_approved' => '初审通过',
'voided' => '版本作废',
'period_end_updated' => '设置执行截止日期',
'periods_corrected' => '更正执行区间',

View File

@ -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,

View File

@ -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();

View File

@ -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},审核完成后再发起新的变价。"]);
}

View File

@ -2,7 +2,9 @@
报价管理 → 报价历史中,有报价审核权限的账号可勾选本页待审核记录,或用表头勾选框全选本页可审核项,点击“批量审核通过”。确认窗口列出变更单号、快递、变更类型和执行期间;核对原报价、计费规则及实际执行日期后提交。已审核和受自审限制的记录不显示勾选框。
批量接口沿用当前公司和报价管理页级权限,同时检查管理员/超级管理员审核身份;仅处理明确提交的记录ID,最多100条,不隐式选择其他页或其他公司。逐条调用现有单条审核入口,保留自审限制、报价期间冲突校验、版本生成、审核日志和原签署后续流程。单条失败不撤销其他成功项;完成后显示成功/未通过数量及每条结果,返回原页码。
批量接口沿用当前公司和报价管理页级权限,按配置检查当前环节指定人员;仅处理明确提交的记录ID,最多100条,不隐式选择其他页或其他公司。逐条调用现有单条审核入口,保留自审限制、报价期间冲突校验、版本生成、审核日志和原签署后续流程。单条失败不撤销其他成功项;完成后显示成功/未通过数量及每条结果,返回原页码。
在系统设置 → 流程审核权限设置中配置报价初审、复审名单后,所有未完成存量报价和变价统一两级审核。每环节任意一人通过即可;初审只转为待复审,复审通过才生成版本并执行原签署后续流程。管理员身份不能越过指定名单。退回或撤回后重新提交必须重走初审;待复审的后台变价仍视为未完成,不能再次发起同一快递变价。既有已完成报价和审计记录保留。
存量报价仍按既有规则审核生效,不自动发起签署;历史签署资料必须逐份核对,不接受批量标记为已经核验。非存量变价沿用原单条审核的签署准备与推送流程。

View File

@ -16,13 +16,13 @@
@if(collect($stockEntry->files)->contains('source', 'workbook_embedded'))
<p class="quote-review__hint">工作表内嵌图片已按原始字节独立留存,未裁剪、未压缩。提取成功不代表已核对一致;后续调价仍保留本版原件。</p>
@endif
@if($canReview && $change->status === 'pending_review')
@if($canReview && in_array($change->status, ['pending_review', 'pending_final_review']))
<div class="quote-review__form">
<label><input type="checkbox" form="quote-approval-form" name="stock_rules_confirmed" value="1" required> 我已逐项核对原报价、计费规则和实际执行日期</label>
@if(collect($stockEntry->files)->contains('kind', 'signed'))
<p><label><input type="checkbox" form="quote-approval-form" name="stock_signature_verified" value="1"> 我已核验历史签署资料与本报价一致,按历史签署资料归档</label></p>
@endif
<p class="quote-review__hint">存量报价审核通过后按实际执行日期生效,无需签章。历史签署资料可另行核验归档,不影响报价生效。</p>
<p class="quote-review__hint">存量报价最终审核通过后按实际执行日期生效,无需签章。历史签署资料可另行核验归档,不影响报价生效。</p>
</div>
@endif
</div>

View File

@ -68,16 +68,16 @@
@endif
<div class="quote-history__table-wrap"><table><thead><tr>@if($canReview)<th><input type="checkbox" data-review-all aria-label="全选本页可审核记录"></th>@endif<th>变更单号</th><th>原报价</th><th>快递公司</th><th>变更类型</th><th>明细</th><th>生效日期</th><th>生效方式</th><th>追溯核算</th><th>状态</th><th>新版本</th><th>更新时间</th><th>操作</th></tr></thead><tbody>
@foreach($changes as $change)
@php($badge = match($change->status){'pending_review'=>'pending','approved'=>'approved','returned'=>'returned',default=>''})
<tr>@if($canReview)<td>@if(in_array($change->id, $reviewableChangeIds, true) && $change->status === 'pending_review')<input type="checkbox" name="ids[]" value="{{ $change->id }}" data-review-choice data-review-label="{{ $change->number }} · {{ $change->carrier_name }} · {{ $change->change_type }} · {{ $change->periodLabel() }}" aria-label="选择 {{ $change->number }}">@else<span class="quote-history__hint" title="{{ $change->status === 'pending_review' ? '当前账号无权审核此单' : '仅待审核记录可勾选' }}">—</span>@endif</td>@endif<td class="quote-history__number">{{ $change->number }}</td><td>{{ $change->source_quote_id }}</td><td>{{ $change->carrier_name }}</td><td>{{ $change->change_type }}</td><td>{{ $change->items->count() }} 项</td><td>{{ $change->effective_date->toDateString() }}</td><td><span class="quote-history__badge @if($change->isRetrospective()) quote-history__badge--pending @endif">{{ $change->isRetrospective() ? '追溯变价' : '正常生效' }}</span></td><td><span class="quote-history__badge @if($change->recalculation_status==='blocked') quote-history__badge--returned @elseif($change->recalculation_status==='pending') quote-history__badge--pending @endif">{{ $change->recalculationStatusLabel() }}</span></td><td><span class="quote-history__badge @if($badge) quote-history__badge--{{ $badge }} @endif">{{ $change->statusLabel() }}</span></td><td>{{ $change->version?->version_code ?? '—' }}</td><td>{{ $change->updated_at?->format('Y-m-d H:i') }}</td><td><a class="quote-history__link" href="{{ route('business.courier-quote-changes.show',$change) }}">查看</a>@if($change->isEditable() && $change->created_by===user_id()) · <a class="quote-history__link" href="{{ route('business.courier-quote-changes.edit',$change) }}">编辑</a>@endif</td></tr>
@php($badge = match($change->status){'pending_review','pending_final_review'=>'pending','approved'=>'approved','returned'=>'returned',default=>''})
<tr>@if($canReview)<td>@if(in_array($change->id, $reviewableChangeIds, true) && in_array($change->status, ['pending_review', 'pending_final_review']))<input type="checkbox" name="ids[]" value="{{ $change->id }}" data-review-choice data-review-label="{{ $change->number }} · {{ $change->carrier_name }} · {{ $change->change_type }} · {{ $change->periodLabel() }}" aria-label="选择 {{ $change->number }}">@else<span class="quote-history__hint" title="{{ in_array($change->status, ['pending_review', 'pending_final_review']) ? '当前账号无权审核此单' : '仅待审核记录可勾选' }}">—</span>@endif</td>@endif<td class="quote-history__number">{{ $change->number }}</td><td>{{ $change->source_quote_id }}</td><td>{{ $change->carrier_name }}</td><td>{{ $change->change_type }}</td><td>{{ $change->items->count() }} 项</td><td>{{ $change->effective_date->toDateString() }}</td><td><span class="quote-history__badge @if($change->isRetrospective()) quote-history__badge--pending @endif">{{ $change->isRetrospective() ? '追溯变价' : '正常生效' }}</span></td><td><span class="quote-history__badge @if($change->recalculation_status==='blocked') quote-history__badge--returned @elseif($change->recalculation_status==='pending') quote-history__badge--pending @endif">{{ $change->recalculationStatusLabel() }}</span></td><td><span class="quote-history__badge @if($badge) quote-history__badge--{{ $badge }} @endif">{{ ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}</span></td><td>{{ $change->version?->version_code ?? '—' }}</td><td>{{ $change->updated_at?->format('Y-m-d H:i') }}</td><td><a class="quote-history__link" href="{{ route('business.courier-quote-changes.show',$change) }}">查看</a>@if($change->isEditable() && $change->created_by===user_id()) · <a class="quote-history__link" href="{{ route('business.courier-quote-changes.edit',$change) }}">编辑</a>@endif</td></tr>
@endforeach
</tbody></table></div>
@if($canReview)
<dialog class="qh-review-dialog" data-review-dialog aria-labelledby="qh-review-dialog-title">
<h3 id="qh-review-dialog-title">确认批量审核通过</h3>
<p>将审核下列报价,并按现有流程生成新版本。请先核对原报价、计费规则与实际执行日期。</p>
<p>将处理下列报价的当前审核环节。初审通过后转复审,复审通过后生成新版本;请先核对原报价、计费规则与实际执行日期。</p>
<ul data-review-selection></ul>
<p>存量报价审核后生效,不自动发起签署;其他变价沿用单条审核的签署准备和推送流程。历史签署资料不会在此批量标记为已核验。</p>
<p>存量报价最终审核后生效,不自动发起签署;其他变价复审通过后沿用单条审核的签署准备和推送流程。历史签署资料不会在此批量标记为已核验。</p>
<label class="qh-review-confirm"><input type="checkbox" name="stock_rules_confirmed" value="1" required>我已核对所有选中报价的原报价、计费规则及实际执行日期</label>
<div class="qh-review-dialog-actions"><button type="button" class="quote-history__button" data-review-cancel>取消</button><button type="submit" class="quote-history__button quote-history__button--primary" data-review-submit>确认审核通过</button></div>
</dialog>

View File

@ -75,12 +75,15 @@
<a class="quote-review__button" href="{{ route('business.courier-quote-changes.edit',$change) }}"><span class="material-icons-outlined" aria-hidden="true">edit</span><span>编辑草稿</span></a>
<form method="POST" action="{{ route('business.courier-quote-changes.submit',$change) }}">@csrf<button class="quote-review__button quote-review__button--primary" type="submit"><span class="material-icons-outlined" aria-hidden="true">send</span><span>提交审核</span></button></form>
@endif
@if($canReview && $change->status==='pending_review')
<form id="quote-approval-form" method="POST" action="{{ route('business.courier-quote-changes.approve',$change) }}" onsubmit="return confirm('审核通过后将生成不可覆盖的新报价版本,确认继续吗?')">@csrf<button class="quote-review__button quote-review__button--primary" type="submit"><span class="material-icons-outlined" aria-hidden="true">verified</span><span>审核通过</span></button></form>
@if($canReview && in_array($change->status, ['pending_review', 'pending_final_review']))
@php($firstReview = ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review')
<form id="quote-approval-form" method="POST" action="{{ route('business.courier-quote-changes.approve',$change) }}" onsubmit="return confirm('{{ $firstReview ? '初审通过后转复审,复审通过才生成生效报价版本,确认继续吗?' : '审核通过后将生成不可覆盖的新报价版本,确认继续吗?' }}')">@csrf<button class="quote-review__button quote-review__button--primary" type="submit"><span class="material-icons-outlined" aria-hidden="true">verified</span><span>{{ $firstReview ? '初审通过,转复审' : (($quoteWorkflow['staged'] ?? false) ? '复审通过' : '审核通过') }}</span></button></form>
@endif
</div>
</div>
@if(!$change->isStockQuote() && ($quoteWorkflow['configured'] ?? false))
@if($quoteWorkflow['staged'] ?? false)
<div class="quote-review__alert" role="status"><span class="material-icons-outlined" aria-hidden="true">verified_user</span><div>初审:{{ implode('、', array_column($quoteWorkflow['first_reviewers'], 'display_name')) }}(任意一人通过);复审:{{ implode('、', array_column($quoteWorkflow['final_reviewers'], 'display_name')) }}(任意一人通过)。复审通过后才生成生效报价版本,退回修改后需重新初审。当前:{{ $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}。</div></div>
@elseif(!$change->isStockQuote() && ($quoteWorkflow['configured'] ?? false))
<div class="quote-review__alert" role="status"><span class="material-icons-outlined" aria-hidden="true">verified_user</span><div>变价发起:{{ 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 待审核单可由发起人撤回修改后重提。</div></div>
@endif
@if(is_string(session('success')))<div style="margin-bottom:16px;border:1px solid #BAD0AB;border-radius:8px;background:#F3F8EF;padding:10px 12px;color:#40622F" role="status">{{ session('success') }}</div>@endif
@ -88,7 +91,7 @@
@if($reviewWarnings)<div class="quote-review__alert" role="alert" style="border-color:#E6B7B7;background:#FFF4F4;color:#8A1515"><span class="material-icons-outlined" aria-hidden="true">report</span><div><strong>审核提醒(请重点核对)</strong>@foreach($reviewWarnings as $warning)<br>· {{ $warning }}@endforeach</div></div>@endif
@if($change->isRetrospective())<div class="quote-review__alert" role="status"><span class="material-icons-outlined" aria-hidden="true">history</span><div><strong>追溯变价 · {{ $change->recalculationStatusLabel() }}</strong><br>执行期间:{{ $change->periodLabel() }}。{{ $change->recalculation_note ?: '审核完成后应按执行期间生成补款或扣款明细,原运费和原始 Excel 保持不变。' }}</div></div>@endif
<section class="quote-review__panel" aria-labelledby="review-base-title">
<header class="quote-review__header"><div class="quote-review__title" id="review-base-title"><span class="material-icons-outlined" aria-hidden="true">assignment</span><span>{{ $change->number }} · {{ $change->statusLabel() }}</span></div></header>
<header class="quote-review__header"><div class="quote-review__title" id="review-base-title"><span class="material-icons-outlined" aria-hidden="true">assignment</span><span>{{ $change->number }} · {{ ($quoteWorkflow['staged'] ?? false) && $change->status === 'pending_review' ? '待初审' : $change->statusLabel() }}</span></div></header>
<div class="quote-review__body">
<dl class="quote-review__meta">
<div><dt>原报价版本</dt><dd>{{ $change->source_quote_id }}</dd></div>
@ -248,7 +251,7 @@
</section>
@endif
<section class="quote-review__panel" aria-labelledby="review-events-title"><header class="quote-review__header"><div class="quote-review__title" id="review-events-title"><span class="material-icons-outlined" aria-hidden="true">history</span><span>状态与审计记录</span></div></header><div class="quote-review__body"><div class="quote-review__timeline">@foreach($change->events as $event)<div class="quote-review__event"><time class="quote-review__event-time">{{ $event->created_at?->format('Y-m-d H:i') }}</time><div><div class="quote-review__event-title">{{ $event->eventLabel() }}</div><div class="quote-review__event-note">{{ $event->note }}</div><div class="quote-review__event-actor">操作人:{{ $event->actor?->name ?? ('用户 #' . $event->created_by) }}</div></div></div>@endforeach</div>
@if($canReview && $change->status==='pending_review')<form class="quote-review__review-form" method="POST" action="{{ route('business.courier-quote-changes.return',$change) }}">@csrf<div class="quote-review__field"><label for="review_note">退回原因</label><textarea class="quote-review__control" id="review_note" name="review_note" minlength="2" maxlength="1000" required placeholder="明确说明需要修改的价格、范围或依据"></textarea></div><button class="quote-review__button quote-review__button--danger" type="submit"><span class="material-icons-outlined" aria-hidden="true">undo</span><span>退回修改</span></button></form>@endif
@if($canReview && in_array($change->status, ['pending_review', 'pending_final_review']))<form class="quote-review__review-form" method="POST" action="{{ route('business.courier-quote-changes.return',$change) }}">@csrf<div class="quote-review__field"><label for="review_note">退回原因</label><textarea class="quote-review__control" id="review_note" name="review_note" minlength="2" maxlength="1000" required placeholder="明确说明需要修改的价格、范围或依据"></textarea></div><button class="quote-review__button quote-review__button--danger" type="submit"><span class="material-icons-outlined" aria-hidden="true">undo</span><span>退回修改</span></button></form>@endif
</div></section>
</main>
</x-slot>

View File

@ -1,8 +1,8 @@
<section class="mt-5 rounded-xl border border-gray-200 bg-white p-6" aria-label="报价变价发起和审核人员">
<h2 class="text-sm font-semibold mb-3">报价变价发起和审核人员</h2>
<p class="text-sm text-gray-600 mb-4">指定人员发起变价,由任意一名指定审核人通过即可。@if($quotePermissions['self_reviewers'] ?? []){{ implode('、', array_column($quotePermissions['self_reviewers'], 'display_name')) }}已获授权,可审核本人发起的变价;移出审核名单时同步撤销该授权。@else 发起人不能审核自己的变价。@endif 该设置不改变快递入驻和存量报价补录流程。</p>
<p class="text-sm text-gray-600 mb-4">指定人员发起变价。所有存量报价、变价统一两级审核:初审、复审各任意一名指定人员通过即可,复审通过后生成生效版本。@if($quotePermissions['self_reviewers'] ?? []){{ implode('、', array_column($quotePermissions['self_reviewers'], 'display_name')) }}已获授权,可审核本人发起的变价;移出审核名单时同步撤销该授权。@else 发起人不能审核自己的变价。@endif 快递入驻沿用上方初审、复审设置。</p>
@if(!$quotePermissions['configured'])<p class="text-sm mb-4" role="status">尚未单独配置报价变价人员,当前沿用原有权限;保存后按下方名单执行。</p>@endif
<form method="POST" action="{{ route('system-settings.workflow-reviewers.quote.update') }}" data-reviewers-form data-search-url="{{ route('system-settings.workflow-reviewers.search', ['workflow' => 'quote']) }}" data-reviewer-stages="{{ json_encode([['initiators', '加入发起人员'], ['reviewers', '加入审核人员']]) }}">
<form method="POST" action="{{ route('system-settings.workflow-reviewers.quote.update') }}" data-reviewers-form data-search-url="{{ route('system-settings.workflow-reviewers.search', ['workflow' => 'quote']) }}" data-reviewer-stages="{{ json_encode([['initiators', '加入发起人员'], ['first_reviewers', '加入初审人员'], ['final_reviewers', '加入复审人员']]) }}">
@csrf @method('PATCH')
<label for="quote-reviewer-search" class="block text-xs font-semibold mb-2">查找钉钉花名册人员</label>
<div class="flex flex-wrap gap-2 mb-2">
@ -12,8 +12,8 @@
<p class="text-xs text-gray-600 mb-3">人员须在职、已绑定启用账号并有报价管理页面权限,无需管理员身份。每类最多 10 人。</p>
<p data-reviewer-search-status role="status" class="text-sm mb-3" aria-live="polite"></p>
<div data-reviewer-results class="mb-5"></div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 border-t border-gray-200 pt-5">
@foreach(['initiators' => '变价发起人员', 'reviewers' => '变价审核人员'] as $stage => $label)
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 border-t border-gray-200 pt-5">
@foreach(['initiators' => '变价发起人员', 'first_reviewers' => '报价初审人员', 'final_reviewers' => '报价复审人员'] as $stage => $label)
<div>
<h3 class="text-sm font-semibold mb-2">{{ $label }}</h3>
<ul data-reviewer-selected="{{ $stage }}" class="space-y-2" aria-label="{{ $label }}">
@ -26,13 +26,13 @@
</li>
@endforeach
</ul>
<p class="text-xs text-gray-600 mt-2">{{ $stage === 'reviewers' ? '任意一人通过即可,其余人无需重复审核。' : '可创建、保存和提交本人发起的报价变价。' }}</p>
<p class="text-xs text-gray-600 mt-2">{{ $stage !== 'initiators' ? '任意一人通过即可,其余人无需重复审核。' : '可创建、保存和提交本人发起的报价变价。' }}</p>
</div>
@endforeach
</div>
<div class="flex flex-wrap items-center gap-4 mt-6">
<button type="submit" class="settings-primary rounded-lg px-4 py-2 text-sm">保存变价人员</button>
<span class="text-xs text-gray-600">保存后立即对未完成变价生效,已完成的审核记录保持不变。</span>
<button type="submit" class="settings-primary rounded-lg px-4 py-2 text-sm">保存报价审核人员</button>
<span class="text-xs text-gray-600">保存后立即对所有未完成报价和以后新提交报价生效;已完成审核记录保留。</span>
</div>
</form>
<h3 class="text-sm font-semibold mt-6 mb-3">变价权限变更记录(最近 10 次)</h3>
@ -40,6 +40,7 @@
<div class="border-t border-gray-200 py-3 text-sm">
<p>{{ $entry['actor'] }} · {{ \Illuminate\Support\Carbon::parse($entry['at'])->format('Y-m-d H:i') }}</p>
<p class="text-xs text-gray-600 mt-1">发起:{{ implode('、', array_column($entry['after']['initiators'], 'display_name')) }};审核:{{ implode('、', array_column($entry['after']['reviewers'], 'display_name')) }}</p>
@if(!empty($entry['after']['first_reviewers']))<p class="text-xs text-gray-600 mt-1">初审:{{ implode('、', array_column($entry['after']['first_reviewers'], 'display_name')) }};复审:{{ implode('、', array_column($entry['after']['final_reviewers'], 'display_name')) }}</p>@endif
@if($entry['after']['self_reviewers'] ?? [])<p class="text-xs text-gray-600 mt-1">可审核本人单据:{{ implode('、', array_column($entry['after']['self_reviewers'], 'display_name')) }}</p>@endif
</div>
@empty

View File

@ -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(),