diff --git a/modules/EcommerceFinance/Services/PlantingLossCalculator.php b/modules/EcommerceFinance/Services/PlantingLossCalculator.php index e05ea5bf..6d40c670 100644 --- a/modules/EcommerceFinance/Services/PlantingLossCalculator.php +++ b/modules/EcommerceFinance/Services/PlantingLossCalculator.php @@ -16,7 +16,7 @@ use Modules\EcommerceFinance\Repositories\ShippingOrderRepository; * 2. 用线上订单号去匹配发货数据(jst_oms_shipping)中 M-1、M 两个月发货的交易单号,匹配到的保留; * 3. 匹配到的单里,任务备注或卖家备注写了“拍A发B”或“拍A发A”的不扣款,单独列出发给运营; * 4. 实际只发了「信誉订单虚拟条码」「透明挂钩」这类商品的不扣款; - * 5. 其余匹配到的作为扣款项,扣款金额 = Σ 发货商品成本价 × 数量 × 1.2(成本价+成本价×20%), + * 5. 其余匹配到的作为扣款项,扣款金额 = Σ 发货商品成本价 × 数量 + 该订单在发货数据中的运费(2026-10-19 更正), * 成本价按发货条形码(=商品编码)取普通商品资料。未匹配到发货的不计入种菜损耗。 */ class PlantingLossCalculator @@ -34,9 +34,6 @@ class PlantingLossCalculator /** 发货商品名称或条码含这些字样的不计扣款。 */ public const FREE_GOODS_KEYWORDS = ['信誉订单虚拟条码', '虚拟条码', '透明挂钩']; - /** 扣款 = 成本价 × (1 + 20%)。 */ - public const MARKUP_PERCENT = 20; - public const SKU_DATASET = 'operations_replica.rpt.jst_sku'; private const CHUNK = 1000; @@ -104,10 +101,10 @@ class PlantingLossCalculator return false; } - /** 成本价(元,字符串)× 数量 × 1.2 → 分。 */ + /** 成本价(元,字符串)× 数量 → 分。 */ public static function deductionCents(string $costPrice, int $qty): int { - return (int) round((float) $costPrice * 100 * $qty * (100 + self::MARKUP_PERCENT) / 100); + return (int) round((float) $costPrice * 100 * $qty); } /** @@ -168,23 +165,37 @@ class PlantingLossCalculator } $lineCents = self::deductionCents($cost, $line['qty']); $cents += $lineCents; - $deductLines[] = sprintf('%s × %d × %s × 1.2 = %s', $line['barcode'], $line['qty'], $cost, number_format($lineCents / 100, 2, '.', '')); + $deductLines[] = sprintf('%s × %d × %s = %s', $line['barcode'], $line['qty'], $cost, number_format($lineCents / 100, 2, '.', '')); } + $freight = $shipment['freight'] ?? null; + if ($deductLines !== []) { + if ($freight === null) { + $deductLines[] = '运费缺失'; + } else { + $cents += (int) round((float) $freight * 100); + $deductLines[] = '运费 ' . $freight; + } + } + $missing = array_values(array_unique($missingCost)); + $missingText = implode(';', array_filter([ + $missing === [] ? '' : '成本价缺失:' . implode('、', $missing), + $deductLines !== [] && $freight === null ? '运费缺失' : '', + ])); $keyword = $shipment === null ? null : self::exemptionKeyword((string) $row['task_remark'], (string) $row['seller_remark']); [$result, $basis] = match (true) { $shipment === null => [self::RESULT_UNMATCHED, self::shippingLabel($month) . ' 发货数据中无此交易单号'], $keyword !== null => [self::RESULT_EXEMPT, '备注含“' . $keyword . '”'], $deductLines === [] => [self::RESULT_FREE_GOODS, '只发了虚拟条码/透明挂钩'], - $missingCost !== [] => [self::RESULT_DEDUCT, '成本价缺失:' . implode('、', array_unique($missingCost)) . ',扣款金额未含该商品'], - default => [self::RESULT_DEDUCT, '已匹配发货,按成本价×1.2扣款'], + $missingText !== '' => [self::RESULT_DEDUCT, $missingText . ',扣款金额未含缺失部分'], + default => [self::RESULT_DEDUCT, '已匹配发货,按成本价×数量+运费扣款'], }; $row['loss_result'] = $result; $row['loss_basis'] = $basis; $row['deduction_amount'] = $result === self::RESULT_DEDUCT ? number_format($cents / 100, 2, '.', '') : null; $row['deduction_detail'] = $result === self::RESULT_DEDUCT ? implode("\n", $deductLines) : ''; - $row['cost_missing'] = $result === self::RESULT_DEDUCT && $missingCost !== []; + $row['cost_missing'] = $result === self::RESULT_DEDUCT && $missingText !== ''; $row['shipped_at'] = $shipment['shipped_at'] ?? ''; $row['express_no'] = $shipment['express_no'] ?? ''; $row['warehouse_name'] = $shipment['warehouse_name'] ?? ''; diff --git a/modules/EcommerceFinance/View/PlantingLossPageData.php b/modules/EcommerceFinance/View/PlantingLossPageData.php index c6768b8c..f2fbaf17 100644 --- a/modules/EcommerceFinance/View/PlantingLossPageData.php +++ b/modules/EcommerceFinance/View/PlantingLossPageData.php @@ -6,7 +6,7 @@ use Illuminate\Pagination\LengthAwarePaginator; use Modules\EcommerceFinance\Repositories\PlantingReimbursementRepository as Repository; use Modules\EcommerceFinance\Services\PlantingLossCalculator as Calculator; -/** 种菜数据汇总 → 种菜损耗:种菜报销明细匹配近两个月发货数据,拍A发B/拍A发A、只发虚拟条码/透明挂钩的不扣款,其余按成本价×1.2 扣款。 */ +/** 种菜数据汇总 → 种菜损耗:种菜报销明细匹配近两个月发货数据,拍A发B/拍A发A、只发虚拟条码/透明挂钩的不扣款,其余按成本价×数量+运费扣款。 */ class PlantingLossPageData { use PlantingPageFilters; @@ -25,7 +25,7 @@ class PlantingLossPageData ]; public const COLUMNS = [ - 'loss_result' => '损耗判定', 'deduction_amount' => '扣款金额', 'loss_basis' => '判定说明', 'deduction_detail' => '扣款计算(条码×数量×成本价×1.2)', + 'loss_result' => '损耗判定', 'deduction_amount' => '扣款金额', 'loss_basis' => '判定说明', 'deduction_detail' => '扣款计算(条码×数量×成本价+运费)', 'completed_at' => '报销完成时间', 'work_order_no' => '工单编号', 'platform' => '平台', 'shop_name' => '店铺名称', 'online_order_no' => '线上订单号', 'task_remark' => '任务备注', 'seller_remark' => '卖家备注', 'actual_paid_amount' => '实付金额', 'task_payment' => '任务付款金额', 'reimbursement_amount' => '最终报销金额', diff --git a/resources/views/business/pages/billing-transactions/planting-loss.blade.php b/resources/views/business/pages/billing-transactions/planting-loss.blade.php index d4efda69..a2be3683 100644 --- a/resources/views/business/pages/billing-transactions/planting-loss.blade.php +++ b/resources/views/business/pages/billing-transactions/planting-loss.blade.php @@ -13,7 +13,7 @@ @endphp
{{ $plantingFilters['month'] }} 月种菜报销明细(完成时间 {{ substr($plantingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingWindow['to'])->subDay()->format('Y-m-d') }})的线上订单号,匹配 {{ $shippingLabel }} 发货数据(发货时间 {{ substr($plantingShippingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingShippingWindow['to'])->subDay()->format('Y-m-d') }})中的交易单号。匹配到的单中,任务备注或卖家备注写了“拍A发B / 拍A发A”的、以及只发了信誉订单虚拟条码/透明挂钩的不扣款,其余按发货商品成本价×1.2 扣款。
+{{ $plantingFilters['month'] }} 月种菜报销明细(完成时间 {{ substr($plantingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingWindow['to'])->subDay()->format('Y-m-d') }})的线上订单号,匹配 {{ $shippingLabel }} 发货数据(发货时间 {{ substr($plantingShippingWindow['from'], 0, 10) }} 至 {{ \Illuminate\Support\Carbon::parse($plantingShippingWindow['to'])->subDay()->format('Y-m-d') }})中的交易单号。匹配到的单中,任务备注或卖家备注写了“拍A发B / 拍A发A”的、以及只发了信誉订单虚拟条码/透明挂钩的不扣款,其余按发货商品成本价×数量+该单运费扣款。