Info.php 6.01 KB
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use Guang\InfoModel;
use Guang\IndexModel;
use LibModels\Web\Guang\InfoData;

class InfoController extends WebAction
{

    /**
     * 逛详情页
     */
    public function indexAction()
    {
        $id = $this->param('id','');
        if(empty($id)) {
            $id = $this->get('id');
        }
        $page = $this->get('page', 1);//评论分页
        $col = $this->get('col', 0);//收藏
        $pjax = $this->get("_pjax");
        $limit = 20; //评论每页显示条数

        if ($pjax) {
            $this->_view->display('comment', InfoModel::commentList($id, $page, $limit));
            exit;
        }
        $uid = $this->getUid();
        $udid = $this->getUdid();
        //登陆后自动收藏
        if ($col == 1 && $uid > 0) {
            InfoData::setFavorite($id, $uid);
        }
        $gender = Helpers::getGenderByCookie();
        $channel = Helpers::getChannelNameByCookie();

        $info = InfoModel::articleInfo($id, $uid, $udid, $page, $gender, $channel, $limit);
        // 判断参数是否有效, 无效会跳转到错误页面
        if (!is_numeric($id) || !isset($info['header']) ) {
            $this->error();
        }
        $data = array(
            'guangDetailPage' => true,
            'pathNav' => $info['pathNav'],
            'guang' => array(
                'id' => $id,
                'header' => isset($info['header']) ? $info['header']: array(),
                'content' => isset($info['content']) ? $info['content'] : array(),
                'brands' => isset($info['brands']) ? $info['brands'] : array(),
                'userInfo' => isset($info['userInfo']) ? $info['userInfo'] : array(),
                'tag' => isset($info['tag']) ? $info['tag'] : array(),
                //分享
                'shareImg' => $info['header']['shareImg'],
                'sharedTitle' => $info['header']['title'],
                'shareDesc' => $info['header']['desc'],
                'weixinUrl' => $info['header']['weixinUrl'],
                'relatedPost' => isset($info['relatedPost']) ? $info['relatedPost'] : array(),
                'commentInfo' => $this->getSession('comment_'.$udid),
                'comment' => isset($info['comment']) ? $info['comment'] : array(),
                'exRecos' => isset($info['exRecos']) ? $info['exRecos'] : array(),
                'hotTags' => isset($info['hotTags']) ? $info['hotTags'] : array(),
                'ads' => IndexModel::getAds($channel),
            )
        );
        $this->setTitle($info['header']['title'].' | YOHO!BUY有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证');
        $this->setKeywords('Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,品牌服饰,男士护肤,黑框眼镜,匡威,板鞋,i.t,izzue,5cm,eastpak,vans,lylescott,g-shock,new balance,lacoste,melissa,casio,卡西欧手表,舒雅,jasonwood,odm,AAAA,香港购物,日本潮流');
        $this->setDescription('潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜');
        $this->setWebNavHeader($channel);
        $this->_view->display('info', $data);
    }

    /**
     * 添加评论
     */
    public function commentAction()
    {
        $id = $this->post('id');
        $uid = $this->getUid();
        $udid = $this->getUdid();
        $comment = $this->post('comment');
        $limit = 20;
        if (!$uid) {
            //评论内容存session
            $this->setSession('comment_'.$udid, $comment);
            $this->helpJsonResult(401, '', '');
        }
        $result = InfoData::addComment($id, $uid, $comment);
        if (isset($result['code']) && $result['code'] == 200) {
            if ($this->getSession('comment_'.$udid)) {
                $this->setSession('comment_'.$udid, '');
            }
            $commentInfo = InfoModel::commentList($id, 1, $limit);
            $data['content'] = $this->_view->render('comment', $commentInfo);
            $data['count'] = $commentInfo['comment']['commentNum'];
            $this->helpJsonResult(200, '评论成功', $data);

        } else {
            $this->helpJsonResult(400, '评论失败', '');
        }
    }

    /**
     * 赞
     */
    public function praiseAction()
    {
        $id = $this->get('id');
        $udid = $this->getUdid();
        $result = InfoData::setPraise($id, $udid);
        if (isset($result['code']) && $result['code'] == 200) {
            $this->helpJsonResult(200, '!', $result['data']);
        } else {
            $this->helpJsonResult(400, '', '');
        }
    }

    /**
     * 取消赞
     */
    public function cancelPraiseAction()
    {
        $id = $this->get('id');
        $udid = $this->getUdid();
        $result = InfoData::cancelPraise($id, $udid);
        if (isset($result['code']) && $result['code'] == 200) {
            $this->helpJsonResult(200, '', $result['data']);
        } else {
            $this->helpJsonResult(400, '', '');
        }
    }

    /**
     * 收藏
     */
    public function collectAction()
    {
        $id = $this->get('id');
        $uid = $this->getUid();
        if (!$uid) {
            $this->helpJsonResult(401, '', '');
        }
        $result = InfoData::setFavorite($id, $uid);
        if (isset($result['code']) && $result['code'] == 200) {
            $this->helpJsonResult(200, '', '');
        } else {
            $this->helpJsonResult(400, '', '');
        }
    }

    /**
     * 取消收藏
     */
    public function cancelCollectAction()
    {
        $id = $this->get('id');
        $uid = $this->getUid();
        $result = InfoData::cancelFavorite($id, $uid);
        if (isset($result['code']) && $result['code'] == 200) {
            $this->helpJsonResult(200, '', '');
        } else {
            $this->helpJsonResult(400, '', '');
        }
    }

}