Browse Source

修改用户个人资料,修改密码,充值密码,匹配

lizhen_gitee 3 years ago
parent
commit
087bd48cf0

+ 22 - 1
application/api/controller/Baseconfig.php

@@ -3,7 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-
+use think\Db;
 /**
  * 基础配置接口
  */
@@ -26,4 +26,25 @@ class Baseconfig extends Api
         $this->success('success',$config);
     }
 
+    //个人资料的一下枚举
+    public function userinfo_enum(){
+        $enum_hobby = Db::name('enum_hobby')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_job = Db::name('enum_job')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_marital = Db::name('enum_marital')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_education = Db::name('enum_education')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_tag = Db::name('enum_tag')->field('id,name')->order('weight desc,id desc')->select();
+        $enum_wages = Db::name('enum_wages')->field('id,name')->order('weight desc,id desc')->select();
+
+        $data = [
+            'enum_hobby' => $enum_hobby,
+            'enum_job' => $enum_job,
+            'enum_marital' => $enum_marital,
+            'enum_education' => $enum_education,
+            'enum_tag' => $enum_tag,
+            'enum_wages' => $enum_wages,
+        ];
+
+        $this->success('success',$data);
+    }
+
 }

+ 42 - 0
application/api/controller/Matching.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+
+/**
+ * 匹配接口
+ */
+class Index extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 视频匹配
+     *
+     */
+    public function get_video_user()
+    {
+        $gender = $this->auth->gender;
+        if($gender == 1){
+            $mapgender = 0;
+        }else{
+            $mapgender = 1;
+        }
+
+        $map = [
+            'status' => 1,
+            'gender' => $mapgender,
+        ];
+        $user = Db::name('user')->where($map)->orderby('rand()')->find();
+        $this->success('请求成功',$user);
+    }
+
+    /*
+     * 语音匹配
+     */
+    public function get_audio_user(){
+
+    }
+}

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

