123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace app\api\controller;
- use app\common\model\UserLevelRank;
- use app\common\model\UserMessage;
- use app\common\validate\UserVali;
- use think\Db;
- use app\common\model\User;
- /**
- * @title 会员个人中心
- * @controller UserCenter
- * @group base
- */
- class UserCenter extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * @title 获取个人信息
- * @desc 个人信息
- * @author qc
- * @url /api/User_center/getUserInfo
- * @method GET
- * @tag 个人信息
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:会员id
- * @return name:phone type:int default:-- desc:手机号
- * @return name:openid type:string default:-- desc:openid
- * @return name:name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像地址
- *
- */
- public function getUserInfo()
- {
- $field = 'id,phone,name,level_id,headimg,openid';
- $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray();
- $this->success('获取成功',['detail'=>$user_info]);
- }
- /**
- * @title 编辑个人信息
- * @desc 编辑个人信息
- * @author qc
- * @url /api/User_center/updateUserInfo
- * @method POST
- * @tag 编辑信息
- * @header name:Authorization require:1 desc:Token
- * @param name:name type:string default:-- desc:昵称
- * @param name:headimg type:string default:-- desc:头像地址
- * @return name:id type:int default:-- desc:会员id
- * @return name:phone type:int default:-- desc:手机号
- * @return name:openid type:string default:-- desc:openid
- * @return name:name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像地址
- */
- public function updateUserInfo()
- {
- $headimg = input('post.headimg');
- $name = trim(input('post.name',''));
- $update_data= [];
- $update_data['name'] = $name;
- $update_data['headimg'] = $headimg;
- Db::name('store_member')->where('id',$this->user_id)->update($update_data);
- $field = 'id,phone,name,headimg,openid';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
- $this->success('编辑成功',['detail'=>$user_info]);
- }
- /**
- * @title 绑定手机号
- * @desc 绑定手机号
- * @author qc
- * @url /api/User_center/modifyPhone
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:phone type:int require:1 default:-- desc:手机号
- * @param name:code type:int require:1 default:-- desc:手机号验证码
- * @return name:phone type:int default:-- desc:手机号
- * @return name:name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像地址
- */
- public function modifyPhone()
- {
- $uid = $this->user_id;
- $phone = input('post.phone');
- $code = input('post.code');
- if(empty($phone) || empty($code) ) $this->error('参数错误');
- $field = 'id,phone,name,headimg';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->user_id)->find();
- if($user_info['phone'] == $phone)$this->error('更换手机号与绑定手机号一致!');
- $check_code = $this->checkPhoneCode($phone,$code);
- if(!$check_code) $this->error('验证码错误');
- //判断手机号是否已注册
- $member_id = Db::name('store_member')
- ->where('phone','=',$phone)->where('is_deleted','=',0)->where('id','<>',$this->user_id)->value('id');
- if($member_id) $this->error('手机号已注册过');
- Db::name('store_member')->where('id',$uid)->update(['phone'=>$phone]);
- $user_info['phone'] = $phone;
- $this->updatePhoneCode($check_code);
- $this->success('绑定成功',$user_info);
- }
- }
|