|
|
@@ -1188,7 +1188,8 @@ class OrderService extends BaseService
|
|
|
}
|
|
|
|
|
|
//配对生成花店侧采购冲销记录 xhCg/xhCgItem,直接构造模型保存,不复用 PurchaseClass::addPurchase 的完整业务规则
|
|
|
- $ghs = GhsClass::getById($ghsId);
|
|
|
+ //此处需要加锁,因为下面还要用它同步扣减 xhGhs.expendAmount(累计消费镜像字段)
|
|
|
+ $ghs = GhsClass::getLockById($ghsId);
|
|
|
$cgSn = orderSn::getPurchaseSn($snData);
|
|
|
$cgData = [
|
|
|
'mainId' => $ghs['ownMainId'] ?? 0,
|
|
|
@@ -1259,13 +1260,23 @@ class OrderService extends BaseService
|
|
|
PurchaseItemClass::add($cgItemData, true);
|
|
|
}
|
|
|
|
|
|
+ //累计消费金额同步:冲销单本质是负金额订单,$actPrice 已经是负数。
|
|
|
+ //xhGhsCustom.buyAmount 与 xhGhs.expendAmount 是同一份"累计消费"的两边镜像
|
|
|
+ //(参考 CustomController::actionRefreshBuyamount 按订单 actPrice 汇总重算两边字段的口径),
|
|
|
+ //这里直接按 actPrice 同步扣减,两边保持一致;但冲销单不算一次新的"下单",buyNum/买入次数不增加。
|
|
|
+ $lockCustom = CustomClass::getLockById($customId);
|
|
|
+ if (empty($lockCustom)) {
|
|
|
+ util::fail('没有找到客户');
|
|
|
+ }
|
|
|
+ $lockCustom->buyAmount = bcadd($lockCustom->buyAmount ?? '0.00', $actPrice, 2);
|
|
|
+ $lockCustom->save(false, ['buyAmount']);
|
|
|
+
|
|
|
+ $ghs->expendAmount = bcadd($ghs->expendAmount ?? '0.00', $actPrice, 2);
|
|
|
+ $ghs->save(false, ['expendAmount']);
|
|
|
+
|
|
|
//余额处理:returnBalance==1 加回客户余额;==0 不改 balance,只把 payWay 记在订单上作为返款渠道记录
|
|
|
$customBalance = null;
|
|
|
if ($returnBalance == 1) {
|
|
|
- $lockCustom = CustomClass::getLockById($customId);
|
|
|
- if (empty($lockCustom)) {
|
|
|
- util::fail('没有找到客户');
|
|
|
- }
|
|
|
$customBalance = CustomClass::forwardReturnBalance($lockCustom, $order, $totalAmount);
|
|
|
}
|
|
|
|