Esempio n. 1
0
 static function favoriteBoolean($appID, $userID, $isFavorite)
 {
     if (!is_bool($isFavorite)) {
         throw new ErrorException('Argument 3 passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that must be a boolean');
     }
     $linkKey = 'link_' . $appID;
     $userKey = 'user_' . $userID;
     $datetime = date('Y-m-d H:i:s');
     //哪些人收藏了app
     $appArray = CommonFunc::getRedis($linkKey, 'appFavorite');
     $memberArray = CommonFunc::getRedis($userKey, 'favorite');
     if ($isFavorite) {
         if (isset($memberArray[$appID])) {
             throw new ErrorException('你已经收藏过该App');
         }
         $appArray[$userID] = array('time' => $datetime);
         CommonFunc::setRedis($linkKey, 'appFavorite', $appArray);
         $memberArray[$appID] = array('appID' => $appID, 'time' => $datetime);
         CommonFunc::setRedis($userKey, 'favorite', $memberArray);
     } else {
         if (!isset($memberArray[$appID])) {
             throw new ErrorException('取消收藏失败');
         }
         if (isset($appArray[$userID])) {
             unset($appArray[$userID]);
             CommonFunc::setRedis($linkKey, 'appFavorite', $appArray);
         }
         if (isset($memberArray[$appID])) {
             unset($memberArray[$appID]);
             CommonFunc::setRedis($userKey, 'favorite', $memberArray);
         }
     }
     return true;
 }
Esempio n. 2
0
 public function appComment()
 {
     if (!$this->isNewRecord) {
         return;
     }
     $userKey = 'user_' . $this->AuthorId;
     $userRedisInfo = CommonFunc::getRedis($userKey);
     if (!isset($userRedisInfo['comment'])) {
         $userRedisInfo['comment'] = array();
     }
     if (!isset($userRedisInfo['comment'][$this->AppId])) {
         $userRedisInfo['comment'][$this->AppId] = $this->AppId;
         CommonFunc::setRedis($userKey, 'comment', $userRedisInfo['comment']);
         $deltaT = abs(time() - strtotime($this->appWhichReply->UpdateTime));
         $updateTime = explode(' ', $this->appWhichReply->UpdateTime);
         $dateObj = date_diff(date_create($updateTime[0]), date_create(date('Y-m-d')));
         $intervalDays = $dateObj->days + 1;
         if ($deltaT > 0 && $deltaT <= APP_COMMENT_IN_ONE_DAY) {
             $mostCommentPoint = APP_COMMENT_IN_ONE_DAY_MOSTCOMMENT_POINT;
         } elseif ($deltaT > APP_COMMENT_IN_ONE_DAY && $deltaT <= APP_COMMENT_IN_THREE_DAYS) {
             $mostCommentPoint = APP_COMMENT_IN_THREE_DAYS_MOSTCOMMENT_POINT;
         } elseif ($deltaT > APP_COMMENT_IN_THREE_DAYS && $deltaT <= APP_COMMENT_IN_ONE_WEEK) {
             $mostCommentPoint = APP_COMMENT_IN_ONE_WEEK_MOSTCOMMENT_POINT;
         } elseif ($deltaT > APP_COMMENT_IN_ONE_WEEK) {
             $mostCommentPoint = APP_COMMENT_OVER_ONE_WEEK_MOSTCOMMENT_POINT;
         }
         $this->appWhichReply->MostComment += $mostCommentPoint;
         $this->appWhichReply->FastUp += round($mostCommentPoint * 1.0 / $intervalDays, 2);
         $this->appWhichReply->Sort += APP_COMMENT_SORT_POINT;
         $this->appWhichReply->save();
     }
     $noticeUserArray = array();
     if (empty($this->Pid)) {
         //评论APP
         if ($this->appWhichReply->CommitUserId != $this->AuthorId) {
             $noticeUserArray[] = array('type' => 1, 'userId' => $this->appWhichReply->CommitUserId);
         }
     } else {
         $noticeUserArray[] = array('type' => 2, 'userId' => $this->ToAuthorId);
     }
     preg_match_all("/@(.*?)\\s/i", $this->Content, $matches);
     if (!empty($matches[1])) {
         $atUserArray = array_unique($matches[1]);
         foreach ($atUserArray as $atWho) {
             $user = User::model()->findByAttributes(array('UserName' => htmlspecialchars_decode($atWho)));
             $targetUserID = '';
             if ($user instanceof User) {
                 $targetUserID = $user->ID;
             }
             if ($targetUserID != $this->AuthorId && !empty($targetUserID)) {
                 $noticeUserArray[] = array('type' => 3, 'userId' => $targetUserID);
             }
         }
     }
     foreach ($noticeUserArray as $notice) {
         Notice::createNotice($notice['type'], $notice['userId'], '', $this->appWhichReply->Id, $this->Id);
     }
 }
