Esempio n. 1
0
 public function run()
 {
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $mobile = $this->getDataItem('mobile', '');
     //帐号
     $smsCode = $this->getDataItem('sms_code', '');
     //短信验证
     $password = $this->getDataItem('password', '');
     if (empty($mobile) || empty($smsCode) || empty($password)) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少必传参数或者参数格式错误!');
     }
     if ($this->userInfoByAccount($mobile)) {
         $this->setResult(['success' => 100, 'message' => '手机号码已经使用过了.']);
         return false;
     }
     if (!MobileSMS::Check('update_mobile', $smsCode, $mobile, $this->apiAccessToken->id)) {
         $this->setResult(['success' => 101, 'message' => '短信验证码错误']);
         return false;
     }
     $UserBase = UserBase::findFirst('user_id = ' . $this->getUserAuth()->userId);
     if ($UserBase->user_account) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '已经绑定过的账号无法初始化账号信息!');
     }
     $UserBase->user_account = $mobile;
     $UserBase->bind_phone = $mobile;
     $UserBase->user_password = $this->hashPassword($password);
     if ($UserBase->save()) {
         $this->setResult(['success' => 1, 'message' => '绑定手机号码成功.']);
     } else {
         $this->setResult(['success' => 0, 'message' => '保存数据异常.']);
     }
 }
Esempio n. 2
0
 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]);
 }
Esempio n. 3
0
 /**
  * 修改问题
  * @date: 2016-1-12 
  * @author: futao
  */
 public function editAction()
 {
     $this->setLeftNav('edit');
     $req = $this->request;
     if (!$req->isPost()) {
         $id = intval($req->getQuery('id', null, 0));
         if ($id != '') {
             $info = Question::findFirst('question_id = ' . $id . ' and question_state = 1');
         }
         if (!$info) {
             echo "无效!";
             exit;
         }
         $user = UserBase::findFirst('user_id =' . $info->user_id);
         if (unserialize(base64_decode($info->question_content))) {
             $info->question_content = unserialize(base64_decode($info->question_content));
         }
         if (json_decode($info->question_pics)) {
             $info->question_pics = json_decode($info->question_pics);
         }
         //全部标签
         $allTag = BeautyParlorTagInfo::find("parent_id != 0");
         //已选择标签
         $questionTag = QuestionTag::find('question_id = ' . $info->question_id);
         //选择的标签转换成字符串
         foreach ($questionTag as $k => $v) {
             if ($k == 0) {
                 $tagIds = $v->tag_id;
             } else {
                 $tagIds = $tagIds . "," . $v->tag_id;
             }
         }
         $this->view->setVar('question_tag', $questionTag);
         $this->view->setVar('alltag', $allTag);
         $this->view->setVar('user', $user);
         $this->view->setVar('info', $info);
         $this->view->setVar('tagids', $tagIds);
         return;
     }
     $this->view->disable();
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $question_id = $req->getPost('question_id', null, 0);
     $question_browsers = $req->getPost('question_browsers', null, 0);
     $questionTag = $req->getPost('question_tag', null, '');
     //修改标签
     if ($questionTag != '' && is_array($questionTag)) {
         QuestionTag::find("question_id = {$question_id}")->delete();
         foreach ($questionTag as $val) {
             unset($tagId);
             unset($tagName);
             $tagArr = explode(',', $val);
             $tagId = $tagArr[0];
             $tagName = $tagArr[1];
             $tagNameArr[] = $tagName;
             $questionTagModel = new QuestionTag();
             $questionTagModel->question_id = $question_id;
             $questionTagModel->tag_id = $tagId;
             $questionTagModel->tag_name = $tagName;
             $questionTagModel->save();
         }
     }
     $allTag = BeautyParlorTagInfo::find("parent_id != 0")->toArray();
     if ($question_id > 0 && $question_browsers >= 0) {
         $questionModel = Question::findFirst("question_id = {$question_id} and question_state = 1");
         //////////////////////////question_tag字段重新赋值
         if (json_decode($questionModel->question_tag)) {
             $questionTagArr = json_decode($questionModel->question_tag);
             foreach ($allTag as $k => $v) {
                 foreach ($questionTagArr as $key => $val) {
                     if ($questionTagArr[$key] == $allTag[$k]['tag_title']) {
                         unset($questionTagArr[$key]);
                     }
                 }
             }
         }
         $questionTagArr = array_values($questionTagArr);
         foreach ($tagNameArr as $v) {
             $questionTagArr[] = $v;
         }
         ////////////////////////////////////////////////////////////
         $questionModel->question_tag = json_encode(array_unique($questionTagArr));
         $questionModel->question_browsers = $question_browsers;
         if ($questionModel->save()) {
             $echo("修改成功!", true);
         } else {
             $echo("修改失败!");
         }
     } else {
         $echo("参数错误!");
     }
 }
