Newsale.php 4.02 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->get('channel', 1);
        if (!is_numeric($channel)) {
            $this->error();
        }

        $data = array();
        $data['newArrival'] = true;
        $data['headerBanner'] = \Product\NewsaleModel::getNewFocus($channel);
        $goodsList = \Product\NewsaleModel::getNewProducts($channel, 20);
        if (!empty($goodsList)) {
            $data += $goodsList;
        }
        // 设置一些筛选的默认参数
        $data += array(
            'brand' => 0,
            'sort' => 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->get('channel', 1);
        if (!is_numeric($channel)) {
            $this->error();
        }

        $data = array();
        $data['discount'] = true;
        $data['headerBanner'] = \Product\NewsaleModel::getNewFocus($channel);
        $goodsList = \Product\NewsaleModel::getSaleProducts($channel, 20);
        if (!empty($goodsList)) {
            $data += $goodsList;
        }
        // 设置一些筛选的默认参数
        $data += array(
            'brand' => 0,
            'sort' => 0,
            'gender' => $this->getCookie('_Channel', 'boys'),
            'price' => 0,
            'size' => 0,
            'dayLimit' => 1,
            'discount' => '0.1,0.3'
        );
        $data['tabs'] = array(
            array(
                'title' => '1-3折',
                'dataId' => '0.1,0.3',
                'focus' => true
            ),
            array(
                'title' => '4-6折',
                'dataId' => '0.4,0.6',
            ),
            array(
                'title' => '7-9折',
                'dataId' => '0.7,0.9',
            ),
            array(
                'title' => 'ALL',
                'dataId' => '0.1,0.9',
            )
        );

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

    /**
     * Ajax方式筛选新品到着、折扣专区商品
     * 
     * @return array 根据指定条件筛选之后的商品
     */
    public function selectNewSaleAction()
    {
        if ($this->isAjax()) {
            $gender = $this->get('gender', '1,3');
            $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('p_d', null);
            $channel = $this->get('channel', '1');
            $dayLimit = $this->get('dayLimit', '1');
            $limit = $this->get('limit', 20);
            $page = $this->get('page', 1);

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

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

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

}