From 09907d63f815f48c81806b4e374f7b607880a86c Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Thu, 8 Oct 2026 13:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E7=BB=A9=E6=98=8E=E7=BB=86=EF=BC=9A?= =?UTF-8?q?=E5=86=B2=E5=87=8F=E9=87=91=E9=A2=9D=E6=8C=89=E8=A1=8C=E9=87=91?= =?UTF-8?q?=E9=A2=9D=E5=8F=96=E6=95=B0=EF=BC=88=E6=94=B6=E5=85=A5=E4=BE=A7?= =?UTF-8?q?-=E6=94=AF=E5=87=BA=E4=BE=A7=EF=BC=8C=E8=B4=9F=E6=95=B0?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E5=87=80=E6=89=A3=E5=87=8F=EF=BC=89=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=A5=E8=A1=8C=E5=88=97=E6=95=B0=E7=BC=BA?= =?UTF-8?q?=20planting=5Famount=20=E5=AF=BC=E8=87=B4=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/SyncStoreReceiptOrderMatches.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/SyncStoreReceiptOrderMatches.php b/app/Console/Commands/SyncStoreReceiptOrderMatches.php index 334a487b..15c5a9cc 100644 --- a/app/Console/Commands/SyncStoreReceiptOrderMatches.php +++ b/app/Console/Commands/SyncStoreReceiptOrderMatches.php @@ -5,6 +5,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use InvalidArgumentException; use App\Business\JstOrderLabelPlantingRules; use Modules\EcommerceFinance\Services\AccountLedgerRemarkMap; @@ -211,6 +212,10 @@ class SyncStoreReceiptOrderMatches extends Command } $select = ['store_name', 'bill_item', $orderColumn, $timeColumn, $amountColumn]; + // 「冲减金额」按行金额(收入侧 − 支出侧)取数,账单表有支出列时一并取出。 + if (Schema::connection($connection)->hasColumn($billTable, 'expense_amount')) { + $select[] = 'expense_amount'; + } if ($realStoreColumn !== '') { $select[] = $realStoreColumn; } @@ -333,6 +338,9 @@ class SyncStoreReceiptOrderMatches extends Command } $amount = (float) $bill->{$amountColumn}; + // 「冲减金额」按行金额取数=收入侧 − 支出侧(负数表示净扣减)。 + // 得物/天猫这类平台把「卖家承担优惠 / 扣回」记在支出侧,只取收入侧会漏掉扣减、并把退款冲回当成冲减。 + $offsetAmount = $amount - (float) ($bill->expense_amount ?? 0); if ($bucket === 'income') { $groups[$key]['payment_count']++; $groups[$key]['income_amount'] += $amount; @@ -345,8 +353,8 @@ class SyncStoreReceiptOrderMatches extends Command $promoRowsByKey[$key] = ($promoRowsByKey[$key] ?? 0) + 1; } else { $groups[$key]['offset_seen'] = true; - $groups[$key]['offset_amount'] += $amount; - $offsetTotal += $amount; + $groups[$key]['offset_amount'] += $offsetAmount; + $offsetTotal += $offsetAmount; $promoRowsByKey[$key] = ($promoRowsByKey[$key] ?? 0) + 1; } @@ -884,6 +892,8 @@ class SyncStoreReceiptOrderMatches extends Command 'income_amount' => 0, 'discount_amount' => ! empty($group['discount_seen']) ? round((float) $group['discount_amount'], 2) : null, 'offset_amount' => ! empty($group['offset_seen']) ? round((float) $group['offset_amount'], 2) : null, + // 补行没有订单侧商品金额,种菜金额同样留空(列必须与其它行一致,否则批量插入会因列数不匹配失败)。 + 'planting_amount' => null, 'product_amount' => null, 'difference' => null, 'match_status' => self::STATUS_UNMATCHED,