|
|
@@ -98,6 +98,7 @@ class PurchaseOrderClass extends BaseClass
|
|
|
|
|
|
/**
|
|
|
* 减少本单剩余待结;减到 ≤0 则标已结清。不改 debtPrice。
|
|
|
+ * 消欠成功时若 clearId==0 则写 1(结账痕迹,供隔天售后判定)。
|
|
|
* @return bool 是否本单因此从待结变为已结清
|
|
|
*/
|
|
|
public static function reduceRemainDebtPrice($order, $amount)
|
|
|
@@ -120,11 +121,17 @@ class PurchaseOrderClass extends BaseClass
|
|
|
}
|
|
|
$order->remainDebtPrice = $newRemain;
|
|
|
$cleared = false;
|
|
|
+ $saveAttrs = ['remainDebtPrice', 'debt'];
|
|
|
if (bccomp($newRemain, '0', 2) <= 0) {
|
|
|
$order->debt = self::DEBT_NO;
|
|
|
$cleared = true;
|
|
|
}
|
|
|
- $order->save(false, ['remainDebtPrice', 'debt']);
|
|
|
+ // 售后返充 FIFO 消欠也算结账痕迹
|
|
|
+ if (intval($order->clearId ?? 0) === 0) {
|
|
|
+ $order->clearId = 1;
|
|
|
+ $saveAttrs[] = 'clearId';
|
|
|
+ }
|
|
|
+ $order->save(false, $saveAttrs);
|
|
|
return $cleared;
|
|
|
}
|
|
|
|
|
|
@@ -272,14 +279,23 @@ class PurchaseOrderClass extends BaseClass
|
|
|
|
|
|
// 本单刚因当天售后结清时减 debtNum(隔天 FIFO 内部自行处理)
|
|
|
$clearOrderDebt = !empty($order->_purchaseDebtClearedByRefund);
|
|
|
+ $orderSaveAttrs = [];
|
|
|
if (!$clearOrderDebt && intval($order->debt ?? 0) === self::DEBT_YES
|
|
|
&& bccomp((string)($order->actPrice ?? '1'), '0', 2) <= 0
|
|
|
&& bccomp((string)($order->remainDebtPrice ?? '1'), '0', 2) <= 0) {
|
|
|
$order->debt = self::DEBT_NO;
|
|
|
$order->remainDebtPrice = '0.00';
|
|
|
- $order->save(false, ['debt', 'remainDebtPrice']);
|
|
|
+ $orderSaveAttrs = ['debt', 'remainDebtPrice'];
|
|
|
$clearOrderDebt = true;
|
|
|
}
|
|
|
+ // 采购售后返充余额:本单 clearId==0 打结账痕迹 1(与销售侧语义一致)
|
|
|
+ if (intval($order->clearId ?? 0) === 0) {
|
|
|
+ $order->clearId = 1;
|
|
|
+ $orderSaveAttrs[] = 'clearId';
|
|
|
+ }
|
|
|
+ if (!empty($orderSaveAttrs)) {
|
|
|
+ $order->save(false, array_values(array_unique($orderSaveAttrs)));
|
|
|
+ }
|
|
|
if ($clearOrderDebt) {
|
|
|
$ghs->debtNum = max(0, intval($ghs->debtNum ?? 0) - 1);
|
|
|
}
|