...
|
...
|
@@ -105,16 +105,16 @@ class GoodsController extends HomebaseController { |
|
|
public function goods_search($search) {
|
|
|
unset($search['sort']);
|
|
|
if($search['region']) {
|
|
|
$where['region_id'] = $search['region'];
|
|
|
$where['g.region_id'] = $search['region'];
|
|
|
}
|
|
|
if($search['price']) {
|
|
|
$where['goods_price'] = array('between', explode('-', $search['price']));
|
|
|
$where['g.goods_price'] = array('between', explode('-', $search['price']));
|
|
|
if ($search['price'] == 20000) {
|
|
|
$where['goods_price'] = array('lt', $search['price']);
|
|
|
$where['g.goods_price'] = array('gt', $search['price']);
|
|
|
}
|
|
|
}
|
|
|
if($search['brand']) {
|
|
|
$where['brand_id'] = $search['brand'];
|
|
|
$where['g.brand_id'] = $search['brand'];
|
|
|
}
|
|
|
// 地区
|
|
|
$url['region_all'] = $search;
|
...
|
...
|
@@ -136,7 +136,7 @@ class GoodsController extends HomebaseController { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 商品列表处理方法,根据不同条件显示不同的列表
|
|
|
* 商品列表处理方法,根据不同条件显示不同的列表(pc端)
|
|
|
* @param array $where 查询条件
|
|
|
*/
|
|
|
private function _lists($where=array(),$order = null){
|
...
|
...
|
@@ -178,7 +178,7 @@ class GoodsController extends HomebaseController { |
|
|
return $posts;
|
|
|
}
|
|
|
|
|
|
// 商品列表页(手机端)
|
|
|
// 商品列表页(微信端)
|
|
|
public function goods_list_mobile() {
|
|
|
if(IS_POST) {
|
|
|
// 处理筛选内容
|
...
|
...
|
@@ -186,21 +186,22 @@ class GoodsController extends HomebaseController { |
|
|
$search['price'] = I('post.price');
|
|
|
$search['brand'] = I('post.brand');
|
|
|
$where = $this->goods_search($search);
|
|
|
$_GET['p'] = I('post.page',0,'intval');
|
|
|
// $_GET['p'] = I('post.page',0,'intval');
|
|
|
|
|
|
if(I('post.id',0,'intval')) {
|
|
|
$ids = $this->product_model->getChildId(I('post.id'));
|
|
|
$where['g.is_del'] = 0;
|
|
|
$where['g.sort_id'] = array('in',$ids);
|
|
|
$goodsList = $this->_lists($where,$search['sort']);
|
|
|
$goodsList = $this->_lists_mobile($where,$search['sort']);
|
|
|
} elseif(I('post.cid',0,'intval')) {
|
|
|
$where['g.is_del'] = 0;
|
|
|
$where['g.sort_id'] = array('in',I('post.cid'));
|
|
|
$goodsList = $this->_lists($where,$search['sort']);
|
|
|
$goodsList = $this->_lists_mobile($where,$search['sort']);
|
|
|
} else {
|
|
|
$this->ajaxReturn(array('status'=>false,'msg'=>'参数错误'));
|
|
|
}
|
|
|
foreach ($goodsList as $k=>$v) {
|
|
|
$goodsList[$k]['url'] = U('Portal/Goods/detail',array('id'=>$v['id']));
|
|
|
$goodsList[$k]['thumb'] = sp_get_image_preview_url($v['thumb']);
|
|
|
}
|
|
|
$this->ajaxReturn(array('status'=>true,'msg'=>'成功','data'=>$goodsList));
|
...
|
...
|
@@ -208,15 +209,61 @@ class GoodsController extends HomebaseController { |
|
|
$this->assign('id',I('get.id',0,'intval'));
|
|
|
$this->assign('cid',I('get.cid',0,'intval'));
|
|
|
// 筛选功能数组
|
|
|
$price_search = array('0-300','300-2000','2000-5000','5000-10000','10000-20000','20000');
|
|
|
$price = array('0-300'=>'0-300元','300-2000'=>'300-2000元','2000-5000'=>'2000-5000元','5000-10000'=>'5000-10000元','10000-20000'=>'10000-20000元','20000'=>'20000元以上');
|
|
|
$i = 0;
|
|
|
foreach($price as $k=>$v) {
|
|
|
$price_search[$i]['value'] = $k;
|
|
|
$price_search[$i]['label'] = $v;
|
|
|
$i++;
|
|
|
}
|
|
|
$this->assign('price_search',json_encode($price_search));
|
|
|
$this->region();
|
|
|
$this->assign('brandList',json_encode($this->goods_brand_model->getListName()));
|
|
|
$brandList = $this->goods_brand_model->getList();
|
|
|
foreach($brandList as $k=>$v) {
|
|
|
$brand_search[$k]['value'] = $v['id'];
|
|
|
$brand_search[$k]['label'] = $v['brand_name'];
|
|
|
}
|
|
|
$this->assign('brandList',json_encode($brand_search));
|
|
|
$this->assign('search_page',U('Portal/Goods/search_page'));
|
|
|
$this->display('goods_list');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 商品列表处理方法,根据不同条件显示不同的列表(微信端)
|
|
|
* @param array $where 查询条件
|
|
|
*/
|
|
|
private function _lists_mobile($where=array(),$order = null){
|
|
|
$this->goods_model
|
|
|
->where($where);
|
|
|
// 排序处理
|
|
|
if($order) {
|
|
|
if($order == 'news') {
|
|
|
$order = array('g.ctime'=>'DESC');
|
|
|
}
|
|
|
if($order == 'price_up') {
|
|
|
$order = array('g.goods_price'=>'ASC');
|
|
|
}
|
|
|
if($order == 'price_down') {
|
|
|
$order = array('g.goods_price'=>'DESC');
|
|
|
}
|
|
|
if($order == 'buy') {
|
|
|
$order = array('g.istop'=>'DESC');
|
|
|
}
|
|
|
} else {
|
|
|
$order = array('g.ctime'=>'DESC');
|
|
|
}
|
|
|
|
|
|
$posts = $this->goods_model->field(array('g.id,g.sort_id,g.brand_id,g.region_id,g.goods_name,g.short_name,g.goods_price,g.price,g.num,g.thumb,gb.brand_name,p.name'))->alias('g')
|
|
|
->join('__GOODS_BRAND__ as gb on g.brand_id = gb.id')
|
|
|
->join('__PRODUCT__ as p on g.sort_id = p.id')
|
|
|
->where($where)
|
|
|
// ->limit(12*(I('post.page',0,'intval')-1) , 12)
|
|
|
->order($order)
|
|
|
->select();
|
|
|
return $posts;
|
|
|
}
|
|
|
|
|
|
// 商品搜索页面
|
|
|
public function search() {
|
|
|
$keyword = $where['g.goods_name|g.short_name|gb.brand_name|p.name'] = I('get.keyword');
|
...
|
...
|
@@ -310,6 +357,8 @@ class GoodsController extends HomebaseController { |
|
|
'<a href='.U('goods_list',array('cid'=>$product['id'])).'>'.$product['name'].'</a>';
|
|
|
$this->assign('goods_nav',$nav);
|
|
|
$info['images'] = json_decode($info['image'], true);
|
|
|
$cart_count = M('Cart')->where(array('user_id'=>$user_id))->sum('num');
|
|
|
$this->assign('cart_count',$cart_count);
|
|
|
$this->assign('news',$news);
|
|
|
$this->assign($info);
|
|
|
$this->display();
|
...
|
...
|
|