Detail.php 8.35 KB
<?php

use Action\AbstractAction;
use Plugin\Helpers;
use LibModels\Wap\Product\DetailData;
use Product\DetailModel;

/**
 * 商品详情的控制器
 */
class DetailController extends AbstractAction
{

    /**
     * 商品详情
     *
     * @param int productId
     * @param int goodsId
     */
    public function indexAction()
    {
        $productId = $this->param('productId');
//        $productId = 356648;
        if (!is_numeric($productId)) {
            $this->error();
        }
        $goodsId = $this->param('goodsId');
//        $goodsId = 455366;
        if (!is_numeric($goodsId)) {
            $this->error();
        }
        $uid = $this->getUid();

        $vipLevel = 0;
        if (isset($this->_vip)) {
            $vipLevel = Helpers::getVipLevel($this->_vip);
        }

        $data = DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel);
//        \Plugin\DataProcess\CouponFloorProcess::debugOut($data);
        if (array() === $data) {
            $this->error();
        }

        $data['goodsDetailPage'] = true;
        $data['pageFooter'] = true;

        if (isset($data['goodsName'])) {
            $this->setTitle($data['goodsName']);
        }
        if (!$this->isApp()){
            $this->setNavHeader('商品详情');
        }
        // 渲染模板
        $this->_view->display('index', $data);
    }

    /**
     * 商品详情 (SKN)
     *
     * @param int productSkn
     */
    public function showAction()
    {
        $productSkn = $this->param('productSkn');
        if (!is_numeric($productSkn)) {
            $this->error();
        }
        $uid = $this->getUid();

        $vipLevel = 0;
        if (isset($this->_vip)) {
            $vipLevel = Helpers::getVipLevel($this->_vip);
        }

        $data = DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn);
        if (array() === $data) {
            $this->error();
        }
        $data['goodsDetailPage'] = true;
        $data['pageFooter'] = true;

        if (isset($data['goodsName'])) {
            $this->setTitle($data['goodsName']);
        }
        $this->setNavHeader('商品详情');
        // 渲染模板
        $this->_view->display('index', $data);
    }

    /**
     * 尺码描述信息
     */
    public function introAction()
    {
        $productSkn = $this->param('productSkn');
        if (!is_numeric($productSkn)) {
            echo ' ';
        }

        // 加入uid和udid参数,为了实现记录浏览记录的功能
        $uid = $this->getUid();
        $udid = $this->getUdid();
        $data = DetailModel::getSizeInfo($productSkn, $uid, $udid);
        if (array() === $data) {
            echo ' ';
            exit();
        }
        $this->_view->display('intro', $data);
    }

    /**
     * 购买评价列表
     *
     * @param int productId
     * @param int total
     */
    public function commentsAction()
    {
        $productId = $this->get('product_id', 0);
        $total = $this->get('total');
        if (!is_numeric($total)) {
            $total = 0;
        }
        if ($total) {
            $this->setNavHeader('购买评价(' . $total . ')', true, false);
        } else {
            $this->setNavHeader('购买评价', true, false);
        }
        $this->setTitle('购买评价');

        $data = array(
            'goodsCommentsPage' => true,
            'pageFooter' => true,
            'comments' => array(
                'list' => DetailModel::getComments($productId),
            ),
        );

        // 渲染模板
        $this->_view->display('comments', $data);
    }

    /**
     * 购买咨询列表
     *
     * @param int productId
     * @param int total
     */
    public function consultsAction()
    {
        $productId = $this->get('product_id', 0);
        $total = $this->get('total', 0);
        if (!is_numeric($total)) {
            $total = 0;
        }
        if ($total) {
            $this->setNavHeader('购买咨询(' . $total . ')', true, false);
        } else {
            $this->setNavHeader('购买咨询', true, false);
        }
        $this->setTitle('购买咨询');

        $uid = $this->getUid();
        $consults = DetailModel::getConsults($uid, $productId);
        $data = array(
            'goodsConsultsPage' => true,
            'pageFooter' => true,
            'consults' => array(
                'list' => $consults
            ),
            'faq' => DetailModel::getCommonConsults(),
            'showReadMore' => count($consults) > 2,
            'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)),
        );

        // 渲染模板
        $this->_view->display('consults', $data);
    }


    /*
     * 咨询点赞
     */
    public function consultupvoteAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $productId = $this->post('productId', 0);
            $total = $this->post('total', 0);
            $uid = $this->getUid();
            $id = $this->post('id');
            $result = DetailModel::upvoteConsult($uid, $id, $productId, $total);
        }

        $this->echoJson($result);
    }

    /*
     * 咨询有用
     */
    public function consultusefulAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $productId = $this->post('productId', 0);
            $total = $this->post('total', 0);
            $uid = $this->getUid();
            $id = $this->post('id');
            $result = DetailModel::usefulConsult($uid, $id, $productId, $total);
        }

        $this->echoJson($result);
    }

    /**
     * 我要咨询表单
     */
    public function consultformAction()
    {
        $uid = $this->getUid();
        if (!$uid) {
            $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/'))));
        }

        $this->setTitle('我要咨询');
        $this->setNavHeader('我要咨询', true, false);

        $productId = $this->get('product_id', 0);

        // 渲染模板
        $this->_view->display('consultform', array(
            'consultformPage' => true,
            'productId' => $productId,
            'formUrl' => Helpers::url('/product/detail/consultsubmit'),
        ));
    }

    /**
     * 添加咨询操作
     *
     * @param int product_id 商品ID
     * @param string content 咨询内容
     * @return json
     */
    public function consultsubmitAction()
    {
        $result = array('code' => 400, 'message' => '请输入咨询内容', 'data' => '');

        if ($this->isAjax()) {
            $uid = $this->getUid();
            $productId = $this->post('product_id', 0);
            $content = $this->post('content');
            $result = DetailData::addConsult($uid, $productId, $content);
        }

        $this->echoJson($result);
    }

    /**
     * 为你优选
     *
     * @param int productSkn 商品SKN号
     * @return json
     */
    public function preferenceAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $productSkn = $this->get('productSkn');
            $brandId = $this->get('brandId');
            $channel = Helpers::getChannelByCookie();
            $result = DetailModel::getPreference($productSkn, $channel, $brandId);
        }

        if (empty($result)) {
            echo ' ';
        } else {
            $this->_view->display('preference', $result);
        }
    }

    /**
     * 限购商品说明页面
     */
    public function limitHelpAction()
    {
        $this->_view->display('limit-help', array());
    }

    /**
     * 限购商品详情页
     */
    public function limitAction()
    {
        $productCode = $this->get('code', '');
        if (empty($productCode)) {
            $this->error();
        }

        $uid = $this->getUid();
        $data = DetailModel::getLimitProductData($uid, $productCode);
        if (empty($data)) {
            $this->error();
        }
        // APP下载链接地址
        $data['appSrc'] = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
        $data['wxshare'] = array(
                'shareLink' => Helpers::url('/product/detail/limit', array('code' => $productCode), 'default'),
                'shareImg' => strtr($data['banner'], array('//' => 'http://')),
                'shareTitle' => $data['name'],
                'shareDesc' => '我在Yoho!Buy有货发现了一个限定发售商品',
           );
        $this->_view->display('limit', $data);
    }

}