Browse Source

用户接口,基础接口

lizhen_gitee 8 months ago
parent
commit
1d9ce27d19

+ 12 - 8
application/api/controller/Baseconfig.php

@@ -12,16 +12,8 @@ class Baseconfig extends Api
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
 
-   
-    public function index(){
 
-        $config = [
-            'kefu_user_ids'            => config('site.kefu_user_ids'),//在线客服人员
-            
-        ];
 
-        $this->success('success',$config);
-    }
 
 
     /**
@@ -81,6 +73,18 @@ class Baseconfig extends Api
         $this->success('success',$data);
     }
 
+//////////////////////////////上面没用到///////////////////////////
+
+    public function index(){
+
+        $config = [
+            'kefu_mobile' => config('site.kefu_mobile'),//客服电话
+
+        ];
+
+        $this->success('success',$config);
+    }
+
     //关键字过滤
     public function keyworld_config(){
         $config = config('keyworld');

+ 58 - 159
application/api/controller/User.php

@@ -28,36 +28,7 @@ class User extends Api
 
     }
 
-    /**
-     * 会员中心
-     */
-    public function index()
-    {
-        $this->success('', ['welcome' => $this->auth->nickname]);
-    }
 
-    /**
-     * 会员登录
-     *
-     * @ApiMethod (POST)
-     * @param string $account  账号
-     * @param string $password 密码
-     */
-    public function login()
-    {
-        $account = $this->request->post('account');
-        $password = $this->request->post('password');
-        if (!$account || !$password) {
-            $this->error(__('Invalid parameters'));
-        }
-        $ret = $this->auth->login($account, $password);
-        if ($ret) {
-            $data = ['userinfo' => $this->auth->getUserinfo()];
-            $this->success(__('Logged in successful'), $data);
-        } else {
-            $this->error($this->auth->getError());
-        }
-    }
 
     /**
      * 手机验证码登录
@@ -100,69 +71,6 @@ class User extends Api
 
 
     /**
-     * 退出登录
-     * @ApiMethod (POST)
-     */
-    public function logout()
-    {
-        if (!$this->request->isPost()) {
-            $this->error(__('Invalid parameters'));
-        }
-        $this->auth->logout();
-        $this->success(__('Logout successful'));
-    }
-
-    /**
-     * 修改会员个人信息
-     *
-     * @ApiMethod (POST)
-     * @param string $avatar   头像地址
-     * @param string $username 用户名
-     * @param string $nickname 昵称
-     * @param string $bio      个人简介
-     */
-    public function profile()
-    {
-        $field_array = [
-            'avatar','mobile',
-        ];
-
-        $data = [];
-        foreach($field_array as $key => $field){
-
-            //前端传不了post,改了
-            /*if(!request()->has($field,'post')){
-                continue;
-            }*/
-            if(!input('?'.$field)){
-                continue;
-            }
-
-            $newone = input($field);
-
-            if($field == 'avatar'){
-                $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
-            }
-
-            $data[$field] = $newone;
-        }
-
-        //dump($data);
-        if(empty($data)){
-            $this->success();
-        }
-
-        //修改用户
-        $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
-        if($update_rs === false){
-            $this->error('修改资料失败');
-        }
-
-        $this->success();
-    }
-
-
-    /**
      * 修改手机号
      *
      * @ApiMethod (POST)
@@ -199,71 +107,10 @@ class User extends Api
 
 
     /**
-     * 重置密码
-     *
-     * @ApiMethod (POST)
-     * @param string $mobile      手机号
-     * @param string $newpassword 新密码
-     * @param string $captcha     验证码
-     */
-    public function resetpwd()
-    {
-        $type = $this->request->post("type", "mobile");
-        $mobile = $this->request->post("mobile");
-        $email = $this->request->post("email");
-        $newpassword = $this->request->post("newpassword");
-        $captcha = $this->request->post("captcha");
-        if (!$newpassword || !$captcha) {
-            $this->error(__('Invalid parameters'));
-        }
-        //验证Token
-        if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
-            $this->error(__('Password must be 6 to 30 characters'));
-        }
-        if ($type == 'mobile') {
-            if (!Validate::regex($mobile, "^1\d{10}$")) {
-                $this->error(__('Mobile is incorrect'));
-            }
-            $user = \app\common\model\User::getByMobile($mobile);
-            if (!$user) {
-                $this->error(__('User not found'));
-            }
-            $ret = Sms::check($mobile, $captcha, 'resetpwd');
-            if (!$ret) {
-                $this->error(__('Captcha is incorrect'));
-            }
-            Sms::flush($mobile, 'resetpwd');
-        } else {
-            if (!Validate::is($email, "email")) {
-                $this->error(__('Email is incorrect'));
-            }
-            $user = \app\common\model\User::getByEmail($email);
-            if (!$user) {
-                $this->error(__('User not found'));
-            }
-            $ret = Ems::check($email, $captcha, 'resetpwd');
-            if (!$ret) {
-                $this->error(__('Captcha is incorrect'));
-            }
-            Ems::flush($email, 'resetpwd');
-        }
-        //模拟一次登录
-        $this->auth->direct($user->id);
-        $ret = $this->auth->changepwd($newpassword, '', true);
-        if ($ret) {
-            $this->success(__('Reset password successful'));
-        } else {
-            $this->error($this->auth->getError());
-        }
-    }
-
-    ///////////////////////////////////////////
-
-    /**
      * 微信小程序登录+注册
-     * code得到注册手机号
+     * code得到注册手机号,此手机号登录+注册
      */
