Browse Source

钱包迁移

lizhen_gitee 2 years ago
parent
commit
e69bd0646f
2 changed files with 17 additions and 3 deletions
  1. 14 0
      application/common/library/Auth.php
  2. 3 3
      application/common/model/Wallet.php

+ 14 - 0
application/common/library/Auth.php

@@ -235,6 +235,13 @@ class Auth
             }
             $userpower = UserPower::getByUserId($user->id);
             $this->_user->power = $userpower;
+            //注册到钱包
+            $wallet_data = [
+                'user_id' => $user->id,
+                'money'   => 0,
+                'jewel'   => 0,
+            ];
+            Db::name('user_wallet')->insertGetId($wallet_data);
             //注册成功的事件
             Hook::listen("user_register_successed", $this->_user, $data);
             \app\common\model\NewBagHave::insert(["user_id" => $user->id, "createtime" => time()]);
@@ -864,6 +871,13 @@ class Auth
                 $powerData = ['user_id' => $user->id];
                 Db::name('user_power')->insertGetId($powerData);
             }
+            //注册到钱包
+            $wallet_data = [
+                'user_id' => $user->id,
+                'money'   => 0,
+                'jewel'   => 0,
+            ];
+            Db::name('user_wallet')->insertGetId($wallet_data);
             //注册成功的事件
             Hook::listen("user_register_successed", $this->_user, $data);
             \app\common\model\NewBagHave::insert(["user_id" => $user->id, "createtime" => time()]);

+ 3 - 3
application/common/model/Wallet.php

@@ -39,7 +39,7 @@ class Wallet extends Model
     public function getWallet($user_id = '', $wallet_name = '')
     {
         //所有钱包余额
-        $wallet = Db::name('user')->lock(true)->where(['id' => $user_id])->find();
+        $wallet = Db::name('user_wallet')->lock(true)->where(['user_id' => $user_id])->find();
         if(!$wallet) {
             abort(500,'钱包余额获取失败');
         }
@@ -115,7 +115,7 @@ class Wallet extends Model
 
 
         //检测
-        $wallet = Db::name('user')->field('money,jewel')->lock(true)->where(['id'=>$user_id])->find();
+        $wallet = Db::name('user_wallet')->field('money,jewel')->lock(true)->where(['user_id'=>$user_id])->find();
         if(!$wallet)
         {
             $result['msg'] = '不存在的用户';
@@ -146,7 +146,7 @@ class Wallet extends Model
                 $data['invite_user_id'] = $inviteId;
             }
             //新的方式
-            $rs1 = Db::name('user')->where(['id'=>$user_id])->update([$accountType => $data['balance']]);
+            $rs1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->update([$accountType => $data['balance']]);
 
             /////////////
             $log_table = 'user_'.$accountType.'_log';