Complaints.php 3.32 KB
<?php

use Action\WebAction;
use LibModels\Web\Home\ComplaintsData;
use Home\ComplaintsModel;
use Home\UserModel;
use WebPlugin\Paging;
use WebPlugin\Helpers;

/**
 * 个人中心-我的投诉
 */
class ComplaintsController extends WebAction
{

    public function indexAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();
        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //面包屑-左侧导航
        $path = UserModel::getCenterCrumb('我的投诉');
        $leftNav = UserModel::getCenterLeftNav('我的投诉',$uid);
        //分页
        $page = $this->get('page', 1);
        $limit = 10;
        $paging = new Paging('yoho');

        $complaints = ComplaintsModel::getComplaintsList($uid, $page, $limit);

        $total = isset($complaints['pager']['total']) ? $complaints['pager']['total'] : 0;
        $pageTotal = isset($complaints['pager']['pageTotal']) ? $complaints['pager']['pageTotal'] : 0;
        $page = isset($complaints['pager']['page']) ? $complaints['pager']['page'] : 0;
        unset($complaints['pager']);
        $paging->setTotal($total)->setSize($limit)->setQuery(array('page' => $page));

        $data = array(
            'path' => $path,
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => $leftNav,
            'complaints' => $complaints,
            'pager' => array(
                'hasCheckAll' => false,
                'count' => $total,
                'curPage' => $page,
                'totalPages' => $pageTotal,
                'pagerHtml' => $paging->view(false)
            )
        );
        $this->_view->display('complaints', array('meComplaintsPage' => true, 'complaints' => $data));
    }

    /**
     * 添加投诉-ajax
     */
    public function addComplaintsAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');

        do {

            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $params['uid'] = $this->auditJumpLogin();
            $params['title'] = trim($this->post('title', ''));
            $params['customer'] = trim($this->post('customer', ''));
            $params['complaintsType'] = $this->post('complaintsType', '');
            $params['orderCode'] = trim($this->post('orderCode', ''));
            $params['content'] = trim($this->post('content', ''));
            $data = ComplaintsData::addComplaints($params);
            if (!isset($data['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($data);
    }

    /**
     * 撤销投诉-ajax
     */
    public function cancelComplaintsAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');

        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $uid = $this->auditJumpLogin();
            $id = $this->post('id', '');
            $data = ComplaintsData::cancelComplaints($uid, $id);
            if (!isset($data['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($data);
    }

}