/** * 喜欢增加策略 * Enter description here ... * @param PwUserBo $userBo * @param int $typeid * @param int $fromid */ public function addLike(PwUserBo $userBo, $typeid, $fromid = 0) { $uid = $userBo->uid; $likeDs = $this->_getLikeContentDs(); list($beLikeUid, $isspecial, $count, $fid, $extend) = $this->_getSourceInfo($typeid, $fromid); if ($beLikeUid == $uid) { return new PwError('BBS:like.fail.myself.post'); } $time = Pw::getTime(); //判断是否存在喜欢内容 $info = $likeDs->getInfoByTypeidFromid($typeid, $fromid); $likeid = isset($info['likeid']) ? (int) $info['likeid'] : 0; Wind::import('SRV:like.dm.PwLikeDm'); $dm = new PwLikeDm(); $dm->setTypeid($typeid)->setFromid($fromid)->setIsspecial($isspecial); if ($likeid < 1) { $likeid = $likeDs->addInfo($dm); } //判断是否喜欢过 $logInfo = $this->_getLikeLogDs()->getInfoByUidLikeid($uid, $likeid); if ($logInfo) { return new PwError('BBS:like.fail.already.liked'); } //写入喜欢记录 Wind::import('SRV:like.dm.PwLikeLogDm'); $logDm = new PwLikeLogDm(); $logDm->setUid($uid)->setLikeid($likeid)->setCreatedTime($time); $logid = $this->_getLikeLogDs()->addInfo($logDm); if ($logid < 1) { return new PwError('BBS:like.fail'); } //更新喜欢内容 $count++; $this->_updateLikeCount($typeid, $fromid, $count); $likeDs->updateUsers($likeid, $uid); //写入用户喜欢统计 Wind::import('SRV:user.dm.PwUserInfoDm'); $likeNumber = isset($userBo->info['likes']) ? intval($userBo->info['likes']) : 0; $likeNumber++; $infoDm = new PwUserInfoDm($uid); $infoDm->setLikes($likeNumber); $userDs = Wekit::load('user.PwUser'); $userDs->editUser($infoDm, PwUser::FETCH_DATA); //用户积分 Wind::import('SRV:forum.bo.PwForumBo'); $forumBo = new PwForumBo($fid); Wind::import('SRV:credit.bo.PwCreditBo'); $credit = PwCreditBo::getInstance(); $credit->operate('belike', new PwUserBo($beLikeUid), true, array('forumname' => $userBo->username), $forumBo->getCreditSet('belike')); $credit->execute(); //喜欢挂勾 $dm->setBeLikeUid($beLikeUid); //$this->_getHook()->runDo('addLike', $userBo, $dm); PwSimpleHook::getInstance('PwLikeService_addLike')->runDo($userBo, $dm); //喜欢后续操作 如果不需要排行,return true $this->setLikeBrand($likeid, $count, $typeid, $fromid); return array('likeCount' => $likeNumber, 'extend' => $extend); }
public function addLike(PwUserBo $userBo, PwLikeDm $dm) { if (!Wekit::C('site', 'task.isOpen')) { return true; } $data = $dm->getData(); if ($data['typeid'] != PwLikeContent::THREAD) { return false; } /* @var $dm PwLikeDm */ $bp = new PwTaskComplete($userBo->uid, $this); $thread = Wekit::load('forum.PwThread')->getThread($data['fromid']); $this->fid = $thread['fid']; $bp->doTask('bbs', 'like'); }
public function addLike(PwUserBo $userBo, PwLikeDm $dm) { Wind::import('SRV:medal.srv.PwAutoAwardMedal'); $data = $dm->getData(); $ds = Wekit::load('user.PwUserBehavior'); $behavior = $ds->getBehavior($data['belikeuid'], 'belike_times'); $condition = isset($behavior['number']) ? (int) $behavior['number'] : 0; $bp = new PwAutoAwardMedal(new PwUserBo($data['belikeuid'])); $bp->autoAwardMedal(6, $condition); //喜欢统计 $condition = isset($userBo->info['likes']) ? (int) $userBo->info['likes'] : 0; $bp = new PwAutoAwardMedal($userBo); $bp->autoAwardMedal(9, $condition); //like_count return true; }
/** * 更新内容 * * @param PwLikeDm $dm */ public function updateInfo(PwLikeDm $dm) { $resource = $dm->beforeUpdate(); if ($resource instanceof PwError) { return $resource; } return $this->_getLikeContentDao()->updateInfo($dm->likeid, $dm->getData()); }
public function addLike(PwUserBo $userBo, PwLikeDm $dm) { $data = $dm->getData(); $ds = Wekit::load('user.PwUserBehavior'); return $ds->replaceBehavior($data['belikeuid'], 'belike_times'); }