Ejemplo n.º 1
0
    /**
        * @brief 根据用户id获取站内信列表
        * @author whd
        * @exampleUrl http://dev.mobile-api.haodf.com/patientapi/message_getinboxmsglistbyuserid?userId=613876396&type=all&pageId=1&pageSize=10&xdoc=1
        *
        * @Param $userId 用户id
        * @Param $type (all,unread)
        * @Param $pageId 当前页码
        * @Param $pageSize 每页显示数
        *
        * @Returns  array('id', 'title', 'isread', 'senderName', 'content', 'ctime') 
     */
    public function getInboxMsgListByUserId($userId, $type, $pageId, $pageSize)
    {/*{{{*/
        $user = DAL::get()->find('user', $userId);
        if ($user->isNull())
        {
            $this->setErrorCode(107);
            return 0;
        }
        $this->_initPageInfo($pageId, $pageSize);
        $options = array();
        $options['filterSourceType'] = Message::TYPE_PATIENTCLUB;
        if ($type == 'unread')
        {
            $options['isread'] = 0;
        }
        if ($type == 'orderbyunread')
        {
            $options['orderby'] = 'isread';
        }
		$res = StationLetterClient::getInstance()->getMsgs($userId, Box::TYPE_INBOX, $pageId, $pageSize, $options);
        $mailList = $res['msgInfos'];
        $infos = array();
        $senderIds = array();
        foreach ($mailList as $mail)
        {
            if(empty($mail))
                continue;
            $info = array();
            $info['id'] = $mail['id'];//boxmsgref->id
            $info['title'] = strip_tags($mail['title']);
            $info['isread'] = $mail['isread'];//状态
            $info['senderName'] = $mail['senderId'];
            $info['content'] = mb_substr(trim(XString::fixHtmlText(str_replace(' ', '', $mail['content']))), 0, 15, 'GBK');
            $info['ctime'] = strtotime($mail['ctime']);
            $infos[] = $info;
            $senderIds[] = $mail['senderId'];
        }
        $userList = DAL::get()->find('User', $senderIds);
        foreach($infos as $key => $info)
        {
            if ($userList[$info['senderName']]->isNull())
                $infos[$key]['senderName'] = '身份不明';
            else
                $infos[$key]['senderName'] = $userList[$info['senderName']]->name;
        }
        $this->pageInfo = $res['pageInfo'];
        $this->content = $infos;
    }/*}}}*/