From 5c8db5a586e5cba9715a08255c8dec2437b886af Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Thu, 5 Nov 2026 19:47:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=80=E6=AC=BE=E5=BE=85=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E8=BF=81=E5=85=A5=E8=B4=B9=E6=AF=94=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Business/Pages.php | 14 ++++- app/Utilities/SidebarMenu.php | 1 + app/Utilities/SidebarPermissions.php | 28 +++------ config/business_navigation.php | 22 +++---- resources/views/business/pages/home.blade.php | 2 +- routes/admin.php | 28 +++++++-- .../Business/NonJingxiRefundPageTest.php | 12 ++-- tests/Feature/Business/PagesTest.php | 4 +- tests/Feature/Settings/NavigationTest.php | 57 ++++++++++++------- .../SystemSettings/UserPermissionsTest.php | 12 ++-- 10 files changed, 108 insertions(+), 72 deletions(-) diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 63a0cd08..fb42ca32 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -989,6 +989,16 @@ class Pages extends Controller return redirect()->to($url . ($query === null ? '' : '?' . $query)); } + if ($section === 'refunds' && $page === 'refund-pending') { + $url = route('business.pages.show', [ + 'section' => 'fee-ratio-monitoring', + 'page' => 'refund-pending', + ]); + $query = request()->getQueryString(); + + return redirect()->to($url . ($query === null ? '' : '?' . $query)); + } + if ($section === 'billing-transactions' && in_array($page, self::ACCOUNT_BALANCE_PAGES, true)) { $url = route('business.pages.show', array_filter([ 'section' => self::ACCOUNT_BALANCE_SECTION, @@ -7175,7 +7185,7 @@ class Pages extends Controller 'refundError' => $error, 'refundPending' => $pending, 'refundIndexPending' => $indexPending, - 'refundPageSection' => 'refunds', + 'refundPageSection' => $pendingConfirmation ? 'fee-ratio-monitoring' : 'refunds', 'refundPageSlug' => $pendingConfirmation ? 'refund-pending' : 'non-jingxi-refund-data', 'refundPageLabel' => $pageLabel, 'refundPendingConfirmationMode' => $pendingConfirmation, @@ -7221,7 +7231,7 @@ class Pages extends Controller { return $this->exportRefundRows( $request, - 'refunds', + 'fee-ratio-monitoring', 'refund-pending', 'refund_pending', true, diff --git a/app/Utilities/SidebarMenu.php b/app/Utilities/SidebarMenu.php index e6d9abf2..2556bf27 100644 --- a/app/Utilities/SidebarMenu.php +++ b/app/Utilities/SidebarMenu.php @@ -54,6 +54,7 @@ class SidebarMenu ['prototype-finance-reports', 'asset-report', '公司资产报表', 'account_balance'], ]], ['title' => '费比异常数据监控', 'items' => [ + ['fee-ratio-monitoring', 'refund-pending', '退款待确认', 'assignment_return'], ['fee-ratio-monitoring', 'overview', '异常数据监控', 'monitor_heart'], ]], ]; diff --git a/app/Utilities/SidebarPermissions.php b/app/Utilities/SidebarPermissions.php index 38b3d5d7..411a3065 100644 --- a/app/Utilities/SidebarPermissions.php +++ b/app/Utilities/SidebarPermissions.php @@ -11,6 +11,8 @@ class SidebarPermissions { private const LEGACY_PAGE_KEYS = [ 'refunds/small-payment-work-orders' => 'financial-operations/small-payment-work-orders', + 'refunds/refund-pending' => 'fee-ratio-monitoring/refund-pending', + 'refunds/refund-pending/export-details' => 'fee-ratio-monitoring/refund-pending/export-details', 'financial-ledger' => 'financial-operations/ledger', 'financial-ledger/ledger' => 'financial-operations/ledger', ]; @@ -66,17 +68,13 @@ class SidebarPermissions $settings = self::settings(); $userSubject = 'user_' . $user->id; if (in_array($userSubject, $settings['configured'] ?? [], true)) { - return self::withFinanceMonitoringAccess( - self::normalizeAllowedKeys((array) ($settings['subjects'][$userSubject] ?? [])), - ); + return self::normalizeAllowedKeys((array) ($settings['subjects'][$userSubject] ?? [])); } $groups = UserAccessGroup::forUser($user); if ($groups->isNotEmpty()) { - return self::withFinanceMonitoringAccess( - self::normalizeAllowedKeys( - $groups->flatMap(fn ($group) => $group->page_permissions ?? [])->all() - ), + return self::normalizeAllowedKeys( + $groups->flatMap(fn ($group) => $group->page_permissions ?? [])->all() ); } @@ -86,19 +84,7 @@ class SidebarPermissions return null; } - return self::withFinanceMonitoringAccess( - self::normalizeAllowedKeys((array) ($settings['subjects'][$subject] ?? [])), - ); - } - - /** @param list $allowed */ - private static function withFinanceMonitoringAccess(array $allowed): array - { - if (! in_array('fee-ratio-monitoring/overview', $allowed, true)) { - $allowed[] = 'fee-ratio-monitoring/overview'; - } - - return $allowed; + return self::normalizeAllowedKeys((array) ($settings['subjects'][$subject] ?? [])); } public static function hasLimitedDingTalkAccess(User $user): bool @@ -437,6 +423,8 @@ class SidebarPermissions if ($key === 'refunds') { $normalized[] = self::LEGACY_PAGE_KEYS['refunds/small-payment-work-orders']; + $normalized[] = 'fee-ratio-monitoring/refund-pending'; + $normalized[] = 'fee-ratio-monitoring/refund-pending/export-details'; } } diff --git a/config/business_navigation.php b/config/business_navigation.php index d1f5eb7c..627ee835 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -673,17 +673,6 @@ $navigation = [ 'pages' => [ ['slug' => 'jingxi-refund-data', 'title' => '京喜退款数据'], ['slug' => 'non-jingxi-refund-data', 'title' => '售后(退货退款)'], - [ - 'slug' => 'refund-pending', - 'title' => '退款待确认', - 'operations' => [ - [ - 'slug' => 'export-details', - 'title' => '导出明细', - 'description' => '允许查看导出按钮并下载全部待确认明细。', - ], - ], - ], ], ], [ @@ -1042,6 +1031,17 @@ $navigation = [ 'title' => '费比异常数据监控', 'icon' => 'monitor_heart', 'pages' => [ + [ + 'slug' => 'refund-pending', + 'title' => '退款待确认', + 'operations' => [ + [ + 'slug' => 'export-details', + 'title' => '导出明细', + 'description' => '允许查看导出按钮并下载全部待确认明细。', + ], + ], + ], [ 'slug' => 'overview', 'title' => '异常数据监控', diff --git a/resources/views/business/pages/home.blade.php b/resources/views/business/pages/home.blade.php index d297f6db..69be1ef7 100644 --- a/resources/views/business/pages/home.blade.php +++ b/resources/views/business/pages/home.blade.php @@ -325,7 +325,7 @@ @endif 查看退款待确认 diff --git a/routes/admin.php b/routes/admin.php index 1471d0ad..405a6f08 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -484,17 +484,35 @@ Route::get('workspace/refunds/non-jingxi-refund-data/export', 'Business\Pages@ex ->middleware('business.page:refunds,non-jingxi-refund-data') ->name('business.refunds.non-jingxi-refund-data.export'); -Route::get('workspace/refunds/refund-pending/export', 'Business\Pages@exportRefundPending') +Route::get('workspace/fee-ratio-monitoring/refund-pending/export', 'Business\Pages@exportRefundPending') ->middleware([ - 'business.page:refunds,refund-pending', - 'business.operation:refunds,refund-pending,export-details', + 'business.page:fee-ratio-monitoring,refund-pending', + 'business.operation:fee-ratio-monitoring,refund-pending,export-details', ]) ->name('business.refunds.refund-pending.export'); -Route::get('workspace/refunds/refund-pending/month-details', 'Business\Pages@refundPendingMonthDetails') - ->middleware('business.page:refunds,refund-pending') +Route::get('workspace/fee-ratio-monitoring/refund-pending/month-details', 'Business\Pages@refundPendingMonthDetails') + ->middleware('business.page:fee-ratio-monitoring,refund-pending') ->name('business.refunds.refund-pending.month-details'); +Route::get('workspace/refunds/refund-pending/export', function () { + $url = route('business.refunds.refund-pending.export', [ + 'company_id' => request()->route('company_id'), + ]); + $query = request()->getQueryString(); + + return redirect()->to($url . ($query === null ? '' : '?' . $query)); +})->name('business.refunds.refund-pending.legacy-export'); + +Route::get('workspace/refunds/refund-pending/month-details', function () { + $url = route('business.refunds.refund-pending.month-details', [ + 'company_id' => request()->route('company_id'), + ]); + $query = request()->getQueryString(); + + return redirect()->to($url . ($query === null ? '' : '?' . $query)); +})->name('business.refunds.refund-pending.legacy-month-details'); + Route::get('workspace/other/after-sales-return-refund/export', 'Business\Pages@exportAfterSalesReturnRefunds') ->middleware('business.page:other,after-sales-return-refund') ->name('business.other.after-sales-return-refund.export'); diff --git a/tests/Feature/Business/NonJingxiRefundPageTest.php b/tests/Feature/Business/NonJingxiRefundPageTest.php index bf9d8b39..d2bdea94 100644 --- a/tests/Feature/Business/NonJingxiRefundPageTest.php +++ b/tests/Feature/Business/NonJingxiRefundPageTest.php @@ -181,7 +181,7 @@ class NonJingxiRefundPageTest extends FeatureTestCase $this->app->instance(NonJingxiRefundMirrorRepository::class, $repository); $response = $this->loginAs()->get(route('business.pages.show', [ - 'section' => 'refunds', + 'section' => 'fee-ratio-monitoring', 'page' => 'refund-pending', 'from' => '2026-11-01', 'to' => '2026-11-04', @@ -211,7 +211,7 @@ class NonJingxiRefundPageTest extends FeatureTestCase ->assertDontSee('data-refund-month-export', false) ->assertSee('data-refund-page="pending-confirmation"', false) ->assertSee('data-refund-month-summary', false) - ->assertSee('workspace/refunds/refund-pending/month-details', false); + ->assertSee('workspace/fee-ratio-monitoring/refund-pending/month-details', false); } public function test_refund_pending_hides_export_and_blocks_export_url_without_operation_permission(): void @@ -219,7 +219,7 @@ class NonJingxiRefundPageTest extends FeatureTestCase $this->grantAdminPermission(); $this->user->syncRoles([Role::where('name', 'user')->firstOrFail()->id]); $subject = 'user_' . $this->user->id; - $pageKey = 'refunds/refund-pending'; + $pageKey = 'fee-ratio-monitoring/refund-pending'; setting()->set('system.sidebar_permissions', [ 'configured' => [$subject], 'subjects' => [$subject => [$pageKey]], @@ -244,15 +244,15 @@ class NonJingxiRefundPageTest extends FeatureTestCase ->andReturn(['months' => [], 'platforms' => []]); $this->app->instance(NonJingxiRefundMirrorRepository::class, $repository); - $this->assertFalse(BusinessOperationPermissions::can('refunds', 'refund-pending', 'export-details', $this->user)); + $this->assertFalse(BusinessOperationPermissions::can('fee-ratio-monitoring', 'refund-pending', 'export-details', $this->user)); $this->loginAs()->get(route('business.pages.show', [ - 'section' => 'refunds', + 'section' => 'fee-ratio-monitoring', 'page' => 'refund-pending', ])) ->assertOk() ->assertDontSeeText('导出全部明细') ->assertDontSee('data-refund-all-export', false) - ->assertDontSee('workspace/refunds/refund-pending/export', false); + ->assertDontSee('workspace/fee-ratio-monitoring/refund-pending/export', false); $this->withExceptionHandling() ->get(route('business.refunds.refund-pending.export')) diff --git a/tests/Feature/Business/PagesTest.php b/tests/Feature/Business/PagesTest.php index 9138f464..4ae17546 100644 --- a/tests/Feature/Business/PagesTest.php +++ b/tests/Feature/Business/PagesTest.php @@ -80,7 +80,9 @@ class PagesTest extends FeatureTestCase ->assertSeeText('淘系退款清单') ->assertSeeText('同步失败,已保留上次成功数据') ->assertSeeText('PDOException') - ->assertSeeText('查看退款待确认'); + ->assertSeeText('查看退款待确认') + ->assertSee('/workspace/fee-ratio-monitoring/refund-pending', false) + ->assertDontSee('/workspace/refunds/refund-pending', false); } public function testLogStatisticsPageIsAvailableUnderOther(): void diff --git a/tests/Feature/Settings/NavigationTest.php b/tests/Feature/Settings/NavigationTest.php index 051732e5..c6b32b4b 100644 --- a/tests/Feature/Settings/NavigationTest.php +++ b/tests/Feature/Settings/NavigationTest.php @@ -22,7 +22,8 @@ class NavigationTest extends FeatureTestCase ->assertSee('/workspace/order-profit', false) ->assertSeeText('订单利润') ->assertSee('/workspace/refunds/non-jingxi-refund-data', false) - ->assertSee('/workspace/refunds/refund-pending', false) + ->assertDontSee('/workspace/refunds/refund-pending', false) + ->assertSee('/workspace/fee-ratio-monitoring/refund-pending', false) ->assertSee('/workspace/product-inventory/normal-products', false) ->assertSee('/workspace/product-inventory/monthly-weighted-average-price', false) ->assertSee('/workspace/product-inventory/inventory-report', false); @@ -43,7 +44,7 @@ class NavigationTest extends FeatureTestCase { $this->loginAs() ->get(route('business.pages.show', [ - 'section' => 'refunds', + 'section' => 'fee-ratio-monitoring', 'page' => 'refund-pending', ])) ->assertOk() @@ -52,6 +53,19 @@ class NavigationTest extends FeatureTestCase ->assertSeeText('数据来自聚水潭售后共享镜像'); } + public function testLegacyRefundPendingUrlRedirectsToFeeRatioMonitoring(): void + { + $this->loginAs() + ->get('/1/workspace/refunds/refund-pending?from=2026-10-01') + ->assertRedirect('/1/workspace/fee-ratio-monitoring/refund-pending?from=2026-10-01'); + + $this->get('/1/workspace/refunds/refund-pending/month-details?month=2026-10') + ->assertRedirect('/1/workspace/fee-ratio-monitoring/refund-pending/month-details?month=2026-10'); + + $this->get('/1/workspace/refunds/refund-pending/export?from=2026-10-01&to=2026-10-31') + ->assertRedirect('/1/workspace/fee-ratio-monitoring/refund-pending/export?from=2026-10-01&to=2026-10-31'); + } + public function testInventoryReportMenuPageIsAvailable(): void { $this->loginAs() @@ -288,14 +302,22 @@ class NavigationTest extends FeatureTestCase $this->assertNotNull($section); $this->assertSame('费比异常数据监控', $section['title']); $this->assertSame('monitor_heart', $section['icon']); - $this->assertSame('异常数据监控', $section['pages'][0]['title']); - $this->assertSame('待接入', $section['pages'][0]['directory']['status']); + $this->assertSame( + ['refund-pending', 'overview'], + array_column($section['pages'], 'slug'), + ); + $this->assertSame( + ['退款待确认', '异常数据监控'], + array_column($section['pages'], 'title'), + ); + $this->assertSame('待接入', $section['pages'][1]['directory']['status']); $sidebarGroup = collect(SidebarMenu::groups($this->user)) ->firstWhere('title', '费比异常数据监控'); $this->assertNotNull($sidebarGroup); $this->assertSame('fee-ratio-monitoring', $sidebarGroup['items'][0]['section']); - $this->assertSame('overview', $sidebarGroup['items'][0]['page']); + $this->assertSame('refund-pending', $sidebarGroup['items'][0]['page']); + $this->assertSame('overview', $sidebarGroup['items'][1]['page']); $this->loginAs() ->get(route('business.pages.show', [ @@ -308,32 +330,27 @@ class NavigationTest extends FeatureTestCase ->assertSeeText('费比异常数据尚未接入'); } - public function testExistingRegularPermissionSetsInheritFeeRatioMonitoring(): void + public function testLegacyRefundPendingPermissionFollowsTheMovedPage(): void { $this->user->roles()->sync([Role::where('name', 'user')->firstOrFail()->id]); $subject = 'role_user'; setting()->set('system.sidebar_permissions', [ 'configured' => [$subject], 'subjects' => [$subject => [ - 'financial-risk-control/store-violation-alert', - 'financial-risk-control/process-statistics', + 'refunds/refund-pending', + 'refunds/refund-pending/export-details', ]], ]); setting()->save(); $this->assertContains( - 'fee-ratio-monitoring/overview', + 'fee-ratio-monitoring/refund-pending', + SidebarPermissions::allowedKeys($this->user), + ); + $this->assertContains( + 'fee-ratio-monitoring/refund-pending/export-details', SidebarPermissions::allowedKeys($this->user), ); - - $this->loginAs() - ->get(route('business.pages.show', [ - 'section' => 'financial-risk-control', - 'page' => 'store-violation-alert', - ])) - ->assertOk() - ->assertSee('/workspace/fee-ratio-monitoring/overview', false) - ->assertSeeText('费比异常数据监控'); } public function test_business_pages_render_menu_filter_and_open_page_tabs(): void @@ -563,11 +580,11 @@ class NavigationTest extends FeatureTestCase $this->assertSame('退款数据', $refund['title']); $this->assertSame('assignment_return', $refund['icon']); $this->assertSame( - ['jingxi-refund-data', 'non-jingxi-refund-data', 'refund-pending'], + ['jingxi-refund-data', 'non-jingxi-refund-data'], array_column($refund['pages'], 'slug') ); $this->assertSame( - ['京喜退款数据', '售后(退货退款)', '退款待确认'], + ['京喜退款数据', '售后(退货退款)'], array_column($refund['pages'], 'title') ); $this->assertNotNull($financialOperations); diff --git a/tests/Feature/SystemSettings/UserPermissionsTest.php b/tests/Feature/SystemSettings/UserPermissionsTest.php index 2c20407f..bf486809 100644 --- a/tests/Feature/SystemSettings/UserPermissionsTest.php +++ b/tests/Feature/SystemSettings/UserPermissionsTest.php @@ -127,7 +127,7 @@ class UserPermissionsTest extends FeatureTestCase ->assertSee('aria-label="页面位置"', false) ->assertSeeText('主体商标规则') ->assertSeeText('退款待确认 · 导出明细') - ->assertSee('value="refunds/refund-pending/export-details"', false); + ->assertSee('value="fee-ratio-monitoring/refund-pending/export-details"', false); $this->patch(route('system-settings.sidebar.update'), [ 'subject' => 'user_'.$target->id, 'permissions' => ['store-management/basic-information'], ])->assertRedirect(route('system-settings.sidebar.edit', ['subject' => 'user_'.$target->id])); @@ -139,22 +139,22 @@ class UserPermissionsTest extends FeatureTestCase { $target = $this->account('user'); $subject = 'user_' . $target->id; - $pageKey = 'refunds/refund-pending'; + $pageKey = 'fee-ratio-monitoring/refund-pending'; $operationKey = $pageKey . '/export-details'; setting()->set('system.sidebar_permissions', [ 'configured' => [$subject], 'subjects' => [$subject => [$pageKey]], ]); - $this->assertTrue(SidebarPermissions::canViewPage($target, 'refunds', 'refund-pending')); - $this->assertFalse(BusinessOperationPermissions::can('refunds', 'refund-pending', 'export-details', $target)); + $this->assertTrue(SidebarPermissions::canViewPage($target, 'fee-ratio-monitoring', 'refund-pending')); + $this->assertFalse(BusinessOperationPermissions::can('fee-ratio-monitoring', 'refund-pending', 'export-details', $target)); $this->loginAs()->patch(route('system-settings.sidebar.update'), [ 'subject' => $subject, 'permissions' => [$pageKey, $operationKey], ])->assertRedirect(route('system-settings.sidebar.edit', ['subject' => $subject])); - $this->assertTrue(BusinessOperationPermissions::can('refunds', 'refund-pending', 'export-details', $target)); + $this->assertTrue(BusinessOperationPermissions::can('fee-ratio-monitoring', 'refund-pending', 'export-details', $target)); $this->assertSame([$pageKey, $operationKey], SidebarPermissions::allowedKeys($target)); } @@ -167,7 +167,7 @@ class UserPermissionsTest extends FeatureTestCase 'subjects' => [$subject => ['refunds']], ]); - $this->assertTrue(BusinessOperationPermissions::can('refunds', 'refund-pending', 'export-details', $target)); + $this->assertTrue(BusinessOperationPermissions::can('fee-ratio-monitoring', 'refund-pending', 'export-details', $target)); } public function test_super_admin_cannot_be_limited_by_page_settings_and_regular_users_cannot_configure_access(): void -- 2.47.2