request->get('id', ''); $settle = SettleClass::getById($id); if ($settle['mainId'] != $this->mainId) { util::fail('不是你的账单'); } $respond = SettleClass::getMyDetail($settle); util::success($respond); } public function actionGetList() { $get = Yii::$app->request->get(); $where = []; if (isset($get['status']) && is_numeric($get['status'])) { $where['status'] = $get['status']; } $customId = $get['customId'] ?? 0; if (!empty($customId)) { $custom = CustomClass::getById($customId, true); if ($custom->shopId != $this->shopId) { util::fail('不是你的客户'); } $where['customId'] = $customId; } $where['shopId'] = $this->shopId; $list = SettleClass::getMySettleList($where); $totalAmount = SettleClass::sum(['shopId' => $this->shopId, 'status' => 2, 'customId' => $customId], 'actPrice'); $list['totalAmount'] = floatval($totalAmount); util::success($list); } //结清尾款 ssh 20220708 public function actionConfirmSettle() { $post = Yii::$app->request->post(); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay'); $idData = $post['id'] ?? ''; if (is_numeric($idData)) { util::fail('请求参数错误哦'); } $customId = $post['customId'] ?? 0; $custom = CustomClass::getLockById($customId); if (empty($custom)) { util::fail('没有找到客户'); } $hdId = $custom->hdId ?? 0; $hd = HdClass::getlockById($hdId); if (empty($hd)) { util::fail('客户信息缺失'); } //先充值 $totalClear = 0; $idList = json_decode($idData, true); $ids = array_column($idList, 'id'); if (empty($ids)) { util::fail('请选择订单'); } $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,mainId,remainDebtPrice,orderSn', null, true); $clearData = []; if (!empty($orderList)) { foreach ($orderList as $order) { if ($order->mainId != $this->mainId) { util::fail('不是你的订单哦'); } $orderId = $order->id; $orderSn = $order->orderSn ?? ''; $remainDebtPrice = $order->remainDebtPrice ?? 0; $clearData[] = ['orderId' => $orderId, 'clearAmount' => $remainDebtPrice, 'orderSn' => $orderSn]; $totalClear = bcadd($totalClear, $remainDebtPrice, 2); } } if ($totalClear <= 0) { util::fail('不需要销账'); } $staffId = $this->shopAdminId; $staffName = $this->shopAdminName; $customName = $custom->name ?? ''; $userId = $custom->userId; $hdName = $hd->name; $shopId = $this->shopId; $mainId = $this->mainId; $orderSn = orderSn::getRechargeSn(); $shop = $this->shop; //避免重复提交 util::checkRepeatCommit($staffId, 6); $addData = [ 'orderSn' => $orderSn, 'modPrice' => 1, 'payWay' => $payWay, 'style' => 1, 'shopId' => $shopId, 'mainId' => $mainId, 'hdId' => $hdId, 'hdName' => $hdName, 'onlinePay' => 1, 'amount' => $totalClear, 'staffId' => $staffId, 'staffName' => $staffName, 'payStatus' => 0, 'payTime' => '0000-00-00 00:00:00', 'status' => 0, 'remark' => '', 'customId' => $customId, 'customName' => $customName, 'userId' => $userId, ]; $respond = RechargeClass::addRecharge($addData); $retId = $respond->id; //创建待结账单 $settleParams = ['staffId' => $staffId, 'staffName' => $staffName]; $settle = SettleClass::addSettle($clearData, $shop, $custom, $hd, $settleParams); $settleId = $settle->id; $settleAmount = $settle->actPrice; $settleNo = $settle->orderSn ?? ''; $respond->settleId = $settleId; $respond->settleAmount = $settleAmount; $respond->settleNo = $settleNo; $respond->save(); //充值成功并且销账成功 $recharge = RechargeClass::getLockById($retId); $params = ['onlinePay' => 1, 'side' => 0]; RechargeClass::complete($recharge, $payWay, $params); $transaction->commit(); util::complete(); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("失败:" . $exception->getMessage()); util::fail('操作失败'); } } }