|
|
@@ -38,7 +38,32 @@ class OrderClearClass extends BaseClass
|
|
|
if (floatval($customBalance) == 0) {
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+ $where = ['customId' => $customId, 'debt' => 1];
|
|
|
+ $orderList = OrderClass::getAllByCondition($where, 'id asc', '*', null, true);
|
|
|
+ if (empty($orderList)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $totalAmount = 0;
|
|
|
+ foreach ($orderList as $order) {
|
|
|
+ $remainDebtPrice = $order->remainDebtPrice ?? 0;
|
|
|
+ $totalAmount = bcadd($totalAmount, $remainDebtPrice, 2);
|
|
|
+ if ($totalAmount <= $customBalance) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = ['customId' => $customId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY];
|
|
|
+ $list = OrderClearClass::getAllByCondition($where, null, '*', null, true);
|
|
|
+ if (!empty($list)) {
|
|
|
+ foreach ($list as $item) {
|
|
|
+ //只要新建账单,老账单就取消掉
|
|
|
+ $item->status = PurchaseClearClass::STATUS_EXPIRE;
|
|
|
+ $item->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//订单结算 ssh 2021.3.14
|