| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace hd\controllers;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\order\classes\OrderClass;
- use bizHd\order\classes\SettleClass;
- use bizHd\recharge\classes\RechargeClass;
- use common\components\dict;
- use common\components\orderSn;
- use common\components\util;
- use Yii;
- class SettleController extends BaseController
- {
- public $guestAccess = [];
- //取消结账单 ssh 20250714
- public function actionCancelSettle()
- {
- util::fail('开发中');
- }
- public function actionGetDetail()
- {
- $id = Yii::$app->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('操作失败');
- }
- }
- }
|