mainId ?? 0; $orderId = $order->id ?? 0; $settleId = $order->settleId ?? 0; if (!empty($settleId)) { util::fail('已经结过了'); } $remainDebtPrice = $order->remainDebtPrice ?? 0; if ($remainDebtPrice <= 0) { $orderSn = $order->orderSn ?? ''; util::fail('已经结过了哦(单号 ' . $orderSn . ')'); } $shopId = $order->shopId ?? 0; $settleOrderSn = orderSn::getSettleSn(); $customId = $order->customId ?? 0; $customName = $order->customName ?? ''; $staffId = $staff->id ?? 0; $staffName = $staff->name ?? ''; $settleData = [ 'prePrice' => $remainDebtPrice, 'actPrice' => $remainDebtPrice, 'realPrice' => $remainDebtPrice, 'payWay' => $payWay, 'hdShopId' => $shopId, 'shopId' => $shopId, 'mainId' => $mainId, 'purchaseIds' => $orderId, 'saleIds' => $orderId, 'num' => 1, 'status' => 2, 'customId' => $customId, 'customName' => $customName, 'payTime' => date("Y-m-d H:i:s"), 'hdShopAdminId' => $staffId, 'hdShopName' => $staffName, 'orderSn' => $settleOrderSn, ]; $settleReturn = self::addData($settleData); $settleId = $settleReturn->id ?? 0; $order->settleId = $settleId; $order->debt = 0; $order->remainDebtPrice = 0; $order->save(); if ($payWay == dict::getDict('payWay', 'cash')) { $mainId = $order->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('门店信息错误'); } $moneyBalance = bcadd($main->money, $remainDebtPrice, 2); $main->money = $moneyBalance; $main->save(); $moneyEvent = $customName . "现金结尾款" . floatval($remainDebtPrice) . "元(单号 {$settleOrderSn})"; $moneyRemark = ''; $capitalType = dict::getDict('capitalType', 'hdXsClear', 'id'); $change = [ 'relateId' => $orderId, 'amount' => $remainDebtPrice, 'balance' => $moneyBalance, 'io' => 1, 'mainId' => $mainId, 'capitalType' => $capitalType, 'ptStyle' => dict::getDict('ptStyle', 'hd'), 'event' => $moneyEvent, 'remark' => $moneyRemark, ]; ShopMoneyChangeClass::addData($change); } //客户欠款金额减少 $custom = CustomClass::getLockById($customId); CustomClass::clearDebtAmountReduce($custom, $remainDebtPrice, $settleReturn); //制作单上的尾款也去掉 WorkClass::updateByCondition(['orderId' => $orderId], ['orderDebtPrice' => 0]); } public static function addData($data) { return self::add($data, true); } }