瀏覽代碼

充值提现

zac3533 1 年之前
父節點
當前提交
ee9c65ddda
共有 2 個文件被更改,包括 28 次插入2 次删除
  1. 12 2
      application/admin/controller/trade/MoneyIn.php
  2. 16 0
      application/admin/controller/trade/MoneyOut.php

+ 12 - 2
application/admin/controller/trade/MoneyIn.php

@@ -2,8 +2,10 @@
 
 namespace app\admin\controller\trade;
 
+use think\Db;
+use Exception;
 use app\common\controller\Backend;
-use app\common\model\Users;
+use app\common\model\MoneyLog;
 use think\exception\DbException;
 use think\exception\PDOException;
 use think\exception\ValidateException;
@@ -79,12 +81,20 @@ class MoneyIn extends Backend
             $this->error(__('No Results were found'));
         }
         $result = false;
+        Db::startTrans();
         try {
+
+            //充值
+            if ($status == $this->model::Success) {
+                (new MoneyLog())->change($row->user_id, $row->amount, MoneyLog::Recharge, $row->user_id, '充值');
+            }
+
             $result = $row->allowField(true)->save(['status' => $status]);
             //累积充值金额
             //(new Users())->where('id', $row->user_id)->setInc('money_in_sum', $row->amount);
-
+            Db::commit();
         } catch (ValidateException|PDOException $e) {
+            Db::rollback();
             $this->error($e->getMessage());
         }
         if (false === $result) {

+ 16 - 0
application/admin/controller/trade/MoneyOut.php

@@ -4,6 +4,7 @@ namespace app\admin\controller\trade;
 
 use think\Db;
 use Exception;
+use app\common\model\MoneyLog;
 use think\exception\DbException;
 use think\exception\PDOException;
 use app\common\controller\Backend;
@@ -83,9 +84,22 @@ class MoneyOut extends Backend
             $this->error(__('No Results were found'));
         }
         $result = false;
+        Db::startTrans();
         try {
+
+            //余额变动
+            $amount = $row->amount;
+            $action = MoneyLog::Reject;
+            if($status == $this->model::Success){
+                $amount = $row->real_amount;
+                $action = MoneyLog::Withdraw;
+            }
+            $action = $status == $this->model::Success? MoneyLog::Withdraw :MoneyLog::Reject;
+            (new MoneyLog())->change($row->user_id, $amount, $action, $row->user_id, '提现');
             $result = $row->allowField(true)->save(['status'=>$status]);
+            Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
             $this->error($e->getMessage());
         }
         if (false === $result) {
@@ -93,4 +107,6 @@ class MoneyOut extends Backend
         }
         $this->success();
     }
+
+
 }