瀏覽代碼

可提现余额

shish 5 年之前
父節點
當前提交
654b7ed520

+ 13 - 3
app-ghs/controllers/CashController.php

@@ -21,12 +21,22 @@ class CashController extends BaseController
     public function actionApply()
     {
         $get = Yii::$app->request->get();
-        $shop = $this->shop;
         $get['shopAdminId'] = $this->shopAdminId;
         $shopAdmin = $this->shopAdmin;
         $get['shopAdminName'] = $shopAdmin->name ?? '';
-        CashClass::addApply($get, $shop);
-        util::complete();
+        $get['shopId'] = $this->shopId;
+        $get['sjId'] = $this->sjId;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            CashClass::addApply($get);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("提现申请报错:" . $exception->getMessage());
+            util::fail('申请失败');
+        }
     }
 
 }

+ 13 - 3
app-hd/controllers/CashController.php

@@ -21,12 +21,22 @@ class CashController extends BaseController
     public function actionApply()
     {
         $get = Yii::$app->request->get();
-        $shop = $this->shop;
         $get['shopAdminId'] = $this->shopAdminId;
         $shopAdmin = $this->shopAdmin;
         $get['shopAdminName'] = $shopAdmin->name ?? '';
-        CashClass::addApply($get, $shop);
-        util::complete();
+        $get['shopId'] = $this->shopId;
+        $get['sjId'] = $this->sjId;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            CashClass::addApply($get);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("提现申请报错:" . $exception->getMessage());
+            util::fail('申请失败');
+        }
     }
 
 }

+ 0 - 2
app-pt/controllers/CashController.php

@@ -27,7 +27,6 @@ class CashController extends BaseController
     //提现审核通过 shish 2021.5.17
     public function actionCheck()
     {
-        util::complete();
         $get = Yii::$app->request->get();
         $id = isset($get['id']) ? $get['id'] : 0;
         $cash = CashClass::getById($id, true);
@@ -35,7 +34,6 @@ class CashController extends BaseController
             util::fail('已经完成转账,请不要重复请求!');
         }
         $cashAmount = isset($cash->amount) ? floatval($cash->amount) : 0;
-
         $shopAdminId = $cash->shopAdminId;
         $shopAdmin = ShopAdminClass::getById($shopAdminId);
         if (empty($shopAdmin)) {

+ 30 - 22
biz/sj/classes/CashClass.php

@@ -37,42 +37,50 @@ class CashClass extends BaseClass
     }
 
     //申请提现
-    public static function addApply($params, $shop)
+    public static function addApply($params)
     {
+        $shopId = $params['shopId'] ?? 0;
+        if (empty($shopId)) {
+            util::fail('没有找到门店');
+        }
+        $cashList = self::getByCondition(['shopId' => $shopId, 'status' => 1], true);
+        if (!empty($cashList)) {
+            util::fail('已有提现申请审核中');
+        }
+        $shop = ShopClass::getLockById($shopId);
+        if (empty($shop)) {
+            util::fail('没有找到门店哦');
+        }
         $txBalance = $shop->txBalance ?? 0.00;
         if ($txBalance <= 0) {
             util::fail('可提现余额不足');
         }
+        if (bccomp($txBalance, $shop->balance) == 1) {
+            util::fail('余额有问题,总余额比可提现余额还少');
+        }
+        //可提现余额减少,总余额减少,冻结金额增加
+        $shop->txBalance = 0;
+        $shop->freezeBalance = bcadd($shop->freezeBalance, $txBalance, 2);
+        $shop->balance = bcsub($shop->balance, $txBalance, 2);
+        $shop->save();
+
         $cashName = $shop->cashName ?? '';
         $cashAccount = $shop->cashAccount ?? '';
         if (empty($cashName) || empty($cashAccount)) {
             util::fail('请填写提现帐号');
         }
-        $sjId = $shop->merchantId ?? 0;
-        $shopId = $shop->id;
-        $cashList = self::getByCondition(['shopId' => $shopId, 'status' => 1], true);
-        if (!empty($cashList)) {
-            util::fail('已有提现申请待审核');
-        }
         $shopName = $shop->shopName ?? '';
         $sjName = $shop->merchantName ?? '';
         $txBalance = $shop->txBalance ?? 0;
         $orderSn = orderSn::getCashSn();
-        $shopAdminId = $params['shopAdminId'] ?? 0;
-        $shopAdminName = $params['shopAdminName'] ?? '';
-        $data = [
-            'sjId' => $sjId,
-            'orderSn' => $orderSn,
-            'shopId' => $shopId,
-            'event' => '申请提现',
-            'sjName' => $sjName,
-            'shopName' => $shopName,
-            'amount' => $txBalance,
-            'shopAdminId' => $shopAdminId,
-            'shopAdminName' => $shopAdminName,
-        ];
-        self::add($data);
-        noticeUtil::push("客户:{$sjName} {$shopName}申请提现,金额:{$txBalance},orderSn:" . $orderSn, '15280215347');
+        $params['orderSn'] = $orderSn;
+        $params['event'] = '申请提现';
+        $params['sjName'] = $sjName;
+        $params['shopName'] = $shopName;
+        $params['amount'] = $txBalance;
+        $return = self::add($params, true);
+        noticeUtil::push("客户:{$sjName} {$shopName}申请提现,金额:{$txBalance}", '15280215347');
+        return $return;
     }
 
 }