|
|
@@ -157,6 +157,7 @@ class RechargeClass extends BaseClass
|
|
|
$settleId = $recharge->settleId;
|
|
|
$settleAmount = 0;
|
|
|
$lastClearOrderId = 0;
|
|
|
+ $lastClearOrderSn = '';
|
|
|
$realClearAmount = 0;
|
|
|
$lastClearOrderAmount = 0;
|
|
|
if (!empty($settleId)) {
|
|
|
@@ -170,29 +171,30 @@ class RechargeClass extends BaseClass
|
|
|
$orderList = OrderClass::getAllByCondition(['customId' => $customId, 'debt' => 1], 'id asc', '*', null, true);
|
|
|
if (!empty($orderList)) {
|
|
|
$totalRemainAmount = 0;
|
|
|
- $need = [];
|
|
|
- $hasPass = false;
|
|
|
+ $needClearIds = [];
|
|
|
+ $hasOver = false;
|
|
|
foreach ($orderList as $order) {
|
|
|
$orderId = $order->id ?? 0;
|
|
|
$remainDebtPrice = $order->remainDebtPrice ?? 0;
|
|
|
$currentTotal = bcadd($totalRemainAmount, $remainDebtPrice, 2);
|
|
|
if ($currentTotal > $totalAmount) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- if (!$hasPass) {
|
|
|
+ //如果剩下的钱不够销结账单,可以拿来销订单,具体请查看原型文档来理解
|
|
|
+ if (!$hasOver) {
|
|
|
$lastClearOrderAmount = bcsub($totalAmount, $totalRemainAmount, 2);
|
|
|
if ($lastClearOrderAmount > 0) {
|
|
|
$lastClearOrderId = $orderId;
|
|
|
+ $lastClearOrderSn = $order->orderSn ?? '';
|
|
|
}
|
|
|
}
|
|
|
- $hasPass = true;
|
|
|
+ $hasOver = true;
|
|
|
+ continue;
|
|
|
}
|
|
|
$totalRemainAmount = bcadd($totalRemainAmount, $remainDebtPrice, 2);
|
|
|
- $need[] = $orderId;
|
|
|
+ $needClearIds[] = $orderId;
|
|
|
}
|
|
|
- if (!empty($need)) {
|
|
|
+ if (!empty($needClearIds)) {
|
|
|
//创建结账单,并且销结账单
|
|
|
- $orderData = OrderClass::getAllByCondition(['id' => ['in', $need]], null, '*', null, true);
|
|
|
+ $orderData = OrderClass::getAllByCondition(['id' => ['in', $needClearIds]], null, '*', null, true);
|
|
|
$staffId = $recharge->staffId ?? 0;
|
|
|
$staffName = $recharge->staffName ?? '';
|
|
|
$settleParams = ['staffId' => $staffId, 'staffName' => $staffName];
|
|
|
@@ -230,6 +232,7 @@ class RechargeClass extends BaseClass
|
|
|
'settleId' => $settleId,
|
|
|
'settleAmount' => $settleAmount,
|
|
|
'orderId' => $lastClearOrderId,
|
|
|
+ 'orderSn' => $lastClearOrderSn,
|
|
|
'orderAmount' => $lastClearOrderAmount,
|
|
|
'remark' => '',
|
|
|
];
|