123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\api\controller;
- use app\common\constant\CommonConstant;
- use app\common\service\UserService;
- 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("avatar", type="string", desc="头像地址")
- * @Apidoc\Returned("nickname", type="string", desc="昵称")
- * @Apidoc\Returned("name", type="string", desc="姓名")
- * @Apidoc\Returned("mobile", type="string", desc="手机号码")
- * @Apidoc\Returned("department", type="string", desc="部门(多个部门以逗号分隔)")
- * @Apidoc\Returned("title", type="string", desc="职位")
- * @Apidoc\Returned("signature", type="string", desc="个人签名")
- * @Apidoc\Returned("signature_status", type="string", desc="签名状态:1=未操作,2=待审核,3=审核通过,4=审核驳回")
- * @Apidoc\Returned("department_list", type="array", desc="部门列表")
- * @Apidoc\Returned("subject", type="string", desc="主体名称")
- * @Apidoc\Returned("subject_image", type="string", desc="主体图片")
- */
- public function user_info()
- {
- $user = $this->user;
- unset($user['status'],$user['is_deleted'],$user['create_at']);
- $department_data = UserService::get_user_department_list($user['department']);;
- $user['department_list'] = $department_data;
- $user['subject'] = sysconf('subject');
- $user['subject_image'] = sysconf('subject_image');
- $this->success('获取成功', $user);
- }
- /**
- * 编辑个人信息
- *
- * @Apidoc\Method("POST")
- * @Apidoc\Param("type", type="integer", require=true, desc="类型:1=头像地址,2=昵称,3=手机号码,4=签名")
- * @Apidoc\Param("avatar", type="string", require=false, desc="头像地址")
- * @Apidoc\Param("nickname", type="string", require=false, desc="昵称")
- * @Apidoc\Param("mobile", type="string", require=false, desc="手机号码")
- * @Apidoc\Param("signature", type="string", require=false, desc="签名")
- */
- public function edit()
- {
- $type = input('type') ?: 0;
- $avatar = input('avatar') ?: '';
- $nickname = input('nickname') ?: '';
- $mobile = input('mobile') ?: '';
- $signature = input('signature') ?: '';
- $data = [];
- switch ($type){
- case 1:
- if (!$avatar) {
- $this->error('请上传头像');
- }
- break;
- case 2:
- if (!$nickname) {
- $this->error('请输入昵称');
- }
- break;
- case 3:
- if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
- $this->error('手机号格式不正确');
- }
- break;
- case 4:
- if (!$signature) {
- $this->error('请上传签名');
- }
- break;
- }
- if ($avatar) {
- $data['avatar'] = $avatar;
- }
- if ($nickname) {
- $data['nickname'] = $nickname;
- }
- if ($mobile) {
- if (!preg_match("/^1[23456789]\d{9}$/", $mobile)) {
- $this->error('手机号格式不正确');
- }
- $data['mobile'] = $mobile;
- }
- if ($signature) {
- $data['signature'] = $signature;
- $data['signature_status'] = CommonConstant::SIGNATURE_STATUS_2;
- }
- if ($data) {
- $user = $this->user;
- $user->save($data);
- }
- $this->success('编辑成功');
- }
- }
|