1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\api\controller;
- use think\Db;
- use app\common\model\User;
- use hg\apidoc\annotation as Apidoc;
- /**
- * @Apidoc\Title("个人中心")
- * @Apidoc\Group("api")
- * @Apidoc\Sort("2")
- */
- class Member extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
- /**
- * 获取个人信息
- *
- * @Apidoc\Method("POST")
- * @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()
- {
- $user = $this->user;
- $this->success('获取成功',$user);
- }
- /**
- * 编辑个人信息
- *
- * @Apidoc\Method("POST")
- * @Apidoc\Param("type", type="int", require=true, desc="修改的类型(1:昵称,2:签名,3:手机号)")
- * @Apidoc\Param("nickname", type="string", desc="昵称")
- * @Apidoc\Param("signature", type="string", desc="签名")
- * @Apidoc\Param("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('编辑成功');
- }
- }
|