|
|
<?php
|
|
|
|
|
|
use Action\AbstractAction;
|
|
|
use LibModels\Wap\Product\SearchData;
|
|
|
use LibModels\Wap\Category\BrandData;
|
|
|
use LibModels\Wap\Category\ClassData;
|
|
|
use Category\ClassModel;
|
|
|
use Plugin\DataProcess\ListProcess;
|
|
|
use Plugin\Helpers;
|
|
|
|
|
|
/**
|
|
|
* 商品列表页
|
|
|
*/
|
|
|
class ListController extends AbstractAction
|
|
|
{
|
|
|
/**
|
|
|
* 搜索列表页
|
|
|
*/
|
|
|
public function indexAction()
|
|
|
{
|
|
|
$query = $this->get('query', null);
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->getCookie('_Channel', 'boys');
|
|
|
$p_d = $this->get('p_d', null);
|
|
|
$misort = $this->get('misort', null);
|
|
|
$msort = $this->get('msort', null);
|
|
|
|
|
|
$data = array(
|
|
|
'pageHeader' => array(
|
|
|
'navBack' => true,
|
|
|
'navTitle' => '搜索',
|
|
|
'navHome' => '/'
|
|
|
),
|
|
|
'goodListPage' => true,
|
|
|
'goodList' => array(
|
|
|
'brand' => 0,
|
|
|
'msort' => 0,
|
|
|
'gender' => $gender,
|
|
|
'price' => 0,
|
|
|
'size' => 0,
|
|
|
'discount' => ''
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// 首先查询是否属于内置品类
|
|
|
$classes = ClassModel::getClassesArr();
|
|
|
$classFlag = array_search($query, $classes);
|
|
|
if($classFlag !== false)// 属于内部品类
|
|
|
{
|
|
|
$data['pageHeader']['navTitle'] = '所有'.$query;
|
|
|
}
|
|
|
|
|
|
// 如果存在搜索字符串就显示搜索栏
|
|
|
if(!is_null($query) && $classFlag === false)
|
|
|
{
|
|
|
$data['search'] = array(
|
|
|
'default' => $query
|
|
|
);
|
|
|
}
|
|
|
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
|
|
|
// 查询数据
|
|
|
$listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
|
|
|
// 如果存在品牌信息就显示品牌字段
|
|
|
if(isset($tmpData['brand']) && !empty($tmpData['brand']))
|
|
|
{
|
|
|
$brandData = $tmpData['brand'];
|
|
|
$data['brandWay'] = array(
|
|
|
'url' => '/product/list/brand?brand='.$brandData['id'],
|
|
|
'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),
|
|
|
'name' => $brandData['brand_name']
|
|
|
);
|
|
|
|
|
|
// 设置品牌默认值
|
|
|
$data['goodList']['brand'] = $brandData['id'];
|
|
|
}
|
|
|
|
|
|
$data['goodList'] += ListProcess::getListData($tmpData);
|
|
|
}
|
|
|
|
|
|
$this->_view->display('index', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Ajax异步筛选请求
|
|
|
*/
|
|
|
public function searchAction()
|
|
|
{
|
|
|
if($this->isAjax())
|
|
|
{
|
|
|
$query = $this->get('query', null);
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->get('gender', null);
|
|
|
$color = $this->get('color', null);
|
|
|
$size = $this->get('size', null);
|
|
|
$price = $this->get('price', null);
|
|
|
$p_d = $this->get('discount', null);
|
|
|
$sort = $this->get('msort', null);
|
|
|
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
|
|
|
// 转换排序方式
|
|
|
$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;
|
|
|
}
|
|
|
|
|
|
$data = array();
|
|
|
// 查询数据
|
|
|
$listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
|
|
|
unset($tmpData['filter']);// 不要筛选条件的数据
|
|
|
$data = ListProcess::getListData($tmpData);
|
|
|
}
|
|
|
|
|
|
if(empty($data))
|
|
|
{
|
|
|
echo ' ';
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$this->_view->display('list', $data);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 品牌商品列表页
|
|
|
*/
|
|
|
public function brandAction()
|
|
|
{
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->getCookie('_Channel', 'boys');
|
|
|
$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);
|
|
|
|
|
|
$data = array(
|
|
|
'pageHeader' => array(
|
|
|
'navBack' => true,
|
|
|
'navHome' => '/'
|
|
|
),
|
|
|
'goodListPage' => true,
|
|
|
'goodList' => array(
|
|
|
'brandHome' => array(
|
|
|
'id' => $brand
|
|
|
),
|
|
|
'brand' => $brand,
|
|
|
'msort' => 0,
|
|
|
'gender' => $gender,
|
|
|
'sort' => 0,
|
|
|
'price' => 0,
|
|
|
'size' => 0,
|
|
|
'discount' => '',
|
|
|
'p_d' => ''
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// 获取品牌介绍信息
|
|
|
$introData = BrandData::getBrandIntro($brand);
|
|
|
if(isset($introData['code']) && $introData['code'] === 200)
|
|
|
{
|
|
|
$data['goodList']['brandHome']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : '';
|
|
|
}
|
|
|
|
|
|
// 获取品牌banner的数据
|
|
|
$uid = $this->getUid();
|
|
|
$bannerData = BrandData::getBrandBanner($brand, $uid);
|
|
|
if(isset($bannerData['code']) && $bannerData['code'] === 200)
|
|
|
{
|
|
|
$data['goodList']['brandHome']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : '';
|
|
|
}
|
|
|
|
|
|
// 查询数据
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
$listData = BrandData::selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
// 设置品牌名称
|
|
|
$data['pageHeader']['navTitle'] = isset($tmpData['brand_name']) ? $tmpData['brand_name'] : '';
|
|
|
|
|
|
$data['goodList'] += ListProcess::getListData($tmpData);
|
|
|
}
|
|
|
|
|
|
$this->_view->display('index', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 品类商品列表页
|
|
|
*/
|
|
|
public function classAction()
|
|
|
{
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->getCookie('_Channel', 'boys');
|
|
|
$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);
|
|
|
|
|
|
$data = array(
|
|
|
'pageHeader' => array(
|
|
|
'navBack' => true,
|
|
|
'navHome' => '/'
|
|
|
),
|
|
|
'goodListPage' => true,
|
|
|
'goodList' => array(
|
|
|
'brand' => 0,
|
|
|
'msort' => 0,
|
|
|
'gender' => $gender,
|
|
|
'sort' => $sort,
|
|
|
'price' => 0,
|
|
|
'size' => 0,
|
|
|
'discount' => ''
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// 根据id查询类的名称
|
|
|
$classes = ClassModel::getClassesArr();
|
|
|
$data['pageHeader']['navTitle'] = isset($classes[$sort]) ? $classes[$sort] : '';
|
|
|
|
|
|
// 查询数据
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
$listData = ClassData::selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
|
|
|
$data['goodList'] += ListProcess::getListData($tmpData);
|
|
|
}
|
|
|
|
|
|
$this->_view->display('index', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 性别数据转换
|
|
|
*
|
|
|
* @param string &$gender 从cookie中获取的gender值,最后得到转换之后接口调用的值
|
|
|
*/
|
|
|
private function genderTrans(&$gender)
|
|
|
{
|
|
|
if($gender === 'boys')
|
|
|
{
|
|
|
$gender = '1,3';
|
|
|
}
|
|
|
elseif($gender === 'girls')
|
|
|
{
|
|
|
$gender = '2,3';
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$gender = '1,2,3';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |