Browse Source

用户接口

lizhen_gitee 6 months ago
parent
commit
a69c057570

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

@@ -55,76 +55,43 @@ class User extends Api
      */
     public function profile()
     {
-        $user = $this->auth->getUser();
-        $username = $this->request->post('username');
-        $nickname = $this->request->post('nickname');
-        $bio = $this->request->post('bio');
-        $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
-        if ($username) {
-            $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
-            if ($exists) {
-                $this->error(__('Username already exists'));
-            }
-            $user->username = $username;
-        }
-        if ($nickname) {
-            $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
-            if ($exists) {
-                $this->error(__('Nickname already exists'));
-            }
-            $user->nickname = $nickname;
-        }
-        $user->bio = $bio;
-        $user->avatar = $avatar;
-        $user->save();
-        $this->success();
-    }
+        $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
+        $nickname = input('nickname', '');
+        $mobile = input('mobile', '');
 
-    /**
-     * 微信小程序登录+注册
-     * code得到openid
-     */
-    public function wxmini_openid_login() {
-        $code = input('code');
-        if (!$code) {
-            $this->error(__('Invalid parameters'));
-        }
+        //修改用户
+        $data = [];
 
-        $config = config('wxMiniProgram');
-        $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
-        $openidInfo = $this->getJson($getopenid);
-        if(!isset($openidInfo['openid'])) {
-            $this->error('用户openid获取失败',$openidInfo);
+        if(!empty($avatar))
+        {
+            $data['avatar'] = $avatar;
         }
 
-        $openid  = $openidInfo['openid'];
-        if (!$openid) {
-            $this->error('用户openid获取失败');
+        if(!empty($mobile))
+        {
+            if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $this->auth->id)->find()) {
+                $this->error('手机号已被占用');
+            }
+            $data['mobile'] = $mobile;
         }
 
-        //用户信息
-        $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
+        if(!empty($nickname))
+        {
+            $data['nickname'] = $nickname;
+        }
 
-        if($userInfo) {
-            if ($userInfo['status'] == 0) {
-                $this->error('账号已被禁用');
-            }
-            if ($userInfo['status'] == -1) {
-                $this->error('账号已被注销');
+        if(!empty($data)){
+            $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
+            if($update_rs === false){
+                $this->error('修改资料失败');
             }
-            //如果已经有账号则直接登录
-            $res = $this->auth->direct($userInfo['id']);
-        } else {
-            $res = $this->auth->openid_register($openid);
-        }
-        if($res) {
-            $this->success("登录成功!",$this->auth->getUserinfo());
-        } else {
-            $this->error($this->auth->getError());
         }
 
+        $this->success();
     }
 
+
+
     /**
      * 微信小程序登录+注册
      * code得到注册手机号,此手机号登录+注册
@@ -182,6 +149,52 @@ class User extends Api
     ////////////////////////////////下面的都没用到///////////////////////////////
 
     /**
+     * 微信小程序登录+注册
+     * code得到openid
+     * 没用到
+     */
+    public function wxmini_openid_login() {
+        $code = input('code');
+        if (!$code) {
+            $this->error(__('Invalid parameters'));
+        }
+
+        $config = config('wxMiniProgram');
+        $getopenid = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['appid'].'&secret='.$config['secret'].'&js_code='.$code.'&grant_type=authorization_code';
+        $openidInfo = $this->getJson($getopenid);
+        if(!isset($openidInfo['openid'])) {
+            $this->error('用户openid获取失败',$openidInfo);
+        }
+
+        $openid  = $openidInfo['openid'];
+        if (!$openid) {
+            $this->error('用户openid获取失败');
+        }
+
+        //用户信息
+        $userInfo = Db::name('user')->where(['mini_openid'=>$openid])->find();
+
+        if($userInfo) {
+            if ($userInfo['status'] == 0) {
+                $this->error('账号已被禁用');
+            }
+            if ($userInfo['status'] == -1) {
+                $this->error('账号已被注销');
+            }
+            //如果已经有账号则直接登录
+            $res = $this->auth->direct($userInfo['id']);
+        } else {
+            $res = $this->auth->openid_register($openid);
+        }
+        if($res) {
+            $this->success("登录成功!",$this->auth->getUserinfo());
+        } else {
+            $this->error($this->auth->getError());
+        }
+
+    }
+
+    /**
      * 会员中心
      */
     public function index()

+ 2 - 2
application/config.php

@@ -367,9 +367,9 @@ return [
         ],
 
     //各种url
-    'pay_notify_url' => 'https://*.huxiukeji.cn',  //支付异步回调域名
+    'pay_notify_url' => 'https://youting.huxiukeji.cn',  //支付异步回调域名
 
     //默认头像
-    'user_default_avatar' => '/assets/img/avatar.png',
+    'default_avatar' => '/assets/img/default_avatar.png',
 
 ];

+ 1 - 1
application/extra/site.php

@@ -1,7 +1,7 @@
 <?php
 
 return array (
-  'name' => '最新版2024',
+  'name' => '游艇预约',
   'beian' => '',
   'cdnurl' => '',
   'version' => '1.0.3',

+ 1 - 1
application/extra/upload.php

@@ -9,7 +9,7 @@ return [
     /**
      * CDN地址
      */
-    'cdnurl'    => '',
+    'cdnurl'    => 'https://youtingmini.oss-cn-shenzhen.aliyuncs.com',
     /**
      * 文件保存格式
      */

BIN
public/assets/img/default_avatar.png