|
|
@@ -19,9 +19,9 @@ class SettleClass extends BaseClass
|
|
|
|
|
|
//$side 0 表示花店创建结账单,1客户创建结账单,二者区别有花店有带$staff信息,客户没有
|
|
|
//$params 预留参数
|
|
|
- public static function addSettle($orderList, $shop, $custom, $hd, $params = [])
|
|
|
+ public static function addSettle($orderData, $shop, $custom, $hd, $params = [])
|
|
|
{
|
|
|
- $totalRemain = 0;
|
|
|
+ $totalClear = 0;
|
|
|
$shopId = $shop->id;
|
|
|
$mainId = $shop->mainId;
|
|
|
$sjId = $shop->sjId;
|
|
|
@@ -42,24 +42,16 @@ class SettleClass extends BaseClass
|
|
|
$staffName = $params['staffName'] ?? '';
|
|
|
|
|
|
$settleOrderSn = orderSn::getSettleSn();
|
|
|
- $idList = [];
|
|
|
- foreach ($orderList as $order) {
|
|
|
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
|
|
|
- $totalRemain = bcadd($totalRemain, $remainDebtPrice, 2);
|
|
|
- $idList[] = $order->id;
|
|
|
- }
|
|
|
- $string = implode(",", $idList);
|
|
|
- $num = count($orderList);
|
|
|
+ $num = count($orderData);
|
|
|
$settleData = [
|
|
|
- 'prePrice' => $totalRemain,
|
|
|
- 'actPrice' => $totalRemain,
|
|
|
- 'realPrice' => $totalRemain,
|
|
|
+ 'prePrice' => 0,
|
|
|
+ 'actPrice' => 0,
|
|
|
+ 'realPrice' => 0,
|
|
|
'payWay' => 0,
|
|
|
'shopId' => $shopId,
|
|
|
'mainId' => $mainId,
|
|
|
'sjId' => $sjId,
|
|
|
'purchaseIds' => '',
|
|
|
- 'saleIds' => $string,
|
|
|
'num' => $num,
|
|
|
'status' => 1,
|
|
|
'customId' => $customId,
|
|
|
@@ -79,39 +71,56 @@ class SettleClass extends BaseClass
|
|
|
'orderSn' => $settleOrderSn,
|
|
|
'payTime' => '0000-00-00 00:00:00',
|
|
|
];
|
|
|
- return self::addData($settleData);
|
|
|
+ $set = self::addData($settleData);
|
|
|
+ $settleId = $set->id;
|
|
|
+ foreach ($orderData as $order) {
|
|
|
+ $orderId = $order['orderId'];
|
|
|
+ $clearAmount = $order['clearAmount'] ?? 0;
|
|
|
+ OrderSettleClass::add(['orderId' => $orderId, 'settleId' => $settleId, 'status' => 0, 'amount' => $clearAmount]);
|
|
|
+ $totalClear = bcadd($totalClear, $clearAmount, 2);
|
|
|
+ }
|
|
|
+ $set->prePrice = $totalClear;
|
|
|
+ $set->actPrice = $totalClear;
|
|
|
+ $set->realPrice = $totalClear;
|
|
|
+ $set->save();
|
|
|
+ return $set;
|
|
|
}
|
|
|
|
|
|
public static function clearSettle($set)
|
|
|
{
|
|
|
$settleId = $set->id;
|
|
|
- $str = $set->saleIds;
|
|
|
- $ids = explode(",", $str);
|
|
|
- $ids = array_filter(array_unique($ids));
|
|
|
- $totalDebtPrice = 0;
|
|
|
+ $orderSettle = OrderSettleClass::getAllByCondition(['settleId' => $settleId], null, '*', null, true);
|
|
|
+ $ids = [];
|
|
|
+ $amountMap = [];
|
|
|
+ if (!empty($orderSettle)) {
|
|
|
+ foreach ($orderSettle as $os) {
|
|
|
+ $orderId = $os->orderId;
|
|
|
+ $ids[] = $orderId;
|
|
|
+ $amountMap[$orderId] = $os->amount;
|
|
|
+ $os->status = 1;
|
|
|
+ $os->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $totalClearAmount = 0;
|
|
|
if (empty($ids)) {
|
|
|
- return ['totalDebtPrice' => $totalDebtPrice];
|
|
|
+ return ['totalDebtPrice' => $totalClearAmount];
|
|
|
}
|
|
|
$orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
if (!empty($orderList)) {
|
|
|
foreach ($orderList as $order) {
|
|
|
- $remainDebtPrice = $order->remainDebtPrice;
|
|
|
- $totalDebtPrice = bcadd($totalDebtPrice, $remainDebtPrice, 2);
|
|
|
- $order->remainDebtPrice = 0;
|
|
|
- $order->debt = 0;
|
|
|
+ $orderId = $order->id;
|
|
|
+ $mayClearAmount = $amountMap[$orderId] ?? 0;
|
|
|
+ $totalClearAmount = bcadd($totalClearAmount, $mayClearAmount, 2);
|
|
|
+ $order->remainDebtPrice = bcsub($order->remainDebtPrice, $mayClearAmount, 2);
|
|
|
+ if ($order->remainDebtPrice <= 0) {
|
|
|
+ $order->debt = 0;
|
|
|
+ }
|
|
|
$order->settleTime = date("Y-m-d H:i:s");
|
|
|
$order->save();
|
|
|
-
|
|
|
- $orderId = $order->id;
|
|
|
- $relate = [
|
|
|
- 'settleId' => $settleId,
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'amount' => $remainDebtPrice,
|
|
|
- ];
|
|
|
- OrderSettleClass::add($relate, true);
|
|
|
}
|
|
|
}
|
|
|
- return ['totalDebtPrice' => $totalDebtPrice];
|
|
|
+ return ['totalClearAmount' => $totalClearAmount];
|
|
|
}
|
|
|
|
|
|
//结清尾款 ssh 20220708
|