123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?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/Usercenter/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:synopsis type:string default:-- desc:个人简介
- * @return name:background type:string default:-- desc:个人中心背景图片地址
- * @return name:password type:string default:-- desc:不加密
- * @return name:decode_password type:string default:-- desc:加密后
- * @return name:true_name type:string default:-- desc:真实姓名
- */
- public function getUserInfo()
- {
- $uid = $this->uid;
- $field = 'phone,name,headimg,synopsis,status,background,decode_password,password,true_name';
- $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('该用户已被禁用');
- $this->success('获取成功',$user_info);
- }
- /**
- * @title 编辑个人信息
- * @desc 编辑个人信息
- * @author qc
- * @url /api/Usercenter/updateUserInfo
- * @method POST
- * @tag 编辑信息
- * @header name:Authorization require:1 desc:Token
- * @param name:type type:int require:1 default:1 desc:修改的类型(1:昵称,2:头像)
- * @param name:name type:string require:0 default:-- desc:姓名(type为1时必传)
- * @param name:synopsis type:string require:0 default:-- desc:个人简介(type为2时必传)
- * @param name:headimg type:string require:0 default:-- desc:头像地址(type为3时必传)
- * @return name:phone type:int default:-- desc:手机号
- * @return name:name type:string default:-- desc:姓名
- * @return name:headimg type:string default:-- desc:头像地址
- * @return name:synopsis type:string default:-- desc:个人简介
- * @return name:background type:string default:-- desc:个人中心背景图片地址
- * @return name:password type:string default:-- desc:不加密
- * @return name:decode_password type:string default:-- desc:加密后
- * @return name:true_name type:string default:-- desc:真实姓名
- */
- public function updateUserInfo()
- {
- $type = input('post.type',1);
- $headimg = input('post.headimg');
- $name = input('post.name');
- if(!in_array($type,[1,2])) $this->error('参数错误');
- $update_data= [];
- if($type == 1 && $name) $update_data['name'] = $name;
- if($type == 2 && $headimg) $update_data['headimg'] = $headimg;
- if(empty($update_data)) $this->error('参数错误');
- Db::name('store_member')->where('id',$this->uid)->update($update_data);
- $field = 'phone,name,headimg,synopsis,status,background,decode_password,password';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- $this->success('编辑成功',$user_info);
- }
- /**
- * @title 绑定手机号
- * @desc 绑定手机号
- * @author qc
- * @url /api/Usercenter/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:手机号验证码
- * @param name:true_name type:string require:1 default:-- desc:真实姓名
- * @param name:password type:string 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:synopsis type:string default:-- desc:个人简介
- * @return name:background type:string default:-- desc:个人中心背景图片地址
- * @return name:password type:string default:-- desc:不加密
- * @return name:decode_password type:string default:-- desc:加密后
- * @return name:true_name type:string default:-- desc:真实姓名
- */
- public function modifyPhone()
- {
- $uid = $this->uid;
- $phone = input('post.phone');
- $code = input('post.code');
- $password = input('post.password');
- $true_name = input('post.true_name');
- if(empty($phone) || empty($code) || !$password || !$true_name) $this->error('参数错误');
- $store_member_sms = Db::name('store_member_sms')
- ->field('id,code')->where('phone',$phone)
- ->where('used',0)->order('id desc')
- ->find();
- // if($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('手机号已注册过');
- $up = [
- 'phone'=>$phone,
- 'password'=>$password,
- 'decode_password'=>md5($password),
- 'true_name'=>$true_name
- ];
- $res = Db::name('store_member')->where('id',$uid)->update($up);
- $field = 'phone,name,headimg,synopsis,status,background,decode_password,password';
- $user_info = Db::name('store_member')->field($field)->where('id',$this->uid)->find();
- if($res !==false){
- Db::name('store_member_sms')->where('id',$store_member_sms['id'])->update(['used'=>1]);
- $this->success('绑定成功',$user_info);
- }else{
- $this->error('绑定失败');
- }
- }
- /**
- * @title 发送短信验证码
- * @desc 发送短信验证码
- * @author QGF
- * @url /api/Usercenter/sendSms
- * @method POST
- * @tag 短信验证码
- * @param name:phone type:int require:1 default:-- desc:要获取验证码的手机号
- * @return name:code type:string default:-- desc:验证码
- */
- public function sendSms(){
- $phone = input('post.phone');
- if(empty($phone)) $this ->error('参数错误');
- $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
- AlibabaCloud::accessKeyClient('LTAI5tKATi9QpdtaBpEHeCP4', 'F8B77fPPitlfRScTuPmQxfphLRpt6a')
- ->regionId('cn-hangzhou')->asDefaultClient();
- try {
- $result = AlibabaCloud::rpc()
- ->product('Dysmsapi')
- ->version('2017-05-25')
- ->action('SendSms')
- ->method('POST')
- ->host('dysmsapi.aliyuncs.com')
- ->options([
- 'query' => [
- 'RegionId' => "cn-hangzhou",
- 'PhoneNumbers' => $phone,
- 'SignName' => "火星帝界",
- 'TemplateCode' => "SMS_223135158",
- 'TemplateParam' => json_encode(array("code"=>$code)),
- ],
- ])->request();
- $result = $result->toArray();
- if($result['Code'] == "OK")
- {
- $sms_data = array(
- 'phone'=>$phone,
- 'code'=>$code,
- 'result'=>$result['Message']
- );
- Db::name('store_member_sms')->insert($sms_data);
- $this->error('发送成功',$code);
- }else{
- $this->error('发送失败');
- }
- } catch (ClientException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- } catch (ServerException $e) {
- echo $e->getErrorMessage() . PHP_EOL;
- }
- }
- /**
- * @title 获取我的留言
- * @desc 获取我的留言
- * @author qc
- * @url /api/Usercenter/getMyMessage
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int : default:1 desc:页数
- * @param name:page_num type:int : default:20 desc:每页数
- * @return name:message type:string default:-- desc:留言内容
- * @return name:images type:string default:-- desc:留言图片,多张有逗号(,)隔开
- * @return name:create_at type:string default:-- desc:留言时间
- * @return name:headimg type:string default:-- desc:留言人头像
- * @return name:name type:string default:-- desc:留言人名称
- */
- public function getMyMessage()
- {
- $page = input('page',1);
- $page_num = input('page_num',20);
- $off_set = $page*$page_num - $page_num;
- $list = Db::table('ticket_note')->alias('n')
- ->field('n.id,n.message,n.images,n.create_at,m.headimg,m.name')
- ->join('store_member m','n.from_uid = m.id','LEFT')
- ->where(['from_uid'=>$this->uid,'n.status'=>1])
- ->order('n.id desc')
- ->limit($off_set,$page_num)
- ->select();
- $this->success('获取成功',$list);
- }
- /**
- * @title 留言
- * @desc 留言
- * @author qc
- * @url /api/Usercenter/leaveMessage
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:message type:string require:1 default:-- desc:留言内容
- * @param name:images type:string require:0 default:-- desc:影评图片(逗号隔开)
- * @param name:tel type:string require:0 default:-- desc:电话
- */
- public function leaveMessage()
- {
- $insert_data = [
- 'from_uid'=>$this->uid,
- 'to_uid'=>input('post.to_uid',0),
- 'message'=>input('post.message'),
- 'images'=>input('post.images'),
- 'tel'=>input('post.tel'),
- 'create_at'=>date('Y-m-d H:i:s')
- ];
- Db::table('ticket_note')->insert($insert_data);
- $this->success('留言成功',Db::getLastInsID());
- }
- }
|