コード例 #1
0
ファイル: SetBaseInfo.php プロジェクト: fu-tao/meelier_c
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return;
     }
     $area = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'persional_sign'];
     $field = $this->getDataItem('field');
     //字段
     $value = Keyword::Filter($this->getDataItem('value', ''));
     //值
     if ($field == "persional_sign") {
         if ($this->count_string_len($value) > 40) {
             return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '个性签名字数超过了40个字符');
         } else {
             $value = base64_encode(serialize($value));
         }
     }
     if (!in_array($field, $area)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '字段名不存在.');
     }
     $fieldsArr = ['user_cover' => 'user_cover', 'user_nickname' => 'user_nickname', 'user_gender' => 'user_gender', 'user_birthday' => 'user_birthday', 'user_realname' => 'user_realname', 'persional_sign' => 'persional_sign', 'user_district' => 'user_district', 'user_money' => 'user_money', 'user_money_virtual' => 'user_money_virtual', 'user_mobile' => 'user_account'];
     $user = UserBase::findFirst('user_id=' . $this->getUserAuth()->userId);
     $f = $fieldsArr[$field];
     if ($field == 'user_cover') {
         $up = new UploadPic();
         $value = $up->userCover();
         if ($value == false) {
             return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '文件流不能为空.');
         }
     }
     $user->{$f} = $value;
     if ($user->save()) {
         $this->success = 1;
         $this->message = $field . ' 更新成功';
     }
     $this->setResult(['success' => $this->success, 'message' => $this->message]);
 }
コード例 #2
0
 /**
  * 更新用户信息
  * @date: 2016-1-5 
  * @author: futao
  */
 public function editsaveAction()
 {
     $req = $this->request;
     $district = $req->getPost('district', null, '');
     $nickname = $req->getPost('nickname', null, '');
     $realname = $req->getPost('realname', null, '');
     $phone = $req->getPost('phone', null, '');
     $persional_sign = $req->getPost('persional_sign', null, '');
     $birthday = $req->getPost('birthday', null, '');
     $userId = intval($req->getPost('user_id', null, 0));
     $gender = $req->getPost('sex', null, 2);
     $experience = $req->getPost("experience", null, '');
     //从业经验
     $field = $req->getPost("field", null, '');
     //擅长领域
     $experttitle = $req->getPost("experttitle", null, '');
     //专家头衔
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $usermodel = UserBase::findFirst("user_id = {$userId} and is_manage = 1");
     if (!$usermodel) {
         $echo("用户不存在!");
         return;
     }
     if ($field == "" || !is_array($field)) {
         $echo("擅长领域必填!");
         return;
     }
     $data = ['experience' => $experience, 'experttitle' => $experttitle, 'field' => $field];
     $datajson = json_encode($data);
     $info = UserAttribute::findFirst("user_id = {$userId} and attr_type = 103");
     $info->attr_value_json = $datajson;
     $info->save();
     //用户头像
     if ($_FILES['avatar']['name'] != '') {
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $cover = $uploadFile->userCover();
         if ($cover == false) {
             if ($_FILES['avatar']['error'] == 1) {
                 $echo('封面大小超过了2M!');
             } else {
                 $echo('封面必须上传!');
             }
             return;
         }
         $usermodel->user_cover = $cover;
     }
     $usermodel->user_district = $district;
     $usermodel->user_nickname = $nickname;
     $usermodel->user_realname = $realname;
     $usermodel->bind_phone = $phone;
     //个性签名编码
     if ($persional_sign != '') {
         $usermodel->persional_sign = base64_encode(serialize($persional_sign));
     }
     //$usermodel->persional_sign=$persional_sign;
     $usermodel->user_birthday = $birthday;
     $usermodel->user_gender = $gender;
     if ($usermodel->save()) {
         $echo('ok', true);
     } else {
         $echo("添加失败!");
     }
 }
コード例 #3
0
ファイル: SetBaseInfo.php プロジェクト: fu-tao/meelier_c2.0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $area = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'persional_sign'];
     $field = $this->getDataItem('field');
     //字段
     $value = trim($this->getDataItem('value', ''));
     //值
     if (!in_array($field, $area)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '字段名不存在.');
     }
     if ($user = UserBase::findFirst('user_id=' . $this->getUserAuth()->userId)) {
         if ($field == 'user_cover') {
             $up = new UploadPic();
             $user->user_cover = $up->userCover();
             if (!$user->user_cover) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '文件流不能为空.');
             }
             $value = PicUrl::UserCover($user->user_cover, $this->getDi());
         } elseif ($field == 'user_district') {
             if (!is_numeric($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '城市格式错误.');
             }
             if (!\Apps\Common\Models\SysAreaZipDistrictPhonecode::count('K_ID = ' . $value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '城市不存在.');
             }
             $user->user_district = $value;
             // 获取城市信息
             $city = (new SysAreaZipDistrictPhonecode())->getOne($value);
             $value = $city['FULL_NAME'] ?: '';
         } elseif ($field == 'persional_sign') {
             if ($value && $this->utf8_strlen($value) > 30) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '个性签名字数超过了30个字符');
             } else {
                 $user->persional_sign = $value ? base64_encode(serialize($value)) : '';
             }
         } elseif ($field == 'user_nickname') {
             $nicknameLength = $this->utf8_strlen($value);
             if ($nicknameLength < 1 || $nicknameLength > 10) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '昵称长度需在1~10字节之间');
             }
             $user->user_nickname = $value;
         } elseif ($field == 'user_realname') {
             if (empty($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '姓名不能为空');
             }
             if ($this->utf8_strlen($value) > 10) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '姓名不能超过10个字符');
             }
             $user->user_realname = $value;
         } elseif ($field == 'user_gender') {
             if (!in_array($value, ['0', '1', '2'])) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '请输入正确的性别');
             }
             $user->user_gender = $value;
         } elseif ($field == 'user_birthday') {
             if (!$this->validateDate($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '日期格式错误');
             }
             $user->user_birthday = $value;
         }
         if ($user->save()) {
             $this->setResult(['success' => 1, 'message' => $field . ' 更新成功', 'value' => $value]);
             return true;
         }
     }
     $this->setResult(['success' => 0, 'message' => '更新失败', 'value' => '']);
 }