user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $repository = Mockery::mock(CourierFreightReconciliationMirrorRepository::class); $repository->shouldReceive('available')->once()->andReturnTrue(); $repository->shouldReceive('ready')->once()->andReturnTrue(); $repository->shouldReceive('paginate')->once()->with( Mockery::on(static fn (array $filters): bool => $filters['express_no'] === 'FIXTURE'), 1, Mockery::type('int'), )->andReturn([ 'data' => [[ 'detail_id' => 1, 'waybill' => 'FIXTURE-WAYBILL', 'product_id' => 'ITEM-1', 'send_time' => '2026-08-01 09:00:00', 'transaction_order_no' => 'SO-1', 'province' => '江苏省', 'city' => '常州市', 'district' => '武进区', 'barcode' => 'SKU-1', 'express_name' => '测试快递', 'express_name_2' => '测试快递', 'quantity' => 1, 'product_name' => '测试商品', 'platform' => '淘宝天猫', 'shop_name' => '测试店铺', 'warehouse' => '测试仓库', 'volume' => 1.2, 'supplier' => '测试供应商', 'length' => 1.0, 'width' => 2.0, 'height' => 3.0, 'freight' => 20.0, 'weight' => 1.25, 'reconciliation_weight' => 1.25, 'reconciliation_volume' => 1.2, 'month' => '2026-08', 'status' => '已发货', ]], 'total' => 1, 'summary' => ['count' => 1, 'freight' => 20.0, 'payable_amount' => 20.0, 'actual_payment' => 0.0, 'confirmed_amount' => 0.0, 'reconciliation_difference' => 0.0], 'state' => ['status' => 'succeeded'], 'sync' => ['code' => 'fresh', 'last_succeeded_at' => '2026-08-02 09:00:00', 'lag_minutes' => 1], ]); $this->app->instance(CourierFreightReconciliationMirrorRepository::class, $repository); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'courier-payables', 'page' => 'freight-reconciliation', 'express_no' => 'FIXTURE', ])) ->assertOk() ->assertSeeText('FIXTURE-WAYBILL') ->assertSeeText('条形码') ->assertSeeText('交易订单号') ->assertSeeText('对账体积(cm3)') ->assertSeeText('SKU-1') ->assertSeeText('测试供应商') ->assertSeeText('运费合计') ->assertSeeText('20.00') ->assertSeeText('数据新鲜') ->assertSeeText('共享业务镜像') ->assertDontSee('class="business-blank-page"', false); } public function testTaobaoAlipayBillsEndpointIsAvailableToWorkspaceUsers() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $repository = Mockery::mock(StoreReceivingAlipayBillMirrorRepository::class); $repository->shouldReceive('paginate')->once()->andReturn([ 'current_page' => 1, 'last_page' => 1, 'per_page' => 10, 'total' => 1, 'data' => [[ 'record_code' => 'time-format-test', 'occurred_at' => '2026-07-15 23:59:12', ]], 'summary' => ['income' => 1.0, 'expense' => 0.0, 'count' => 1, 'balance' => 1.0], 'sync' => ['status' => 'succeeded', 'last_succeeded_at' => '2026-09-07 09:00:00'], ]); $this->app->instance(StoreReceivingAlipayBillMirrorRepository::class, $repository); $this->loginAs() ->withHeader('X-Requested-With', 'XMLHttpRequest') ->get(route('ecommerce-finance.alipay-bills.index')) ->assertOk() ->assertJsonStructure([ 'current_page', 'data', 'total', 'summary' => ['income', 'expense', 'count', 'balance'], ]) ->assertJsonPath('data.0.occurred_at', '2026-07-15 23:59:12'); } public function testTaobaoAlipayBillsPageProvidesTheVueMountPoint() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'billing-transactions', 'page' => 'store-receiving-bills', 'tab' => 'taobao-alipay', ])) ->assertOk() ->assertSee('class="biz-card mt-6 business-blank-page"', false) ->assertSee('public/js/business/pages.min.js', false); } public function testTaobaoAlipayBillsExportUsesTheMirrorRepository() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $repository = Mockery::mock(StoreReceivingAlipayBillMirrorRepository::class); $repository->shouldReceive('exportRows')->once()->with(Mockery::on( static fn (array $filters): bool => ($filters['store_name'] ?? '') === '天猫-经营店' && ($filters['start'] ?? '') === '2026-08-01' && ($filters['end'] ?? '') === '2026-08-31' ))->andReturn([[ 'record_code' => '1', 'store_name' => '天猫-经营店', 'alipay_account' => 'CommonBillTGCPay', 'bill_item' => '交易佣金', 'account_order_no' => 'KEY-1', 'business_serial_no' => '1001', 'merchant_order_no' => 'P-1', 'business_base_order_no' => 'ORDER-1', 'goods_name' => 'SKU-1', 'occurred_at' => '2026-08-01 09:00:00', 'income' => 100.25, 'expense' => 0, 'balance' => 100.25, 'business_type' => '收入', 'online_order_no' => 'ORDER-1', 'business_description' => 'double', 'business_bill_source' => 'CommonBillTGCPay', 'created_at' => '2026-08-02 09:00:00', 'updated_at' => '2026-08-02 10:00:00', ]]); $this->app->instance(StoreReceivingAlipayBillMirrorRepository::class, $repository); $this->loginAs() ->get(route('ecommerce-finance.alipay-bills.export', [ 'store_name' => '天猫-经营店', 'start' => '2026-08-01', 'end' => '2026-08-31', ])) ->assertOk() ->assertHeader('content-type', 'text/csv; charset=UTF-8') ->assertDownload('taobao_alipay_bills.csv'); } public function testSupplierPayablesPageRendersItsSpecificContent() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'supplier-payables', 'page' => 'payment-reconciliation', ])) ->assertOk() ->assertSee('id="goods-reconciliation-app"', false) ->assertSee('public/js/ecommerce-finance/goods-reconciliations.min.js', false) ->assertDontSee('class="business-blank-page"', false); } public function testOrderDataTablesRenderAsRawDataPageTabs() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $this->loginAs() ->get(route('business.pages.show', ['section' => 'order-data'])) ->assertRedirect(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'after-sales-expenses', ])); $this->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', ])) ->assertRedirect(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'after-sales-expenses', ])); $this->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'after-sales-expenses', ])) ->assertOk() ->assertSeeText('订单售后费用明细') ->assertSee('aria-label="订单售后费用明细"', false) ->assertSeeText('内部订单号') ->assertSeeText('800503发空包/赠品费用') ->assertSee('class="business-tab-bar"', false) ->assertSee(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'after-sales-expenses', ]), false) ->assertSee(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'promotion-expenses', ]), false) ->assertDontSee(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'after-sales-expenses', ]), false) ->assertDontSee('class="business-blank-page"', false); $this->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'promotion-expenses', ])) ->assertOk() ->assertSeeText('商品推广费用明细') ->assertSee('aria-label="商品推广费用明细"', false) ->assertSeeText('店铺') ->assertSeeText('8001201直通车/钻展/快车等') ->assertDontSee('class="business-blank-page"', false); } public function testOrderDataIncludesTheConfiguredBillOffsetSubpage(): void { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $this->loginAs(); $this->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'bill-offset', ])) ->assertOk() ->assertSeeInOrder([ route('business.pages.show', [ 'section' => 'order-data', 'page' => 'raw-data', 'tab' => 'after-sales-expenses', ]), route('business.pages.show', [ 'section' => 'order-data', 'page' => 'bill-offset', ]), ], false); $this->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'bill-offset', ])) ->assertOk() ->assertSeeText('账单冲减') ->assertSeeText('账单冲减镜像尚未完成首次同步'); $this->withExceptionHandling(); foreach (['national-subsidy', 'hundred-subsidy', 'consumption-coupon'] as $removedSlug) { $this->withHeader('X-Requested-With', 'XMLHttpRequest') ->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => $removedSlug, ])) ->assertNotFound(); } } private function billOffsetSourceRows(array $rows, array $filters = [], bool $hasMore = false, ?string $error = null): array { $paginator = new \Illuminate\Pagination\Paginator($rows, 100, 1); $paginator->hasMorePagesWhen($hasMore); return [ 'orderDataRows' => $paginator, 'orderDataFilters' => $filters, 'orderDataStatus' => ['X-Caiwu-Data-Status' => 'mirror'], 'orderDataError' => $error, ]; } public function testBillOffsetPageUsesTheSameOriginalOrderRowsAndAccountField(): void { $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $source = Mockery::mock(OrderDataPageData::class); $source->shouldReceive('afterSales')->once()->with(null, null, null, false)->andReturn($this->billOffsetSourceRows([ ['internal_order_no' => '9228703', 'online_order_no' => '5127724585360006527', 'shop_name' => '测试店铺', 'product_code' => 'SKU-1', 'account_500112' => -20, 'reversal_order_amount' => 987.65], ], ['from' => '2026-08-01', 'to' => '2026-08-31'])); $this->app->instance(OrderDataPageData::class, $source); $this->loginAs()->get(route('business.pages.show', [ 'section' => 'order-data', 'page' => 'bill-offset', 'from' => '2026-08-01', 'to' => '2026-08-31', ]))->assertOk()->assertSeeText('9228703')->assertSeeText('测试店铺')->assertSeeText('-20.00') ->assertDontSeeText('987.65')->assertSeeText('本页冲减收入合计') ->assertSee('id="bill-offset-export-button"', false)->assertSeeText('数据状态:MIRROR'); } public function testBillOffsetKeepsUnknownAccountAmountsEmpty(): void { $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $source = Mockery::mock(OrderDataPageData::class); $source->shouldReceive('afterSales')->once()->andReturn($this->billOffsetSourceRows([ ['internal_order_no' => 'ORDER-EMPTY', 'account_500112' => null, 'reversal_order_amount' => 987.65], ])); $this->app->instance(OrderDataPageData::class, $source); $this->loginAs()->get(route('business.pages.show', ['section' => 'order-data', 'page' => 'bill-offset'])) ->assertOk()->assertSeeText('ORDER-EMPTY')->assertDontSeeText('987.65')->assertDontSeeText('0.00'); } public function testBillOffsetShowsTheOriginalDataErrorAndBlocksAnEmptyExport(): void { $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $source = Mockery::mock(OrderDataPageData::class); $source->shouldReceive('afterSales')->twice()->andReturn($this->billOffsetSourceRows([], [], false, '订单售后费用数据暂时无法读取,请稍后重试。')); $this->app->instance(OrderDataPageData::class, $source); $this->loginAs()->get(route('business.pages.show', ['section' => 'order-data', 'page' => 'bill-offset'])) ->assertOk()->assertSeeText('订单售后费用数据暂时无法读取,请稍后重试。'); $this->withExceptionHandling()->get(route('business.bill-offset.export'))->assertStatus(503); } public function testBillOffsetExportIncludesAllPagesFromOriginalDataWithTheSameFilters(): void { $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); $source = Mockery::mock(OrderDataPageData::class); $filters = ['from' => '2026-08-01', 'to' => '2026-08-31', 'order_no' => 'ORDER', 'shop_name' => '', 'sku_id' => '']; $source->shouldReceive('afterSales')->once()->with($filters, 1, 100, false)->andReturn($this->billOffsetSourceRows([ ['internal_order_no' => 'ORDER-1', 'online_order_no' => '001234567890123456789', 'shop_name' => '测试店铺', 'account_500112' => -20], ], $filters, true)); $source->shouldReceive('afterSales')->once()->with($filters, 2, 100, false)->andReturn($this->billOffsetSourceRows([ ['internal_order_no' => 'ORDER-101', 'account_500112' => null, 'reversal_order_amount' => 987.65], ], $filters)); $this->app->instance(OrderDataPageData::class, $source); $response = $this->loginAs()->get(route('business.bill-offset.export', $filters)); $response->assertOk()->assertHeader('Content-Type', 'text/csv; charset=UTF-8'); $csv = $response->streamedContent(); $this->assertStringContainsString('500112冲减收入', $csv); $this->assertStringContainsString("'001234567890123456789", $csv); $this->assertStringContainsString('ORDER-1', $csv); $this->assertStringContainsString('ORDER-101', $csv); $this->assertStringNotContainsString('987.65', $csv); $lines = preg_split('/\r?\n/', trim($csv)); $this->assertCount(3, $lines); $this->assertSame('', str_getcsv($lines[2])[8]); } public function testFinancialAfterSalesPageRendersMirroredJushuitanRefunds(): void { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $refundStates = [ NonJingxiRefundMirrorRepository::INFO_DATASET => [ 'status' => 'succeeded', 'initial_completed_at' => '2026-08-24 12:00:00', ], NonJingxiRefundMirrorRepository::ITEM_DATASET => [ 'status' => 'succeeded', 'initial_completed_at' => '2026-08-24 12:00:00', ], ]; $refunds = \Mockery::mock(NonJingxiRefundMirrorRepository::class); $refunds->shouldReceive('available')->once()->andReturnTrue(); $refunds->shouldReceive('states')->once()->andReturn($refundStates); $refunds->shouldReceive('syncStatus')->once()->with($refundStates)->andReturn([ 'code' => 'healthy', 'last_succeeded_at' => '2026-08-24 12:00:00', ]); $refunds->shouldReceive('ready')->once()->andReturnTrue(); $refunds->shouldReceive('queryReady')->once()->andReturnTrue(); $refunds->shouldReceive('paginate')->once()->withArgs( static fn (array $filters, int $page, int $limit): bool => $filters === [ 'from' => '2026-08-24', 'to' => '2026-08-24', 'order_no' => '', 'shop_name' => '天猫旗舰店', 'sku_id' => '', ] && $page === 1 && $limit === 10 )->andReturn([ 'data' => [(object) [ 'refundDate' => '2026-08-24 10:00:00', 'outer_as_id' => 'AS-FIN-001', 'o_id' => 'ORDER-FIN-001', 'so_id' => 'SUB-FIN-001', 'type' => '退款', 'shop_name' => '天猫旗舰店', 'platform' => '天猫', 'i_id' => 'ITEM-FIN-001', 'sku_id' => 'SKU-FIN-001', 'qty' => 1, 'detailRefundMoney' => 99.5, 'refundType' => '退货退款', 'RefundMoneyIncome' => 99.5, 'AfSalesMoney' => 99.5, 'status' => '完成', ]], 'total' => 1, ]); $this->app->instance(NonJingxiRefundMirrorRepository::class, $refunds); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'financial-operations', 'page' => 'after-sales-expenses', 'from' => '2026-08-24', 'to' => '2026-08-24', 'shop_name' => '天猫旗舰店', ])) ->assertOk() ->assertDontSeeText('聚水潭售后工单') ->assertDontSeeText('WO-FIN-005') ->assertSeeText('售后(退货退款)明细') ->assertSeeText('AS-FIN-001') ->assertSeeText('ORDER-FIN-001') ->assertSeeText('SKU-FIN-001') ->assertSeeText('99.50') ->assertSeeText('退款回款金额'); } public function testRefundPagesUseTheGenericBusinessPageRoute() { $this->user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $repository = \Mockery::mock(NonJingxiRefundMirrorRepository::class); $repository->shouldReceive('available')->once()->andReturnFalse(); $repository->shouldNotReceive('states'); $repository->shouldNotReceive('syncStatus'); $repository->shouldNotReceive('ready'); $repository->shouldNotReceive('queryReady'); $repository->shouldNotReceive('paginate'); $this->app->instance(NonJingxiRefundMirrorRepository::class, $repository); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'refunds', ])) ->assertRedirect(route('business.pages.show', [ 'section' => 'refunds', 'page' => 'jingxi-refund-data', ])); $this->get(route('business.pages.show', [ 'section' => 'refunds', 'page' => 'jingxi-refund-data', ])) ->assertOk() ->assertSeeText('京喜退款数据') ->assertSee('aria-label="京喜退款数据"', false) ->assertSee('data-header-row="labels"', false) ->assertSeeInOrder([ '店铺', '账单项目', '线上单号', '单据类型', '商品编码', '商品名称', '费用计算时间', '费用发生时间', '费用项', '收入金额', '支出金额', '币种', '钱包余额备注', '备注', ], false) ->assertSeeText('当前暂无京喜退款数据。') ->assertDontSee('class="biz-empty"', false); $response = $this->get(route('business.pages.show', [ 'section' => 'refunds', 'page' => 'non-jingxi-refund-data', ])); $response ->assertOk() ->assertSeeText('售后(退货退款)') ->assertSee('aria-label="售后(退货退款)"', false) ->assertSee('aria-label="售后(退货退款)分页"', false) ->assertDontSeeText('非京喜退款数据') ->assertSeeText('共享业务镜像尚未建立') ->assertSeeText('数据暂时无法读取') ->assertSee('class="upstream-data-table refund-data-table refund-data-table--wide"', false) ->assertSee('data-header-row="labels"', false) ->assertSee('data-header-row="fields"', false) ->assertDontSee('class="biz-empty"', false); $html = $response->getContent(); $headerRows = []; preg_match_all( '/