Пример #1
0
 /**
  * 发送通知
  * @param int $uid
  * @param string $type
  * @param int $param
  * @param array $extendParams
  * @param $updateUnRead 是否更新未读数
  */
 public function sendNotice($uid, $type, $param = 0, $extendParams = array(), $updateUnRead = true)
 {
     $action = $this->_getAction($type);
     if (!$action) {
         return new PwError('MESSAGE::notice.type.undefined');
     }
     $typeId = $this->_getTypeId($type);
     // 看是否发通知
     if ($this->_checkPrivate($uid, $typeId) !== true) {
         return false;
     }
     //aggregated notice
     Wind::import('SRV:message.dm.PwMessageNoticesDm');
     $dm = new PwMessageNoticesDm();
     $action->aggregate && ($notice = $this->_getNoticesDs()->getNoticeByUid($uid, $typeId, $param));
     $extendParams = $action->formatExtendParams($extendParams, $notice);
     $noticeTitle = $action->buildTitle($param, $extendParams, $notice);
     $dm->setToUid($uid)->setRead(0)->setType($typeId)->setParam($param)->setExtendParams($extendParams)->setTitle($noticeTitle);
     if (!$notice) {
         $noticeId = $this->_getNoticesDs()->addNotice($dm);
     } else {
         $dm->setId($notice['id']);
         $dm->setModifiedTime(Pw::getTime());
         $this->_getNoticesDs()->updateNotice($dm);
         $noticeId = $notice['id'];
     }
     //更新通知未读数
     if ($updateUnRead && (!$notice || $notice['is_read'])) {
         Wind::import('SRV:user.dm.PwUserInfoDm');
         $dm = new PwUserInfoDm($uid);
         $dm->addNotice(1);
         $this->_getUserDs()->editUser($dm, PwUser::FETCH_DATA);
     }
     return true;
 }