Bläddra i källkod

完善找回密码

Jason 1 år sedan
förälder
incheckning
fa37e6782d

+ 0 - 1
application/api/controller/Common.php

@@ -7,7 +7,6 @@ use app\common\exception\UploadException;
 use app\common\library\Upload;
 use app\common\model\Area;
 use app\common\model\Version;
-use fast\Random;
 use think\captcha\Captcha;
 use think\Config;
 use think\Hook;

+ 1 - 2
application/api/controller/Index.php

@@ -6,14 +6,13 @@ use app\common\controller\Api;
 use app\common\model\Config;
 use app\common\model\Moneylog;
 use app\common\model\News;
-use app\common\model\Order as OrderModel;
 
 /**
  * 首页接口
  */
 class Index extends Api
 {
-    protected $noNeedLogin = ['base',];
+    protected $noNeedLogin = ['base'];
     protected $noNeedRight = ['*'];
 
     /**

+ 2 - 4
application/api/controller/Money.php

@@ -3,10 +3,8 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\model\Config;
 use app\common\model\MoneyIn;
 use app\common\model\MoneyOut;
-use app\common\model\Order AS OrderModel;
 use app\common\model\User AS UserModel;
 use think\Db;
 use think\Exception;
@@ -81,7 +79,7 @@ class Money extends Api
                 $this->error(__('参数有误'));
             }
             $insert_data['order_no'] = 'U' . time() . $user['id'];
-            $insert_data['address']  = $recharge_info['usdt'];
+            $insert_data['usdt_address']  = $recharge_info['usdt'];
         }else{
             if(empty($recharge_info['bank'])){
                 $this->error(__('参数有误'));
@@ -302,7 +300,7 @@ class Money extends Api
         if($type == 1){
             //充值列表
             $info_list = MoneyIn::where('user_id', $user['id'])
-                ->field('order_no,order_type,amount,status,create_time')
+                ->field('order_no,order_type,usdt_address,bank_name,bank_card,account_name,amount,status,create_time')
                 ->order('id DESC')
                 ->paginate($this->pageSize);
             foreach ($info_list as $k => $v) {

+ 17 - 0
application/api/controller/Order.php

@@ -76,4 +76,21 @@ class Order extends Api
 
         $this->success('', $data);
     }
+
+    /**
+     * 提交订单
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function submit()
+    {
+        $user = $this->auth->getUser();
+
+        $data['order_no']   = 'sn45784545';
+        $data['title']      = '商品标题111';
+        $data['amount']     = 4545;
+        $data['bonus']      = $user['bonus_sum'];
+
+        $this->success('');
+    }
 }

+ 0 - 1
application/api/controller/Sms.php

@@ -9,7 +9,6 @@ use app\common\model\User;
 use think\Hook;
 use fast\Random;
 use Exception;
-use think\Cache;
 use think\exception\PDOException;
 use think\exception\ValidateException;
 use think\Log;

+ 99 - 1
application/api/controller/User.php

@@ -6,9 +6,14 @@ use app\common\controller\Api;
 use app\common\library\Ems;
 use app\common\library\Sms;
 use app\common\model\Order as OrderModel;
+use app\common\model\User as UserModel;
 use fast\Random;
+use think\Cache;
 use think\Config;
+use think\Db;
 use think\Env;
+use think\Exception;
+use think\Hook;
 use think\Validate;
 
 /**
@@ -16,7 +21,7 @@ use think\Validate;
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
+    protected $noNeedLogin = ['login', 'register', 'find_pwd_send_sms', 'verify_code', 'reset_pwd'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -200,6 +205,99 @@ class User extends Api
         }
         $this->error(__('资金密码重置失败'));
     }
+
+    /**
+     * 找回密码发送验证码
+     * @return void
+     * @throws \think\Exception
+     */
+    public function find_pwd_send_sms()
+    {
+        $code           = $this->request->post('country_code');
+        $mobile         = $this->request->post('mobile');
+        $captcha        = $this->request->post('captcha');
+
+        if(!captcha_check($captcha)){
+            $this->error(__('验证码错误'));
+        };
+
+        $user = UserModel::getByCodeAndMobile($code,$mobile);
+        if(empty($user)){
+            $this->error(__('手机号码不存在'));
+        }
+        if($user['is_lock']){
+            $this->error(__('账号锁定'));
+        }
+
+        (new \app\api\controller\Sms())->send_international_sms($user['code'], $user['mobile'], 'find_pwd');
+    }
+
+    public function verify_code()
+    {
+        $country_code   = $this->request->post('country_code');
+        $mobile         = $this->request->post('mobile');
+        $code           = $this->request->post('code');
+
+        $verify = (new \app\api\controller\Sms())->check($country_code, $mobile, $code, 'find_pwd');
+
+        if($verify){
+            $token = uniqid();
+            Cache::set($token, ['code' => $country_code, 'mobile' => $mobile], 60 * 10);//临时token缓存10分钟
+            $this->success('', $token);
+        }
+        $this->error(__('手机验证码错误'));
+    }
+
+    public function reset_pwd()
+    {
+        $token          = $this->request->post('token');
+        $new_pwd        = $this->request->post("new_pwd", '', null);
+        $confirm_pwd    = $this->request->post("confirm_pwd", '', null);
+
+        $rule = [
+            'new_pwd'       => 'require|regex:\S{6,30}',
+            'confirm_pwd'   => 'require|regex:\S{6,30}|confirm:new_pwd',
+        ];
+
+        $msg = [
+            'new_pwd.confirm' => __('Password and confirm password don\'t match')
+        ];
+        $data = [
+            'new_pwd'       => $new_pwd,
+            'confirm_pwd'   => $confirm_pwd,
+        ];
+        $field = [
+            'new_pwd'   => __('新资金密码'),
+            'confirm_pwd' => __('新密码')
+        ];
+        $validate = new Validate($rule, $msg, $field);
+        $result = $validate->check($data);
+        if (!$result) {
+            $this->error(__($validate->getError()));
+        }
+
+        $info = Cache::get($token);
+        if(empty($info)){
+            $this->error(__('操作超时'));
+        }
+        Db::startTrans();
+        try {
+            $salt = Random::alnum();
+            $new_password = $this->auth->getEncryptPassword($new_pwd, $salt);
+            UserModel::where($info)
+                ->update([
+                    'login_pwd' => $new_password,
+                    'salt' => $salt
+                ]);
+
+            Db::commit();
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        Cache::rm($token);//删除缓存
+        $this->success('');
+    }
     /**
      * 手机验证码登录
      *

+ 15 - 0
application/api/controller/Validate.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use app\common\model\User;
+use think\captcha\Captcha;
 
 /**
  * 验证接口
@@ -19,6 +20,20 @@ class Validate extends Api
         parent::_initialize();
     }
 
+    /**
+     * 获取验证码
+     *
+     * @ApiMethod (POST)
+     * @param string $email 邮箱
+     * @param string $id    排除会员ID
+     */
+    public function get_captcha()
+    {
+        $captcha = new Captcha();
+        return $captcha->entry();
+
+        return captcha_src();
+    }
     /**
      * 检测邮箱
      *

+ 5 - 0
application/api/lang/zh-cn.php

@@ -9,4 +9,9 @@ return [
     '余额不足'                                         => '您的可用余额不足',
     '资金密码有误'                                      => '资金密码不正确',
     'Please login first'                              => '请重新登录',
+    '验证码错误'                                        => '验证码错误',
+    '手机号码不存在'                                     => '手机号码不存在',
+    '账号锁定'                                          => '账号锁定,请联系客服',
+    '手机验证码错误'                                     => '手机验证码错误',
+    '操作超时'                                          => '操作超时',
 ];