| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?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 20220708
- public function actionConfirmSettle()
- {
- $post = Yii::$app->request->post();
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $staff = $this->shopAdmin;
- $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
- $id = $post['id'] ?? '';
- $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('客户信息缺失');
- }
- //1、先充值
- $rechargeAmount = 0;
- if (is_numeric($id)) {
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- $rechargeAmount = $order->remainDebtPrice ?? 0;
- } else {
- $idArr = json_decode($id, true);
- $ids = array_column($idArr, 'id');
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (!empty($orderList)) {
- foreach ($orderList as $order) {
- $remainDebtPrice = $order->remainDebtPrice ?? 0;
- $rechargeAmount = bcadd($rechargeAmount, $remainDebtPrice, 2);
- }
- }
- }
- if (empty($rechargeAmount)) {
- util::fail('不需要销账');
- }
- $staffId = $this->shopAdminId;
- $staffName = $this->shopAdminName;
- $customName = $custom->name ?? '';
- $hdName = $hd->name;
- $shopId = $this->shopId;
- $mainId = $this->mainId;
- $orderSn = orderSn::getRechargeSn();
- $rechargeData = [
- 'orderSn' => $orderSn,
- 'modPrice' => 1,
- 'payWay' => $payWay,
- 'shopId' => $shopId,
- 'mainId' => $mainId,
- 'hdId' => $hdId,
- 'hdName' => $hdName,
- 'onlinePay' => 1,
- 'amount' => $rechargeAmount,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'payStatus' => 0,
- 'payTime' => '0000-00-00 00:00:00',
- 'status' => 0,
- 'remark' => '',
- 'customId' => $customId,
- 'customName' => $customName,
- ];
- $respond = RechargeClass::addRecharge($rechargeData);
- $id = $respond->id;
- $recharge = RechargeClass::getLockById($id);
- $params = [
- 'onlinePay' => 1,
- 'side' => 0,
- ];
- RechargeClass::complete($recharge, $payWay, $params);
- //2、再销账
- if (is_numeric($id)) {
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- SettleClass::confirmSettle($order, $payWay, $staff);
- } else {
- $idArr = json_decode($id, true);
- $ids = array_column($idArr, 'id');
- $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
- if (!empty($orderList)) {
- foreach ($orderList as $order) {
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- SettleClass::confirmSettle($order, $payWay, $staff);
- }
- }
- }
- $transaction->commit();
- util::complete();
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("失败:" . $exception->getMessage());
- util::fail('操作失败');
- }
- }
- }
|