shish %!s(int64=5) %!d(string=hai) anos
pai
achega
f09182f4de
Modificáronse 2 ficheiros con 25 adicións e 15 borrados
  1. 24 14
      app-pt/controllers/CashController.php
  2. 1 1
      biz/sj/classes/CashClass.php

+ 24 - 14
app-pt/controllers/CashController.php

@@ -27,6 +27,19 @@ class CashController extends BaseController
         util::success($list);
     }
 
+    public static function rollback($cash, $shop, $transaction, $cashAmount, $remark)
+    {
+        $cash->remark = $remark;
+        $cash->status = CashClass::STATUS_CHECK_NO;
+        $cash->save();
+        //冻结金额回滚
+        $shop->freezeBalance = bcsub($shop->freezeBalance, $cashAmount, 2);
+        $shop->balance = bcadd($shop->balance, $cashAmount, 2);
+        $shop->txBalance = bcadd($shop->txBalance, $cashAmount, 2);
+        $shop->save();
+        $transaction->commit();
+    }
+
     //提现审核通过 shish 2021.5.17
     public function actionCheck()
     {
@@ -46,21 +59,24 @@ class CashController extends BaseController
             }
             $shopId = $cash->shopId;
             $shop = ShopClass::getLockById($shopId);
+            $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
             if (empty($shop)) {
                 util::fail('没有找到门店');
             }
             $ptStyle = $shop->ptStyle ?? dict::getDict('ptStyle', 'hd');
-            $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
             if ($cashAmount <= 0) {
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
                 util::fail('提现金额有问题');
             }
             $miniCashAmount = dict::getDict('miniCashAmount');
             if (getenv('YII_ENV', 'local') != 'production') {
                 if ($cashAmount > $miniCashAmount) {
-                    util::fail("测试环境提现金额不能超过{$miniCashAmount}元");
+                    self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
+                    util::fail("测试提现不超过{$miniCashAmount}元");
                 }
             }
             if ($cashAmount < $miniCashAmount) {
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
                 util::fail("余额不足{$miniCashAmount}元");
             }
 
@@ -72,30 +88,24 @@ class CashController extends BaseController
             }
 
             if ($status != CashClass::STATUS_CHECK_YES) {
-                $cash->remark = $remark;
-                $cash->status = CashClass::STATUS_CHECK_NO;
-                $cash->save();
-                //冻结金额回滚
-                $shop->freezeBalance = bcsub($shop->freezeBalance, $cashAmount, 2);
-                $shop->balance = bcadd($shop->balance, $cashAmount, 2);
-                $shop->txBalance = bcadd($shop->txBalance, $cashAmount, 2);
-                $shop->save();
-                $transaction->commit();
-                util::complete();
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
+                util::fail('已审核过');
             }
 
             $cashAccount = $shop->cashAccount ?? '';
             $cashName = $shop->cashName ?? '';
             if (empty($cashAccount) || empty($cashName)) {
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
                 util::fail('提现帐号未填写完整');
             }
-
             $cashSn = $cash->orderSn;
             if (empty($cashSn)) {
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
                 util::fail('没有找到订单号');
             }
 
             if (bccomp($cashAmount, $shop->freezeBalance) == 1) {
+                self::rollback($cash, $shop, $transaction, $cashAmount, $remark);
                 util::fail('冻结金额不足提现');
             }
 
@@ -178,7 +188,7 @@ class CashController extends BaseController
             }
         } catch (Exception $exception) {
             $transaction->rollBack();
-            Yii::info("提现审核失败:" . $exception->getMessage());
+            Yii::info("审核失败:" . $exception->getMessage());
             util::fail('审核失败,请排查原因');
         }
     }

+ 1 - 1
biz/sj/classes/CashClass.php

@@ -54,7 +54,7 @@ class CashClass extends BaseClass
             }
         }
         if (bccomp($miniCashAmount, $txBalance) == 1) {
-            util::fail("可提现余额不足{$miniCashAmount}元");
+            util::fail("满{$miniCashAmount}元可提现");
         }
 
         //可提现余额减少,总余额减少,冻结金额增加