فهرست منبع

存入与取出

shish 3 سال پیش
والد
کامیت
7a040cbb1f
2فایلهای تغییر یافته به همراه104 افزوده شده و 66 حذف شده
  1. 54 35
      app-ghs/controllers/ShopMoneyController.php
  2. 50 31
      app-hd/controllers/ShopMoneyController.php

+ 54 - 35
app-ghs/controllers/ShopMoneyController.php

@@ -21,22 +21,33 @@ class ShopMoneyController extends BaseController
         if (is_numeric($amount) == false || $amount <= 0) {
             util::fail('请填写金额');
         }
-        $mainId = $this->mainId;
-        $staffId = $this->shopAdminId ?? 0;
-        $staff = $this->shopAdmin;
-        $data = [];
-        $data['mainId'] = $mainId;
-        $data['sjId'] = $this->sjId;
-        $data['amount'] = $amount;
-        $data['staffId'] = $staffId;
-        $data['staffName'] = $staff->name ?? '';
-        $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有门店信息');
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $mainId = $this->mainId;
+            $staffId = $this->shopAdminId ?? 0;
+            $staff = $this->shopAdmin;
+            $data = [];
+            $data['mainId'] = $mainId;
+            $data['sjId'] = $this->sjId;
+            $data['amount'] = $amount;
+            $data['staffId'] = $staffId;
+            $data['staffName'] = $staff->name ?? '';
+            $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+            $main = MainClass::getLockById($mainId);
+            if (empty($main)) {
+                util::fail('没有门店信息');
+            }
+            ShopMoneyClass::inAmount($data, $main);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('存入失败');
         }
-        ShopMoneyClass::inAmount($data, $main);
-        util::complete();
     }
 
     //取出现金 ssh 20220811
@@ -46,27 +57,35 @@ class ShopMoneyController extends BaseController
         if (isset($staff->super) == false || $staff->super != 1) {
             util::fail('没有权限');
         }
-
-        $get = Yii::$app->request->get();
-        $amount = $get['amount'] ?? 0;
-        if (is_numeric($amount) == false || $amount <= 0) {
-            util::fail('请填写金额');
-        }
-        $mainId = $this->mainId;
-        $staffId = $this->shopAdminId ?? 0;
-        $data = [];
-        $data['mainId'] = $mainId;
-        $data['sjId'] = $this->sjId;
-        $data['amount'] = $amount;
-        $data['staffId'] = $staffId;
-        $data['staffName'] = $staff->name ?? '';
-        $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有门店信息');
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $get = Yii::$app->request->get();
+            $amount = $get['amount'] ?? 0;
+            if (is_numeric($amount) == false || $amount <= 0) {
+                util::fail('请填写金额');
+            }
+            $mainId = $this->mainId;
+            $staffId = $this->shopAdminId ?? 0;
+            $data = [];
+            $data['mainId'] = $mainId;
+            $data['sjId'] = $this->sjId;
+            $data['amount'] = $amount;
+            $data['staffId'] = $staffId;
+            $data['staffName'] = $staff->name ?? '';
+            $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
+            $main = MainClass::getLockById($mainId);
+            if (empty($main)) {
+                util::fail('没有门店信息');
+            }
+            ShopMoneyClass::outAmount($data, $main);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('取出失败');
         }
-        ShopMoneyClass::outAmount($data, $main);
-        util::complete();
     }
 
 }

+ 50 - 31
app-hd/controllers/ShopMoneyController.php

@@ -22,22 +22,32 @@ class ShopMoneyController extends BaseController
         if (is_numeric($amount) == false || $amount <= 0) {
             util::fail('请填写金额');
         }
-        $mainId = $this->mainId;
-        $staffId = $this->shopAdminId ?? 0;
-        $staff = $this->shopAdmin;
-        $data = [];
-        $data['mainId'] = $mainId;
-        $data['sjId'] = $this->sjId;
-        $data['amount'] = $amount;
-        $data['staffId'] = $staffId;
-        $data['staffName'] = $staff->name ?? '';
-        $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有门店信息');
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $mainId = $this->mainId;
+            $staffId = $this->shopAdminId ?? 0;
+            $staff = $this->shopAdmin;
+            $data = [];
+            $data['mainId'] = $mainId;
+            $data['sjId'] = $this->sjId;
+            $data['amount'] = $amount;
+            $data['staffId'] = $staffId;
+            $data['staffName'] = $staff->name ?? '';
+            $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
+            $main = MainClass::getLockById($mainId);
+            if (empty($main)) {
+                util::fail('没有门店信息');
+            }
+            ShopMoneyClass::inAmount($data, $main);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('存入失败');
         }
-        ShopMoneyClass::inAmount($data, $main);
-        util::complete();
     }
 
     //取出现金 ssh 20220811
@@ -48,23 +58,32 @@ class ShopMoneyController extends BaseController
         if (is_numeric($amount) == false || $amount <= 0) {
             util::fail('请填写金额');
         }
-        $mainId = $this->mainId;
-        $staffId = $this->shopAdminId ?? 0;
-        $staff = $this->shopAdmin;
-        $data = [];
-        $data['mainId'] = $mainId;
-        $data['sjId'] = $this->sjId;
-        $data['amount'] = $amount;
-        $data['staffId'] = $staffId;
-        $data['staffName'] = $staff->name ?? '';
-        $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
-        $main = MainClass::getLockById($mainId);
-        if (empty($main)) {
-            util::fail('没有门店信息');
+
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+            $mainId = $this->mainId;
+            $staffId = $this->shopAdminId ?? 0;
+            $staff = $this->shopAdmin;
+            $data = [];
+            $data['mainId'] = $mainId;
+            $data['sjId'] = $this->sjId;
+            $data['amount'] = $amount;
+            $data['staffId'] = $staffId;
+            $data['staffName'] = $staff->name ?? '';
+            $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
+            $main = MainClass::getLockById($mainId);
+            if (empty($main)) {
+                util::fail('没有门店信息');
+            }
+            ShopMoneyClass::outAmount($data, $main);
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $e->getMessage());
+            util::fail('取出失败');
         }
-        ShopMoneyClass::outAmount($data, $main);
-        util::complete();
     }
 
-
 }