From 0c3bc0d5f6bb5c4110740a5379d900a2bb802d41 Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Thu, 5 Nov 2026 20:13:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=97=E9=93=BA=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BD=93=E5=89=8D=E8=8A=82=E7=82=B9=E5=81=9C?= =?UTF-8?q?=E7=95=99=E6=97=B6=E9=95=BF=20(#908)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/business_navigation.php | 3 ++ .../ShopInfoFlowMirrorRepository.php | 54 ++++++++++++++++++- tests/Feature/Settings/NavigationTest.php | 5 ++ .../ShopInfoFlowMirrorRepositoryTest.php | 40 +++++++++----- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/config/business_navigation.php b/config/business_navigation.php index 627ee835..c0788dde 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -977,6 +977,9 @@ $navigation = [ ['name' => 'flow_type', 'label' => '流程类型'], ['name' => 'approval_status', 'label' => '审批状态'], ['name' => 'current_approver', 'label' => '当前审批人'], + ['name' => 'current_node', 'label' => '当前节点'], + ['name' => 'node_entered_at', 'label' => '进入当前节点时间'], + ['name' => 'node_waiting_duration', 'label' => '节点停留时长'], ['name' => 'shop_name', 'label' => '店铺名称'], ['name' => 'platform', 'label' => '平台'], ['name' => 'shop_head', 'label' => '店铺运营负责人'], diff --git a/modules/EcommerceFinance/Repositories/ShopInfoFlowMirrorRepository.php b/modules/EcommerceFinance/Repositories/ShopInfoFlowMirrorRepository.php index 402584d7..5d0f328d 100644 --- a/modules/EcommerceFinance/Repositories/ShopInfoFlowMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/ShopInfoFlowMirrorRepository.php @@ -3,6 +3,7 @@ namespace Modules\EcommerceFinance\Repositories; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Carbon; use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry; use RuntimeException; @@ -180,14 +181,34 @@ class ShopInfoFlowMirrorRepository { $flowType = (int) ($row->flow_type ?? 0); $statusCode = $row->approval_status_code !== null ? (int) $row->approval_status_code : null; + $approvalStatus = $statusCode === null + ? '' + : (self::APPROVAL_STATUSES[$statusCode] ?? (string) $statusCode); + $currentApprover = trim((string) ($row->current_approver ?? '')); + $currentNode = match ($statusCode) { + 0 => '暂存', + 1, 7 => $currentApprover !== '' ? '审批节点(' . $currentApprover . ')' : '待分配审批人', + 2 => '已拒绝', + 3 => '已完成', + 4 => '已撤回', + 5 => '待签署', + 6 => '已签署', + default => '', + }; + $nodeEnteredAt = in_array($statusCode, [1, 7], true) + ? trim((string) ($row->flow_updated_at ?? '')) + : ''; return [ 'id' => $row->id, 'flow_id' => (string) $row->flow_id, 'flow_type' => self::FLOW_TYPES[$flowType] ?? ('其它(' . $flowType . ')'), 'flow_subject' => (string) ($row->flow_subject ?? ''), - 'approval_status' => $statusCode === null ? '' : (self::APPROVAL_STATUSES[$statusCode] ?? (string) $statusCode), - 'current_approver' => (string) ($row->current_approver ?? ''), + 'approval_status' => $approvalStatus, + 'current_approver' => $currentApprover, + 'current_node' => $currentNode, + 'node_entered_at' => $nodeEnteredAt, + 'node_waiting_duration' => $this->waitingDuration($nodeEnteredAt), 'apply_user' => (string) ($row->apply_user ?? ''), 'apply_time' => (string) ($row->apply_time ?? ''), 'apply_department' => (string) ($row->apply_department ?? ''), @@ -213,4 +234,33 @@ class ShopInfoFlowMirrorRepository 'flow_updated_at' => (string) ($row->flow_updated_at ?? ''), ]; } + + private function waitingDuration(string $enteredAt): string + { + if ($enteredAt === '') { + return ''; + } + + try { + $minutes = (int) max(0, Carbon::parse($enteredAt)->diffInMinutes(now(), true)); + } catch (\Throwable) { + return ''; + } + + if ($minutes < 1) { + return '不到1分钟'; + } + + $days = intdiv($minutes, 1440); + $hours = intdiv($minutes % 1440, 60); + $remainingMinutes = $minutes % 60; + if ($days > 0) { + return $days . '天' . ($hours > 0 ? $hours . '小时' : ''); + } + if ($hours > 0) { + return $hours . '小时' . ($remainingMinutes > 0 ? $remainingMinutes . '分钟' : ''); + } + + return $remainingMinutes . '分钟'; + } } diff --git a/tests/Feature/Settings/NavigationTest.php b/tests/Feature/Settings/NavigationTest.php index 9fb205d6..192a56a2 100644 --- a/tests/Feature/Settings/NavigationTest.php +++ b/tests/Feature/Settings/NavigationTest.php @@ -250,6 +250,9 @@ class NavigationTest extends FeatureTestCase ['name' => 'flow_type', 'label' => '流程类型'], ['name' => 'approval_status', 'label' => '审批状态'], ['name' => 'current_approver', 'label' => '当前审批人'], + ['name' => 'current_node', 'label' => '当前节点'], + ['name' => 'node_entered_at', 'label' => '进入当前节点时间'], + ['name' => 'node_waiting_duration', 'label' => '节点停留时长'], ['name' => 'shop_name', 'label' => '店铺名称'], ['name' => 'platform', 'label' => '平台'], ['name' => 'shop_head', 'label' => '店铺运营负责人'], @@ -414,6 +417,8 @@ class NavigationTest extends FeatureTestCase // 店铺申请流程镜像:列头与查询条件都按外部店铺申请页对齐。 ->assertSeeText('单据编号') ->assertSeeText('审批状态') + ->assertSeeText('当前节点') + ->assertSeeText('节点停留时长') ->assertSeeText('ERP店铺名称') ->assertSee('data-directory-multi-select="flow_type"', false) ->assertSee('data-directory-multi-select="approval_status"', false) diff --git a/tests/Unit/EcommerceFinance/ShopInfoFlowMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/ShopInfoFlowMirrorRepositoryTest.php index cbb7bf7c..4937ba35 100644 --- a/tests/Unit/EcommerceFinance/ShopInfoFlowMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/ShopInfoFlowMirrorRepositoryTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\EcommerceFinance; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository; @@ -90,20 +91,33 @@ class ShopInfoFlowMirrorRepositoryTest extends TestCase public function test_it_lists_applications_with_oa_approval_state(): void { - $result = $this->repository->paginate(1, 10); + Carbon::setTestNow('2026-10-02 12:30:00'); - $this->assertSame(3, $result['total']); - $rows = collect($result['data'])->keyBy('flow_id'); + try { + $result = $this->repository->paginate(1, 10); - $this->assertSame('店铺开店', $rows['shp-1']['flow_type']); - $this->assertSame('完成', $rows['shp-1']['approval_status']); - $this->assertSame('店铺变更', $rows['shp-2']['flow_type']); - $this->assertSame('流程中', $rows['shp-2']['approval_status']); - $this->assertSame('审核人A', $rows['shp-2']['current_approver']); - $this->assertSame('店铺关店', $rows['shp-3']['flow_type']); - $this->assertSame('拒绝', $rows['shp-3']['approval_status']); - // 默认按申请时间倒序。 - $this->assertSame(['shp-3', 'shp-2', 'shp-1'], array_column($result['data'], 'flow_id')); + $this->assertSame(3, $result['total']); + $rows = collect($result['data'])->keyBy('flow_id'); + + $this->assertSame('店铺开店', $rows['shp-1']['flow_type']); + $this->assertSame('完成', $rows['shp-1']['approval_status']); + $this->assertSame('已完成', $rows['shp-1']['current_node']); + $this->assertSame('', $rows['shp-1']['node_waiting_duration']); + $this->assertSame('店铺变更', $rows['shp-2']['flow_type']); + $this->assertSame('流程中', $rows['shp-2']['approval_status']); + $this->assertSame('审核人A', $rows['shp-2']['current_approver']); + $this->assertSame('审批节点(审核人A)', $rows['shp-2']['current_node']); + $this->assertSame('2026-10-02 10:00:00', $rows['shp-2']['node_entered_at']); + $this->assertSame('2小时30分钟', $rows['shp-2']['node_waiting_duration']); + $this->assertSame('店铺关店', $rows['shp-3']['flow_type']); + $this->assertSame('拒绝', $rows['shp-3']['approval_status']); + $this->assertSame('已拒绝', $rows['shp-3']['current_node']); + $this->assertSame('', $rows['shp-3']['node_waiting_duration']); + // 默认按申请时间倒序。 + $this->assertSame(['shp-3', 'shp-2', 'shp-1'], array_column($result['data'], 'flow_id')); + } finally { + Carbon::setTestNow(); + } } public function test_it_filters_by_type_status_platform_and_dates(): void @@ -133,5 +147,7 @@ class ShopInfoFlowMirrorRepositoryTest extends TestCase $this->assertSame('', $rows['shp-4']['approval_status']); $this->assertSame('', $rows['shp-4']['current_approver']); + $this->assertSame('', $rows['shp-4']['current_node']); + $this->assertSame('', $rows['shp-4']['node_waiting_duration']); } }