Message.php 4.86 KB
<?php

use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\MessageModel;
use LibModels\Web\Home\MessageData;
use WebPlugin\Paging;

/**
 * 个人中心——我的消息
 */
class messageController extends WebAction
{

    /**
     * 我的信息
     */
    public function indexAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin(true, Helpers::url('/home/message'));
        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //分页
        $page = $this->get('page', 1);
        $size = 10;
        //获取消息列表
        $inboxlist = MessageModel::getInboxList($uid, $page, $size);
        $data = array(
            //面包屑-左侧导航
            'path' => UserModel::getCenterCrumb('我的信息'),
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => UserModel::getCenterLeftNav('我的信息', $uid),
            'messages' => $inboxlist['messages'],
            'pager' => $inboxlist['pager'],
        );
        $this->_view->display('message', array('meMessagePage' => true, 'message' => $data));
    }

    /**
     * 消息详细
     */
    public function contentAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();
        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        $id = $this->get('id', '');
        $page = $this->get('page', 1);
        $size = 10;
        $content = MessageModel::getContentData($uid, $page, $size, $id);
        $data = array(
            'path' => UserModel::getCenterCrumb('我的信息'),
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => UserModel::getCenterLeftNav('我的信息', $uid),
            'message' => $content,
        );


        $this->_view->display('message-content', array('meMessagePage' => true, 'message' => $data));
    }

    /**
     * 删除消息
     */
    public function delMessageAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');
        do {
            if (!$this->isAjax()) {
                break;
            }
            //获取相关参数
            $uid = $this->getUid(true);
            $id = $this->get('id', '');
            if (!$uid || !$id) {
                $result = array('code' => 400, 'message' => '缺少参数', 'data' => '');
                $this->echoJson($result);
                break;
            }
            $messages = MessageData::delMessageData($uid, $id);
            if (isset($messages['code']) && $messages['code'] == 200) {
                $page = $this->get('page', 1);
                $size = 10;
                $inboxlist = MessageModel::getInboxList($uid, $page, $size); //重新获取消息列表
                $result['messages'] = $inboxlist['messages'];
                $result['pager'] = $inboxlist['pager'];
                $this->_view->display('message-list', array('messages' => $result));
            }
            else {
                $result = array('code' => 400, 'message' => '删除失败', 'data' => '');
                $this->echoJson($result);
            }
        }
        while (false);
    }

    /**
     * 批量设置消息为已读
     */
    public function readMessageAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');
        do {
            if (!$this->isAjax()) {
                break;
            }
            //获取相关信息
            $uid = $this->getUid(true);
            $ids = $this->get('id', '');
            if (!$uid || !$ids) {
                $result = array('code' => 400, 'message' => '缺失必填项', 'data' => '');
                break;
            }
            $result = MessageData::setRead($uid, $ids);
            if (!isset($result['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($result);
    }

    /**
     * 领取生日券
     */
    public function pickCouponAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');

        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            //获取相关参数
            $uid = $this->getUid(true);
            $id = $this->get('id', '');
            if (!$uid || !$id) {
                $result = array('code' => 400, 'message' => '缺失必填项', 'data' => '');
                break;
            }
            $result =MessageData::getBirthCoupon($uid, $id);
            if (!isset($result['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($result);
    }

}