Esempio n. 4
0
 /**
  * 修改密码
  * @return $this|ResponseResult
  */
 public function setPasswdAction()
 {
     $req = $this->request;
     if ($req->isPost()) {
         $id = intval($req->getPost('id', null, 0));
         $pwd = $req->getPost('pwd');
         if (empty($pwd)) {
             return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常');
         }
         $info = UserBase::findFirst('user_id=' . $id);
         if ($info) {
             $info->update(['user_password' => UserCommon::hashPassword($pwd, $this->di)]);
         }
         return (new ResponseResult())->sendResult('ok');
     } else {
         return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常');
     }
 }
Esempio n. 5
0
 /**
  * 通过用户账号获取用户信息
  * @param $account
  * @return UserBase
  */
 public function userInfoByAccount($account)
 {
     //return UserBase::findFirst("user_account='".$account."'");
     return UserBase::findFirst(['conditions' => 'user_account = :account:', 'bind' => ['account' => $account]]);
 }
Esempio n. 6
0
 public function run()
 {
     $account = $this->getDataItem('account', 1);
     //帐号
     $password = $this->getDataItem('password', 1);
     //密码
     $nickname = Keyword::Filter($this->getDataItem('nickname', 1));
     //昵称
     $smsCode = $this->getDataItem('sms_code', '');
     //短信验证
     if ($this->userInfoByAccount($account)) {
         $this->setResult(['success' => 101, 'user_token' => $this->userToken, 'message' => '账户名已存在']);
         return;
     }
     if (empty($password) || empty($nickname)) {
         $this->setResult(['success' => 103, 'user_token' => $this->userToken, 'message' => '密码和昵称不能为空']);
         return;
     }
     if (empty($smsCode)) {
         $this->setResult(['success' => 102, 'user_token' => $this->userToken, 'message' => '短信验证码必填']);
         return;
     }
     if (!MobileSMS::Check('register', $smsCode, $account, $this->apiAccessToken->id)) {
         $this->setResult(['success' => 102, 'user_token' => $this->userToken, 'message' => '短信验证码错误']);
         return;
     }
     $this->userInfo = new UserBase();
     $this->userInfo->user_account = $account;
     $this->userInfo->user_password = $this->hashPassword($password);
     $this->userInfo->user_nickname = $nickname;
     $this->userInfo->user_cover = $this->getConfig()->defaultCover;
     //'default.jpg';
     $this->userInfo->bind_phone = $account;
     if ($this->userInfo->save()) {
         $this->success = 1;
         $this->message = '注册成功';
         $this->saveUserAuth($this->apiAccessToken->id, $this->userInfo->user_id);
         $this->userToken = $this->getUserAuth()->userToken;
     } else {
         $this->message = '注册失败';
         $this->databaseErrorLog($this->userInfo);
     }
     if ($this->success == 1) {
         if ($model = UserBase::findFirst('user_id = ' . $this->userInfo->user_id)) {
             $info = $model->toArray();
         } else {
             $info = [];
         }
         $info['user_mobile'] = $info['bind_phone'];
         $info['user_cover'] = $info['user_cover'] ? PicUrl::UserCover($info['user_cover'], $this->getDi()) : '';
         // 获取城市信息
         $SysAreaZipDistrictPhonecode = new SysAreaZipDistrictPhonecode();
         $city = $SysAreaZipDistrictPhonecode->getOne($info['user_district']);
         $info['user_district'] = $city['FULL_NAME'] ?: '';
         // 删除不要的字段
         unset($info['user_account'], $info['user_password'], $info['user_state'], $info['user_addtime'], $info['is_manage']);
         $this->setResult(array_merge($info, ['success' => $this->success, 'user_token' => $this->userToken, 'message' => $this->message]));
     } else {
         $this->setResult(['success' => $this->success, 'user_token' => $this->userToken, 'message' => $this->message, 'user_id' => $this->userInfo->user_id]);
     }
 }