@@ -25,7 +25,7 @@ class Sms extends Api
     public function send()
     {
         $mobile = $this->request->post("mobile");
-        $event = $this->request->post("event");
+        $event = $this->request->post("event",'default');
         $event = $event ? $event : 'register';
 
         if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
@@ -74,7 +74,7 @@ class Sms extends Api
     public function check()
     {
         $mobile = $this->request->post("mobile");
-        $event = $this->request->post("event");
+        $event = $this->request->post("event",'default');
         $event = $event ? $event : 'register';
         $captcha = $this->request->post("captcha");
 

+ 63 - 14
application/api/controller/User.php

@@ -147,6 +147,7 @@ class User extends Api
             'truename' => $this->auth->truename,
             'nickname' => $this->auth->nickname,
             //'group_id' => $this->auth->group_id,
+            'alipay_account' => $this->auth->alipay_account,
             'idcard_status' => $this->auth->idcard_status,
             'bio' => $this->auth->bio,
             'birthday' => $this->auth->birthday,
@@ -157,13 +158,19 @@ class User extends Api
             'gender' => $this->auth->gender,
             'email' => $this->auth->email,
             'mobile' => $this->auth->mobile,
+            'setpassword' => $this->auth->password ? 1 : 0,
 //            'cover_image' => $this->auth->cover_image,
 //            'photo_images' => $this->auth->photo_images,
 //            'vip_endtime' => $this->auth->vip_endtime,
         ];
         //$info['is_vip'] = intval($info['vip_endtime']) - time() > 0 ? 1 : 0;
         $info['age'] = birthtime_to_age($info['birthday']);
-        //$info = info_domain_image($info,['avatar','cover_image','photo_images']);
+
+        $info = info_domain_image($info,['avatar']);
+
+        //实名过了才行
+        $info['truename'] = $info['idcard_status'] == 1 ? $info['truename'] : '';
+        $info['alipay_account'] = $info['idcard_status'] == 1 ? $info['alipay_account'] : '';
 
         if($type == 'return'){
             $info = array_merge($info, Token::get($this->auth->getToken())); //token 等多个字段
@@ -175,7 +182,7 @@ class User extends Api
 
     //实名认证信息
     public function idcard_confirm_info(){
-        $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->find();
+        $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
         $this->success('success',$check);
     }
 
@@ -184,16 +191,17 @@ class User extends Api
         $truename = input('truename','');
         $idcard = input('idcard','');
         $idcard_images = input('idcard_images','');
+        $alipay_account = input('alipay_account','');
 
-        if(empty($truename) || empty($idcard) || empty($idcard_images)){
+        if(empty($truename) || empty($idcard) || empty($idcard_images) || empty($alipay_account)){
             $this->error('实名认证信息必填');
         }
 
-        if($this->auth->idcardstatus == 1){
+        if($this->auth->idcard_status == 1){
             $this->error('您已经完成实名认证');
         }
 
-        if($this->auth->idcardstatus == 0){
+        if($this->auth->idcard_status == 0){
             $this->error('您已经提交实名认证,请等待审核');
         }
 
@@ -215,17 +223,17 @@ class User extends Api
             'truename' => $truename,
             'idcard' => $idcard,
             'idcard_images' => $idcard_images,
+            'alipay_account' => $alipay_account,
             'status' => 0,
             'createtime' => time(),
             'updatetime' => time(),
         ];
 
         //更新
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>0]);
         if(!empty($check)){
-            $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcardstatus'=>0]);
             $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
         }else{
-            $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcardstatus'=>0]);
             $rs = Db::name('user_idconfirm')->insertGetId($data);
         }
 
@@ -327,22 +335,30 @@ class User extends Api
      * 修改手机号
      *
      * @ApiMethod (POST)
-     * @param string $mobile  手机号
+     * @param string $mobile   手机号
      * @param string $captcha 验证码
      */
     public function changemobile()
     {
         $user = $this->auth->getUser();
-        $mobile = $this->request->post('mobile');
-        $captcha = $this->request->post('captcha');
-        if (!$mobile || !$captcha) {
+        $oldcaptcha = $this->request->request('oldcaptcha');
+        $mobile = $this->request->request('mobile');
+        $captcha = $this->request->request('captcha');
+        if (!$oldcaptcha || !$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
         if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }
-        if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
-            $this->error(__('Mobile already exists'));
+        if($user->mobile == $mobile){
+            $this->error('新手机号不能与旧手机号相同');
+        }
+        if (\app\common\model\User::where('mobile', $mobile)->find()) {
+            $this->error(__('Mobile already exist'));
+        }
+        $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
+        if (!$result) {
+            $this->error(__('Captcha is incorrect'));
         }
         $result = Sms::check($mobile, $captcha, 'changemobile');
         if (!$result) {
@@ -354,6 +370,7 @@ class User extends Api
         $user->mobile = $mobile;
         $user->save();
 
+        Sms::flush($user->mobile, 'changemobile');
         Sms::flush($mobile, 'changemobile');
         $this->success();
     }
@@ -400,7 +417,8 @@ class User extends Api
      */
     public function resetpwd()
     {
-        $type = $this->request->post("type");
+        //$type = $this->request->post("type");
+        $type = 'mobile';
         $mobile = $this->request->post("mobile");
         $email = $this->request->post("email");
         $newpassword = $this->request->post("newpassword");
@@ -444,4 +462,35 @@ class User extends Api
             $this->error($this->auth->getError());
         }
     }
+
+    /**
+     * 修改密码
+     *
+     * @ApiMethod (POST)
+     * @param string $newpassword 新密码
+     * @param string $oldpassword 旧密码
+     */
+    public function changepwd(){
+        $newpassword = input('post.newpassword');
+        $oldpassword = input('post.oldpassword','');
+
+        if (!$newpassword) {
+            $this->error(__('Invalid parameters'));
+        }
+        if($this->auth->password && empty($oldpassword)){
+            $this->error('原密码必填');
+        }
+
+        if(empty($this->auth->password)){
+            $ret = $this->auth->changepwd($newpassword, '', true);
+        }else{
+            $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
+        }
+
+        if ($ret) {
+            $this->success(__('Reset password successful'));
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 }

+ 4 - 0
application/common/library/Sms.php

@@ -31,6 +31,7 @@ class Sms
      */
     public static function get($mobile, $event = 'default')
     {
+        $event = 'default';
         $sms = \app\common\model\Sms::
         where(['mobile' => $mobile, 'event' => $event])
             ->order('id', 'DESC')
@@ -49,6 +50,7 @@ class Sms
      */
     public static function send($mobile, $code = null, $event = 'default')
     {
+        $event = 'default';
         $code = is_null($code) ? mt_rand(1000, 9999) : $code;
         $time = time();
         $ip = request()->ip();
@@ -90,6 +92,7 @@ class Sms
      */
     public static function check($mobile, $code, $event = 'default')
     {
+        $event = 'default';
         if($code == 9999){
             return true;
         }
@@ -127,6 +130,7 @@ class Sms
      */
     public static function flush($mobile, $event = 'default')
     {
+        $event = 'default';
         \app\common\model\Sms::
         where(['mobile' => $mobile, 'event' => $event])
             ->delete();