From d1ff01803b876aee7e5d9901c737c072a969c469 Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 26 Oct 2026 14:57:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=88=90=E6=9C=AC=E6=AE=8B=E7=95=99=E7=BB=84=E5=90=88=E7=88=B6?= =?UTF-8?q?=E8=A1=8C=E4=B8=8E=E5=88=86=E5=8D=95=E5=8C=B9=E9=85=8D=20(#596)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/SyncStoreReceiptProductCost.php | 437 ++++++++++++++++-- .../Unit/StoreReceiptProductCostLineTest.php | 121 +++++ 2 files changed, 531 insertions(+), 27 deletions(-) diff --git a/app/Console/Commands/SyncStoreReceiptProductCost.php b/app/Console/Commands/SyncStoreReceiptProductCost.php index 3164612c..6e9ff39a 100644 --- a/app/Console/Commands/SyncStoreReceiptProductCost.php +++ b/app/Console/Commands/SyncStoreReceiptProductCost.php @@ -108,6 +108,9 @@ class SyncStoreReceiptProductCost extends Command /** 线上代发价格的钉钉代发来源。 */ private const DING_DAIFA_TABLE = 'ding_online_daifa_price_mirror'; + /** @var array,amount:float}>>|null */ + private ?array $goodsProfitProfileScopeIndex = null; + /** * 订单侧两个来源:淘系(企微客户订单)与聚水潭订单。 * 两边的仓库字段不同:淘系明细没有 send_warehouse,用订单上的 wms_co_id; @@ -2089,13 +2092,28 @@ class SyncStoreReceiptProductCost extends Command return; } + $nonLeafOrderIds = []; + foreach ($unique as $row) { + $parentOrderId = trim((string) ($row['parent_o_id'] ?? '')); + if ($parentOrderId !== '' && $parentOrderId !== '0') { + $nonLeafOrderIds[$parentOrderId] = true; + } + } + + // 分单订单可能把同一组合父行拆到多个末级子单,商品利润组件仍是整单口径。 + // 只有所有子单的组件完全一致且父行金额合计对平时,才合并成一组组件。 + $this->applyGoodsProfitSplitFamilies($unique, $stats, $profiles); + $groups = []; foreach ($unique as $key => $row) { $source = trim((string) ($row['source'] ?? '')); $orderId = trim((string) ($row['o_id'] ?? '')); $shopSkuId = trim((string) ($row['shop_sku_id'] ?? '')); $shopItemId = trim((string) ($row['shop_i_id'] ?? '')); - if (in_array('', [$source, $orderId, $shopSkuId, $shopItemId], true)) { + if ( + in_array('', [$source, $orderId, $shopSkuId, $shopItemId], true) + || isset($nonLeafOrderIds[$orderId]) + ) { continue; } $profileKey = self::goodsProfitSplitProfileKey($source, $orderId, $shopSkuId, $shopItemId); @@ -2137,22 +2155,30 @@ class SyncStoreReceiptProductCost extends Command } $componentCodes = array_fill_keys(array_keys($components), true); $parentRows = []; - $bundleParentRows = []; + $activeBundleParentRows = []; foreach ($groupKeys as $key) { + if (! isset($unique[$key])) { + continue; + } $sku = mb_strtoupper(trim((string) ($unique[$key]['sku'] ?? ''))); if ($sku === '' || isset($componentCodes[$sku])) { continue; } $parentRows[$sku][] = $key; - if (self::isBundleParentRow($unique[$key])) { - $bundleParentRows[$sku][] = $key; + $quantity = (float) ($unique[$key]['qty'] ?? 0); + $amount = (float) ($unique[$key]['amount'] ?? 0); + if ( + self::isBundleParentRow($unique[$key]) + && ($quantity > 0 || abs($amount) > 0.005) + ) { + $activeBundleParentRows[$sku][] = $key; } } - // 订单镜像可能同时残留上一版组合组件。存在唯一组合父行时,只按 - // 该父行与商品利润原表组件对账;对平后同组旧组件会一并剔除。 - if (count($bundleParentRows) === 1) { - $parentRows = $bundleParentRows; + // 订单镜像可能同时残留上一版零数量父行。存在唯一有效组合父行时, + // 只按该父行与商品利润原表组件对账;零数量旧父行随同组一起剔除。 + if (count($activeBundleParentRows) === 1) { + $parentRows = $activeBundleParentRows; } if (count($parentRows) !== 1) { @@ -2199,24 +2225,13 @@ class SyncStoreReceiptProductCost extends Command foreach ($groupKeys as $key) { unset($unique[$key]); } - foreach ($validComponents as $code => $component) { - $rowKey = (string) ($firstParent['row_key'] ?? $parentSku) - . ':goods-profit:' . sha1($parentSku . "\0" . $code); - $unique[$rowKey] = array_merge($firstParent, [ - 'sku' => $code, - 'sku_type' => 'normal', - 'base_price' => 0.0, - 'item_name' => $code, - 'qty' => round((float) $component['qty'], 4), - 'amount' => round((float) $component['amount'], 2), - 'warehouse' => $resolvedWarehouse, - 'parent_o_id' => '', - 'row_key' => $rowKey, - 'src_combine_sku_id' => '', - 'properties_value' => '', - 'bundle_component_source' => 'goods_profit_current_order', - ]); - } + $this->addGoodsProfitSplitComponents( + $unique, + $firstParent, + $parentSku, + $validComponents, + $resolvedWarehouse, + ); $stats['bundle_stats']['goods_profit_split_groups']++; $stats['bundle_stats']['goods_profit_split_parent_rows'] += count($parentKeys); @@ -2225,6 +2240,373 @@ class SyncStoreReceiptProductCost extends Command $stats['bundle_stats']['goods_profit_split_component_codes'][$code] = true; } } + + // 极少数订单的活动父行使用了新平台 SKU,而商品利润组件仍挂在旧平台 SKU 下。 + // 同一订单、同一平台款式下仅有一个组件集合金额与活动父行对平时,允许跨 SKU 替换。 + $this->applyGoodsProfitCrossSkuSplits($unique, $stats, $profiles); + } + + /** + * 合并分单末级父行后应用商品利润组件。 + * + * @param array> $unique + * @param array $stats + * @param array> $profiles + */ + private function applyGoodsProfitSplitFamilies(array &$unique, array &$stats, array $profiles): void + { + $families = []; + foreach ($unique as $key => $row) { + $parentOrderId = trim((string) ($row['parent_o_id'] ?? '')); + if ( + $parentOrderId === '' + || $parentOrderId === '0' + || ! self::isBundleParentRow($row) + ) { + continue; + } + + $quantity = (float) ($row['qty'] ?? 0); + $amount = (float) ($row['amount'] ?? 0); + if ($quantity <= 0 && abs($amount) <= 0.005) { + continue; + } + + $source = trim((string) ($row['source'] ?? '')); + $shopSkuId = trim((string) ($row['shop_sku_id'] ?? '')); + $shopItemId = trim((string) ($row['shop_i_id'] ?? '')); + $parentSku = mb_strtoupper(trim((string) ($row['sku'] ?? ''))); + $orderId = trim((string) ($row['o_id'] ?? '')); + if ( + in_array('', [$source, $orderId, $shopSkuId, $shopItemId, $parentSku], true) + ) { + continue; + } + + $familyKey = $source . "\0" . $parentOrderId . "\0" . $shopSkuId . "\0" . $shopItemId; + $families[$familyKey]['first_parent_key'] = $families[$familyKey]['first_parent_key'] ?? $key; + $families[$familyKey]['parent_keys'][] = $key; + $families[$familyKey]['parent_skus'][$parentSku] = true; + $families[$familyKey]['profile_keys'][ + self::goodsProfitSplitProfileKey($source, $orderId, $shopSkuId, $shopItemId) + ] = true; + } + + foreach ($families as $family) { + if (count($family['parent_keys']) < 2 || count($family['parent_skus']) !== 1) { + continue; + } + + $componentSets = []; + foreach (array_keys($family['profile_keys']) as $profileKey) { + $components = $profiles[$profileKey]['components'] ?? null; + if (! is_array($components) || $components === []) { + continue 2; + } + $componentSets[] = $components; + } + if ($componentSets === []) { + continue; + } + $components = reset($componentSets); + foreach ($componentSets as $componentSet) { + if ($componentSet !== $components) { + continue 2; + } + } + + $validComponents = self::validGoodsProfitComponents($components); + $componentAmount = (float) array_sum(array_column($validComponents, 'amount')); + $parentAmount = 0.0; + foreach ($family['parent_keys'] as $parentKey) { + if (isset($unique[$parentKey])) { + $parentAmount += (float) ($unique[$parentKey]['amount'] ?? 0); + } + } + if ( + $validComponents === [] + || $parentAmount <= 0 + || abs(round($componentAmount - $parentAmount, 2)) > 0.01 + ) { + continue; + } + + $firstParent = $unique[$family['first_parent_key']]; + $familyRootOrderId = trim((string) ($firstParent['parent_o_id'] ?? '')); + $resolvedWarehouse = ''; + foreach ($unique as $row) { + $rowRootOrderId = trim((string) ($row['parent_o_id'] ?? '')); + if ($rowRootOrderId === '' || $rowRootOrderId === '0') { + $rowRootOrderId = trim((string) ($row['o_id'] ?? '')); + } + if ( + trim((string) ($row['source'] ?? '')) !== trim((string) ($firstParent['source'] ?? '')) + || $rowRootOrderId !== $familyRootOrderId + || trim((string) ($row['shop_sku_id'] ?? '')) !== trim((string) ($firstParent['shop_sku_id'] ?? '')) + || trim((string) ($row['shop_i_id'] ?? '')) !== trim((string) ($firstParent['shop_i_id'] ?? '')) + ) { + continue; + } + if (trim((string) ($row['warehouse'] ?? '')) !== '') { + $resolvedWarehouse = trim((string) $row['warehouse']); + break; + } + } + + $componentCodes = array_fill_keys(array_keys($validComponents), true); + $parentRows = 0; + foreach ($unique as $key => $row) { + $rowRootOrderId = trim((string) ($row['parent_o_id'] ?? '')); + if ($rowRootOrderId === '' || $rowRootOrderId === '0') { + $rowRootOrderId = trim((string) ($row['o_id'] ?? '')); + } + if ( + trim((string) ($row['source'] ?? '')) !== trim((string) ($firstParent['source'] ?? '')) + || $rowRootOrderId !== $familyRootOrderId + || trim((string) ($row['shop_sku_id'] ?? '')) !== trim((string) ($firstParent['shop_sku_id'] ?? '')) + || trim((string) ($row['shop_i_id'] ?? '')) !== trim((string) ($firstParent['shop_i_id'] ?? '')) + ) { + continue; + } + + $sku = mb_strtoupper(trim((string) ($row['sku'] ?? ''))); + if (! self::isBundleParentRow($row) && ! isset($componentCodes[$sku])) { + continue; + } + if (self::isBundleParentRow($row)) { + $parentRows++; + } + unset($unique[$key]); + } + + $parentSku = (string) array_key_first($family['parent_skus']); + $this->addGoodsProfitSplitComponents( + $unique, + $firstParent, + $parentSku, + $validComponents, + $resolvedWarehouse, + ); + $stats['bundle_stats']['goods_profit_split_groups']++; + $stats['bundle_stats']['goods_profit_split_parent_rows'] += $parentRows; + $stats['bundle_stats']['goods_profit_split_component_rows'] += count($validComponents); + foreach (array_keys($validComponents) as $code) { + $stats['bundle_stats']['goods_profit_split_component_codes'][$code] = true; + } + } + } + + /** + * 活动父行平台 SKU 与商品利润组件平台 SKU 不一致时,只在组件集合唯一时替换。 + * + * @param array> $unique + * @param array $stats + * @param array> $profiles + */ + private function applyGoodsProfitCrossSkuSplits(array &$unique, array &$stats, array $profiles): void + { + $profilesByScope = $this->buildGoodsProfitProfileScopeIndex($profiles); + + $parentsByScope = []; + foreach ($unique as $key => $row) { + $source = trim((string) ($row['source'] ?? '')); + $orderId = trim((string) ($row['o_id'] ?? '')); + $shopSkuId = trim((string) ($row['shop_sku_id'] ?? '')); + $shopItemId = trim((string) ($row['shop_i_id'] ?? '')); + $sku = mb_strtoupper(trim((string) ($row['sku'] ?? ''))); + if ( + in_array('', [$source, $orderId, $shopSkuId, $shopItemId, $sku], true) + || ! self::isBundleParentRow($row) + || (float) ($row['qty'] ?? 0) <= 0 + || (float) ($row['amount'] ?? 0) <= 0 + || isset($profiles[self::goodsProfitSplitProfileKey($source, $orderId, $shopSkuId, $shopItemId)]) + ) { + continue; + } + $scopeKey = $source . "\0" . $orderId . "\0" . $shopItemId; + $parentsByScope[$scopeKey]['keys'][] = $key; + $parentsByScope[$scopeKey]['skus'][$sku] = true; + $parentsByScope[$scopeKey]['amount'] = ($parentsByScope[$scopeKey]['amount'] ?? 0.0) + + (float) ($row['amount'] ?? 0); + $parentsByScope[$scopeKey]['shop_sku_id'] = $shopSkuId; + } + + foreach ($parentsByScope as $scopeKey => $parentGroup) { + if (count($parentGroup['skus']) !== 1 || (float) ($parentGroup['amount'] ?? 0) <= 0) { + continue; + } + + $candidates = []; + foreach ($profilesByScope[$scopeKey] ?? [] as $candidate) { + if ( + $candidate['shop_sku_id'] !== $parentGroup['shop_sku_id'] + && abs(round((float) $candidate['amount'] - (float) $parentGroup['amount'], 2)) <= 0.01 + ) { + $candidates[] = $candidate; + } + } + if (count($candidates) !== 1) { + continue; + } + + $candidate = $candidates[0]; + $componentCodes = array_fill_keys(array_keys($candidate['components']), true); + [$source, $orderId, $shopItemId] = explode("\0", $scopeKey); + $linkedRows = false; + $resolvedWarehouse = ''; + foreach ($unique as $row) { + if ( + trim((string) ($row['source'] ?? '')) !== $source + || trim((string) ($row['o_id'] ?? '')) !== $orderId + || trim((string) ($row['shop_sku_id'] ?? '')) !== $candidate['shop_sku_id'] + || trim((string) ($row['shop_i_id'] ?? '')) !== $shopItemId + ) { + continue; + } + if (trim((string) ($row['warehouse'] ?? '')) !== '') { + $resolvedWarehouse = trim((string) $row['warehouse']); + } + $linkedParent = mb_strtoupper(trim((string) ($row['src_combine_sku_id'] ?? ''))); + if ( + self::isBundleParentRow($row) + || self::isChineseBundleParentSku($linkedParent) + ) { + $linkedRows = true; + } + } + if (! $linkedRows) { + continue; + } + + $firstParent = $unique[$parentGroup['keys'][0]]; + foreach ($unique as $key => $row) { + if ( + trim((string) ($row['source'] ?? '')) !== $source + || trim((string) ($row['o_id'] ?? '')) !== $orderId + || trim((string) ($row['shop_sku_id'] ?? '')) !== $candidate['shop_sku_id'] + || trim((string) ($row['shop_i_id'] ?? '')) !== $shopItemId + ) { + continue; + } + $sku = mb_strtoupper(trim((string) ($row['sku'] ?? ''))); + $linkedParent = mb_strtoupper(trim((string) ($row['src_combine_sku_id'] ?? ''))); + if ( + self::isBundleParentRow($row) + || isset($componentCodes[$sku]) + || self::isChineseBundleParentSku($linkedParent) + ) { + unset($unique[$key]); + } + } + foreach ($parentGroup['keys'] as $parentKey) { + unset($unique[$parentKey]); + } + + $parentSku = (string) array_key_first($parentGroup['skus']); + $this->addGoodsProfitSplitComponents( + $unique, + $firstParent, + $parentSku, + $candidate['components'], + $resolvedWarehouse, + ); + $stats['bundle_stats']['goods_profit_split_groups']++; + $stats['bundle_stats']['goods_profit_split_parent_rows'] += count($parentGroup['keys']); + $stats['bundle_stats']['goods_profit_split_component_rows'] += count($candidate['components']); + foreach (array_keys($candidate['components']) as $code) { + $stats['bundle_stats']['goods_profit_split_component_codes'][$code] = true; + } + } + } + + /** + * 商品利润画像全场一致,跨 SKU 候选索引只构建一次,避免每个账单重复扫描。 + * + * @param array> $profiles + * @return array,amount:float}>> + */ + private function buildGoodsProfitProfileScopeIndex(array $profiles): array + { + if ($this->goodsProfitProfileScopeIndex !== null) { + return $this->goodsProfitProfileScopeIndex; + } + + $index = []; + foreach ($profiles as $profileKey => $profile) { + $parts = explode("\0", $profileKey); + if (count($parts) !== 4 || ! is_array($profile['components'] ?? null)) { + continue; + } + $validComponents = self::validGoodsProfitComponents($profile['components']); + if ($validComponents === []) { + continue; + } + $scopeKey = $parts[0] . "\0" . $parts[1] . "\0" . $parts[3]; + $index[$scopeKey][] = [ + 'shop_sku_id' => $parts[2], + 'components' => $validComponents, + 'amount' => round((float) array_sum(array_column($validComponents, 'amount')), 2), + ]; + } + + return $this->goodsProfitProfileScopeIndex = $index; + } + + /** + * @param array $components + * @return array + */ + private static function validGoodsProfitComponents(array $components): array + { + $valid = []; + foreach ($components as $componentCode => $component) { + $code = mb_strtoupper(trim((string) $componentCode)); + $quantity = (float) ($component['qty'] ?? 0); + $amount = (float) ($component['amount'] ?? 0); + if ($code === '' || $quantity <= 0 || $amount <= 0) { + continue; + } + $valid[$code] = [ + 'qty' => round($quantity, 4), + 'amount' => round($amount, 2), + ]; + } + ksort($valid, SORT_STRING); + + return $valid; + } + + /** + * @param array> $unique + * @param array $firstParent + * @param array $components + */ + private function addGoodsProfitSplitComponents( + array &$unique, + array $firstParent, + string $parentSku, + array $components, + string $resolvedWarehouse, + ): void { + foreach ($components as $code => $component) { + $rowKey = (string) ($firstParent['row_key'] ?? $parentSku) + . ':goods-profit:' . sha1($parentSku . "\0" . $code); + $unique[$rowKey] = array_merge($firstParent, [ + 'sku' => $code, + 'sku_type' => 'normal', + 'base_price' => 0.0, + 'item_name' => $code, + 'qty' => round((float) $component['qty'], 4), + 'amount' => round((float) $component['amount'], 2), + 'warehouse' => $resolvedWarehouse, + 'parent_o_id' => '', + 'row_key' => $rowKey, + 'src_combine_sku_id' => '', + 'properties_value' => '', + 'bundle_component_source' => 'goods_profit_current_order', + 'keep_after_leaf_filter' => true, + ]); + } } /** @param array $row */ @@ -2774,7 +3156,8 @@ class SyncStoreReceiptProductCost extends Command if ($parentIds !== []) { $leaves = array_filter( $unique, - static fn (array $row): bool => ! isset($parentIds[trim((string) $row['o_id'])]) + static fn (array $row): bool => ! empty($row['keep_after_leaf_filter']) + || ! isset($parentIds[trim((string) $row['o_id'])]) ); // 兜底:理论上不会出现全部被过滤(除非数据自相矛盾),真有则保留原集合避免整单丢失。 if ($leaves !== []) { diff --git a/tests/Unit/StoreReceiptProductCostLineTest.php b/tests/Unit/StoreReceiptProductCostLineTest.php index 7ea0bb97..7350f4f1 100644 --- a/tests/Unit/StoreReceiptProductCostLineTest.php +++ b/tests/Unit/StoreReceiptProductCostLineTest.php @@ -641,6 +641,127 @@ class StoreReceiptProductCostLineTest extends TestCase $this->assertSame(649.0, round(array_sum(array_column($lines, 'amount')), 2)); } + public function test_goods_profit_bundle_parent_ignores_zero_quantity_stale_parent_rows(): void + { + $profileKey = "jst\0" . "8986587\0" . "3533103677164802\0" . 'GOODS-ITEM-ZERO-PARENTS'; + $components = [ + 'SJ038020N1410V02' => ['qty' => 1, 'amount' => 377.31], + 'SJ038069N1410V01' => ['qty' => 3, 'amount' => 42.69], + ]; + + [$lines, , , , , $stats] = $this->costLines([ + $this->row('old-parent-1', '运营组合套装12630', 'GOODS-ITEM-ZERO-PARENTS', 0, 0), + $this->row('old-parent-2', '运营组合套装13014', 'GOODS-ITEM-ZERO-PARENTS', 0, 0), + $this->row('current-parent', '运营组合套装13015', 'GOODS-ITEM-ZERO-PARENTS', 1, 420), + ], [], [ + $profileKey => [ + 'source' => 'goods_profit_current_order', + 'components' => $components, + ], + ]); + + $codes = array_column($lines, 'sku'); + sort($codes, SORT_STRING); + + $this->assertSame(['SJ038020N1410V02', 'SJ038069N1410V01'], $codes); + $this->assertSame(420.0, round(array_sum(array_column($lines, 'amount')), 2)); + $this->assertSame(1, $stats['bundle_stats']['goods_profit_split_groups']); + $this->assertSame(1, $stats['bundle_stats']['goods_profit_split_parent_rows']); + } + + public function test_goods_profit_bundle_combines_split_parent_branches_before_reconcile(): void + { + $components = [ + 'DNZ038526N1280V01' => ['qty' => 2, 'amount' => 1111.84], + 'GBGJ-DNZ038401N1440V01' => ['qty' => 2, 'amount' => 954.58], + 'GBGJ-ZWJ024903AN1407V01' => ['qty' => 2, 'amount' => 633.90], + 'GBGJ-ZWJ024903BN1407V01' => ['qty' => 2, 'amount' => 633.90], + ]; + $common = [ + 'shop_sku_id' => 'SPLIT-SKU', + ]; + + [$lines, , , , , $stats] = $this->costLines([ + $this->row('split-root', 'MKH-运营组合套装260706016', 'SPLIT-ITEM', 2, 3334.22, '', $common + [ + 'o_id' => 'SPLIT-ROOT', + ]), + $this->row('split-child-1', 'MKH-运营组合套装260706016', 'SPLIT-ITEM', 1, 1667.11, '', $common + [ + 'o_id' => 'SPLIT-CHILD-1', + 'parent_o_id' => 'SPLIT-ROOT', + ]), + $this->row('split-child-2', 'MKH-运营组合套装260706016', 'SPLIT-ITEM', 1, 1667.11, '', $common + [ + 'o_id' => 'SPLIT-CHILD-2', + 'parent_o_id' => 'SPLIT-ROOT', + ]), + ], [], [ + "jst\0SPLIT-CHILD-1\0SPLIT-SKU\0SPLIT-ITEM" => [ + 'source' => 'goods_profit_current_order', + 'components' => $components, + ], + "jst\0SPLIT-CHILD-2\0SPLIT-SKU\0SPLIT-ITEM" => [ + 'source' => 'goods_profit_current_order', + 'components' => $components, + ], + ]); + + $bySku = collect($lines)->keyBy('sku'); + $this->assertCount(4, $lines); + $this->assertSame(2.0, $bySku['DNZ038526N1280V01']['qty']); + $this->assertSame(3334.22, round(array_sum(array_column($lines, 'amount')), 2)); + $this->assertSame(1, $stats['bundle_stats']['goods_profit_split_groups']); + $this->assertSame(3, $stats['bundle_stats']['goods_profit_split_parent_rows']); + } + + public function test_goods_profit_bundle_uses_unique_component_group_from_stale_shop_sku(): void + { + $components = [ + 'SJ038020N1410V02' => ['qty' => 1, 'amount' => 377.31], + 'SJ038069N1410V01' => ['qty' => 3, 'amount' => 42.69], + ]; + $common = [ + 'o_id' => 'CROSS-SKU-ORDER', + 'shop_i_id' => 'CROSS-SKU-ITEM', + ]; + + [$lines, , , , , $stats] = $this->costLines([ + $this->row('old-parent', '运营组合套装12630', 'CROSS-SKU-ITEM', 0, 0, '', $common + [ + 'shop_sku_id' => 'OLD-SKU', + ]), + $this->row('component-1', 'SJ038020N1410V02', 'CROSS-SKU-ITEM', 1, 377.31, '运营组合套装12630', $common + [ + 'shop_sku_id' => 'OLD-SKU', + ]), + $this->row('component-2', 'SJ038069N1410V01', 'CROSS-SKU-ITEM', 3, 42.69, '运营组合套装12630', $common + [ + 'shop_sku_id' => 'OLD-SKU', + ]), + $this->row('current-parent', '运营组合套装13011', 'CROSS-SKU-ITEM', 1, 420, '', $common + [ + 'shop_sku_id' => 'NEW-SKU', + ]), + $this->row('separate-item', 'SN021702N230V01', 'CROSS-SKU-ITEM', 1, 49.97, '', [ + 'o_id' => 'CROSS-SKU-CHILD', + 'parent_o_id' => 'CROSS-SKU-ORDER', + 'shop_i_id' => 'CROSS-SKU-ITEM', + 'shop_sku_id' => 'OTHER-SKU', + ]), + ], [], [ + "jst\0CROSS-SKU-ORDER\0OLD-SKU\0CROSS-SKU-ITEM" => [ + 'source' => 'goods_profit_current_order', + 'components' => $components, + ], + ]); + + $codes = array_column($lines, 'sku'); + sort($codes, SORT_STRING); + + $this->assertSame([ + 'SJ038020N1410V02', + 'SJ038069N1410V01', + 'SN021702N230V01', + ], $codes); + $this->assertSame(469.97, round(array_sum(array_column($lines, 'amount')), 2)); + $this->assertSame(1, $stats['bundle_stats']['goods_profit_split_groups']); + $this->assertSame(1, $stats['bundle_stats']['goods_profit_split_parent_rows']); + } + public function test_goods_profit_current_order_split_is_not_applied_when_amount_differs(): void { $profileKey = "jst\0" . "8986587\0" . "3533103677164802\0" . 'GOODS-ITEM-3'; From b25ae15a4b62ca576bd9e5225a095797f4805bb7 Mon Sep 17 00:00:00 2001 From: DoDo <1060330844@qq.com> Date: Mon, 26 Oct 2026 15:04:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E7=A8=8E=E5=8A=A1=E7=B1=BB=E5=9E=8B=E4=B8=8E=E5=B7=A5=E5=95=86?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AD=97=E6=AE=B5=20(#597)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 公司基础信息和主体维度报表增加税务类型、工商类型字段,并复用 fin_companies 已完成核对的数据。 --- app/Business/UpstreamBusinessInformation.php | 21 ++- config/business_navigation.php | 5 +- docs/主体维度经营报表需求说明.md | 36 ++--- .../BusinessInformationMirrorRepository.php | 128 +++++++++++------- .../pages/partials/directory-table.blade.php | 13 +- .../pages/partials/prototype-page.blade.php | 4 +- tests/Feature/Business/ManagementCrudTest.php | 7 +- tests/Feature/Business/PrototypePageTest.php | 7 +- ...usinessInformationMirrorRepositoryTest.php | 25 +++- .../StoreReportRepositoryTest.php | 17 ++- .../UpstreamBusinessInformationTest.php | 1 + 11 files changed, 185 insertions(+), 79 deletions(-) diff --git a/app/Business/UpstreamBusinessInformation.php b/app/Business/UpstreamBusinessInformation.php index 837dc4a3..9481db3a 100644 --- a/app/Business/UpstreamBusinessInformation.php +++ b/app/Business/UpstreamBusinessInformation.php @@ -591,10 +591,22 @@ SQL); $rows = array_values($entities); $details = $this->companyDetails(array_column($rows, 'entity')); + try { + $classifications = $this->mirror->companyClassificationsByNames(array_column($rows, 'entity')); + } catch (Throwable) { + $classifications = []; + } foreach ($rows as &$row) { $row['company_details'] = $details[$row['entity']] ?? []; $row['city'] = $this->cityFromDetails($row['company_details']); $row['company_status'] = $row['company_details'][0]['company_status'] ?? null; + $classification = $classifications[$row['entity']] ?? []; + $row['tax_type'] = $classification['tax_type'] + ?? $row['company_details'][0]['taxpayer_category'] + ?? null; + $row['business_registration_type'] = $classification['business_registration_type'] + ?? $row['company_details'][0]['business_registration_type'] + ?? null; } unset($row); @@ -693,7 +705,7 @@ SQL); return false; } - foreach (['city', 'entity', 'plan', 'new_entity'] as $key) { + foreach (['city', 'entity', 'tax_type', 'business_registration_type', 'plan', 'new_entity'] as $key) { $needle = trim((string) ($filters[$key] ?? '')); if ($needle !== '' && mb_stripos((string) ($row[$key] ?? ''), $needle) === false) { return false; @@ -717,7 +729,7 @@ SQL); { $key = (string) ($filters['_sort'] ?? 'entity'); $allowed = [ - 'city', 'entity', 'company_type', 'rolling_12m_income', + 'city', 'entity', 'company_type', 'tax_type', 'business_registration_type', 'rolling_12m_income', ...array_map(static fn (int $month): string => sprintf('income_%02d', $month), range(1, 12)), 'can_change_entity', 'plan', 'new_entity', ]; @@ -818,7 +830,8 @@ SQL); 'company_status' => $row['companyStatus'] ?? $row['company_status'] ?? null, 'financial_officer' => $row['financialManager'] ?? $row['financial_officer'] ?? null, 'supervisor' => $row['supervisor'] ?? null, - 'taxpayer_category' => $row['taxCategoryAndType'] ?? $row['taxpayer_category'] ?? null, + 'taxpayer_category' => $row['finance_tax_type'] ?? $row['taxCategoryAndType'] ?? $row['taxpayer_category'] ?? null, + 'business_registration_type' => $row['business_registration_type'] ?? null, 'shareholders' => $row['shareholders'] ?? null, ]); } @@ -1062,6 +1075,8 @@ SQL); '1' => '已注销', default => $row['company_status'] ?? null, }; + $businessType = trim((string) ($row['business_registration_type'] ?? '')); + $row['business_registration_type'] = in_array($businessType, ['', '/'], true) ? null : $businessType; return $row; } diff --git a/config/business_navigation.php b/config/business_navigation.php index b5ae5cb2..dd31dff8 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -18,6 +18,8 @@ $navigation = [ ['name' => 'city', 'label' => '市'], ['name' => 'entity', 'label' => '主体'], ['name' => 'company_type', 'label' => '公司类型'], + ['name' => 'tax_type', 'label' => '税务类型'], + ['name' => 'business_registration_type', 'label' => '工商类型'], ['name' => 'rolling_12m_income', 'label' => '最近12个月累计收入', 'kind' => 'number'], ...array_map(static fn (int $month): array => ['name' => sprintf('income_%02d', $month), 'label' => $month . '月收入', 'kind' => 'number'], range(1, 12)), ['name' => 'can_change_entity', 'label' => '能否变更主体'], @@ -93,7 +95,8 @@ $navigation = [ 'fields' => [ ['name' => 'unified_social_credit_code', 'label' => '统一社会信用代码'], ['name' => 'company_name', 'label' => '公司名称'], - ['name' => 'taxpayer_type', 'label' => '纳税人类型', 'source' => 'taxpayer_category'], + ['name' => 'taxpayer_type', 'label' => '税务类型', 'source' => 'taxpayer_category'], + ['name' => 'business_registration_type', 'label' => '工商类型'], ['name' => 'company_status', 'label' => '公司状态'], ['name' => 'subscribed_capital', 'label' => '认缴注册资本(万元)', 'kind' => 'number'], ['name' => 'registered_at', 'label' => '注册时间', 'kind' => 'date', 'source' => 'establishment_date'], diff --git a/docs/主体维度经营报表需求说明.md b/docs/主体维度经营报表需求说明.md index d1ba2f85..e0c651c8 100644 --- a/docs/主体维度经营报表需求说明.md +++ b/docs/主体维度经营报表需求说明.md @@ -27,22 +27,24 @@ | 1 | 市 | 由主体基础资料 `rpt.fys_companyInfo.registeredAddress` 解析地级市(`App\Business\RegisteredAddressCity::parse`):直辖市直接返回「XX市」;其余取省/自治区前缀后第一个地级行政区;本地地址省略省市前缀时按常州区划前缀兜底;识别不出按统一缺失值展示,不伪造数据 | | 2 | 主体 | 主体名称;作为主体合并键 | | 3 | 公司类型 | 主体公司类型,来源于 `rpt` | -| 4 | 最近12个月累计收入 | 最近12个完整自然月收入合计,排除当前月 | -| 5 | 1月收入 | 当前年份 1 月收入,当前月或无账单时为空 | -| 6 | 2月收入 | 当前年份 2 月收入,当前月或无账单时为空 | -| 7 | 3月收入 | 当前年份 3 月收入,当前月或无账单时为空 | -| 8 | 4月收入 | 当前年份 4 月收入,当前月或无账单时为空 | -| 9 | 5月收入 | 当前年份 5 月收入,当前月或无账单时为空 | -| 10 | 6月收入 | 当前年份 6 月收入,当前月或无账单时为空 | -| 11 | 7月收入 | 当前年份 7 月收入,当前月或无账单时为空 | -| 12 | 8月收入 | 当前年份 8 月收入,当前月或无账单时为空 | -| 13 | 9月收入 | 当前年份 9 月收入,当前月或无账单时为空 | -| 14 | 10月收入 | 当前年份 10 月收入,当前月或无账单时为空 | -| 15 | 11月收入 | 当前年份 11 月收入,当前月或无账单时为空 | -| 16 | 12月收入 | 当前年份 12 月收入,当前月或无账单时为空 | -| 17 | 能否变更主体 | 逻辑暂未提供,先留空/按统一缺失值规则展示 | -| 18 | 规划 | 逻辑暂未提供,先留空/按统一缺失值规则展示 | -| 19 | 新主体(变更流程同步新主体) | 逻辑暂未提供,先留空/按统一缺失值规则展示 | +| 4 | 税务类型 | 主体税务类型,优先读取 `fin_companies.tax_type`,缺失时使用 `rpt.fys_companyInfo.taxCategoryAndType` | +| 5 | 工商类型 | 主体工商类型,读取 `fin_companies.business_type`;空值或 `/` 按统一缺失值展示 | +| 6 | 最近12个月累计收入 | 最近12个完整自然月收入合计,排除当前月 | +| 7 | 1月收入 | 当前年份 1 月收入,当前月或无账单时为空 | +| 8 | 2月收入 | 当前年份 2 月收入,当前月或无账单时为空 | +| 9 | 3月收入 | 当前年份 3 月收入,当前月或无账单时为空 | +| 10 | 4月收入 | 当前年份 4 月收入,当前月或无账单时为空 | +| 11 | 5月收入 | 当前年份 5 月收入,当前月或无账单时为空 | +| 12 | 6月收入 | 当前年份 6 月收入,当前月或无账单时为空 | +| 13 | 7月收入 | 当前年份 7 月收入,当前月或无账单时为空 | +| 14 | 8月收入 | 当前年份 8 月收入,当前月或无账单时为空 | +| 15 | 9月收入 | 当前年份 9 月收入,当前月或无账单时为空 | +| 16 | 10月收入 | 当前年份 10 月收入,当前月或无账单时为空 | +| 17 | 11月收入 | 当前年份 11 月收入,当前月或无账单时为空 | +| 18 | 12月收入 | 当前年份 12 月收入,当前月或无账单时为空 | +| 19 | 能否变更主体 | 逻辑暂未提供,先留空/按统一缺失值规则展示 | +| 20 | 规划 | 逻辑暂未提供,先留空/按统一缺失值规则展示 | +| 21 | 新主体(变更流程同步新主体) | 逻辑暂未提供,先留空/按统一缺失值规则展示 | 以下字段明确删除,不得出现在主体维度经营报表中: @@ -281,7 +283,7 @@ WHERE businessLicenseName = :entity_name ## 10. 验收标准 1. 页面每个主体只出现一行,同名主体不会重复出现。 -2. 表头严格按第 3 节的 19 列顺序显示,最近12个月累计收入紧邻公司类型之后、1月收入之前。 +2. 表头严格按第 3 节的 21 列顺序显示,税务类型和工商类型紧邻公司类型之后,最近12个月累计收入紧邻工商类型之后、1月收入之前。 3. 页面不出现 ERP 店铺名称、利润中心、店铺负责人、开店时间、店铺状态或店铺累计收入等店铺字段。 4. 月度字段显示当前年份 1–12 月;当前月、未来月份和无账单月份均为空。 5. 最近12个月累计收入使用最近12个完整自然月,排除当前月,并支持跨年滚动。 diff --git a/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php b/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php index d1cd972e..a1145da4 100644 --- a/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/BusinessInformationMirrorRepository.php @@ -156,85 +156,121 @@ SQL) return []; } + $classifications = $this->companyClassificationsByNames($names); + return $this->connection->table('ops_fys_company_info') ->whereIn('businessLicenseName', $names) ->orderByDesc('Id') ->get() - ->map(static fn (object $row): array => (array) $row) + ->map(function (object $row) use ($classifications): array { + $result = (array) $row; + $classification = $classifications[trim((string) $row->businessLicenseName)] ?? []; + $result['finance_tax_type'] = $classification['tax_type'] ?? null; + $result['business_registration_type'] = $classification['business_registration_type'] ?? null; + + return $result; + }) ->groupBy(static fn (array $row): string => (string) $row['businessLicenseName']) ->map(static fn ($rows): array => $rows->values()->all()) ->all(); } + /** @return array */ + public function companyClassificationsByNames(array $names): array + { + $names = array_values(array_unique(array_filter(array_map('trim', $names)))); + if ($names === [] || ! $this->connection->getSchemaBuilder()->hasTable('fin_companies')) { + return []; + } + + return $this->connection->table('fin_companies') + ->select(['name', 'tax_type', 'business_type']) + ->whereIn('name', $names) + ->get() + ->mapWithKeys(static function (object $row): array { + $businessType = trim((string) ($row->business_type ?? '')); + + return [trim((string) $row->name) => [ + 'tax_type' => trim((string) ($row->tax_type ?? '')) ?: null, + 'business_registration_type' => in_array($businessType, ['', '/'], true) ? null : $businessType, + ]]; + }) + ->all(); + } + /** @return array{data: array>, total: int, summary: array} */ private function companies(int $page, int $perPage, array $filters): array { - $query = $this->connection->table('ops_fys_company_info') + $query = $this->connection->table('ops_fys_company_info AS company') + ->leftJoin('fin_companies AS finance_company', 'finance_company.name', '=', 'company.businessLicenseName') ->selectRaw(<<<'SQL' -Id AS id, -unifiedSocialCreditCode AS unified_social_credit_code, -businessLicenseName AS company_name, -registeredCapital AS subscribed_capital, -businessLicenseType AS company_type, -IncorporationDate AS establishment_date, -legalRepresentative AS legal_representative, -registeredAddress AS registered_address, -businessScope AS business_scope, -accountSerialNumber AS basic_deposit_account_number, -registeredCapitalVaildTime AS subscribed_at, -companyStatus AS company_status, -financialManager AS financial_officer, -supervisor AS supervisor, -taxCategoryAndType AS taxpayer_category, +company.Id AS id, +company.unifiedSocialCreditCode AS unified_social_credit_code, +company.businessLicenseName AS company_name, +company.registeredCapital AS subscribed_capital, +company.businessLicenseType AS company_type, +company.IncorporationDate AS establishment_date, +company.legalRepresentative AS legal_representative, +company.registeredAddress AS registered_address, +company.businessScope AS business_scope, +company.accountSerialNumber AS basic_deposit_account_number, +company.registeredCapitalVaildTime AS subscribed_at, +company.companyStatus AS company_status, +company.financialManager AS financial_officer, +company.supervisor AS supervisor, +COALESCE(finance_company.tax_type, company.taxCategoryAndType) AS taxpayer_category, +finance_company.business_type AS business_registration_type, NULL AS shareholders SQL); $this->applyFieldFilters($query, $filters, [ - 'unified_social_credit_code' => 'unifiedSocialCreditCode', 'company_name' => 'businessLicenseName', - 'establishment_date' => 'IncorporationDate', - 'registered_at' => 'IncorporationDate', - 'legal_representative' => 'legalRepresentative', 'registered_address' => 'registeredAddress', - 'city' => 'registeredAddress', - 'business_scope' => 'businessScope', 'subscribed_at' => 'registeredCapitalVaildTime', - 'financial_officer' => 'financialManager', - 'billing_officer' => 'financialManager', - 'supervisor' => 'supervisor', - ], ['subscribed_capital' => 'registeredCapital'], [ - 'company_type' => 'businessLicenseType', - 'taxpayer_type' => 'taxCategoryAndType', - 'taxpayer_category' => 'taxCategoryAndType', + 'unified_social_credit_code' => 'company.unifiedSocialCreditCode', 'company_name' => 'company.businessLicenseName', + 'establishment_date' => 'company.IncorporationDate', + 'registered_at' => 'company.IncorporationDate', + 'legal_representative' => 'company.legalRepresentative', 'registered_address' => 'company.registeredAddress', + 'city' => 'company.registeredAddress', + 'business_scope' => 'company.businessScope', 'subscribed_at' => 'company.registeredCapitalVaildTime', + 'financial_officer' => 'company.financialManager', + 'billing_officer' => 'company.financialManager', + 'supervisor' => 'company.supervisor', + ], ['subscribed_capital' => 'company.registeredCapital'], [ + 'company_type' => 'company.businessLicenseType', + 'taxpayer_type' => 'company.taxCategoryAndType', + 'taxpayer_category' => 'company.taxCategoryAndType', + 'business_registration_type' => 'finance_company.business_type', ]); $companyStatus = trim((string) ($filters['company_status'] ?? '')); if ($companyStatus !== '') { $statusCode = ['正常' => '0', '已注销' => '1'][$companyStatus] ?? $companyStatus; - $query->where('companyStatus', '=', $statusCode); + $query->where('company.companyStatus', '=', $statusCode); } $relatedPeople = mb_substr(trim((string) ($filters['related_people'] ?? '')), 0, 191); if ($relatedPeople !== '') { $like = '%' . addcslashes($relatedPeople, '%_\\') . '%'; $query->where(function ($query) use ($like): void { - $query->where('legalRepresentative', 'like', $like) - ->orWhere('supervisor', 'like', $like) - ->orWhere('financialManager', 'like', $like); + $query->where('company.legalRepresentative', 'like', $like) + ->orWhere('company.supervisor', 'like', $like) + ->orWhere('company.financialManager', 'like', $like); }); } $summary = $this->summaryCounts($query, <<<'SQL' COUNT(*) AS total, -COALESCE(SUM(CASE WHEN companyStatus = '0' THEN 1 ELSE 0 END), 0) AS normal, -COALESCE(SUM(CASE WHEN companyStatus = '1' THEN 1 ELSE 0 END), 0) AS deregistered, -COALESCE(SUM(CASE WHEN taxCategoryAndType = ? THEN 1 ELSE 0 END), 0) AS general_taxpayer, -COALESCE(SUM(CASE WHEN taxCategoryAndType = ? THEN 1 ELSE 0 END), 0) AS small_taxpayer +COALESCE(SUM(CASE WHEN company.companyStatus = '0' THEN 1 ELSE 0 END), 0) AS normal, +COALESCE(SUM(CASE WHEN company.companyStatus = '1' THEN 1 ELSE 0 END), 0) AS deregistered, +COALESCE(SUM(CASE WHEN COALESCE(finance_company.tax_type, company.taxCategoryAndType) = ? THEN 1 ELSE 0 END), 0) AS general_taxpayer, +COALESCE(SUM(CASE WHEN COALESCE(finance_company.tax_type, company.taxCategoryAndType) = ? THEN 1 ELSE 0 END), 0) AS small_taxpayer SQL, ['一般纳税人', '小规模纳税人']); return [ - ...$this->page($query, $page, $perPage, 'Id', $filters, [ - 'unified_social_credit_code' => 'unifiedSocialCreditCode', 'company_name' => 'businessLicenseName', - 'taxpayer_type' => 'taxCategoryAndType', 'company_status' => 'companyStatus', - 'subscribed_capital' => 'registeredCapital', 'registered_at' => 'IncorporationDate', - 'legal_representative' => 'legalRepresentative', 'supervisor' => 'supervisor', - 'billing_officer' => 'financialManager', 'registered_address' => 'registeredAddress', - 'city' => 'registeredAddress', 'business_scope' => 'businessScope', - 'basic_deposit_account' => 'accountSerialNumber', 'subscribed_at' => 'registeredCapitalVaildTime', + ...$this->page($query, $page, $perPage, 'company.Id', $filters, [ + 'unified_social_credit_code' => 'company.unifiedSocialCreditCode', 'company_name' => 'company.businessLicenseName', + 'taxpayer_type' => 'company.taxCategoryAndType', 'company_status' => 'company.companyStatus', + 'subscribed_capital' => 'company.registeredCapital', 'registered_at' => 'company.IncorporationDate', + 'legal_representative' => 'company.legalRepresentative', 'supervisor' => 'company.supervisor', + 'billing_officer' => 'company.financialManager', 'registered_address' => 'company.registeredAddress', + 'city' => 'company.registeredAddress', 'business_scope' => 'company.businessScope', + 'basic_deposit_account' => 'company.accountSerialNumber', 'subscribed_at' => 'company.registeredCapitalVaildTime', + 'business_registration_type' => 'finance_company.business_type', ]), 'summary' => $summary, ]; diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index 638ebe6c..c744a5c9 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -1654,7 +1654,8 @@ 'company-management/basic-information' => [ ['name' => 'unified_social_credit_code', 'label' => '统一社会信用代码', 'placeholder' => '输入完整或部分代码'], ['name' => 'company_name', 'label' => '公司名称', 'placeholder' => '输入公司名称关键词'], - ['name' => 'taxpayer_type', 'label' => '纳税人类型'], + ['name' => 'taxpayer_type', 'label' => '税务类型'], + ['name' => 'business_registration_type', 'label' => '工商类型'], ['name' => 'company_status', 'label' => '公司状态'], ['name' => 'legal_representative', 'label' => '法人', 'placeholder' => '按姓名查询'], ['name' => 'city', 'label' => '城市', 'placeholder' => '城市较多,使用搜索'], @@ -1724,12 +1725,12 @@ ->values() ->all(); $directorySelectFields = match (($section['slug'] ?? '') . '/' . ($page['slug'] ?? '')) { - 'company-management/basic-information' => ['taxpayer_type', 'company_status', 'company_type'], + 'company-management/basic-information' => ['taxpayer_type', 'business_registration_type', 'company_status', 'company_type'], 'store-management/basic-information' => ['platform', 'store_status', 'withdrawal_account'], 'trademark-management/information' => ['trademark_status'], 'store-management/store-accounts' => ['account_type', 'password_configured'], 'store-management/store-report' => ['status', 'can_change', 'company_type'], - 'company-management/subject-operating-report' => ['company_type', 'can_change_entity'], + 'company-management/subject-operating-report' => ['company_type', 'tax_type', 'business_registration_type', 'can_change_entity'], 'company-management/company-cost-arrangement' => ['company_type', 'invoice_type'], 'company-management/tax-forecast' => ['taxpayer_type', 'business_registration_type', 'collection_method'], 'company-management/personnel-inventory' => ['company_type'], @@ -1850,9 +1851,10 @@ 'password_configured' => ['已设置', '未设置', '状态未同步'], 'authorization_status' => ['已授权', '已过期', '未授权'], 'taxpayer_type' => ['一般纳税人', '小规模纳税人', '个体工商户', '无税务登记', 'CORP'], + 'tax_type' => ['一般纳税人', '小规模纳税人', '个体工商户', '无税务登记', 'CORP'], 'company_status' => ['正常', '已注销'], 'company_type' => ['个体工商户', '个体户', '二级公司', '人力资源公司', '仓储公司', '其他', '合同公司', '品牌公司', '店铺-国标公司', '店铺-国标商标', '店铺-大店公司', '店铺-普通公司', '母公司', '资产型'], - 'business_registration_type' => ['有限责任公司', '有限责任公司(自然人独资)', '个人独资企业', '合伙企业', '个体工商户', '其他'], + 'business_registration_type' => ['个人独资企业', '合伙企业', '有限责任公司', '有限责任公司(自然人独资)', '个体工商户', '核定', '其他'], 'collection_method' => ['查账征收', '核定征收', '定期定额'], 'status' => ['0' => '开店中', '3' => '关店中', '6' => '关店'], 'can_change', 'can_change_entity' => ['是', '否'], @@ -4007,7 +4009,8 @@ return; } const labels = { - unified_social_credit_code: '统一社会信用代码', company_name: '公司名称', taxpayer_category: '纳税人类型', + unified_social_credit_code: '统一社会信用代码', company_name: '公司名称', taxpayer_category: '税务类型', + business_registration_type: '工商类型', company_status: '公司状态', subscribed_capital: '认缴注册资本(万元)', establishment_date: '注册时间', legal_representative: '法人', shareholders: '股东', supervisor: '监事', financial_officer: '开票员', registered_address: '注册地址', business_scope: '经营范围', basic_deposit_account_number: '基本存款账户信息', subscribed_at: '认缴时间', diff --git a/resources/views/business/pages/partials/prototype-page.blade.php b/resources/views/business/pages/partials/prototype-page.blade.php index a40b3fb4..06d26061 100644 --- a/resources/views/business/pages/partials/prototype-page.blade.php +++ b/resources/views/business/pages/partials/prototype-page.blade.php @@ -38,11 +38,11 @@ ], 'company-information' => [ 'title' => '公司基础信息', 'description' => '维护公司主体资料与存续状态', - 'columns' => ['统一社会信用代码', '公司名称', '纳税人类型', '公司状态', '认缴注册资本(万元)', '注册时间', '法人', '股东', '监事', '开票员', '城市', '注册地址', '经营范围', '基本存款账户信息', '认缴时间'], + 'columns' => ['统一社会信用代码', '公司名称', '税务类型', '工商类型', '公司状态', '认缴注册资本(万元)', '注册时间', '法人', '股东', '监事', '开票员', '城市', '注册地址', '经营范围', '基本存款账户信息', '认缴时间'], ], 'entity-report' => [ 'title' => '主体维度经营报表', 'description' => '按公司主体汇总店铺经营表现', - 'columns' => ['市', '主体', '公司类型', 'ERP系统店铺名称', '店铺所属利润中心', '店铺负责人', '部门负责人', '开店时间', '状态', ...$recentCompletedMonthSalesColumns, '连续12个月店铺累计销量', '连续12个月主体累计销量', '能否变更主体', '规划', '新主体(变更流程同步新主体)'], + 'columns' => ['市', '主体', '公司类型', '税务类型', '工商类型', 'ERP系统店铺名称', '店铺所属利润中心', '店铺负责人', '部门负责人', '开店时间', '状态', ...$recentCompletedMonthSalesColumns, '连续12个月店铺累计销量', '连续12个月主体累计销量', '能否变更主体', '规划', '新主体(变更流程同步新主体)'], ], 'company-cost-arrangement' => [ 'title' => '公司成本安排', 'description' => '按公司主体查看成本安排', diff --git a/tests/Feature/Business/ManagementCrudTest.php b/tests/Feature/Business/ManagementCrudTest.php index aca1a631..c47abfa7 100644 --- a/tests/Feature/Business/ManagementCrudTest.php +++ b/tests/Feature/Business/ManagementCrudTest.php @@ -405,6 +405,7 @@ class ManagementCrudTest extends FeatureTestCase 'financial_officer' => '测试财务', 'supervisor' => '', 'taxpayer_category' => '小规模纳税人', + 'business_registration_type' => '个人独资企业', 'shareholders' => null, ]); @@ -419,7 +420,9 @@ class ManagementCrudTest extends FeatureTestCase ->assertSeeText('公司基础信息') ->assertSeeText('认缴注册资本(万元)') ->assertSeeText('基本存款账户信息') - ->assertSeeText('纳税人类型') + ->assertSeeText('税务类型') + ->assertSeeText('工商类型') + ->assertSeeText('个人独资企业') ->assertSeeText('已配置') ->assertSeeText('测试上游公司') ->assertSeeText('既有只读上游') @@ -708,7 +711,7 @@ class ManagementCrudTest extends FeatureTestCase ->assertSeeText('保管部门'); $expectedHeaders = [ - ['section' => 'company-management', 'page' => 'subject-operating-report', 'headers' => ['市', '主体', '最近12个月累计收入', '1月收入', '12月收入']], + ['section' => 'company-management', 'page' => 'subject-operating-report', 'headers' => ['市', '主体', '公司类型', '税务类型', '工商类型', '最近12个月累计收入', '1月收入', '12月收入']], ['section' => 'company-management', 'page' => 'company-cost-arrangement', 'headers' => ['公司', '公司类型', '发票类型', '当月收入预测', '往期成本缺口', '供应商成本安排', '快递成本安排', '当月税金预测', '人工成本预测', '其他费用预测']], ['section' => 'company-management', 'page' => 'tax-forecast', 'headers' => ['序号', '公司名称', '公司税务类型', '工商类型', '征收方式', '预计增值税', '企业所得税/经营所得个税', '税金合计']], ['section' => 'company-management', 'page' => 'personnel-inventory', 'headers' => ['人员名称', '税务局密码', '可担任公司数量']], diff --git a/tests/Feature/Business/PrototypePageTest.php b/tests/Feature/Business/PrototypePageTest.php index adfce13e..333e5b27 100644 --- a/tests/Feature/Business/PrototypePageTest.php +++ b/tests/Feature/Business/PrototypePageTest.php @@ -129,6 +129,8 @@ class PrototypePageTest extends FeatureTestCase 'entity' => '测试主体', 'city' => '常州市', 'company_type' => '有限公司', + 'tax_type' => '小规模纳税人', + 'business_registration_type' => '个人独资企业', 'rolling_12m_income' => 100, 'can_change_entity' => null, 'plan' => null, @@ -144,7 +146,10 @@ class PrototypePageTest extends FeatureTestCase ])) ->assertOk() ->assertSeeText('收入汇总') + ->assertSeeTextInOrder(['公司类型', '税务类型', '工商类型', '最近12个月累计收入']) ->assertSeeText('测试主体') + ->assertSeeText('小规模纳税人') + ->assertSeeText('个人独资企业') ->assertSeeText('共 1 条') ->assertSeeText('已从共享业务镜像读取') ->assertDontSee('
', false) @@ -226,7 +231,7 @@ class PrototypePageTest extends FeatureTestCase $this->assertStringContainsString('value="income_01" data-directory-query-column', $html); $this->assertStringNotContainsString('value="income_01" data-directory-query-column checked', $html); $this->assertStringContainsString('value="income_03" data-directory-query-column checked', $html); - $this->assertStringContainsString('筛选字段 17/19', $html); + $this->assertStringContainsString('筛选字段 19/21', $html); // 手动勾选(columns 参数)后,对应月份列恢复显示。 $restored = $this->get(route('business.pages.show', [ diff --git a/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php index 1b56c8a0..25657854 100644 --- a/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/BusinessInformationMirrorRepositoryTest.php @@ -49,6 +49,11 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $this->company(2, '统一代码', '新公司'), $this->company(3, '其他代码', '其他公司'), ]); + $connection->table('fin_companies')->insert([ + ['name' => '旧公司', 'tax_type' => '小规模纳税人', 'business_type' => '/', 'status' => '保留'], + ['name' => '新公司', 'tax_type' => '小规模纳税人', 'business_type' => '个人独资企业', 'status' => '保留'], + ['name' => '其他公司', 'tax_type' => '一般纳税人', 'business_type' => '核定', 'status' => '待注销'], + ]); $connection->table('ops_fys_shop_info')->insert([ ['Id' => 8, 'openTime' => '2026-08-14 10:00:00', 'shopName' => '上游店铺名', 'erpShopName' => '测试店', 'unifiedSocialCreditCode' => '统一代码', 'trademarkNumber' => 'TM', 'platform' => '天猫', 'responsibleDepartment' => '电商', 'shopHead' => '负责人', 'shopState' => '0', 'shopType' => '直营', 'channelType' => '线上'], ]); @@ -93,7 +98,12 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $typedCompany = $this->repository->paginate('company-information.read', 1, 20, [ 'taxpayer_type' => '小规模纳税人', 'company_status' => '正常', 'company_type' => '店铺-普通公司', ]); + $businessTypedCompany = $this->repository->paginate('company-information.read', 1, 20, [ + 'business_registration_type' => '个人独资企业', + ]); $cityCompany = $this->repository->paginate('company-information.read', 1, 20, ['city' => '上海']); + $companyClassifications = $this->repository->companyClassificationsByNames(['旧公司', '新公司', '其他公司']); + $companyDetails = $this->repository->companiesByNames(['新公司']); $this->assertSame(3, $companies['total']); $this->assertSame(1, $companies['data'][0]['id']); @@ -123,13 +133,19 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $this->assertSame('新公司', $filteredCompany['data'][0]['company_name']); $this->assertSame('新公司', $relatedCompany['data'][0]['company_name']); $this->assertSame(1, $typedCompany['total']); + $this->assertSame(1, $businessTypedCompany['total']); + $this->assertSame('个人独资企业', $businessTypedCompany['data'][0]['business_registration_type']); $this->assertSame(1, $cityCompany['total']); + $this->assertSame('小规模纳税人', $companyClassifications['新公司']['tax_type']); + $this->assertSame('个人独资企业', $companyClassifications['新公司']['business_registration_type']); + $this->assertNull($companyClassifications['旧公司']['business_registration_type']); + $this->assertSame('个人独资企业', $companyDetails['新公司'][0]['business_registration_type']); $this->assertSame([ 'total' => 3, 'normal' => 2, 'deregistered' => 1, 'general_taxpayer' => 1, - 'small_taxpayer' => 1, + 'small_taxpayer' => 2, ], $companies['summary']); $this->assertSame([ 'total' => 1, @@ -177,6 +193,13 @@ class BusinessInformationMirrorRepositoryTest extends TestCase $table->string('shopHead')->nullable(); $table->string('customerDeptManager')->nullable(); $table->string('shopState')->nullable(); $table->string('shopType')->nullable(); $table->string('channelType')->nullable(); $table->string('sotreId')->nullable(); $table->dateTime('renewalTime')->nullable(); $table->string('shopBankAccount')->nullable(); }); + $schema->create('fin_companies', function (Blueprint $table): void { + $table->increments('id'); + $table->string('name')->unique(); + $table->string('tax_type')->nullable(); + $table->string('business_type')->nullable(); + $table->string('status')->nullable(); + }); $schema->create('ops_fys_trademark_info', function (Blueprint $table): void { $table->integer('Id'); $table->string('trademarkNumber')->nullable(); $table->string('trademarkName')->nullable(); $table->string('internationalClassification')->nullable(); $table->string('trademarkStatus')->nullable(); $table->dateTime('registrationDate')->nullable(); $table->dateTime('termOfValidity')->nullable(); diff --git a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php index 55dc7e6a..3c58f5df 100644 --- a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php @@ -331,7 +331,7 @@ class StoreReportRepositoryTest extends TestCase $this->insertBill('店铺B', '2026-08-11', 40); $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); $mirror->shouldReceive('ready')->with('store-information.read')->andReturnTrue(); - $mirror->shouldReceive('allStores')->times(5)->andReturn([ + $mirror->shouldReceive('allStores')->times(7)->andReturn([ ['erp_store_name' => '店铺A', 'company_name' => '主体甲', 'store_status' => '0'], ['erp_store_name' => '店铺B', 'company_name' => '主体甲', 'store_status' => '0'], ]); @@ -342,8 +342,16 @@ class StoreReportRepositoryTest extends TestCase 'businessLicenseName' => '主体甲', 'companyStatus' => '0', 'registeredAddress' => '常州市测试路1号', + 'taxCategoryAndType' => '小规模纳税人', + 'business_registration_type' => '个人独资企业', ]], ]); + $mirror->shouldReceive('companyClassificationsByNames')->andReturn([ + '主体甲' => [ + 'tax_type' => '小规模纳税人', + 'business_registration_type' => '个人独资企业', + ], + ]); $accounts = Mockery::mock(StoreAccountMirrorRepository::class); $accounts->shouldReceive('ownershipByStoreName')->andReturn([]); $service = new UpstreamBusinessInformation( @@ -360,6 +368,8 @@ class StoreReportRepositoryTest extends TestCase $this->assertSame(90.0, $rows[0]->rolling_12m_income); $this->assertSame(20.0, $rows[0]->income_07); $this->assertSame(70.0, $rows[0]->income_08); + $this->assertSame('小规模纳税人', $rows[0]->tax_type); + $this->assertSame('个人独资企业', $rows[0]->business_registration_type); $summaryCards = collect($this->app['request']->attributes->get('business-page-summary-cards'))->keyBy('label'); $this->assertSame(1, $summaryCards['主体总数']['value']); $this->assertSame(1, $summaryCards['有效主体']['value']); @@ -373,6 +383,11 @@ class StoreReportRepositoryTest extends TestCase request()->merge(['company_status' => '已注销']); $this->assertSame(0, $service->paginate('company-management', 'subject-operating-report', 50)->total()); request()->merge(['company_status' => null]); + request()->merge(['tax_type' => '小规模纳税人', 'business_registration_type' => '个人独资企业']); + $this->assertSame(1, $service->paginate('company-management', 'subject-operating-report', 50)->total()); + request()->merge(['business_registration_type' => '核定']); + $this->assertSame(0, $service->paginate('company-management', 'subject-operating-report', 50)->total()); + request()->merge(['tax_type' => null, 'business_registration_type' => null]); request()->merge(['income_08' => '71.00']); $this->assertSame(0, $service->paginate('company-management', 'subject-operating-report', 50)->total()); } diff --git a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php index 777a3eab..e139881f 100644 --- a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php +++ b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php @@ -235,6 +235,7 @@ class UpstreamBusinessInformationTest extends TestCase $mirror->shouldReceive('allStores')->andReturn([['erp_store_name' => '测试店铺']]); $mirror->shouldReceive('ready')->with('company-information.read')->andReturnTrue(); $mirror->shouldReceive('companiesByNames')->andReturn([]); + $mirror->shouldReceive('companyClassificationsByNames')->andReturn([]); $storeReports = Mockery::mock(StoreReportRepository::class); $storeReports->shouldReceive('rows')->andReturn([[