shish 1 год назад
Родитель
Сommit
a4c5cf2983
2 измененных файлов с 82 добавлено и 51 удалено
  1. 56 47
      app-hd/controllers/RechargeController.php
  2. 26 4
      biz-hd/recharge/classes/RechargeClass.php

+ 56 - 47
app-hd/controllers/RechargeController.php

@@ -55,54 +55,63 @@ class RechargeController extends BaseController
         $staffId = $shopAdmin->id;
         $staffName = $shopAdmin->name;
 
-        $payWay = $post['payWay'] ?? 0;
-        $amount = $post['amount'] ?? 0;
-        $remark = $post['remark'] ?? '';
-        $customId = $post['customId'] ?? 0;
-        $custom = \bizHd\custom\classes\CustomClass::getById($customId, true);
-        if (empty($custom)) {
-            util::fail('没有找到客户');
-        }
-        $customName = $custom->name;
-        $hdId = $custom->hdId;
-        $hd = HdClass::getById($hdId, true);
-        if (empty($hd)) {
-            util::fail('花店信息缺失');
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $payWay = $post['payWay'] ?? 0;
+            $amount = $post['amount'] ?? 0;
+            $remark = $post['remark'] ?? '';
+            $customId = $post['customId'] ?? 0;
+            $custom = \bizHd\custom\classes\CustomClass::getById($customId, true);
+            if (empty($custom)) {
+                util::fail('没有找到客户');
+            }
+            $customName = $custom->name;
+            $hdId = $custom->hdId;
+            $hd = HdClass::getById($hdId, true);
+            if (empty($hd)) {
+                util::fail('花店信息缺失');
+            }
+            $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' => $amount,
+                'staffId' => $staffId,
+                'staffName' => $staffName,
+                'payStatus' => 0,
+                'payTime' => '0000-00-00 00:00:00',
+                'status' => 0,
+                'remark' => $remark,
+                'customId' => $customId,
+                'customName' => $customName,
+            ];
+            $respond = \bizHd\recharge\classes\RechargeClass::addRecharge($rechargeData);
+
+            $id = $respond->id;
+            $recharge = RechargeClass::getLockById($id);
+            $params = [
+                'onlinePay' => 1,
+                'side' => 0,
+            ];
+            \bizHd\recharge\classes\RechargeClass::complete($recharge, $payWay, $params);
+            $transaction->commit();
+            util::success($post);
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("充值失败原因:" . $e->getMessage());
+            util::fail('充值失败');
         }
-        $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' => $amount,
-            'staffId' => $staffId,
-            'staffName' => $staffName,
-            'payStatus' => 0,
-            'payTime' => '0000-00-00 00:00:00',
-            'status' => 0,
-            'remark' => $remark,
-            'customId' => $customId,
-            'customName' => $customName,
-        ];
-        $respond = \bizHd\recharge\classes\RechargeClass::addRecharge($rechargeData);
-
-        $id = $respond->id;
-        $recharge = RechargeClass::getLockById($id);
-        $params = [
-            'onlinePay' => 1,
-            'side' => 0,
-        ];
-        \bizHd\recharge\classes\RechargeClass::complete($recharge, $payWay, $params);
-
-        util::success($post);
     }
 
     //充值记录 ssh 2021.2.21

+ 26 - 4
biz-hd/recharge/classes/RechargeClass.php

@@ -6,7 +6,9 @@ use biz\shop\classes\ShopClass;
 use bizHd\balance\classes\BalanceChangeClass;
 use bizHd\custom\classes\CustomClass;
 use bizHd\custom\classes\HdClass;
+use bizHd\member\classes\MemberWealClass;
 use bizHd\shop\classes\MainClass;
+use common\components\arrayUtil;
 use common\components\dict;
 use common\components\noticeUtil;
 use common\components\util;
@@ -78,24 +80,44 @@ class RechargeClass extends BaseClass
             Yii::info($msg);
             util::fail($msg);
         }
-        $custom->balance = bcadd($custom->balance, $amount, 2);
-        $custom->save();
-
         $hd = HdClass::getLockById($hdId);
         if (empty($hd)) {
             $msg = '充值回调失败,没有找到花店';
             Yii::info($msg);
             util::fail($msg);
         }
+
+        $shop = ShopClass::getById($shopId);
+        $rechargeWeal = $shop->rechargeWeal ?? 0;
+        if ($rechargeWeal == 1 || $rechargeWeal == 2) {
+            $weal = MemberWealClass::getAllByCondition(['shopId' => $shopId], null, '*');
+            if (!empty($weal)) {
+                $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
+                if ($rechargeWeal == 1) {
+                    //充值升级会员
+                    foreach ($weal as $k => $v) {
+
+                    }
+                } else {
+                    //升级送钱
+                    foreach ($weal as $k => $v) {
+
+                    }
+                }
+            }
+        }
+
+        $custom->balance = bcadd($custom->balance, $amount, 2);
+        $custom->save();
         $hd->balance = bcadd($hd->balance, $amount, 2);
         $hd->save();
-
         if ($hd->balance != $custom->balance) {
             $msg = '充值回调失败,金额不一致';
             Yii::info($msg);
             util::fail($msg);
         }
 
+
         $change = [
             'customId' => $customId,
             'customName' => $customName,