Esempio n. 3
0
 /**
  *用户设置页面
  */
 public function actionSave()
 {
     if (!isset($_POST['username']) || $_POST['username'] === '') {
         echo new ReturnInfo(RET_SUC, array('code' => -1, 'msg' => '昵称不能为空', 'type' => 'username'));
         return;
     }
     $username = $_POST['username'];
     $length = mb_strlen($username, 'UTF8');
     if ($length > 127) {
         echo new ReturnInfo(RET_SUC, array('code' => -1, 'msg' => '昵称长度过长', 'type' => 'username'));
         return;
     }
     $criteria = new CDbCriteria();
     $criteria->condition = 'Username = :username and ID !=' . Yii::app()->user->id;
     $criteria->params = array(':username' => $username);
     $user = User::model()->find($criteria);
     if ($user) {
         echo new ReturnInfo(RET_SUC, array('code' => -1, 'msg' => '昵称已存在', 'type' => 'username'));
         return;
     }
     $email = '';
     if (!isset($_POST['email']) || $_POST['email'] !== '') {
         $email = $_POST['email'];
         if (!preg_match("/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,4}\$/i", $email)) {
             echo new ReturnInfo(RET_SUC, array('code' => -1, 'msg' => '邮箱格式不正确'));
             return;
         }
         $criteria = new CDbCriteria();
         $criteria->condition = 'Email = :email and ID !=' . Yii::app()->user->id;
         $criteria->params = array(':email' => $email);
         $user = User::model()->find($criteria);
         if ($user) {
             echo new ReturnInfo(RET_SUC, array('code' => -1, 'msg' => '邮箱已存在'));
             return;
         }
     }
     $userId = Yii::app()->user->id;
     $editUser = User::model()->findByPk($userId);
     if (!$editUser) {
         throw new THttpException('保存失败');
     }
     $editUser->UserName = $username;
     $editUser->Email = $email;
     if (!$editUser->save()) {
         throw new THttpException('保存失败');
     }
     CommonFunc::setRedis('user_' . $userId, 'userName', $editUser->UserName);
     echo new ReturnInfo(RET_SUC, array('code' => 0, 'msg' => '保存成功'));
 }
Esempio n. 4
0
 static function up(AppInfoList $app, User $user, $isUpped)
 {
     if (!is_bool($isUpped)) {
         throw new ErrorException('Argument 3 passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that must be a boolean');
     }
     $appID = $app->Id;
     $userID = $user->ID;
     $linkKey = 'link_' . $appID;
     $userKey = 'user_' . $userID;
     $datetime = date('Y-m-d H:i:s');
     $appArray = CommonFunc::getRedis($linkKey);
     if (empty($appArray)) {
         $appArray = array('user' => array(), 'count' => 0);
     }
     $memberArray = CommonFunc::getRedis($userKey, 'like');
     if ($isUpped) {
         if (isset($appArray['user'][$userID])) {
             throw new ErrorException('你已经赞过该App');
         }
         if (!isset($appArray['count'])) {
             $appArray['count'] = 0;
         }
         $appArray['count'] += 1;
         $appArray['user'][$userID] = array('ID' => $userID, 'time' => $datetime, 'status' => $user->Status);
         CommonFunc::setRedis($linkKey, '', $appArray);
         $memberArray[$appID] = $appID;
         CommonFunc::setRedis($userKey, 'like', $memberArray);
         $app->Up += 1;
     } else {
         if (!isset($appArray['user'][$userID])) {
             throw new ErrorException('取消赞失败');
         }
         if (isset($appArray['user'][$userID])) {
             $appArray['count'] -= 1;
             unset($appArray['user'][$userID]);
             CommonFunc::setRedis($linkKey, '', $appArray);
             $app->Up -= 1;
         }
         if (isset($memberArray[$appID])) {
             unset($memberArray[$appID]);
             CommonFunc::setRedis($userKey, 'like', $memberArray);
         }
     }
     if ($app->save()) {
         return true;
     } else {
         throw new CDbException($app->getErrors());
     }
 }
