Browse Source

钱包迁移,全局jewel

lizhen_gitee 2 years ago
parent
commit
7aeb4213d2

+ 2 - 2
application/admin/controller/Dashboard.php

@@ -39,9 +39,9 @@ class Dashboard extends Backend
         $recharge_today_wait = Db::name('rechar_order')->where('createtime','BETWEEN',[$todaystatime,$todayendtime])->where('status',0)->sum('money');
         $recharge_yestoday = Db::name('rechar_order')->where('createtime','BETWEEN',[$yestodaystatime,$yestodayendtime])->where('status',1)->sum('money');
         //平台总资产余额、
-        $allmoney = Db::name('user')->sum('money');
+        $allmoney = Db::name('user_wallet')->sum('money');
         //钻石(平台总数量/今日充值数量))
-        $alljewel = Db::name('user')->sum('jewel');
+        $alljewel = Db::name('user_wallet')->sum('jewel');
         $recharge_money_today = Db::name('rechar_order')->where('createtime','BETWEEN',[$todaystatime,$todayendtime])->where('status',1)->sum('jewel');
 
         //

+ 0 - 70
application/admin/controller/user/JewelLog.php

@@ -72,75 +72,5 @@ class JewelLog extends Backend
         return $this->view->fetch();
     }
 
-    /**
-     * 添加
-     */
-    public function add()
-    {
-        if ($this->request->isPost()) {
-            $params = $this->request->post("row/a");
-            if ($params) {
-                $params = $this->preExcludeFields($params);
-
-                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
-                    $params[$this->dataLimitField] = $this->auth->id;
-                }
-                Db::startTrans();
-                try {
-                    //是否采用模型验证
-                    if ($this->modelValidate) {
-                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
-                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
-                        $this->model->validateFailException(true)->validate($validate);
-                    }
-                    // 获取用户的变更前余额
-                    $userJewel = \app\admin\model\User::where('id', $params['user_id'])->value('jewel');
-                    $params['before'] = $userJewel;
-                    $adjustmentValue = intval($params['value']);
-                    switch ($params['mode']) {
-                        case '+':
-                            $params['balance'] = $userJewel + $adjustmentValue;
-                            break;
-                        case '-':
-                            if ($adjustmentValue > $userJewel) {
-                                $this->error('调整砖石余额大于现有砖石余额');
-                            }
-
-                            $params['balance'] = $userJewel - $adjustmentValue;
-                            break;
-                        default:
-                            $this->error('请输入正确的变更方式');
-
-                    }
-
-                    $res1 = $this->model->allowField(true)->save($params);
 
-                    // 调整用户声币余额
-                    $res2 = \app\admin\model\User::where(["id" => $params['user_id']])->update([
-                        'jewel' => Db::raw("jewel{$params['mode']}{$adjustmentValue}"),
-                    ]);
-
-
-                    if ($res1 && $res2) {
-                        Db::commit();
-                        $this->success();
-                    } else {
-                        $this->error(__('Operation failed'));
-                    }
-                    Db::commit();
-                } catch (ValidateException $e) {
-                    Db::rollback();
-                    $this->error($e->getMessage());
-                } catch (PDOException $e) {
-                    Db::rollback();
-                    $this->error($e->getMessage());
-                } catch (Exception $e) {
-                    Db::rollback();
-                    $this->error($e->getMessage());
-                }
-            }
-            $this->error(__('Parameter %s can not be empty', ''));
-        }
-        return $this->view->fetch();
-    }
 }

+ 3 - 13
application/api/controller/Dispatch.php

@@ -387,10 +387,7 @@ class Dispatch extends Common
         }
 
         // 判断用户余额
-        $userModel = new \app\common\model\User();
-        $where = [];
-        $where["id"] = $this->auth->id;
-        $jewel = $userModel->where($where)->value("jewel");
+        $jewel = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('jewel');
         $price = 0;
         $authInfo["price"] >= 0 || $price = 0;
         $authInfo["price"] >= 0 && $price = $authInfo["price"];
