$settleId], null, '*', null, true); $ids = []; $map = []; if (!empty($osList)) { foreach ($osList as $os) { $orderId = $os->orderId; $ids[] = $os->orderId; $amount = $os->amount; $map[$orderId] = ['amount' => $amount]; } } if (empty($ids)) { util::fail('结账单空的'); } $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*'); if (!empty($orderList)) { foreach ($orderList as $key => $orderInfo) { $orderId = $orderInfo['id']; $current = $map[$orderId] ?? []; $currentAmount = $current['amount'] ?? 0; $currentAmount = floatval($currentAmount); $orderList[$key]['actSettleAmount'] = $currentAmount; } } $settle['orderNum'] = count($ids); $settle['orderList'] = $orderList; return $settle; } public static function getMySettleList($where) { return self::getList('*', $where, 'addTime DESC'); } //$side 0 表示花店创建结账单,1客户创建结账单,二者区别有花店有带$staff信息,客户没有 //$params 预留参数 public static function addSettle($orderData, $shop, $custom, $hd, $params = []) { $totalClear = 0; $shopId = $shop->id; $mainId = $shop->mainId; $sjId = $shop->sjId; $customId = $custom->id ?? 0; $customName = $custom->name ?? ''; $customAvatar = $custom->avatar ?? ''; $customMobile = $custom->mobile; $customAddress = $custom->address; $customUserId = $custom->userId; $hdId = $hd->id; $hdName = $hd->name; $hdAvatar = $hd->avatar; $hdMobile = $hd->mobile; $hdAddress = $hd->address; $staffId = $params['staffId'] ?? 0; $staffName = $params['staffName'] ?? ''; $settleOrderSn = orderSn::getSettleSn(); $num = count($orderData); $settleData = [ 'prePrice' => 0, 'actPrice' => 0, 'realPrice' => 0, 'payWay' => 0, 'shopId' => $shopId, 'mainId' => $mainId, 'sjId' => $sjId, 'num' => $num, 'status' => 1, 'customId' => $customId, 'customName' => $customName, 'customAvatar' => $customAvatar, 'customMobile' => $customMobile, 'customAddress' => $customAddress, 'customUserId' => $customUserId, 'hdId' => $hdId, 'hdShopId' => $shopId, 'hdName' => $hdName, 'hdAvatar' => $hdAvatar, 'hdMobile' => $hdMobile, 'hdAddress' => $hdAddress, 'hdStaffId' => $staffId, 'hdStaffName' => $staffName, 'orderSn' => $settleOrderSn, 'payTime' => '0000-00-00 00:00:00', ]; $set = self::addData($settleData); $settleId = $set->id; foreach ($orderData as $order) { $orderId = $order['orderId']; $clearAmount = $order['clearAmount'] ?? 0; $orderSn = $order['orderSn'] ?? ''; OrderSettleClass::add(['orderId' => $orderId, 'settleId' => $settleId, 'status' => 0, 'amount' => $clearAmount, 'orderSn' => $orderSn, 'settleSn' => $settleOrderSn]); $totalClear = bcadd($totalClear, $clearAmount, 2); } $set->prePrice = $totalClear; $set->actPrice = $totalClear; $set->realPrice = $totalClear; $set->save(); return $set; } public static function clearSettle($set, $recharge = []) { //如果带有充值,互相要给信息 if (!empty($recharge)) { $settleId = $set->id; $recharge->settleId = $settleId; $recharge->settleNo = $set->orderSn; $recharge->settleAmount = $set->actPrice; $recharge->save(); $payWay = $recharge->payWay ?? 0; $onlinePay = $recharge->onlinePay ?? 1; $rechargeId = $recharge->id; $rechargeSn = $recharge->orderSn; $set->payWay = $payWay; $set->rechargeId = $rechargeId; $set->rechargeSn = $rechargeSn; $set->onlinePay = $onlinePay; } $set->status = 2; $set->save(); $settleId = $set->id; $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' => $totalClearAmount]; } $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true); if (!empty($orderList)) { foreach ($orderList as $order) { $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(); } } return ['totalClearAmount' => $totalClearAmount, 'settle' => $set]; } public static function addData($data) { return self::add($data, true); } }