Esempio n. 5
0
 /**
  * 检测微信用户是否在这个广告主的账户下
  * @param $openID 用户的微信原始ID
  * @return void
  */
 static function checkUser($openID, $aUser = array())
 {
     if (empty($openID)) {
         $openID = $aUser['openid'];
         $_aUser = WeixinApi::getUserInfo($openID);
         $aUser['subscribe'] = $_aUser['subscribe'];
     } else {
         $aUser = WeixinApi::getUserInfo($openID);
     }
     //用 unionid取数据,和微信登录统一用户
     $unionID = $aUser['unionid'];
     $user = User::model()->findByAttributes(array('unionid' => $unionID));
     if ($user) {
         if ($aUser['nickname'] !== '' && $user->NickName == $user->UserName && !User::checkUserName($aUser['nickname'])) {
             $user->UserName = $aUser['nickname'];
         }
         $user->NickName = $aUser['nickname'];
         $user->Icon = $aUser['headimgurl'];
         $user->IsFollow = $aUser['subscribe'];
         //微信登录的用户,这个字段为空
         $user->Openid = $openID;
         if ($user->save()) {
             //更新redis
             CommonFunc::setRedis('user_' . $user->ID, 'userHeadUrl', $aUser['headimgurl']);
             CommonFunc::setRedis('user_' . $user->ID, 'userName', $user->UserName);
             return $user->ID;
         } else {
             Yii::log(__FILE__ . __LINE__ . 'insert fans error', 'error', 'system.api.weixin');
         }
     } else {
         $model_user = new User();
         if ($aUser['nickname'] === '') {
             $aUser['nickname'] = 'name_' . time();
         }
         $model_user->Account = $aUser['nickname'];
         $model_user->NickName = $aUser['nickname'];
         $model_user->UserName = $aUser['nickname'];
         if (User::checkUserName($aUser['nickname'])) {
             $model_user->UserName = $aUser['nickname'] . '_' . time();
         }
         $model_user->Openid = $openID;
         $model_user->Icon = $aUser['headimgurl'];
         $model_user->unionid = $aUser['unionid'];
         $model_user->CreateTime = date('Y-m-d H:i:s');
         $model_user->Status = 0;
         $model_user->LastLoginTime = date('Y-m-d H:i:s');
         $model_user->IsFollow = $aUser['subscribe'];
         if ($model_user->save()) {
             CommonFunc::setRedis('user_' . $model_user->ID, 'userHeadUrl', $aUser['headimgurl']);
             CommonFunc::setRedis('user_' . $model_user->ID, 'userName', $model_user->UserName);
             return $model_user->ID;
         } else {
             Yii::log(__FILE__ . __LINE__ . 'insert fans error', 'error', 'system.api.weixin');
         }
     }
     Yii::app()->end();
 }
Esempio n. 6
0
 public function actionUpdateUserInfo()
 {
     $aUser = User::model()->findAll();
     foreach ($aUser as $m) {
         CommonFunc::setRedis('user_' . $m->ID, 'userHeadUrl', $m->Icon);
         CommonFunc::setRedis('user_' . $m->ID, 'userName', $m->UserName);
     }
 }