diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index bbca43fd4..402638f20 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -7199,6 +7199,9 @@ class Pages extends Controller ['field' => 'barcode', 'label' => '条形码', 'type' => 'identifier'], ['field' => 'product_name', 'label' => '商品名称', 'type' => 'text'], ['field' => 'qty', 'label' => '数量', 'type' => 'number'], + ['field' => 'qc_charge_weight', 'label' => '计费重量(kg)', 'type' => 'number'], + ['field' => 'qc_rate', 'label' => '续重/费率', 'type' => 'text'], + ['field' => 'qc_freight', 'label' => '核算运费', 'type' => 'number'], ['field' => 'pkg_count', 'label' => '件数', 'type' => 'text'], ['field' => 'receiver_state', 'label' => '省', 'type' => 'text'], ['field' => 'buyer_nick', 'label' => '买家昵称', 'type' => 'text'], @@ -7210,6 +7213,9 @@ class Pages extends Controller ['field' => 'freight', 'label' => '运费', 'type' => 'number'], ['field' => 'online_weight', 'label' => '线上重量', 'type' => 'number'], ['field' => 'actual_weight', 'label' => '实称重量', 'type' => 'number'], + ['field' => 'qc_measured_weight', 'label' => '称重重量(kg)', 'type' => 'number'], + ['field' => 'qc_first_price', 'label' => '首重(元)', 'type' => 'number'], + ['field' => 'qc_miandan', 'label' => '面单(元)', 'type' => 'number'], ['field' => 'length_cm', 'label' => '长(cm)', 'type' => 'number'], ['field' => 'width_cm', 'label' => '宽(cm)', 'type' => 'number'], ['field' => 'height_cm', 'label' => '高(cm)', 'type' => 'number'], @@ -7242,15 +7248,10 @@ class Pages extends Controller ['field' => 'settle_freight', 'label' => '结算运费', 'type' => 'number'], ['field' => 'front_no', 'label' => '换单前单号', 'type' => 'identifier'], // 报价核算(按报价管理里发货日生效的报价) - ['field' => 'qc_freight', 'label' => '核算运费', 'type' => 'number'], ['field' => 'qc_diff', 'label' => '核算-聚水潭运费', 'type' => 'number'], ['field' => 'qc_quote_version', 'label' => '报价版本', 'type' => 'identifier'], ['field' => 'qc_basis', 'label' => '结算重量依据', 'type' => 'text'], ['field' => 'qc_settle_weight', 'label' => '核算结算重量(kg)', 'type' => 'number'], - ['field' => 'qc_charge_weight', 'label' => '计费重量(kg)', 'type' => 'number'], - ['field' => 'qc_first_price', 'label' => '首重(元)', 'type' => 'number'], - ['field' => 'qc_rate', 'label' => '续重/费率', 'type' => 'text'], - ['field' => 'qc_miandan', 'label' => '面单(元)', 'type' => 'number'], ['field' => 'qc_flat_price', 'label' => '一口价(元)', 'type' => 'number'], ['field' => 'qc_extra_fee', 'label' => '多件/超长加收(元)', 'type' => 'number'], ['field' => 'qc_formula', 'label' => '核算公式', 'type' => 'text'], diff --git a/deploy/run-finance-batch.sh b/deploy/run-finance-batch.sh index a18f9b79d..44dea645c 100644 --- a/deploy/run-finance-batch.sh +++ b/deploy/run-finance-batch.sh @@ -8,7 +8,7 @@ is_import=0 CAIWU_BATCH_CALLER_DIR="$PWD" export CAIWU_BATCH_CALLER_DIR case "${1:-}" in - *:import|*:import-*|*:import:*|payables:final-import|payables:unpriced-cycle|product:monthly-weighted-average:base|planting-details:sync-work-orders|jst-order-labels:sync-daily) is_import=1 ;; + jushuitan:apply-shipping-corrections|*:import|*:import-*|*:import:*|payables:final-import|payables:unpriced-cycle|product:monthly-weighted-average:base|planting-details:sync-work-orders|jst-order-labels:sync-daily) is_import=1 ;; jushuitan:align-weights|jushuitan:calc-freight|courier:sync-unshipped-waybills|courier:seed-unshipped-history) ;; jushuitan:sync-shipping|store-receipt:order-match:sync|store-receipt:planting-daily|store-receipt:product-cost:sync|store-receipt:auto-resync|order-data:warm-shop-candidates|business-mirror:sync-tables|business-mirror:sync-promotion-expenses|business-mirror:sync-jushuitan-shop-promotion-fees|business-mirror:sync-ding-process-details|business-mirror:process-ding-refresh-requests|business-mirror:index-work-order-waybills|business-mirror:refresh-paid-sales|ding-invoices:sync|ding-invoices:process-refresh-requests|account-bills:exports:run|finance-ledger:recalculate|product:monthly-weighted-average:auto|product:monthly-weighted-average:compute|product:monthly-weighted-average:report|finance:monthly-weighted-product-cost:auto) ;; *) echo 'Unsupported finance batch command' >&2; exit 64 ;; diff --git a/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php b/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php index 2c2a53b39..aca9691e2 100644 --- a/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php +++ b/modules/EcommerceFinance/Repositories/ShippingOrderRepository.php @@ -222,6 +222,7 @@ class ShippingOrderRepository 'qc_settle_weight' => 'settle_weight', 'qc_charge_weight' => 'charge_weight', 'qc_first_price' => 'first_price', 'qc_rate' => 'rate', 'qc_miandan' => 'miandan', 'qc_flat_price' => 'flat_price', 'qc_extra_fee' => 'extra_fee', 'qc_formula' => 'formula', 'qc_status' => 'status', + 'qc_measured_weight' => null, ]; /** @@ -245,8 +246,11 @@ class ShippingOrderRepository } catch (\Throwable) { return $rows; // 结果表未迁移时不影响发货数据显示 } + $measured = app(\Modules\EcommerceFinance\Services\Freight\ShippingFreightService::class)->measuredForPackages($ids); foreach ($rows as &$row) { $sid = (int) ($row['source_id'] ?? 0); + $isPrimary = ! $detail || (int) ($firstIds[$sid] ?? 0) === (int) ($row['id'] ?? -1); + $row['qc_measured_weight'] = $isPrimary ? ($measured[$sid] ?? null) : null; $res = $results[$sid] ?? null; if ($res === null || ($detail && (int) ($firstIds[$sid] ?? 0) !== (int) ($row['id'] ?? -1))) { continue; diff --git a/modules/EcommerceFinance/Services/Freight/ShippingFreightService.php b/modules/EcommerceFinance/Services/Freight/ShippingFreightService.php index aa9e93e32..7586078a9 100644 --- a/modules/EcommerceFinance/Services/Freight/ShippingFreightService.php +++ b/modules/EcommerceFinance/Services/Freight/ShippingFreightService.php @@ -563,14 +563,14 @@ class ShippingFreightService * @param list $ids * @return list> */ - private function aggregate(array $ids): array + private function aggregate(array $ids, bool $pageOnly = false): array { $rows = $this->db->table('jst_oms_shipping')->whereIn('source_id', $ids)->orderBy('id') ->get(['id', 'source_id', 'express_no', 'express_name1', 'warehouse_name', 'receiver_state', 'receiver_city', 'receiver_district', 'receiver_address', 'receiver_name', 'supplier_name', 'ship_time', 'pkg_count', 'online_weight', 'actual_weight', 'weight_kg', 'length_cm', 'width_cm', 'height_cm', 'volume_cm3', 'm_length_cm', 'm_width_cm', 'm_height_cm', 'm_volume_cm3', 'barcode', 'qty', 'freight']); - $measured = $this->measuredWeights(); + $measured = $this->measuredWeights($pageOnly ? $rows->pluck('barcode')->filter()->map(static fn ($v) => mb_strtoupper(trim((string) $v)))->unique()->values()->all() : null); $out = []; $mw = []; foreach ($rows as $r) { @@ -646,6 +646,15 @@ class ShippingFreightService return array_values($out); } + /** 当前页包裹的导入称重重量;与核算口径共用,缺任一条码时为空。 */ + public function measuredForPackages(array $ids): array + { + $out = []; + foreach ($this->aggregate($ids, true) as $pkg) $out[$pkg['source_id']] = $pkg['measured_weight']; + + return $out; + } + /** @var array|null 快递名称\0条码(大写) => 每件称重重量 kg */ private ?array $measured = null; @@ -654,23 +663,26 @@ class ShippingFreightService * * @return array */ - private function measuredWeights(): array + private function measuredWeights(?array $barcodes = null): array { - if ($this->measured !== null) { + if ($barcodes === null && $this->measured !== null) { return $this->measured; } - $this->measured = []; + $weights = []; try { // 和报价同一个公司:命令行没有当前公司时也不能混用别家公司的称重重量 $query = DB::table('shipping_measured_weights')->where('company_id', $this->companyId()); + if ($barcodes !== null) $query->whereIn('barcode', $barcodes); foreach ($query->get(['carrier_name', 'barcode', 'weight_kg']) as $row) { - $this->measured[trim((string) $row->carrier_name) . "\0" . mb_strtoupper(trim((string) $row->barcode))] = (float) $row->weight_kg; + $weights[trim((string) $row->carrier_name) . "\0" . mb_strtoupper(trim((string) $row->barcode))] = (float) $row->weight_kg; } } catch (\Throwable $e) { report($e); } - return $this->measured; + if ($barcodes === null) $this->measured = $weights; + + return $weights; } /** 导入称重重量后,这些快递从核算起始日起重算(请求结束后执行)。 */ diff --git a/resources/views/business/pages/courier-payables/shipping-data.blade.php b/resources/views/business/pages/courier-payables/shipping-data.blade.php index 1153362e4..0d43c2793 100644 --- a/resources/views/business/pages/courier-payables/shipping-data.blade.php +++ b/resources/views/business/pages/courier-payables/shipping-data.blade.php @@ -11,6 +11,9 @@ ['barcode','条形码','left','text'], ['product_name','商品名称','left','text'], ['qty','数量','right','int'], + ['qc_charge_weight','计费重量(kg)','right','num'], + ['qc_rate','续重/费率','right','text'], + ['qc_freight','核算运费','right','money'], ['pkg_count','件数','center','text'], ['receiver_state','省','left','text'], ['buyer_nick','买家昵称','left','text'], @@ -22,6 +25,9 @@ ['freight','运费','right','money'], ['online_weight','线上重量','right','num'], ['actual_weight','实称重量','right','num'], + ['qc_measured_weight','称重重量(kg)','right','num'], + ['qc_first_price','首重(元)','right','num'], + ['qc_miandan','面单(元)','right','num'], ['length_cm','长(cm)','right','num'], ['width_cm','宽(cm)','right','num'], ['height_cm','高(cm)','right','num'], @@ -54,15 +60,10 @@ ['settle_freight','结算运费','right','money'], ['front_no','换单前单号','left','mono'], // 报价核算(按报价管理里发货日生效的报价;合并口径每个包裹一行,明细口径只在包裹第一行) - ['qc_freight','核算运费','right','money'], ['qc_diff','核算-聚水潭运费','right','money'], ['qc_quote_version','报价版本','left','mono'], ['qc_basis','结算重量依据','left','text'], ['qc_settle_weight','核算结算重量(kg)','right','num'], - ['qc_charge_weight','计费重量(kg)','right','num'], - ['qc_first_price','首重(元)','right','num'], - ['qc_rate','续重/费率','right','text'], - ['qc_miandan','面单(元)','right','num'], ['qc_flat_price','一口价(元)','right','num'], ['qc_extra_fee','多件/超长加收(元)','right','num'], ['qc_formula','核算公式','left','text'], diff --git a/tests/Feature/Business/ShippingDataPageTest.php b/tests/Feature/Business/ShippingDataPageTest.php index e923df89a..8d2e2df91 100644 --- a/tests/Feature/Business/ShippingDataPageTest.php +++ b/tests/Feature/Business/ShippingDataPageTest.php @@ -62,9 +62,29 @@ class ShippingDataPageTest extends FeatureTestCase ->assertSeeText('导出') ->assertSeeText('导出明细') ->assertSeeText('导入称重重量') + ->assertSeeInOrder(['数量', '计费重量(kg)', '续重/费率', '核算运费', '实称重量', '称重重量(kg)', '首重(元)', '面单(元)']) ->assertSee('name="measured_weight_file"', false); } + public function test_measured_weight_column_uses_complete_imported_package_weight_and_does_not_repeat_in_details(): void + { + $db=DB::connection('business_mirror'); + foreach ([['A',2],['B',3]] as $i=>[$barcode,$qty]) $db->table('jst_oms_shipping')->insert([ + 'source_id'=>9901,'sku_source_id'=>$i+1,'express_no'=>'MEASURE9901','express_name1'=>'新北中通', + 'barcode'=>$barcode,'qty'=>$qty,'ship_time'=>'2026-11-03','online_weight'=>$i===0?9:null,'actual_weight'=>$i===0?7:null]); + foreach (['A'=>1.25,'B'=>0.5] as $barcode=>$weight) DB::table('shipping_measured_weights')->insert([ + 'company_id'=>$this->company->id,'carrier_name'=>'新北中通','barcode'=>$barcode,'weight_kg'=>$weight,'updated_by'=>$this->user->id]); + $repo=app(ShippingOrderRepository::class); + $filters=['express_no'=>'MEASURE9901','ship_from'=>'2026-11-01','ship_to'=>'2026-11-30']; + $attach=new \ReflectionMethod($repo,'attachFreight'); + $merged=$attach->invoke($repo,[['source_id'=>9901,'online_weight'=>9]],false); + $this->assertEquals(4,$merged[0]['qc_measured_weight']); + $this->assertEquals(9,$merged[0]['online_weight']); + $detail=$repo->paginate($filters,1,20,'detail'); + $this->assertEquals(4,$detail['data'][0]['qc_measured_weight']); + $this->assertNull($detail['data'][1]['qc_measured_weight']); + } + public function test_measured_weight_import_splits_carriers_and_updates_duplicate_keys(): void { $this->grantPermission();