Newsale.php 7.72 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Product\NewsaleData;
use Plugin\Helpers;

/**
 * 新品到着
 */
class NewsaleController extends AbstractAction
{

    /**
     * 新品到着
     *
     * @param int channel 1:男生,2:女生,3:潮童,4:创意生活
     */
    public function indexAction()
    {
        $this->setTitle('新品到着');
        $this->setNavHeader('新品到着');

        $channel = $this->get('channel') ? $this->get('channel') : Helpers::getChannelByCookie();
        // 设置一些筛选的默认参数
        $data = array(
            'newArrivalPage' => true,
            'showDownloadApp' => true,
            'pageFooter' => true,
            'headerBanner' => \Product\NewsaleModel::getNewFocus($channel),
            'brand' => '0',
            'sort' => '0',
            'gender' => $this->get('gender') ? $this->get('gender') : Helpers::getGenderByCookie(),
            'channel' => $channel,
            'price' => '0',
            'size' => '0',
            'dayLimit' => 1,
            'discount' => '',
            'cartUrl' => Helpers::url('/cart/index/index', null),
        );
        $this->_view->display('new', $data);
    }

    /**
     * 折扣专区
     *
     * @param int channel 1:男生,2:女生,3:潮童,4:创意生活
     */
    public function discountAction()
    {
        $this->setTitle('折扣专区');
        $this->setNavHeader('Sale');

        $channel = $this->get('channel') ? $this->get('channel') : Helpers::getChannelByCookie();
        $gender = $this->get('gender') ? $this->get('gender') : Helpers::getGenderByCookie();
        // 设置一些默认参数
        $data = array(
            'discountPage' => true,
            'headerBanner' => \Product\NewsaleModel::getSaleFocus($channel),
            'showDownloadApp' => true,
            'pageFooter' => true,
            'brand' => '0',
            'sort' => '0',
            'gender' => $gender,
            'channel' => $channel,
            'price' => '0',
            'size' => '0',
            'discount' => '0.1,0.9',
            'cartUrl' => Helpers::url('/cart/index/index', null),
        );

        $this->_view->display('sale', $data);
    }

    /**
     * 热销排行榜
     *
     * @param int channel 1:男生,2:女生,3:潮童,4:创意生活
     */
    public function hotrankAction()
    {
        $this->setTitle('热销排行榜');
        $this->setNavHeader('热销排行榜');

        $channel = Helpers::getChannelByCookie();
        // 设置一些默认参数
        $data = array(
            'hotrankPage' => true,
            'headerBanner' => \Product\NewsaleModel::getNewFocus($channel),
            'showDownloadApp' => true,
            'pageFooter' => true,
            'cartUrl' => Helpers::url('/cart/index/index'),
            'wxshare' => array(
                'shareLink' => 'https://new.m.yohobuy.com/hotrank',
                'shareImg' => 'https://img02.yohoboys.com/staticimg/2016/09/22/11/022e716d92550536a6b218da8c8ef7fdd2.jpg',
                'shareTitle' => 'YOHO!BUY 有货 【新品到着】潮流夯货上架开催,全面盘点当季最热销的 TOP 单品~',
                'shareDesc' => '潮流购物逛不停,新品 IN 品等你来!'
            )
        );

        $this->_view->display('hotrank', $data);
    }

    /**
     * Ajax方式获取热销排行榜商品
     *
     * @return array 根据指定条件筛选之后的商品
     */
    public function selectHotrankAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $sort = $this->get('sort', null);
            $tab_id = $this->get('tab_id', null);
            $limit = $this->get('limit', 50);
            $page = $this->get('page', 1);
            $notab = (boolean)$this->get('notab', false);

            // 获取性别
            $gender = $this->get('gender') ? $this->get('gender') : Helpers::getGenderByCookie();
            $channel = $this->get('channel') ? $this->get('channel') : Helpers::getChannelByCookie();
            $result = \Product\NewsaleModel::selectTopData($gender, $channel, $sort, $tab_id, $notab, $limit, $page);
        }
        if (empty($result)) {
            echo ' ';
        } else {
            $this->_view->display('hotlist', $result);
        }
    }

    /**
     * Ajax方式筛选新品到着、折扣专区商品
     *
     * @return array 根据指定条件筛选之后的商品
     */
    public function selectNewSaleAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $gender = $this->get('gender') ? $this->get('gender') : Helpers::getGenderByCookie();
            $age_level = $this->get('age_level', null);
            $brand = $this->get('brand', null);
            $sort = $this->get('sort', null);
            $color = $this->get('color', null);
            $size = $this->get('size', null);
            $price = $this->get('price', null);
            $p_d = $this->get('discount', null);
            $dayLimit = $this->get('dayLimit', null);
            $limit = $this->get('limit', 60);
            $page = $this->get('page', 1);

            // 转换排序方式
            $orderVal = $this->get('order', null);
            $type = $this->get('type', '');
            $order = Helpers::transOrder($orderVal, $type);

            // 转换频道
            $channel = $this->get('channel') ? $this->get('channel') : Helpers::getChannelByCookie();

            // 产品吴婷要求这么做,目的是保持性别中的所有性别和当前频道性别一致
            if ($gender === '1,2,3') {
                switch ($channel) {
                    case 1:
                        $gender = '1,3';
                        break;
                    case 2:
                        $gender = '2,3';
                        break;
                    default:
                        break;
                }
            }

            $data = NewsaleData::selectNewSaleProducts(
                $gender, '0', $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order, null
            );
            $result = \Product\NewsaleModel::selectData($data);
        }
        if (empty($result)) {
            echo ' ';
        } else {
            $this->_view->display('product', $result);
        }
    }

    /**
     * Ajax方式查询筛选数据
     *
     * @return array 筛选数据
     */
    public function filterAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $gender = $this->get('gender') ? $this->get('gender') : Helpers::getGenderByCookie();
            $age_level = $this->get('$age_level', null);
            $brand = $this->get('brand', null);
            $shop = $this->get('shop_id', null);
            $sort = $this->get('sort', null);
            $color = $this->get('color', null);
            $size = $this->get('size', null);
            $price = $this->get('price', null);
            $p_d = $this->get('discount', null);
            $dayLimit = $this->get('dayLimit', null);
            $limit = $this->get('limit', 60);
            $page = $this->get('page', 1);

            // 转换排序方式
            $orderVal = $this->get('order', null);
            $type = $this->get('type', '');
            $order = Helpers::transOrder($orderVal, $type);

            $channel = $this->get('channel') ? $this->get('channel') : Helpers::getChannelByCookie();
            $data = NewsaleData::selectNewSaleProducts(
                $gender, $age_level, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order, $shop
            );
            $result = \Product\NewsaleModel::filterData($data, $gender);
        }

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

}