123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use think\Db;
- /**
- * @title 会员个人中心
- * @controller UserCenter
- * @group base
- */
- class UserCenter extends Base
- {
- public function initialize()
- {
- parent::check_login();
- }
- /**
- * @title 获取个人信息
- * @desc 个人信息
- * @author qc
- * @url /api/User_center/getUserInfo
- * @method GET
- * @tag 个人信息
- * @header name:Authorization require:1 desc:Token
- * @return name:phone type:int default:-- desc:手机号
- * @return name:name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像地址
- * @return name:crystal type:int default:-- desc:元石
- * @return name:true_name type:string default:-- desc:真实姓名
- * @return name:id_card type:string default:-- desc:身份证号
- * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
- * @return name:auth_at type:string default:-- desc:认证时间
- */
- public function getUserInfo()
- {
- $uid = $this->uid;
- $field = 'id,phone,name,headimg,status,crystal,openid,true_name,id_card,is_auth,auth_at';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if(empty($user_info)) $this->error('用户信息不正确');
- if($user_info['status'] == 0) $this->error('该用户已被禁用');
- $crystal_switch = intval(sysconf('crystal_switch'));
- $user_info['crystal_switch'] = $crystal_switch;
- $this->success('获取成功',$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:头像地址
- * @return name:crystal type:int default:-- desc:元石
- * @return name:true_name type:string default:-- desc:真实姓名
- * @return name:id_card type:string default:-- desc:身份证号
- * @return name:is_auth type:int default:-- desc:是否认证(0否1是)
- */
- public function modifyPhone()
- {
- $uid = $this->uid;
- $phone = input('post.phone');
- $code = input('post.code');
- if(empty($phone) || empty($code) ) $this->error('参数错误');
- $field = 'id,phone,name,headimg,status,crystal,openid,true_name,id_card,is_auth';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- if($user_info['phone'] == $phone)$this->error('更换手机号与绑定手机号一致!');
- $sel_time =date('Y-m-d H:i:s',time()-600);
- $store_member_sms = Db::name('store_member_sms')
- ->field('id,code')->where('phone',$phone)
- ->where('create_at','> time',$sel_time)
- ->where('used',0)->order('id desc')->find();
- if(empty($store_member_sms) || $store_member_sms['code'] != $code) $this->error('验证码错误');
- //判断手机号是否已注册
- $member_id = Db::name('store_member')
- ->where('phone','=',$phone)->where('id','<>',$this->uid)->value('id');
- if($member_id) $this->error('手机号已注册过');
- Db::name('store_member')->where('id',$uid)->update(['phone'=>$phone]);
- $user_info['phone'] = $phone;
- Db::name('store_member_sms')->where('id',$store_member_sms['id'])->update(['used'=>1]);
- $this->success('绑定成功',$user_info);
- }
- /**
- * @title 验证已绑定手机号是否正确
- * @desc 验证已绑定手机号是否正确
- * @author qc
- * @url /api/User_center/checkBindPhone
- * @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:手机号验证码
- */
- public function checkBindPhone()
- {
- $phone = input('post.phone');
- $code = input('post.code');
- if(empty($phone) || empty($code) ) $this->error('参数错误');
- $field = 'id,phone,name,headimg,status,crystal,openid,true_name,id_card,is_auth';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- if($user_info['phone'] != $phone) $this->error('该手机号与当前账户不一致!');
- $sel_time =date('Y-m-d H:i:s',time()-600);
- $store_member_sms = Db::name('store_member_sms')
- ->field('id,code')->where('phone',$phone)
- ->where('create_at','> time',$sel_time)
- ->where('used',0)->order('id desc')->find();
- if(empty($store_member_sms) || $store_member_sms['code'] != $code) $this->error('验证码错误');
- Db::name('store_member_sms')->where('id',$store_member_sms['id'])->update(['used'=>1]);
- $this->success('验证通过');
- }
- /**
- * @title 编辑个人信息
- * @desc 编辑个人信息
- * @author qc
- * @url /api/User_center/updateUserInfo
- * @method POST
- * @tag 编辑信息
- * @header name:Authorization require:1 desc:Token
- * @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',''));
- if(!$headimg && !$name) $this->error('参数错误');
- $update_data= [];
- $update_data['name'] = $name;
- $update_data['headimg'] = $headimg;
- if($name){
- $check_member = Db::name('store_member')->where('name',$name)->where('id','<>',$this->uid)->count();
- if($check_member) $this->error('该用户名已被占用');
- }
- Db::name('store_member')->where('id',$this->uid)->update($update_data);
- $field = 'phone,name,headimg';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- $this->success('编辑成功',$user_info);
- }
- /**
- * @title 会员认证
- * @desc 会员认证
- * @author qc
- * @method POST
- * @tag 编辑信息
- * @url /api/User_center/userCertification
- * @header name:Authorization require:1 desc:Token
- * @param name:true_name type:string require:1 default:-- desc:真实姓名
- * @param name:id_card type:string require:1 default:-- desc:身份证号
- */
- public function userCertification()
- {
- $true_name = input('post.true_name');
- $id_card = input('post.id_card');
- $is_auth = Db::table('store_member')->where('id',$this->uid)->value('is_auth');
- if($is_auth) $this->error('已认证');
- $get_age = $this->getAge($id_card);
- if($get_age < 18)$this->error('未满18周岁!');
- $res = user_certification($id_card,$true_name);
- if(!$res) $this->error('认证失败');
- Db::table('store_member')->where('id',$this->uid)->update(['is_auth'=>1,'true_name'=>$true_name,'id_card'=>$id_card,'auth_at'=>date('Y-m-d H:i:s')]);
- $this->success('认证成功');
- }
- /**
- * @param $id
- * @return false|string
- */
- function getAge($id){
- # 1.从身份证中获取出生日期
- $birth_Date = strtotime(substr($id, 6, 8));//截取日期并转为时间戳
- # 2.格式化[出生日期]
- $Year = date('Y', $birth_Date);//yyyy
- $Month = date('m', $birth_Date);//mm
- $Day = date('d', $birth_Date);//dd
- # 3.格式化[当前日期]
- $current_Y = date('Y');//yyyy
- $current_M = date('m');//mm
- $current_D = date('d');//dd
- # 4.计算年龄()
- $age = $current_Y - $Year;//今年减去生日年
- if($Month > $current_M || $Month == $current_M && $Day > $current_D){//深层判断(日)
- $age--;//如果出生月大于当前月或出生月等于当前月但出生日大于当前日则减一岁
- }
- # 返回
- return $age;
- }
- }
|