|
|
@@ -107,10 +107,15 @@ class OrderClearClass extends BaseClass
|
|
|
if (empty($list)) {
|
|
|
util::fail('请选择订单');
|
|
|
}
|
|
|
- $amount = 0;
|
|
|
-
|
|
|
- $modifyPrice = $post['modifyPrice'] ?? 0.00;
|
|
|
+ $modifyPrice = bcadd((string)($post['modifyPrice'] ?? '0'), '0', 2);
|
|
|
|
|
|
+ $amount = '0.00';
|
|
|
+ if (!empty($orderAmountMap)) {
|
|
|
+ // 充值 FIFO 销账:prePrice=Σ每单销账额(对照 hd Settle,勿用订单全款算优惠)
|
|
|
+ foreach ($orderAmountMap as $mayClear) {
|
|
|
+ $amount = bcadd($amount, (string)$mayClear, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
foreach ($list as $key => $val) {
|
|
|
if ($val['sjId'] != $sjId) {
|
|
|
util::fail('只能结算自己的订单哦');
|
|
|
@@ -121,7 +126,9 @@ class OrderClearClass extends BaseClass
|
|
|
if ($val['customId'] != $customId) {
|
|
|
util::fail('每次只能结算一个客户的订单');
|
|
|
}
|
|
|
- $amount = bcadd($amount, $val['remainDebtPrice'], 2);
|
|
|
+ if (empty($orderAmountMap)) {
|
|
|
+ $amount = bcadd($amount, $val['remainDebtPrice'], 2);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$custom = CustomClass::getLockById($customId);
|
|
|
@@ -201,11 +208,15 @@ class OrderClearClass extends BaseClass
|
|
|
'hasNoticeCustom' => 0,
|
|
|
'remark' => $remark,
|
|
|
];
|
|
|
- if ($modifyPrice < $amount) {
|
|
|
+ if (!empty($orderAmountMap)) {
|
|
|
+ // 自动充值销账:结账单金额=本次来款池,不产生虚假「优惠」
|
|
|
+ $modifyPrice = $amount;
|
|
|
+ }
|
|
|
+ if (bccomp($modifyPrice, $amount, 2) < 0) {
|
|
|
$clearData['discountAmount'] = bcsub($amount, $modifyPrice, 2);
|
|
|
$clearData['discountType'] = dict::getDict('discountType', 'discount');
|
|
|
}
|
|
|
- if ($modifyPrice > $amount) {
|
|
|
+ if (bccomp($modifyPrice, $amount, 2) > 0) {
|
|
|
//noticeUtil::push("结账金额大于总欠款金额 {$modifyPrice} {$amount}", '15280215347');
|
|
|
util::fail('结账金额大于总欠款金额');
|
|
|
}
|
|
|
@@ -273,6 +284,11 @@ class OrderClearClass extends BaseClass
|
|
|
|
|
|
$clearTime = date("Y-m-d H:i:s");
|
|
|
$totalSettled = '0.00';
|
|
|
+ // 手工结账单可能 actPrice < 明细合计(抹零);合并后销单以 actPrice 为本次付款上限
|
|
|
+ $settleBudget = bcadd((string)($clear->actPrice ?? '0'), '0', 2);
|
|
|
+ if ($paymentSettleOnly && bccomp($settleBudget, '0', 2) <= 0) {
|
|
|
+ $settleBudget = bcadd((string)($clear->prePrice ?? '0'), '0', 2);
|
|
|
+ }
|
|
|
|
|
|
foreach ($orderSettleRows as $os) {
|
|
|
$orderId = intval($os->orderId ?? 0);
|
|
|
@@ -281,6 +297,15 @@ class OrderClearClass extends BaseClass
|
|
|
if ($orderId <= 0 || bccomp($mayClear, '0', 2) <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
+ if ($paymentSettleOnly && bccomp($settleBudget, '0', 2) > 0) {
|
|
|
+ $budgetLeft = bcsub($settleBudget, $totalSettled, 2);
|
|
|
+ if (bccomp($budgetLeft, '0', 2) <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (bccomp($mayClear, $budgetLeft, 2) > 0) {
|
|
|
+ $mayClear = $budgetLeft;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$order = OrderClass::getById($orderId, true);
|
|
|
if (empty($order) || ($order->debt ?? 0) == 0) {
|