@@ -431,14 +428,7 @@ class Dispatch extends Common
             $data["createtime"] = time();
             $res = $orderModel->insertGetId($data);
             if($res) {
-                //冻结用户钻石
-                $userWhere['id'] = $this->auth->id;
-                $money = bcmul($authInfo["price"],$num);
-                $res1 = model('User')->where($userWhere)->setDec("jewel",$money);//用户扣减金额
-                $res2 = model('User')->where($userWhere)->setInc("frozen",$money);//用户冻结金额
-                if (!$res1 || !$res2) {
-                    throw new Exception('用户扣减金额失败');
-                }
+
                 \app\common\model\Message::addMessage($authInfo["user_id"],"派单通知","您的技能:".$skillInfo["name"]."有人下单啦,请注意查看!");
                 Db::commit();
                 $this->success('订单创建成功!',["order_no"=>$out_trade_no]);
@@ -525,7 +515,7 @@ class Dispatch extends Common
         $userModel = new \app\common\model\User();
         $where = [];
         $where["id"] = $this->auth->id;
-        $jewel = $userModel->where($where)->value("jewel");
+        $jewel = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('jewel');
         $money = $orderInfo["price"] * $orderInfo["num"];
         if($money > $jewel) {
             $this->error(__('钻石余额不足,请先充值!'),[],100);

+ 1 - 1
application/api/controller/Money.php

@@ -856,7 +856,7 @@ class Money extends Common
             // 减去用户声币余额
             $res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
             // 增加用户钻石余额
-            $res5 = $userModel->where(["id" => $this->auth->id])->setInc("jewel", $exchangeMoney);
+//            $res5 = $userModel->where(["id" => $this->auth->id])->setInc("jewel", $exchangeMoney);
             if ($res1 && $res2 && $res3 && $res4 && $res5) {
                 Db::commit();
                 $this->success("兑换成功!");

+ 7 - 1
application/api/controller/Usercenter.php

@@ -46,8 +46,14 @@ class UserCenter extends Common
         // 获取基本信息
         $where = [];
         $where["id"] = $user_id;
-        $userInfo = $this->userModel->field("id,nickname,pre_nickname,image,mobile,avatar,pre_avatar,gender,money,age,u_id,level,jewel,
+        $userInfo = $this->userModel->field("id,nickname,pre_nickname,image,mobile,avatar,pre_avatar,gender,age,u_id,level,
         age_id,constellation_id,province_id,city_id,desc,ipaddress,is_cool,is_manager,is_stealth,charm_level,wealth_level")->where($where)->find();
+
+        //用户钱包
+        $userwallet = Db::name('user_wallet')->where('user_id',$user_id)->find();
+        $userInfo['money'] = $userwallet['money'];
+        $userInfo['jewel'] = $userwallet['jewel'];
+
         $userInfo['nickname_status'] = $userInfo['avatar_status'] = 0;
         if (!empty($userInfo['pre_nickname']) && $userInfo['pre_nickname'] != $userInfo['nickname']) {
             $userInfo['nickname_status'] = 1;

+ 9 - 1
application/common/library/Auth.php

@@ -27,7 +27,9 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'u_id', 'username', 'nickname', 'mobile', 'pre_userid', 'has_info', 'is_auth', 'is_anchor', 'is_guild', 'guild_id', 'avatar', 'empirical', 'image', 'money', 'level', 'gender', 'age', 'jewel','ipaddress','wealth_level','charm_level'];
+    protected $allowFields = ['id', 'u_id', 'username', 'nickname', 'mobile', 'pre_userid', 'has_info', 'is_auth',
+        'is_anchor', 'is_guild', 'guild_id', 'avatar', 'empirical', 'image', 'level', 'gender', 'age',
+        'ipaddress','wealth_level','charm_level'];
 
     public function __construct($options = [])
     {
@@ -488,6 +490,12 @@ class Auth
         $fansfollows["follows"] = $follows ? $follows : 0;
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
+
+        //用户钱包
+        $userwallet = Db::name('user_wallet')->where('user_id',$this->_user->id)->find();
+        $userinfo['money'] = $userwallet['money'];
+        $userinfo['jewel'] = $userwallet['jewel'];
+
         $userinfo = array_merge($userinfo, Token::get($this->_token));
         $userinfo = array_merge($userinfo, $fansfollows);
         // 获取贵族信息