-    public function wxregmobile_login(){
+    public function wxmini_regmobile_login(){
         $code = input('code');
         if (!$code) {
             $this->error(__('Invalid parameters'));
@@ -297,11 +144,65 @@ class User extends Api
         }
     }
 
+    //////////////////////上面的没用到/////////////////////
+
+
+    /**
+     * 退出登录
+     * @ApiMethod (POST)
+     */
+    public function logout()
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__('Invalid parameters'));
+        }
+        $this->auth->logout();
+        $this->success(__('Logout successful'));
+    }
+
+    /**
+     * 修改会员个人信息
+     *
+     * @ApiMethod (POST)
+     * @param string $avatar   头像地址
+     * @param string $username 用户名
+     * @param string $nickname 昵称
+     * @param string $bio      个人简介
+     */
+    public function profile()
+    {
+
+        $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
+        $mobile = input('mobile', '');
+
+        if(empty($avatar) && empty($mobile)){
+            $this->success();
+        }
+
+        if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $this->auth->id)->find()) {
+            $this->error(__('Mobile already exists'));
+        }
+
+        //修改用户
+        $data = [
+            'avatar' => $avatar,
+            'mobile' => $mobile,
+        ];
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
+        if($update_rs === false){
+            $this->error('修改资料失败');
+        }
+
+        $this->success();
+    }
+
+
+
     /**
      * 微信小程序登录+注册
      * code得到openid
      */
-    public function wxmini_login() {
+    public function wxmini_openid_login() {
         $code = input('code');
         if (!$code) {
             $this->error(__('Invalid parameters'));
@@ -338,7 +239,6 @@ class User extends Api
         }
 
     }
-
     /**
      * json 请求
      * @param $url
@@ -355,9 +255,8 @@ class User extends Api
         return json_decode($output, true);
     }
 
-
     //用户详细资料
-    public function getUserinfo(){
+    public function getuserinfo(){
         $info = $this->auth->getUserinfo();
 
         $this->success(__('success'),$info);

+ 1 - 0
application/extra/site.php

@@ -44,4 +44,5 @@ return array (
   ),
   'apisite_switch' => '1',
   'apisite_notice' => '全站维护中',
+  'kefu_mobile' => '400-1234-1234',
 );