fix(快递应付): 将财务记账明细移至普通快递应付入口

This commit is contained in:
limeng 2026-12-03 16:14:40 +08:00
parent b591eff505
commit 69f8bafddf
12 changed files with 213 additions and 47 deletions

View File

@ -49,10 +49,7 @@ class ImportPayablesFinal extends Command
}
$fields = $registry->fields($section, $dataset);
$storeDataset = 'final:'
. ($section === PayablesFinalRegistry::SECTION_COURIER ? 'courier' : 'supplier')
. ':'
. $dataset;
$storeDataset = $registry->storeDataset($section, $dataset);
$totalCreated = 0;
$totalUpdated = 0;
$totalRows = 0;

View File

@ -5038,17 +5038,14 @@ class Pages extends Controller
}
/**
* 「终版」目录的按表数据:独立存放,初始为空,由页面上的导入/导出/查询/编辑维护。
* 按表维护的页面数据:终版页签及快递记账明细使用各自的独立数据集。
*
* @return array<string,mixed>|null
*/
protected function payablesFinalData(array $section, ?array $page): ?array
{
$sectionSlug = (string) ($section['slug'] ?? '');
if (empty($page) || ! in_array($sectionSlug, [
PayablesFinalRegistry::SECTION_SUPPLIER,
PayablesFinalRegistry::SECTION_COURIER,
], true)) {
if (empty($page)) {
return null;
}
@ -5067,9 +5064,7 @@ class Pages extends Controller
}
$keyword = trim((string) request('keyword', ''));
$storeDataset = PayablesFinalActions::DATASET_PREFIX
. ($sectionSlug === PayablesFinalRegistry::SECTION_COURIER ? 'courier:' : 'supplier:')
. $dataset;
$storeDataset = $registry->storeDataset($sectionSlug, $dataset);
$isSupplierPayablesReport = $dataset === 'supplier-payables-report';
$requestedMonth = trim((string) request('month', ''));
$month = $isSupplierPayablesReport && preg_match('/^\d{4}-\d{2}$/', $requestedMonth) === 1

View File

@ -16,8 +16,7 @@ use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* 「终版」目录的按表数据:界面与基础页面一致,数据独立存放
* (数据集键 final:<目录>:<页面>),初始为空,由页面上的导入、导出、查询、编辑维护。
* 终版页签和快递记账明细的导入、导出及编辑,各入口使用独立数据集。
*/
class PayablesFinalActions extends Controller
{
@ -171,9 +170,7 @@ class PayablesFinalActions extends Controller
private function storeDataset(Request $request): string
{
$section = $this->section($request) === PayablesFinalRegistry::SECTION_COURIER ? 'courier' : 'supplier';
return self::DATASET_PREFIX . $section . ':' . $this->dataset($request);
return $this->registry->storeDataset($this->section($request), $this->dataset($request));
}
private function csvText(mixed $value): string

View File

@ -0,0 +1,27 @@
<?php
namespace Modules\EcommerceFinance\Services;
/** 快递应付的记账明细,沿用财务手工表的 34 列。 */
class CourierBookkeepingRegistry
{
public function fields(): array
{
$text = static fn (string $label): array => ['label' => $label, 'type' => 'text'];
$money = static fn (string $label): array => ['label' => $label, 'type' => 'number'];
return [
'tracking_no' => $text('物流单号'), 'tracking_no_clean' => $text('快递单号整理'), 'carrier' => $text('物流公司'),
'online_order_no' => $text('线上订单号'), 'bookkeeping_reason' => $text('记账原因'), 'product_code' => $text('商品编码'),
'product_name' => $text('商品名称'), 'amount' => $money('记账金额'), 'bookkeeping_data' => $text('记账数据'),
'receiver' => $text('收货人'), 'initiator' => $text('发起人'), 'started_at' => $text('发起时间'),
'shop_name' => $text('店铺名称'), 'buyer_nick' => $text('买家昵称'), 'province' => $text('省份'),
'deducted_at' => $text('扣单时间'), 'cost' => $money('成本'), 'weight' => $money('重量'), 'loss' => $money('损耗'),
'owner' => $text('负责人'), 'platform_product_id' => $text('平台商品id'), 'shipping_warehouse' => $text('订单发货仓库'),
'supplier' => $text('供应商'), 'unshipped' => $text('未发出'), 'return_no' => $text('退回单号'), 'scrapped' => $text('报废'),
'cost_bookkeeping' => $money('成本记账'), 'settle_bookkeeping' => $money('结算记账'), 'settle_freight' => $money('结算运费'),
'analysis' => $text('记账分析'), 'dropship' => $text('是否代发'), 'courier_feedback' => $text('快递反馈'),
'cs_reply' => $text('客服回复'), 'cause' => $text('原因'),
];
}
}

View File

@ -27,19 +27,27 @@ class CourierPayableFinalRegistry
$month = static fn (string $label): array => ['label' => $label, 'type' => 'month'];
return match ($dataset) {
// 表头照财务手工「记账」表(2026 年 10 月起)
'bookkeeping-details' => [
'tracking_no' => $text('物流单号'), 'tracking_no_clean' => $text('快递单号整理'), 'carrier' => $text('物流公司'),
'online_order_no' => $text('线上订单号'), 'bookkeeping_reason' => $text('记账原因'), 'product_code' => $text('商品编码'),
'product_name' => $text('商品名称'), 'amount' => $money('记账金额'), 'bookkeeping_data' => $text('记账数据'),
'receiver' => $text('收货人'), 'initiator' => $text('发起人'), 'started_at' => $text('发起时间'),
'shop_name' => $text('店铺名称'), 'buyer_nick' => $text('买家昵称'), 'province' => $text('省份'),
'deducted_at' => $text('扣单时间'), 'cost' => $money('成本'), 'weight' => $money('重量'), 'loss' => $money('损耗'),
'owner' => $text('负责人'), 'platform_product_id' => $text('平台商品id'), 'shipping_warehouse' => $text('订单发货仓库'),
'supplier' => $text('供应商'), 'unshipped' => $text('未发出'), 'return_no' => $text('退回单号'), 'scrapped' => $text('报废'),
'cost_bookkeeping' => $money('成本记账'), 'settle_bookkeeping' => $money('结算记账'), 'settle_freight' => $money('结算运费'),
'analysis' => $text('记账分析'), 'dropship' => $text('是否代发'), 'courier_feedback' => $text('快递反馈'),
'cs_reply' => $text('客服回复'), 'cause' => $text('原因'),
'started_at' => $text('发起时间'), 'work_order_no' => $text('工单编号'), 'initiator' => $text('发起人'),
'bookkeeping_reason' => $text('记账原因'), 'reason_level_1' => $text('记账原因-一级选项'),
'reason_level_2' => $text('记账原因-二级选项'), 'reason_level_3' => $text('记账原因-三级选项'),
'bookkeeping_type' => $text('记账类型'), 'executor' => $text('执行人'), 'source' => $text('记账来源'),
'amount' => $money('记账金额'), 'remark' => $text('记账备注说明'), 'attachment' => $text('上传附件'),
'attachment_preview' => $text('上传附件(预览)'), 'online_order_no' => $text('线上订单号'),
'internal_order_no' => $text('内部单号'), 'actual_paid_amount' => $money('实付金额'),
'carrier' => $text('物流公司'), 'tracking_no' => $text('物流单号'), 'shop_name' => $text('店铺名称'),
'platform' => $text('平台'), 'shipping_warehouse' => $text('订单发货仓库'),
'processing_status' => $text('记账处理状态'), 'counterparty_agreed' => $text('被记账方是否同意记账'),
'counterparty_note' => $text('被记账方处理说明'), 'specialist_result' => $text('专员记账判定结果'),
'specialist_note' => $text('专员处理说明'), 'updated_at' => $text('修改时间'),
'work_order_type' => $text('工单类型'), 'product_image' => $text('商品图片'),
'product_code' => $text('商品编码'), 'style_code' => $text('款式编码'),
'other_attribute_6' => $text('其它属性6'), 'product_name' => $text('商品名称'),
'platform_sku_id' => $text('平台商品skuid'), 'platform_product_id' => $text('平台商品id'),
'product_quantity' => $money('商品数量'), 'product_price' => $money('商品价格'),
'product_amount' => $money('商品金额'), 'buyer_paid_amount' => $money('买家实付'),
'supplier' => $text('供应商'), 'accepting_department' => $text('受理部门'),
'order_shipped_at' => $text('订单发货时间'), 'work_order_remark' => $text('工单备注'),
],
'compensation-details' => [
'paid_at' => $date('赔付日期'), 'carrier' => $text('承运商'), 'tracking_no' => $text('快递单号'),

View File

@ -5,8 +5,8 @@ namespace Modules\EcommerceFinance\Services;
use Illuminate\Validation\ValidationException;
/**
* 「终版」目录的按表数据登记:确定每个页签的字段(决定导入模板与表格列)
* 以及数据标题;数据本身独立存放,与基础目录互不影响。
* 按表维护的数据登记:确定终版页签和快递记账明细的字段、标题与存储键。
* 各目录的数据独立存放。
*/
class PayablesFinalRegistry
{
@ -14,6 +14,8 @@ class PayablesFinalRegistry
public const SECTION_COURIER = 'courier-payables-final';
public const SECTION_COURIER_BASE = 'courier-payables';
/** @var array<string,string> 供应商应付(终版)页签 */
private const SUPPLIER_TITLES = [
'product-prices' => '商品价格',
@ -117,6 +119,7 @@ class PayablesFinalRegistry
private readonly SupplierPayableMaintenanceRegistry $supplier,
private readonly ProductPriceWorkbookImporter $productPrices,
private readonly CourierPayableFinalRegistry $courier,
private readonly CourierBookkeepingRegistry $bookkeeping,
) {
}
@ -131,6 +134,7 @@ class PayablesFinalRegistry
return match ($section) {
self::SECTION_SUPPLIER => self::SUPPLIER_TITLES,
self::SECTION_COURIER => $this->courier->titles(),
self::SECTION_COURIER_BASE => ['bookkeeping-details' => '记账明细'],
default => [],
};
}
@ -139,7 +143,7 @@ class PayablesFinalRegistry
{
$titles = $this->titles($section);
if (! array_key_exists($dataset, $titles)) {
throw ValidationException::withMessages(['dataset' => '不支持该终版目录页面。']);
throw ValidationException::withMessages(['dataset' => '不支持该数据维护页面。']);
}
return $titles[$dataset];
@ -150,6 +154,10 @@ class PayablesFinalRegistry
{
$this->title($section, $dataset);
if ($section === self::SECTION_COURIER_BASE) {
return self::MONTH_FIELD + $this->bookkeeping->fields();
}
if ($section === self::SECTION_COURIER) {
return self::MONTH_FIELD + $this->courier->fields($dataset);
}
@ -169,6 +177,17 @@ class PayablesFinalRegistry
return self::MONTH_FIELD + $this->patchSupplierFields($dataset, $fields);
}
public function storeDataset(string $section, string $dataset): string
{
$this->title($section, $dataset);
return match ($section) {
self::SECTION_COURIER_BASE => 'courier:' . $dataset,
self::SECTION_COURIER => 'final:courier:' . $dataset,
default => 'final:supplier:' . $dataset,
};
}
/**
* @param array<string,array{label:string,type:string}> $fields
* @return array<string,array{label:string,type:string}>

View File

@ -535,8 +535,9 @@ Route::prefix('workspace/financial-rules/account-mapping/actions')
Route::get('template', [AccountMappingActions::class, 'template'])->name('template');
});
// 「终版」目录的按表数据独立存放,界面与基础页面一致。
// 终版页签和快递记账明细复用维护动作,各入口的数据独立存放。
$payablesFinalDatasets = [
'courier-payables' => ['bookkeeping-details'],
'supplier-payables-final' => [
'product-prices', 'payment-reconciliation', 'return-reconciliation', 'invoice-deductions',
'board-deductions', 'compensation-details', 'advance-details', 'sample-deductions',

View File

@ -0,0 +1,105 @@
<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Illuminate\Http\UploadedFile;
use Modules\EcommerceFinance\Services\PayablesFinalRegistry;
use Modules\EcommerceFinance\Services\SupplierPayableOverrideStore;
use Tests\Feature\FeatureTestCase;
class CourierBookkeepingPagesTest extends FeatureTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->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();
}
}

View File

@ -33,12 +33,8 @@ class CourierPayableFinalPagesTest extends FeatureTestCase
->assertSeeText('编辑')
->assertSeeText('下载导入模板')
->assertSeeText('月份')
->assertSeeTextInOrder(['物流单号', '快递单号整理', '物流公司', '线上订单号', '记账原因', '商品编码', '商品名称', '记账金额',
'记账数据', '收货人', '发起人', '发起时间', '店铺名称', '买家昵称', '省份', '扣单时间', '成本', '重量', '损耗', '负责人',
'平台商品id', '订单发货仓库', '供应商', '未发出', '退回单号', '报废', '成本记账', '结算记账', '结算运费', '记账分析',
'是否代发', '快递反馈', '客服回复', '原因'])
->assertDontSeeText('工单编号')
->assertDontSeeText('记账原因-一级选项')
->assertSeeText('工单编号')
->assertSeeText('记账金额')
->assertSeeText('暂无数据,请点击“导入”上传本表数据。')
->assertSee('workspace/courier-payables-final/actions/bookkeeping-details/template', false);
}
@ -47,15 +43,14 @@ class CourierPayableFinalPagesTest extends FeatureTestCase
{
$file = UploadedFile::fake()->createWithContent(
'bookkeeping-details.csv',
"\xEF\xBB\xBF记录标识,月份,物流单号,物流公司,发起人,发起时间,记账金额,成本,损耗,记账分析\n"
. "2026-10:1,2026-10,WO-FINAL-1,新北中通,终版发起人,2026-10-31 22:59:09,88.88,44.6,8.92,原单退回改0\n"
. "2026-10:2,2026-10,WO-FINAL-1,新北中通,终版发起人,2026-10-31 22:59:09,88.88,44.6,8.92,原单退回改0\n",
"\xEF\xBB\xBF月份,发起时间,工单编号,发起人,记账金额,备注\n"
. "2026-09,2026-09-20 10:00:00,WO-FINAL-1,终版发起人,88.88,终版备注\n",
);
$this->loginAs()
->post(route('business.courier-payables-final.bookkeeping-details.import'), ['import' => $file])
->assertStatus(302)
->assertSessionHas('success', '导入完成:新增 2 条,更新 0 条。'); // 有记录标识,完全一样的两行也各记一条
->assertSessionHas('success', '导入完成:新增 1 条,更新 0 条。');
$this->assertDatabaseHas('supplier_payable_overrides', [
'company_id' => $this->company->id,
@ -68,7 +63,7 @@ class CourierPayableFinalPagesTest extends FeatureTestCase
'page' => 'bookkeeping-details',
]))
->assertOk()
->assertSeeText('2026-10')
->assertSeeText('2026-09')
->assertSeeText('WO-FINAL-1')
->assertSeeText('终版发起人')
->assertDontSeeText('暂无数据,请点击“导入”上传本表数据。');

View File

@ -1594,7 +1594,7 @@ class PagesTest extends FeatureTestCase
$pages = [
['supplier-payables', 'product-prices', '条形码'],
['courier-payables', 'bookkeeping-details', '暂无记账明细'],
['courier-payables', 'bookkeeping-details', '快递单号整理'],
['courier-payables', 'compensation-details', '暂无赔偿明细'],
['courier-payables', 'advance-details', '暂无借支明细'],
['courier-payables', 'other-adjustments', '暂无其他扣款补款明细'],

View File

@ -7,6 +7,28 @@ use Tests\Feature\FeatureTestCase;
class PayablesFinalImportCommandTest extends FeatureTestCase
{
public function test_command_can_import_base_courier_bookkeeping_without_writing_final_data(): void
{
$directory = sys_get_temp_dir() . '/courier-bookkeeping-command-' . uniqid('', true);
mkdir($directory, 0777, true);
file_put_contents($directory . '/bookkeeping.csv',
"记录标识,月份,物流单号,结算运费\ncli:1,2026-10,SF-CLI-1,9.220000000000001\n");
try {
$this->artisan('payables:final-import', [
'--directory' => $directory,
'--section' => 'courier-payables',
'--dataset' => 'bookkeeping-details',
'--company' => (int) $this->company->id,
])->expectsOutputToContain('文件 1 个,读取 1 行')->assertExitCode(0);
$store = app(SupplierPayableOverrideStore::class);
$this->assertSame('9.2200', $store->findRow('courier:bookkeeping-details', 'cli:1', $this->company->id)['settle_freight']);
$this->assertSame([], $store->listRows('final:courier:bookkeeping-details', $this->company->id));
} finally {
@unlink($directory . '/bookkeeping.csv');
@rmdir($directory);
}
}
public function test_command_imports_every_csv_in_a_directory(): void
{
$directory = sys_get_temp_dir() . '/payables-final-command-' . uniqid('', true);

View File

@ -54,8 +54,8 @@ class PayablesFinalImportRunnerTest extends FeatureTestCase
['tail:2', '2026-10', 'SF-TAIL-2', '-9.699999999999999'],
]);
try {
$fields = app(PayablesFinalRegistry::class)->fields('courier-payables-final', 'bookkeeping-details');
$dataset = 'final:courier:bookkeeping-details';
$fields = app(PayablesFinalRegistry::class)->fields('courier-payables', 'bookkeeping-details');
$dataset = 'courier:bookkeeping-details';
$file = new UploadedFile($path, 'tails.xlsx', null, null, true);
$runner = app(PayablesFinalImportRunner::class);
$prepared = $runner->prepare($file, $fields, $dataset, $this->company->id, $this->user->id);