浏览代码

修改个人信息

afa 4 月之前
父节点
当前提交
51299c8a95

+ 5 - 5
application/api/controller/Chabao.php

@@ -47,7 +47,7 @@ class Chabao extends Api
      */
     public function login(UserModel $userModel)
     {
-        $user = $userModel::where('mobile', $this->params['mobile'])->find();
+        $user = $userModel::where('phone', $this->params['mobile'])->find();
         if(!$user) $this->error('账号不存在', [], 4000);
         Token::marshal($user['id'], $user['address']);
         $user['token'] = Token::getEncryptedToken($user['id']);
@@ -61,14 +61,14 @@ class Chabao extends Api
     public function register(UserModel $userModel)
     {
         //手机号存在
-        if($userModel::where('mobile', $this->params['mobile'])->find()) $this->error('账号已存在');
+        if($userModel::where('phone', $this->params['mobile'])->find()) $this->error('账号已存在');
         $newUserID = 0;    
         Db::startTrans();
         try {
             //注册
             $time = time();
             $data = [
-                'mobile'        => $this->params['mobile'],
+                'phone'         => $this->params['phone'],
                 'nickname'      => "188" . substr((string)$time, 2) . rand(10, 99),//188开头,时间戳去掉开头两位,再后面再加两位随机数
                 'avatar'        => $this->request->domain().'/assets/img/logo.png',
                 'create_time'   => $time,
@@ -100,10 +100,10 @@ class Chabao extends Api
         $user = $userModel->getByAddress($this->params['address']);
         
         if(!$user) $this->error('钱包地址不存在');
-        if($user->mobile) $this->error('钱包地址已被绑定');
+        if($user->phone) $this->error('钱包地址已被绑定');
 
         //修改手机号
-        $user->mobile = $this->params['mobile'];
+        $user->phone = $this->params['mobile'];
         $user->save();
         $this->success('ok');
     }

+ 13 - 7
application/api/controller/Ledger.php

@@ -119,14 +119,17 @@ class Ledger extends Api
     public function frozenTransfer(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
     {
         $amount = $this->request->post('amount'); // 茶宝
-        $account= $this->request->post('account', ''); // 账号 
-        if(empty($amount) || empty($account)) $this->error(__('Parameter error'));
+        $account= $this->request->post('account', ''); // 账号
+        $type    = (strlen($account) > 11)? 0: 1;    // type: 0地址 1uid
+        if(empty($amount) || empty($account)){
+            $this->error(__('Parameter error'));
+        }
         $real   = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
         // 启动事务
         Db::startTrans();
         try {
-            // type: 0x, 地址 1uid
-            $user = (substr($account, 0, 2) == '0x')? $userModel->getByAddress($account): $userModel->getByUid($account); 
+
+            $user = (empty($type))? $userModel->getByAddress($account): $userModel->getById($account); 
             if(empty($user)) throw new Exception(__("赠送用户不存在"));    
             if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));
 
@@ -168,14 +171,17 @@ class Ledger extends Api
     {
         $amount = $this->request->post('amount'); // 茶宝
         $account= $this->request->post('account', ''); // 账号
-        if(empty($amount) || empty($account)) $this->error(__('Parameter error'));
+        $type    = (strlen($account) > 11)? 0: 1;    // type: 0地址 1uid
+        if(empty($amount) || empty($account)){
+            $this->error(__('Parameter error'));
+        }
         $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
 
         // 启动事务
         Db::startTrans();
         try {
-            // type: 0x地址 1uid
-            $user = (substr($account, 0, 2) == '0x')? $userModel->getByAddress($account): $userModel->getByUid($account); 
+
+            $user = (empty($type))? $userModel->getByAddress($account): $userModel->getById($account); 
             if(empty($user)) throw new Exception(__("赠送用户不存在"));    
             if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
             $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);

+ 2 - 2
application/api/controller/Member.php

@@ -148,7 +148,7 @@ class Member extends Api
         Db::startTrans();
         try {
             // 不存在时注册
-            $user = $userModel->getByMobile($mobile);
+            $user = $userModel->getByPhone($mobile);
             if (empty($user))  throw new Exception(__('账号不存在'));
              
             // 尝试绑定上级
@@ -171,6 +171,6 @@ class Member extends Api
             $this->error( $e->getMessage());
         }
             $this->success('ok', $user);
-        }
+    }
 
 }

+ 9 - 2
application/api/controller/User.php

@@ -17,7 +17,7 @@ use app\common\model\UserArea;
 use fast\Action;
 use fast\Asset;
 use fast\Random;
-use Google\Service\Storage\Resource\Objects;
+use app\api\logic\UserInfoLogic;
 use think\Config;
 use think\Db;
 use think\Exception;
@@ -54,7 +54,6 @@ class User extends Api
             'token'           => '0', // 平台币余额
             'name'            => $user['name'], // 姓名
             'phone'           => $user['phone'], // 手机号
-            'mobile'          => $user['mobile'], // 手机号
             'rental_power'    => '0', // 自己购买的算力
             'team_power'      => '0', // 团队总算里
             'balance'         => $ledgerWalletModel::getWalletChaBao($this->auth->id), // 余额
@@ -143,9 +142,17 @@ class User extends Api
             $param = $this->request->post();
             $validate = \think\Loader::validate('User');
             if(!$validate->scene(key($param))->check($param) || count($param) > 2 || empty($param)) $this->error(__("Invalid parameters"));
+
+            //手机号修改
+            if(isset($param['phone']) && UserInfoLogic::checkUserByInfo('phone', $this->auth->id) == false) $this->error(__("手机号已存在"));
+
+            //地址时候去重
+            if(!$param['area_code'] && isset($param['address']) && UserInfoLogic::checkUserByInfo('address', $this->auth->id) == false) $this->error(__("钱包地址已存在不能修改"));
+
             if(!empty($param['area_code']) && !empty($param['address'])){
                 $resp = $userArea::setUserAddress($this->auth->id, $param['area_code'], $param['address']);
             }else{
+
                 $resp = $userModel::where('id', $this->auth->id)->update($param);
             }
             // 提交事务

+ 45 - 0
application/api/logic/UserInfoLogic.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace app\api\logic;
+
+use Exception;
+use think\Env;
+use think\Cache;
+use think\Loader ;
+use fast\Asset;
+
+use app\common\model\UserModel;
+
+//用户逻辑
+class UserInfoLogic
+{
+
+
+      //判断用户手机号存在或者重复
+      public static function checkUserByInfo(string $wher, int $user_id)
+      {
+          //用户信息存在
+          $user = (new UserModel)->getById($user_id);
+          if(!empty($user[$wher])) return false;
+          
+          $userInfo = UserModel::getByUserCount($where);
+          if($userInfo > 1) return false;
+          
+          return true;
+      }
+
+ 
+
+
+
+
+
+
+
+
+
+
+
+ 
+
+}

+ 1 - 0
application/api/validate/User.php

@@ -36,6 +36,7 @@ class User extends Validate
         'heading'   => ['heading'],
         'phone'     => ['phone'],
         'avatar'    => ['avatar'],
+        'address'   => ['address'],
         'address'   => ['area_code', 'address'],
     ];
   

+ 10 - 2
application/common/model/UserModel.php

@@ -55,9 +55,17 @@ class UserModel extends Model
         return $this->where('id', $userID)->find();
     }
 
-    public function getByMobile($mobile)
+    public function getByPhone(string $phone)
     {
-        return $this->where("mobile", $mobile)->find();
+        return $this->where("phone", $phone)->find();
+    }
+
+ 
+
+    public static function getByUserCount(string $where)
+    {
+        return self::where([$where=> $where])->count();
+
     }
 
     public function getByUid($nickname){