Favorite.php 6.56 KB
<?php

use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\FavoriteModel;
use LibModels\Web\Product\FavoriteData;
use LibModels\Wap\Home\UserData;
use WebPlugin\Images;

/**
 * 商品收藏
 */
class FavoriteController extends WebAction
{

    /**
     * 我的收藏
     */
    public function indexAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();
        $udid = $uid . $this->getUdid();
        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        $page = $this->get('page', 1);
        $type = $this->get('type', 'product'); //收藏类别
        $sort = $this->get('sort_id', 0); //商品分类
        $reduction = $this->get('is_reduction', 'N'); //降价商品
        $promotion = $this->get('is_promotion', 'N'); //参加活动的商品
        $limit = 10;
        $data = array(
            'path' => UserModel::getCenterCrumb('我的收藏'),
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => UserModel::getCenterLeftNav('我的收藏', $uid),
            'tabs' => FavoriteModel::getFavoriteTabs($type),
        );
        switch (strval($type)) {
            case 'brand':
                $data['favBrands'] = FavoriteModel::favoriteBrandList($uid, $page, $limit, $type); //品牌收藏
                break;
            case 'article':
                $data['favArticles'] = FavoriteModel::favoriteArticleList($uid, $udid, $page, $limit, $type); //文章收藏
                break;
            default:
                $data['favProducts'] = FavoriteModel::favoriteProductList($uid, $page, $limit, $type, $sort, 'N', $reduction, $promotion); //商品收藏
                break;
        }
        $this->_view->display('favorite', array('meFavoritePage' => true, 'meFavorite' => $data));
    }

    /**
     * 品牌收藏-新品到着
     */
    public function newproductAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');
        do {
            //获取相关参数
            $uid = $this->getUid(true);
            $page = $this->get('page', 1);
            $limit = 10;
            $id = $this->get('id', '');
            if (!$uid || !$id) {
                $result = array('code' => 400, 'message' => '缺少参数', 'data' => '');
                break;
            }
            $data = FavoriteModel::newproduct($uid, $page, $limit, $id);
            $result = array('code' => 200, 'message' => '', 'data' => $data);
        }
        while (false);

        $this->echoJson($result);
    }

    /**
     * 商品收藏,降价通知
     */
    public function reductionAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();
        //显示头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        $page = $this->get('page', 1);
        $type = $this->get('type', '');
        $limit = 10;
        $reduction = FavoriteModel::favoriteProductList($uid, $page, $limit, $type, 0, $subscribe = 'Y');
        $data = array(
            'path' => UserModel::getCenterCrumb('我的收藏'),
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => UserModel::getCenterLeftNav('我的收藏', $uid),
            'tabs' => FavoriteModel::getFavoriteTabs('product'),
            'reductionUrl' => Helpers::url('/home/favorite'),
            'goods' => $reduction['goods'],
        );
        $this->_view->display('reduction', array('meFavoritePage' => true, 'meFavorite' => $data));
    }

    /**
     * 订阅降价通知
     */
    public function noticeAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');

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

    /**
     * 取消订阅通知
     */
    public function cancelnoticeAction()
    {
        $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 = FavoriteData::redutionCancel($uid, $id);
            if (!isset($result['code'])) {
                break;
            }
        }
        while (false);
        $this->echoJson($result);
    }

    /**
     * 取消收藏
     */
    public function cancelAction()
    {
        $result = array('code' => 400, 'message' => '', 'data' => '');
        do {
            //判断是否ajax请求
            if (!$this->isAjax()) {
                break;
            }
            //获取相关参数
            $uid = $this->getUid(true);
            $id = $this->get('id', '');
            $type = $this->get('type', '');
            if (!$uid || !$id) {
                $result = array('code' => 400, 'message' => '缺少参数', 'data' => '');
                break;
            }
            switch (strval($type)) {
                case 'brand':
                    $result = FavoriteData::cancelProductFav($uid, $id, true); //取消品牌收藏
                    break;
                case 'article':
                    $result = FavoriteData::changeFavoriteArticle($id, $uid); //取消文章收藏
                    break;
                default:
                    $result = FavoriteData::cancelProductFav($uid, $id); //取消商品收藏
                    break;
            }
            if (!isset($result['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($result);
    }

}