Esempio n. 7
0
 /**
  * 设置成专家信息
  * @date: 2016-1-6 
  * @author: futao
  */
 public function setExpertinfoAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $userId = $req->getQuery('userid', null, 0);
         if (!$userId) {
             echo "用户不存在";
             return;
         }
         $tagList = BeautyParlorTagInfo::find("tag_state = 1 and parent_id !=0");
         $this->view->setVar("userId", $userId);
         $this->view->setVar("tagList", $tagList);
         $this->view->pick('user/setexpertinfo');
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     //$response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数问题!');
     /* $response->sendResult(1);
       	return $response; */
     $experience = $req->getPost("experience", null, '');
     //从业经验
     $userId = $req->getPost("userId", null, '');
     $field = $req->getPost("field", null, '');
     //擅长领域
     $experttitle = $req->getPost("experttitle", null, '');
     //专家头衔
     //验证数据
     if ($field == "" || !is_array($field)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '擅长领域必填!');
         return $response;
     }
     if ($userId == "") {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     $userInfo = UserBase::findFirst($userId);
     if (!$userInfo) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     $data = ['experience' => $experience, 'experttitle' => $experttitle, 'field' => $field];
     $datajson = json_encode($data);
     $userAttr = new UserAttribute();
     $userAttr->attr_value_json = $datajson;
     $userAttr->user_id = $userId;
     $userAttr->attr_type = 103;
     $userAttr->attr_state = 1;
     $userAttr->attr_key = time();
     $userAttrId = $userAttr->save();
     if (!$userAttrId) {
         $response->sendError(ResponseResultStatus::ERROR, '设置失败!');
         return $response;
     }
     $userInfo->user_expert = 1;
     if ($userInfo->save()) {
         $response->sendResult(1);
     } else {
         $response->sendError(ResponseResultStatus::ERROR, '设置失败!');
     }
     return $response;
 }
Esempio n. 8
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' => '']);
 }
Esempio n. 9
0
 public function push()
 {
     if ($this->param['type'] === null || $this->param['ispushservice'] === null || $this->param['phone'] === null || $this->param['content'] === null || $this->param['shop_id'] === null) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     if (strlen($this->param['phone']) != 11) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     if ($this->param['phone'] == '') {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     $userinfo = UserBase::findFirst("user_account = " . $this->param['phone']);
     if (!$userinfo) {
         return $this->returnResult($this->DATAERROR, '数据错误!');
     }
     $user_id = $userinfo->user_id;
     $usermessage = new UserMessage();
     $usermessage->user_id = $user_id;
     if ($this->param['ispushservice'] == 1) {
         $usermessage->is_read_b = 0;
     } else {
         $usermessage->is_read_b = 1;
     }
     $usermessage->message_content = $this->param['content'];
     $usermessage->push_type = $this->param['type'];
     $usermessage->message_state = 1;
     $usermessage->shop_id = $this->param['shop_id'];
     $usermessage->from_user_name = 1;
     $usermessage->from_user_cover = 1;
     $this->db->begin();
     $message_status = $usermessage->save();
     //添加数据到user_message
     if (!$message_status) {
         $this->db->rollback();
         return $this->returnResult($this->MYSQLERROR, "数据库错误");
     }
     /*推送至APP代码*/
     $config = $this->di->get('appConfig')->jpush;
     $app_key = $config->app_key;
     $master_secret = $config->master_secret;
     JPushLog::setLogHandlers([new StreamHandler('jpush.log', Logger::DEBUG)]);
     $client = new JPushClient($app_key, $master_secret);
     //easy push
     try {
         $result = $client->push()->setPlatform(M\all)->setAudience(M\alias([$user_id]))->setNotification(M\notification($this->param['content']))->setOptions(M\options(null, null, null, true, null))->send();
         if ($result->isOk === true) {
             $this->db->commit();
             return $this->returnResult($this->SUCCESS, "推送成功!");
         } else {
             $this->db->rollback();
             return $this->returnResult($this->PUSHFAIL, "推送失败!");
         }
     } catch (APIRequestException $e) {
         /* echo 'Push Fail.' . '<br>';
          		 echo 'Http Code : ' . $e->httpCode . '<br>';
          		echo 'code : ' . $e->code . '<br>';
          		echo 'message : ' . $e->message . '<br>';
          		echo 'Response JSON : ' . $e->json . '<br>';
          		echo 'rateLimitLimit : ' . $e->rateLimitLimit . '<br>';
          		echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . '<br>';
          		echo 'rateLimitReset : ' . $e->rateLimitReset . '<br>';
          		exit; */
         $this->db->rollback();
         return $this->returnResult($this->PUSHFAIL, "推送失败!");
     } catch (APIConnectionException $e) {
         $this->db->rollback();
         return $this->returnResult($this->PUSHFAIL, "推送失败!");
     }
     /*the end*/
 }