user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); } public function test_courier_bookkeeping_uses_finance_columns_and_its_own_actions(): void { $this->loginAs()->get(route('business.pages.show', [ 'section' => 'courier-payables', 'page' => 'bookkeeping-details', ]))->assertOk() ->assertSeeText('导入')->assertSeeText('导出')->assertSeeText('查询')->assertSeeText('编辑') ->assertSeeText('下载导入模板')->assertSeeText('快递单号整理')->assertSeeText('结算运费') ->assertDontSeeText('工单编号') ->assertSee('workspace/courier-payables/actions/bookkeeping-details/import-upload', false); $expected = ['月份', '物流单号', '快递单号整理', '物流公司', '线上订单号', '记账原因', '商品编码', '商品名称', '记账金额', '记账数据', '收货人', '发起人', '发起时间', '店铺名称', '买家昵称', '省份', '扣单时间', '成本', '重量', '损耗', '负责人', '平台商品id', '订单发货仓库', '供应商', '未发出', '退回单号', '报废', '成本记账', '结算记账', '结算运费', '记账分析', '是否代发', '快递反馈', '客服回复', '原因']; $definition = $this->getJson(route('business.courier-payables.bookkeeping-details.definition'))->assertOk(); $this->assertSame($expected, array_column($definition->json('fields'), 'label')); $registry = app(PayablesFinalRegistry::class); $this->assertFalse($registry->supports('courier-payables', 'compensation-details')); $this->assertArrayHasKey('work_order_no', $registry->fields('courier-payables-final', 'bookkeeping-details')); } public function test_import_export_and_edit_are_isolated_from_final_and_other_companies(): void { $store = app(SupplierPayableOverrideStore::class); $store->save('final:courier:bookkeeping-details', 'shared:1', ['work_order_no' => 'FINAL-ONLY'], $this->company->id, $this->user->id); $store->save('final:supplier:payment-reconciliation', 'shared:1', ['supplier' => 'SUPPLIER-ONLY'], $this->company->id, $this->user->id); $store->save('courier:bookkeeping-details', 'shared:1', ['tracking_no' => 'OTHER-COMPANY'], 999999, $this->user->id); $file = UploadedFile::fake()->createWithContent('bookkeeping.csv', "记录标识,月份,物流单号,商品编码,记账金额,结算运费\nshared:1,2026-10,SF-BASE-1,000123,25,9.220000000000001\n"); $this->loginAs()->post(route('business.courier-payables.bookkeeping-details.import'), ['import' => $file]) ->assertRedirect()->assertSessionHas('success', '导入完成:新增 1 条,更新 0 条。'); $this->travel(61)->seconds(); $this->post(route('business.courier-payables.bookkeeping-details.import'), ['import' => $file]) ->assertRedirect()->assertSessionHas('success', '导入完成:新增 0 条,更新 1 条。'); $values = $store->findRow('courier:bookkeeping-details', 'shared:1', $this->company->id); $this->assertSame('000123', $values['product_code']); $this->assertSame(0, bccomp('9.2200', $values['settle_freight'], 4)); $this->patchJson(route('business.courier-payables.bookkeeping-details.update', ['recordKey' => 'shared:1']), [ 'values' => array_merge($values, ['amount' => '26.5', 'courier_feedback' => '已核对']), ])->assertOk(); $this->assertSame('26.5', $store->findRow('courier:bookkeeping-details', 'shared:1', $this->company->id)['amount']); $this->assertSame('FINAL-ONLY', $store->findRow('final:courier:bookkeeping-details', 'shared:1', $this->company->id)['work_order_no']); $this->assertSame('SUPPLIER-ONLY', $store->findRow('final:supplier:payment-reconciliation', 'shared:1', $this->company->id)['supplier']); $this->assertSame('OTHER-COMPANY', $store->findRow('courier:bookkeeping-details', 'shared:1', 999999)['tracking_no']); $export = $this->get(route('business.courier-payables.bookkeeping-details.export'))->assertOk()->streamedContent(); $this->assertStringContainsString('SF-BASE-1', $export); $this->assertStringContainsString('已核对', $export); $this->assertStringNotContainsString('FINAL-ONLY', $export); $this->assertStringNotContainsString('OTHER-COMPANY', $export); $this->get(route('business.pages.show', ['section' => 'courier-payables', 'page' => 'bookkeeping-details', 'keyword' => 'SF-BASE-1'])) ->assertOk()->assertSeeText('SF-BASE-1')->assertDontSeeText('FINAL-ONLY'); } public function test_chunk_upload_uses_the_courier_dataset(): void { $file = UploadedFile::fake()->createWithContent('bookkeeping.csv', "记录标识,月份,物流单号,记账金额\nchunk:1,2026-10,SF-CHUNK-1,12.34\nchunk:2,2026-10,SF-CHUNK-1,12.34\n"); $upload = $this->loginAs()->postJson(route('business.courier-payables.bookkeeping-details.import.upload'), ['import' => $file]) ->assertOk()->assertJsonPath('total', 2); $this->postJson(route('business.courier-payables.bookkeeping-details.import.chunk'), [ 'token' => $upload->json('token'), 'offset' => 0, ])->assertOk()->assertJsonPath('done', true)->assertJsonPath('created', 2); $this->assertDatabaseHas('supplier_payable_overrides', ['dataset' => 'courier:bookkeeping-details', 'record_key' => 'chunk:1']); $this->assertDatabaseHas('supplier_payable_overrides', ['dataset' => 'courier:bookkeeping-details', 'record_key' => 'chunk:2']); } public function test_courier_actions_require_permission_for_the_base_page(): void { $this->user->update(['created_from' => 'dingtalk_roster_limited']); $subject = 'user_' . $this->user->id; setting()->set('system.sidebar_permissions', [ 'configured' => [$subject], 'subjects' => [$subject => ['courier-payables-final/bookkeeping-details']], ]); $this->withExceptionHandling()->loginAs(); $this->getJson(route('business.courier-payables-final.bookkeeping-details.definition'))->assertOk(); foreach (['definition', 'template', 'export'] as $action) { $this->get(route('business.courier-payables.bookkeeping-details.' . $action))->assertForbidden(); } foreach (['import', 'import.upload', 'import.chunk'] as $action) { $this->postJson(route('business.courier-payables.bookkeeping-details.' . $action), [])->assertForbidden(); } $this->patchJson(route('business.courier-payables.bookkeeping-details.update', ['recordKey' => 'denied:1']), [])->assertForbidden(); } }