123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\api\controller;
- use think\Db;
- use app\common\model\User;
- use hg\apidoc\annotation as Apidoc;
- /**
- * @Apidoc\Title("个人中心")
- * @Apidoc\Group("api")
- */
- class Member extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * @Apidoc\Title("获取个人信息")
- * @Apidoc\Desc("个人信息")
- * @Apidoc\Method("GET")
- * @Apidoc\Author("HG")
- * @Apidoc\Tag("")
- * @Apidoc\Returned("phone", type="int", desc="手机号")
- * @Apidoc\Returned("name", type="string", desc="姓名")
- * @Apidoc\Returned("nickname", type="string", desc="昵称")
- * @Apidoc\Returned("headimg", type="string", desc="头像地址")
- * @Apidoc\Returned("title", type="string", desc="职称")
- * @Apidoc\Returned("department", type="string", desc="部门(多个部门以逗号分隔)")
- * @Apidoc\Returned("signature", type="string", desc="个人签名")
- */
- public function user_info()
- {
- $uid = $this->user_id;
- $field = 'phone,name,nickname,headimg,title,department,signature';
- $info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- $this->success('获取成功',$info);
- }
- /**
- * @Apidoc\Title("编辑个人信息")
- * @Apidoc\Desc("个人信息")
- * @Apidoc\Method("POST")
- * @Apidoc\Author("HG")
- * @Apidoc\Tag("")
- * @Apidoc\Query("type", type="int", require=true, desc="修改的类型(1:昵称,2:签名,3:手机号)")
- * @Apidoc\Query("nickname", type="string", desc="昵称")
- * @Apidoc\Query("signature", type="string", desc="签名")
- * @Apidoc\Query("phone", type="string", desc="手机号")
- */
- public function edit()
- {
- $uid = $this->user_id;
- $type = input('type');
- $nickname = input('nickname');
- $signature = input('signature');
- $phone = input('phone');
- if(!in_array($type,[1,2,3])){
- $this->error('参数错误');
- }
- if($type == 1){
- if(empty($nickname)){
- $this->error('参数错误');
- }
- $update_data['nickname'] = $nickname;
- }elseif ($type == 2){
- if(empty($signature)){
- $this->error('参数错误');
- }
- $update_data['signature'] = $signature;
- }elseif ($type == 2){
- if(empty($phone)){
- $this->error('参数错误');
- }
- if(!preg_match("/^1[23456789]\d{9}$/", $phone)){
- $this->error('手机号格式不正确');
- }
- $update_data['phone'] = $phone;
- }
- Db::name('store_member')->where('id',$uid)->update($update_data);
- $this->success('编辑成功');
- }
- }
|