feat: 调整顾家发货明细新增表头 (#1106)

feat: 调整顾家发货明细新增表头 (#1106)
This commit is contained in:
chenxi 2026-11-11 19:14:44 +08:00
parent d6fe74ad1e
commit daca32926d
5 changed files with 108 additions and 20 deletions

View File

@ -60,12 +60,18 @@ class KukaPostingBaseImporter
throw new RuntimeException('顾家过账基础数据字段或店铺范围未配置。');
}
$sourceColumns = array_values(array_filter(array_map(
static fn (array $field): string => trim((string) ($field['source'] ?? '')),
$fields,
)));
if (count($sourceColumns) !== count($fields)) {
throw new RuntimeException('顾家过账基础数据字段配置不完整。');
$requiredSourceColumns = [];
$optionalSourceColumns = [];
foreach ($fields as $field) {
$source = trim((string) ($field['source'] ?? ''));
if ($source === '') {
throw new RuntimeException('顾家过账基础数据字段配置不完整。');
}
if (($field['optional'] ?? false) === true) {
$optionalSourceColumns[] = $source;
} else {
$requiredSourceColumns[] = $source;
}
}
$sheetName = trim((string) ($sheetName ?: config('kuka_posting.source_sheet', '发货明细表')));
@ -89,7 +95,8 @@ class KukaPostingBaseImporter
$sheetName,
$companyId,
$fields,
$sourceColumns,
$requiredSourceColumns,
$optionalSourceColumns,
$allowedStores,
&$storeCounts,
&$orders,
@ -117,7 +124,12 @@ class KukaPostingBaseImporter
$batch = [];
};
foreach ($this->reader->rows($path, $sourceColumns, [], $sheetName) as $sourceValues) {
foreach ($this->reader->rows(
$path,
$requiredSourceColumns,
$optionalSourceColumns,
$sheetName,
) as $sourceValues) {
$sourceRowNumber++;
$storeName = trim((string) ($sourceValues['店铺'] ?? ''));
if ($storeName === '' || ! in_array($storeName, $allowedStores, true)) {

View File

@ -96,13 +96,19 @@ return [
['name' => 'product_code', 'source' => '商品编码', 'label' => '商品编码'],
['name' => 'original_online_order_no', 'source' => '原始线上订单号', 'label' => '原始线上订单号'],
['name' => 'style_code', 'source' => '款式编码', 'label' => '款式编码'],
['name' => 'item_number', 'source' => '货号', 'label' => '货号'],
['name' => 'material_number', 'source' => '物料编号', 'label' => '物料编号', 'optional' => true],
['name' => 'model', 'source' => '型号', 'label' => '型号', 'optional' => true],
['name' => 'cost', 'source' => '成本', 'label' => '成本', 'kind' => 'number', 'optional' => true],
['name' => 'product_material', 'source' => '产品材质', 'label' => '产品材质', 'optional' => true],
['name' => 'shipped_quantity', 'source' => '实发数量', 'label' => '实发数量', 'kind' => 'number'],
['name' => 'shipping_amount', 'source' => '发货金额', 'label' => '发货金额', 'kind' => 'number', 'optional' => true],
['name' => 'product_category', 'source' => '产品分类', 'label' => '产品分类'],
['name' => 'product_short_name', 'source' => '商品简称', 'label' => '商品简称'],
['name' => 'color_spec', 'source' => '颜色规格', 'label' => '颜色规格'],
['name' => 'brand', 'source' => '品牌', 'label' => '品牌'],
['name' => 'cost_source', 'source' => '成本价来源', 'label' => '成本价来源'],
['name' => 'sales_quantity', 'source' => '销售数量', 'label' => '销售数量', 'kind' => 'number'],
['name' => 'shipped_quantity', 'source' => '实发数量', 'label' => '实发数量', 'kind' => 'number'],
['name' => 'actual_shipping_amount', 'source' => '实发金额', 'label' => '实发金额', 'kind' => 'number'],
['name' => 'sales_amount', 'source' => '销售金额', 'label' => '销售金额', 'kind' => 'number'],
['name' => 'paid_amount', 'source' => '已付金额', 'label' => '已付金额', 'kind' => 'number'],
@ -129,7 +135,6 @@ return [
['name' => 'product_name', 'source' => '商品名称', 'label' => '商品名称'],
['name' => 'supplier_product_code', 'source' => '供应商商品编码', 'label' => '供应商商品编码'],
['name' => 'specification_model', 'source' => '规格型号', 'label' => '规格型号'],
['name' => 'item_number', 'source' => '货号', 'label' => '货号'],
['name' => 'material', 'source' => '材质', 'label' => '材质'],
],
'field_widths' => [
@ -166,13 +171,19 @@ return [
'product_code' => 200,
'original_online_order_no' => 190,
'style_code' => 150,
'item_number' => 150,
'material_number' => 150,
'model' => 150,
'cost' => 110,
'product_material' => 170,
'shipped_quantity' => 100,
'shipping_amount' => 120,
'product_category' => 160,
'product_short_name' => 280,
'color_spec' => 170,
'brand' => 140,
'cost_source' => 140,
'sales_quantity' => 100,
'shipped_quantity' => 100,
'actual_shipping_amount' => 120,
'sales_amount' => 120,
'paid_amount' => 120,
@ -199,7 +210,6 @@ return [
'product_name' => 280,
'supplier_product_code' => 170,
'specification_model' => 190,
'item_number' => 150,
'material' => 210,
],
];

View File

@ -23,6 +23,12 @@
$directoryRouteSection = request()->route('section') ?: request()->segment(3) ?: ($section['slug'] ?? '');
$directoryRoutePage = request()->route('page') ?: request()->segment(4) ?: ($page['slug'] ?? '');
$directoryPageKey = (string) $directoryRouteSection . '/' . (string) $directoryRoutePage;
$columnPreferenceVersion = (string) ($columnPreferenceVersion ?? '');
if ($columnPreferenceVersion === '') {
$columnPreferenceVersion = $directoryPageKey === 'company-management/subject-operating-report'
? 'subject-service-company-income-v2'
: ($directoryPageKey === 'store-management/store-report' ? 'empty-month-columns-v1' : '');
}
$isInternalFlowReportPage = $directoryPageKey === 'store-management/internal-flow-report';
$internalFlowProjection = $isInternalFlowReportPage
? request()->attributes->get('internal-flow-report.projection')
@ -1796,7 +1802,7 @@
data-directory-user="{{ auth()->id() ?? 'guest' }}"
data-directory-section="{{ $section['slug'] ?? '' }}"
data-directory-tab="{{ $activeTab['slug'] ?? '' }}"
data-directory-column-preference-version="{{ $directoryPageKey === 'company-management/subject-operating-report' ? 'subject-service-company-income-v2' : ($directoryPageKey === 'store-management/store-report' ? 'empty-month-columns-v1' : '') }}"
data-directory-column-preference-version="{{ $columnPreferenceVersion }}"
aria-label="{{ $page['title'] ?? $section['title'] }}"
>
@if ($directoryUsesFieldQuery)

View File

@ -257,5 +257,6 @@
'showDirectoryIntro' => false,
'enableColumnResize' => true,
'columnWidths' => config('kuka_posting.field_widths', []),
'columnPreferenceVersion' => 'kuka-shipment-columns-v1',
])
</div>

View File

@ -50,14 +50,69 @@ class KukaPostingBasePageTest extends FeatureTestCase
->assertSee('data-directory-resizable="true"', false)
->assertSee('data-directory-column-resize', false)
->assertSee('directory-column-widths', false)
->assertSee('data-directory-column-preference-version="kuka-shipment-columns-v1"', false)
->assertSeeText('物料编号')
->assertSeeText('型号')
->assertSeeText('成本')
->assertSeeText('产品材质')
->assertSeeText('实发数量')
->assertSeeText('发货金额')
->assertSeeText('KUKA-00')
->assertSeeText('SKU-00')
->assertSeeText('ITEM-00')
->assertSeeText('MAT-00')
->assertDontSeeText('KUKA-01')
->assertDontSeeText('SKU-01');
@unlink($file);
}
public function test_new_headers_follow_style_code_in_requested_order(): void
{
$fields = array_values((array) config('kuka_posting.fields'));
$names = array_column($fields, 'name');
$styleIndex = array_search('style_code', $names, true);
$this->assertNotFalse($styleIndex);
$this->assertSame(
['item_number', 'material_number', 'model', 'cost', 'product_material', 'shipped_quantity', 'shipping_amount'],
array_slice($names, $styleIndex + 1, 7),
);
$this->assertSame(count($names), count(array_unique($names)));
$widths = (array) config('kuka_posting.field_widths');
$this->assertSame([], array_values(array_diff($names, array_keys($widths))));
}
public function test_optional_new_columns_do_not_block_legacy_exports(): void
{
$file = $this->workbook(includeOptionalFields: false);
$this->artisan('business-mirror:import-kuka-posting-base', [
'path' => $file,
'--month' => '2026-10',
'--company' => (string) $this->company->id,
])->assertExitCode(0);
$this->assertSame(
12,
DB::connection('business_mirror')->table('kuka_posting_base_rows')
->where('period', '2026-10')
->count(),
);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-basic-data',
]))
->assertOk()
->assertSeeText('物料编号')
->assertSeeText('发货金额');
@unlink($file);
}
public function test_kuka_posting_submenu_can_open_directly_without_a_second_sidebar_entry(): void
{
$file = $this->workbook();
@ -122,9 +177,12 @@ class KukaPostingBasePageTest extends FeatureTestCase
@unlink($incomplete);
}
private function workbook(bool $skipFirstStore = false): string
private function workbook(bool $skipFirstStore = false, bool $includeOptionalFields = true): string
{
$fields = config('kuka_posting.fields');
$fields = array_values(array_filter(
(array) config('kuka_posting.fields'),
static fn (array $field): bool => $includeOptionalFields || ! ($field['optional'] ?? false),
));
$headers = array_column($fields, 'source');
$stores = array_values(config('kuka_posting.stores'));
$rows = [];
@ -204,7 +262,7 @@ XML);
</Relationships>
XML);
$zip->addFromString('xl/worksheets/sheet1.xml', $this->worksheetXml([['汇总']]));
$zip->addFromString('xl/worksheets/sheet2.xml', $this->worksheetXml(array_merge([$headers], $rows)));
$zip->addFromString('xl/worksheets/sheet2.xml', $this->worksheetXml(array_merge([$headers], $rows), $fields));
$zip->close();
return $path;
@ -213,12 +271,13 @@ XML);
/**
* @param list<array<int, string>|array<string, string>> $rows
*/
private function worksheetXml(array $rows): string
private function worksheetXml(array $rows, ?array $fields = null): string
{
$fields ??= (array) config('kuka_posting.fields');
$xmlRows = [];
foreach ($rows as $rowIndex => $row) {
$cells = [];
$values = array_is_list($row) ? $row : $this->rowValues($row);
$values = array_is_list($row) ? $row : $this->rowValues($row, $fields);
foreach ($values as $columnIndex => $value) {
$reference = $this->columnName($columnIndex + 1) . ($rowIndex + 1);
$cells[] = '<c r="' . $reference . '" t="inlineStr"><is><t>'
@ -237,11 +296,11 @@ XML);
* @param array<string, string> $row
* @return list<string>
*/
private function rowValues(array $row): array
private function rowValues(array $row, array $fields): array
{
return array_map(
static fn (array $field): string => (string) ($row[$field['source']] ?? ''),
config('kuka_posting.fields'),
$fields,
);
}