public function lists(){
$category=D( 'Category' )->getCategory() ;
for($i=0;$i<11;$i++){
unset($category[0]['child'][$i]['child']['0']);
}
$this->assign('category', $category);
$condition = intval($_GET['condition']);
$this->assign('condition',$condition);
$sql = condition_to_sql($condition);
$goodlist = M('document')->query('select * from romaego_document as a,romaego_document_product as b where a.display=1 and a.id=b.id'.$sql.' limit 12');
$this->assign('goodlist',$goodlist);
$this->meta_title = '全部商品';
//dump($goodlist);
/******************************/
$pid = I('get.pid',0,'intval');
$path = I('get.path',0,'intval');
$price = safe_replace($_GET['price']);
$style = I('get.style',0,'intval');
$height = safe_replace($_GET['height']);
$property = safe_replace($_GET['property']);
$material = safe_replace($_GET['material']);
$size = $this->safe_replace($_GET['size']);
$order = intval($_GET['order']);
$selectparameters = array($pid,$path,$style,$material,$size,$height,$property,$price,$order);
//输出到前台input记录
$this->assign('selectparameters',$selectparameters);
$category = D('Category')->info($pid);
$leixing = D('Category')->where('id='.$pid)->find();
//获取头部类型名称
$this->assign('leixing',$leixing);
/* 分类信息 */
$category = $this->category();
$cid = D('Category')->getChildrenId($pid);
$getclass = D('Category')->where('pid='.$pid)->select();//获取类型选项
//dump($cid);
//dump($getclass);
//获取每个分类商品有多少个
foreach($getclass as $k=>$v){
if(in_array($getclass[$k]['id'],array('171','367','366','365','364','362','363','360','359','371','372'))){
/* 滤去楼层管理 */
unset($getclass[$k]);
}else{
//$sql = 'select count(*) from romaego_document_product where path like "%'.$getclass[$k]['id'].'%"';
//$getclass[$k]['num'] = D('DocumentProduct')->query($sql);
$catepid['category_id']=$getclass[$k]['id'];
$catepid['status']=1;
$getclass[$k]['num'] = M('Document')->where($catepid)->count();
}
}
//dump($getclass);
$this->assign('getclass',$getclass);
$getstyle = D('Style')->select();//获取风格
$this->assign('getstyle',$getstyle);
//dump($getstyle);
//拉取搜索信息
if($path){
$search = D('Searchkeyword')->where('cateid='.$path)->find();
}else{
$search = D('Searchkeyword')->where('cateid='.$pid)->find();
}
$search['size'] = data_to_array(',', $search['sizerange']);
$search['price'] = data_to_array(',', $search['pricerange']);
/* foreach($search['price'] as $k=>$v){
$search['price'][$k] = explode('-', $search['price'][$k]);
} */
$search['material'] = data_to_array(',', $search['materialrange']);
$search['property'] = data_to_array(',', $search['property']);
$search['height'] = data_to_array(',', $search['heightrange']);
$this->assign('search',$search);
//过滤掉楼层的分类数据
$map_notin = array('not in', '359,360,362,363,364,365,366,367,171' );
$map['category_id']=array(array("in",$cid), $map_notin );
$map['display'] = 1;
$map['status'] = 1;
$list = D("Document")->where($map)->select();
//dump($list);
if($list){
$documentIds = array_get_by_key($list, 'id');
$map =array();
$map['id'] = array('in',$documentIds);
/* 判断分类是否已绑定了商品模型*/
$productModelId = getModelId('product');
$isBindProductModel = in_array( $productModelId, $category['model']);
if($isBindProductModel) {
//指定商品列表页16个商品/页展示
$list_row = 32;
//过滤无效数据, 返回存在DocumentProduct表中存在数据的商品Id
$productIds = D('DocumentProduct')->filterProductId( $documentIds );
}
//dump($productIds);
$map = addMapCondition( $map, array('in', $productIds ) );
//输出分页
//$page=D("DocumentProduct")->getPage($map, $list_row);
//$this->assign('page',$page);
//$num = D("DocumentProduct")->where($map)->count();
//$totalpage = $num?ceil($num/$list_row):1;
//$this->assign('totalnum', $num);
//$this->assign('totalPage', $totalpage);
}
//dump($material);
//过滤经销商地区的商品
// if($localshop){
// $shopsql = ' and b.shop_id in ('.$shopid.')';
// }else{
// $shopsql = ' and b.shop_id=1';
// }
//根据用户选择条件 继续过滤商品
if($path!=0){
//$map['path'] = array('like',"%$path%");
//$pathsql = ' and b.path like "%'.$path.'%"';
$pathsql = ' and a.category_id='.$path;
}
if($style!=0){
//$map['style'] = $style;
$stylesql = ' and b.style='.$style;
}
if(($material!='0')&&($material!=null)){
//$map['material'] = $material;
$materialsql = ' and b.material="'.$material.'"';
}
if($size!=0){
//这个size太难处理了
$sizesql = ' and b.size like "%'.$size.'%"';
}
if($height!=0){
//厚度sql
$heightsql = ' and b.height="'.$height.'"';
}
if(($property!='0')&&($property!='')){
//附加属性一
$propertysql = ' and b.propertyone="'.$property.'"';
}
if(($price!='0')&&($price!='')){
$price = explode('-',$price);
//$map['promotionprice'] = array('EGT',$price[0],'LT',$price[1]);
if(count($price)==2){
//$map['promotionprice'] = array('between',array(intval($price[0]),intval($price[1])));
$promotionpricesql = ' and b.promotionprice between '.intval($price[0]).' and '.intval($price[1]);
}else{
//$map['promotionprice'] = array('EGT',intval($price[0]));
$promotionpricesql = ' and b.promotionprice>='.intval($price[0]);
}
}
if($order!=0){
switch ($order){
case 1:
$ordersql = ' order by a.sale desc';
break;
case 2:
$ordersql = ' order by b.promotionprice asc';
break;
case 3:
$ordersql = ' order by a.view desc';
break;
case 4:
$ordersql = ' order by a.update_time asc';
break;
case 5:
$ordersql = ' order by b.discount asc';
break;
case 6:
$ordersql = ' order by a.collection desc';
break;
case 7:
$ordersql = ' order by a.sale asc';
break;
case 8:
$ordersql = ' order by b.promotionprice desc';
break;
case 9:
$ordersql = ' order by a.view asc';
break;
case 10:
$ordersql = ' order by a.update_time desc';
break;
case 11:
$ordersql = ' order by b.discount desc';
break;
case 12:
$ordersql = ' order by a.collection asc';
break;
default:
$ordersql = '';
break;
}
}
//dump($map);
if($map['id']['0']['1']){
$idsql = ' and a.id in ('.implode(',', $map['id']['0']['1']).')';
$totalsql = 'select a.*,b.pics,b.promotionprice from romaego_document as a,romaego_document_product as b where a.id=b.id'.$idsql.$pathsql.$stylesql.$materialsql.$promotionpricesql.$sizesql.$heightsql.$propertysql.$ordersql;
}else{
$totalsql = 'select * from romaego_document where id=0';
}
//dump($totalsql);
/* 数据分页*/
if($isBindProductModel&&$list){
//$list = D("DocumentProduct")->getLists($map, $list_row, $listsort);
//$list = D('DocumentProduct')->selectGood($map,$list_row);
$list = D('DocumentProduct')->goodselect($totalsql,$list_row);
//dump($list);
//dump(D("Document")->getLastSql());
}
dump($list);
//输出分页
$num = count(D('DocumentProduct')->query($totalsql));
$page=D("DocumentProduct")->currypage($num, $list_row);
$this->assign('page',$page);
$totalpage = $num?ceil($num/$list_row):1;
$this->assign('totalnum', $num);
$this->assign('totalPage', $totalpage);
// 赋值数据集
$this->assign('list',$list);
//频道页循环3级分类
$this->meta_title = $category['title'];
/* 模板赋值并渲染模板 */
$this->assign('ctg', $category);
/*****************************/
$this->display('Goods/allgoods');
}
最佳答案