Newsale.php 4.83 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Product\NewsaleData;
use Product\NewsaleModel;

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

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

        $channel = $this->getCookie('_Channel', 'boys');
        $this->channelTrans($channel);

        $data = array();
        $data['newArrivalPage'] = true;
        $data['headerBanner'] = \Product\NewsaleModel::getNewFocus($channel);
        $goodsList = \Product\NewsaleModel::getNewProducts($channel, 60);
        if (!empty($goodsList)) {
            $data += $goodsList;
        }
        // 设置一些筛选的默认参数
        $data += array(
            'brand' => 0,
            'msort' => 0,
            'gender' => $this->getCookie('_Channel', 'boys'),
            'price' => 0,
            'size' => 0,
            'dayLimit' => 1,
            'discount' => ''
        );

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

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

        $channel = $this->getCookie('_Channel', 'boys');
        $this->channelTrans($channel);

        $data = array();
        $data['discountPage'] = true;
        $data['headerBanner'] = \Product\NewsaleModel::getNewFocus($channel);
        $goodsList = \Product\NewsaleModel::getSaleProducts($channel, 60);
        if (!empty($goodsList)) {
            $data += $goodsList;
        }
        // 设置一些筛选的默认参数
        $data += array(
            'brand' => 0,
            'msort' => 0,
            'gender' => $this->getCookie('_Channel', 'boys'),
            'price' => 0,
            'size' => 0,
            'discount' => '0.1,0.9'
        );
//var_dump($data);exit;
        $this->_view->display('sale', $data);
    }

    /**
     * Ajax方式筛选新品到着、折扣专区商品
     * 
     * @return array 根据指定条件筛选之后的商品
     */
    public function selectNewSaleAction()
    {
        if ($this->isAjax()) {
            $gender = $this->get('gender', 'boys');
            $brand = $this->get('brand', null);
            $sort = $this->get('msort', null);
            $color = $this->get('color', null);
            $size = $this->get('size', null);
            $price = $this->get('price', null);
            $p_d = $this->get('discount', null);
            $channel = $this->getCookie('_Channel', 'boys');
            $dayLimit = $this->get('dayLimit', null);
            $limit = $this->get('limit', 60);
            $page = $this->get('page', 1);

            // 转换性别
            if($gender === 'boys')
            {
                $gender = '1,3';
            }
            elseif($gender === 'girls')
            {
                $gender = '2,3';
            }
            else
            {
                $gender = '1,2,3';
            }

            // 转换排序方式
            $order = $this->get('order', null);
            $type = $this->get('type', '');
            switch ($type) {
                case 'price':
                    $order = ($order == 0) ? 's_p_desc' : 's_p_asc';
                    break;
                case 'discount':
                    $order = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
                    break;
                case 'newest':
                default:
                    $order = ($order == 0) ? 's_t_desc' : 's_t_asc';
                    break;
            }

            // 转换频道
            $this->channelTrans($channel);

            $data = NewsaleData::selectNewSaleProducts(
                $gender, $brand, $sort, $color, 
                $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order
            );
            $result = \Product\NewsaleModel::selectData($data);

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

    /**
     * 转换频道
     * @param  string &$channel  待转换的频道
     * @return integer           转换之后的频道
     */
    private function channelTrans(&$channel)
    {
        switch ($channel) {
            case 'girls':
                $channel = 2;
                break;
            case 'kids':
                $channel = 3;
                break;
            case 'lifestyle':
                $channel = 4;
                break;
            case 'boys':
            default:
                $channel = 1;
                break;
        }
    }

}