where('id',$this->user_id)->find()->toArray(); if($user_info['account_type'] == 2 || ($user_info['account_type']== 1 && $user_info['is_first'])){ $user_level = UserLevelRank::field('r.id,r.level_id,r.end_time,r.end_date,l.name,l.logo') ->alias('r') ->leftJoin('UserLevel l','l.id = r.level_id') ->where([['r.user_id','=',$this->user_id],['r.end_time','>',time()]])->order('r.level_id desc')->find(); }else{ $user_level = UserLevelRank::field('r.id,r.level_id,r.end_time,r.end_date,l.name,l.logo') ->alias('r') ->leftJoin('UserLevel l','l.id = r.level_id') ->where([['r.user_id','=',$user_info['group_first']],['r.end_time','>',time()]])->order('r.level_id desc')->find(); } $this->success('获取成功',['detail'=>$user_info,'user_level'=>$user_level ? $user_level->toArray() :null]); } /** * @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:头像地址 */ 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 = 'phone,name,headimg'; $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); } /** * @title 更换或设置登录密码 * @desc 更换或设置登录密码 * @author qc * @url /api/User_center/modifyPassword * @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:手机号验证码 * @param name:password type:string default:-- desc:密码 */ public function modifyPassword() { $uid = $this->user_id; $phone = input('post.phone'); $code = input('post.code'); $password = input('post.password'); if(empty($phone) || empty($code) || empty($password) ) $this->error('参数错误'); $field = 'id,phone'; $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray(); if(!$user_info['phone']) $this->error('请先绑定手机号'); if($user_info['phone'] != $phone) $this->error('与绑定手机号不一致'); $check_code = $this->checkPhoneCode($phone,$code); if(!$check_code) $this->error('验证码错误'); $validate = new UserVali(); if (!$validate->scene('reset_password')->check(['phone'=>$phone,'password'=>$password])) { $this->error($validate->getError()); } $encryption_password = encrypt_password($password); User::where('id',$uid)->update(['password'=>$password,'encryption_password'=>$encryption_password]); $this->updatePhoneCode($check_code); $this->success('更换成功'); } /** * @title 完善用户openid * @desc 完善用户openid * @author qc * @method POST * @tag 编辑信息 * @url /api/User_center/saveOpenid * @header name:Authorization require:1 desc:Token * @param name:code type:string require:1 default:-- desc:code */ public function saveOpenid() { $code = input('post.code'); if (empty($code)) $this->error('参数错误'); $res = http_get('https://api.weixin.qq.com/sns/oauth2/access_token?appid='.config('app.official_account')['appid'].'&secret='.config('app.official_account')['secret'].'&code='.$code.'&grant_type=authorization_code'); $res = json_decode($res,true); if (empty($res['openid'])) $this->error('未获取到openid'); $member_data = ['openid' => $res['openid']]; Db::name('store_member')->where('id',$this->user_id)->update($member_data); $this->success('已绑定openid'); } /** * @title 消息列表【会员消息】 * @desc 我的点赞 * @author qc * @method GET * @url /api/User_center/getMessageList * @header name:Authorization require:1 desc:Token * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:-- desc:页数 * @param name:page_num type:int default:-- desc:每页数 * * @return name:id type:int default:-- desc:记录id * @return name:title type:string default:-- desc:标题 * @return name:content type:string default:-- desc:内容 * @return name:create_at type:string default:-- desc:时间 * @return name:is_read type:int default:-- desc:是否已读【0否1是】 */ public function getMessageList() { $list = UserMessage::where(['user_id'=>$this->user_id]) ->limit($this->off_set,$this->page_num) ->order(['id'=>'desc']) ->select()->toArray(); $this->success('ok',['list'=>$list]); } /** * @title 消息详情【会员消息】 * @desc 消息详情 * @author qc * @method GET * @url /api/User_center/getMessageInfo * @header name:Authorization require:1 desc:Token * @param name:id type:int default:-- desc:消息记录id * @return name:title type:string default:-- desc:标题 * @return name:content type:string default:-- desc:内容 * @return name:create_at type:string default:-- desc:时间 * @return name:is_read type:int default:-- desc:是否已读【0否1是】 */ public function getMessageInfo() { $detail= UserMessage::where(['user_id'=>$this->user_id,'id'=>input('get.id')])->find()->toArray(); $this->success('ok',['detail'=>$detail]); } }