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; }
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); } }
public function actionIndex() { $noticeModel = Notice::model(); $targetUserid = Yii::app()->user->id; $msgs = $noticeModel->findAll(array('condition' => 'targetUserid =:targetUserid AND readFlag = 1', 'order' => 'createTime', 'params' => array(':targetUserid' => $targetUserid))); $noticeInfo = array(); foreach ($msgs as $msg) { if ($msg->type == 0) { $noticeInfo[] = array('type' => $msg->type, 'msg' => $msg->msg, 'createTime' => $msg->createTime); } else { $appInfo = AppInfoList::model()->find(array('select' => 'Id, AppName', 'condition' => 'Id = :appId', 'params' => array(':appId' => $msg->appId))); $authorId = $msg->reviews->AuthorId; $noticeInfo[] = array('type' => $msg->type, 'msg' => $msg->reviews->Content, 'createTime' => $msg->createTime, 'appName' => $appInfo->AppName, 'appID' => $appInfo->Id, 'authorName' => htmlspecialchars(CommonFunc::getRedis('user_' . $authorId, 'userName')), 'authorID' => $authorId); } } $noticeModel->updateAll(array('readFlag' => '0'), 'targetUserid = :targetUserid', array(':targetUserid' => $targetUserid)); $this->render('msg', array('msg' => $noticeInfo)); }
public function actionGetLikedPeople() { if (isset($_POST['appID']) && isset($_POST['start'])) { $userArray = CommonFunc::getRedis('link_' . $_POST['appID'], 'user'); if (!empty($userArray)) { echo new ReturnInfo(RET_SUC, AppInfoList::getLikedPeople($userArray, $_POST['start'])); return; } } echo new ReturnInfo(-1, '网络连接超时,请稍后重试!'); return; }
private function _getLikedRealUser($appId) { $likedRealUser = array(); $likedUser = CommonFunc::getRedis('link_' . $appId); if ($likedUser) { foreach ($likedUser as $key => $value) { if (!isset($value['status']) || $value['status'] == 0) { $likedRealUser[] = $key; } } } return $likedRealUser; }
public function actionMyFavorite() { $userID = Yii::app()->user->id; if (!empty($userID)) { $userKey = 'user_' . $userID; $interactionApp = CommonFunc::getRedis($userKey, 'favorite'); $interactionAppIds = array_keys($interactionApp); $data = AppInfoList::getInteractionApp($userID, $interactionAppIds); $this->render('myfavorite', array('data' => $data)); } else { throw new THttpException('请登陆后再查看'); } }
public function actionMyFavorite() { $userID = Yii::app()->getRequest()->getQuery('memberid'); //$this->apiUser->ID; if (!empty($userID)) { $userKey = 'user_' . $userID; $interactionApp = CommonFunc::getRedis($userKey, 'favorite'); $interactionAppIds = array_keys($interactionApp); $data = AppInfoList::getInteractionApp($userID, $interactionAppIds); echo new ReturnInfo(RET_SUC, $data); } else { echo new ReturnInfo(RET_ERROR, '请登陆后再查看'); } }
public function actionAppDetail() { $appID = Yii::app()->getRequest()->getQuery('appid'); if (empty($appID)) { echo new ReturnInfo(RET_ERROR, 'Argument appid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not be empty.'); Yii::app()->end(); } $appInfoObj = AppInfoList::model()->findByPk($appID); if (empty($appInfoObj)) { echo new ReturnInfo(RET_ERROR, 'Argument appid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not find a record.'); Yii::app()->end(); } $appInfoArray = array('id' => $appInfoObj->Id, 'appName' => $appInfoObj->AppName, 'remarks' => $appInfoObj->Remarks, 'commentCount' => $appInfoObj->reply_count, 'commitUserId' => $appInfoObj->CommitUserId, 'CommitTime' => AppInfoList::getPeriod($appInfoObj->CommitTime), 'markName' => Source::getSourceName($appInfoObj->SourceId), 'pushListObj' => isset($appInfoObj->pushListObj) && $appInfoObj->pushListObj->FileSize ? $appInfoObj->pushListObj->FileSize : "0MB", 'iconUrl' => $appInfoObj->IconUrl, 'appSource' => $appInfoObj->SourceId, 'appUrl' => $appInfoObj->AppUrl, 'appInfo' => $appInfoObj->AppInfo, 'up' => $appInfoObj->Up); $appID = $appInfoObj->Id; $count_key = 'link_' . $appID; $memberArray = CommonFunc::getRedis('user_' . Yii::app()->user->id); $appInfoArray['hasFavorited'] = false; $appInfoArray['isUpped'] = false; if (!empty($memberArray)) { $appInfoArray['hasFavorited'] = isset($memberArray['favorite'][$appID]) ? 1 : 0; if (!isset($memberArray['like'])) { $memberArray['like'] = array(); } $appInfoArray['isUpped'] = in_array($appInfoObj->Id, $memberArray['like']) ? true : false; } $countArray = CommonFunc::getRedis($count_key); if (!empty($countArray)) { if (!isset($countArray['count'])) { $countArray['count'] = 0; } if (!isset($countArray['user'])) { $countArray['user'] = array(); } $appInfoArray['count'] = $countArray['count']; $appInfoArray['p_user'] = AppInfoList::getLikedPeople($countArray['user'], 0); } else { $appInfoArray['count'] = 0; $appInfoArray['p_user'] = array(); } //发信息的人 $user = $appInfoObj->link_user; if (!empty($user)) { $appInfoArray['username'] = htmlspecialchars($user->UserName); if (!empty($user['Icon'])) { $appInfoArray['userurl'] = $user->Icon; } else { $appInfoArray['userurl'] = ''; } } else { $appInfoArray['username'] = ''; $appInfoArray['userurl'] = ''; } //信息的轮播图片(link_info表) $appInfoArray['imgurl'] = array(); if (!empty($appInfoObj->VideoUrl)) { $appInfoArray['videoUrl'] = $appInfoObj->VideoUrl; } if (!empty($appInfoObj->ScreenShoot)) { $appInfoArray['imgurl'] = explode(',', $appInfoObj->ScreenShoot); } echo new ReturnInfo(RET_SUC, $appInfoArray); }
static function getLikedPeople(array $arr, $start, $length = 50) { $likedPeople = array_slice($arr, $start, $length); $likedPeopleArray = array(); foreach ($likedPeople as $key => $value) { $upUserRedis = CommonFunc::getRedis('user_' . $value['ID']); if (!isset($upUserRedis['userHeadUrl']) || !isset($upUserRedis['userName'])) { $userModal = User::model()->findByPk($value['ID']); } $likedPeopleArray[] = array('userId' => $value['ID'], 'userurl' => !isset($upUserRedis['userHeadUrl']) || $upUserRedis['userHeadUrl'] === '' ? $userModal->Icon : $upUserRedis['userHeadUrl'], 'username' => !isset($upUserRedis['userName']) || $upUserRedis['userName'] === '' ? htmlspecialchars($userModal->UserName) : htmlspecialchars($upUserRedis['userName'])); } return $likedPeopleArray; }
public function actionUpdateAppUp() { $apps = AppInfoList::model()->findAll(); foreach ($apps as $app) { $appUp = CommonFunc::getRedis('link_' . $app->Id, 'count'); if (empty($appUp)) { continue; } $app->Up = $appUp; $app->save(); } }