CaiWuXiTong/modules/EcommerceFinance/Console/CalcShippingFreight.php
limeng 1cf60dd7b0 feat(发货数据): 按报价管理的报价核算运费,结果显示在发货数据页面
从 2026-11-01 起,按发货日在报价管理里生效的报价版本(与报价管理「当前生效」同一判断:未作废、
已审核/签署生效、执行期间覆盖发货日,取执行日期最新)逐包裹核算运费,写入 jst_oms_shipping_freight。
- 结算重量:实称>线上>重量;按各快递计泡系数取 max(重量, 长×宽×高÷系数);免抛仓(含「配件」仓)不计泡、不收多件费;
  超长费计入,其他附加费不计;城市单独报价、整省「X元/公斤」、洞洞板 9000、个别版本系数等按 10 月逐单核对的口径;
- 计算引擎移植自 10 月离线核算脚本,10 月 29.5 万个包裹逐单比对结果一致(仅 x.xx5 边界按正确四舍五入进位);
- 发货数据同步完成后核算该窗口;报价版本新增/作废/签署归档后按该快递从执行日期起自动重算;
- 新命令 jushuitan:calc-freight --from --to [--carrier];
- 发货数据页面/导出新增「报价核算」列:核算运费、核算-聚水潭运费、报价版本、结算重量依据、核算结算重量、
  计费重量、首重、续重/费率、面单、一口价、多件/超长加收、核算公式、核算状态(合并口径每包裹一行,明细只在第一行)。

同时修复发货数据同步 11 月起频繁失败:副本库查发货视图超时后报 20047 DBPROCESS is dead,
原重试只识别 20003/dbnextrow,整次同步失败(11-17 只同步到 62%)。现把 20047 视为可重连重试,
发货视图每批出库单由 300 降到 100。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014nvGZkg27YMEdhry6eiuwf
2026-11-18 13:55:40 +08:00

37 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\EcommerceFinance\Console;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\Freight\FreightCarrierRules;
use Modules\EcommerceFinance\Services\Freight\ShippingFreightService;
/**
* 按报价管理的报价核算发货数据运费(结果显示在发货数据页面「报价核算」列)。
*
* php artisan jushuitan:calc-freight --from=2026-11-01 --to=2026-11-16
* php artisan jushuitan:calc-freight --from=2026-11-01 --to=2026-11-16 --carrier=北京韵达 --carrier=常州德邦
*/
class CalcShippingFreight extends Command
{
protected $signature = 'jushuitan:calc-freight {--from= : 发货日期起(含)} {--to= : 发货日期止(不含)} {--carrier=* : 只核算这些快递(报价名称)}';
protected $description = '按报价管理的报价核算发货数据运费';
public function handle(ShippingFreightService $service): int
{
$from = (string) ($this->option('from') ?: FreightCarrierRules::START_DATE);
$to = (string) ($this->option('to') ?: now()->addDay()->format('Y-m-d'));
if (! preg_match('/^\d{4}-\d{2}-\d{2}$/', $from) || ! preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
$this->error('--from / --to 需要 YYYY-MM-DD');
return self::FAILURE;
}
$carriers = array_values(array_filter(array_map('trim', (array) $this->option('carrier'))));
$res = $service->recalculate($from, $to, $carriers === [] ? null : $carriers);
$this->info(sprintf('运费核算完成:%s ~ %s,包裹 %d 个,核算成功 %d 个,无法核算 %d 个', $from, $to, $res['packages'], $res['ok'], $res['packages'] - $res['ok']));
return self::SUCCESS;
}
}