feat: 店铺流程增加当前节点停留时长 (#908)
This commit is contained in:
parent
039631c518
commit
0c3bc0d5f6
@ -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' => '店铺运营负责人'],
|
||||
|
||||
@ -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 . '分钟';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user