_model_search = model('search'); //显示左侧分类 //默认分类,从而显示相应的属性和品牌 $cate_id = $default_classid = intval(input('param.cate_id', 769)); $keyword = input('param.keyword'); $goods_class_array = array(); if ($default_classid > 0) { $goods_class_array = $this->_model_search->getLeftCategory(array($default_classid)); } elseif ($keyword != '') { //从TAG中查找分类 $goods_class_array = $this->_model_search->getTagCategory($keyword); //取出第一个分类作为默认分类,从而显示相应的属性和品牌 $default_classid = isset($goods_class_array[0]) ? $goods_class_array[0] : ""; $goods_class_array = $this->_model_search->getLeftCategory($goods_class_array, 1); } View::assign('goods_class_array', $goods_class_array); View::assign('default_classid', $default_classid); //获得经过属性过滤的商品信息 list($goods_param, $brand_array, $initial_array, $attr_array, $checked_brand, $checked_attr) = $this->_model_search->getAttribute(input('param.'), $default_classid, 0); View::assign('brand_array', $brand_array); View::assign('initial_array', $initial_array); View::assign('attr_array', $attr_array); View::assign('checked_brand', $checked_brand); View::assign('checked_attr', $checked_attr); //处理排序 $order = 'goodscommon.goods_commend desc,goodscommon.goods_sort asc'; $key = input('param.key'); $sequence = input('param.order'); if (in_array($key, array('1', '2', '3'))) { $sequence = $sequence == '1' ? 'asc' : 'desc'; $order = str_replace(array('1', '2', '3'), array('goods_salenum', 'goods_click', 'goods_promotion_price'), $key); $order .= ' ' . $sequence; } $goods_model = model('goods'); // 字段 $fields = "goods.*,goodscommon.*"; $condition = array(); //执行正常搜索 if (isset($goods_param['class']['depth'])) { $condition[] = array('goodscommon.gc_id_' . $goods_param['class']['depth'],'=',$goods_param['class']['gc_id']); } $b_id = intval(input('param.b_id')); if ($b_id > 0) { $condition[]=array('goodscommon.brand_id','=',$b_id); } if ($keyword != '') { $condition[]=array('goodscommon.goods_name|goodscommon.goods_advword','like', '%' . $keyword . '%'); } $area_id = intval(input('param.area_id')); if ($area_id > 0) { $condition[]=array('goodscommon.areaid_1','=',$area_id); } $gift = intval(input('param.gift')); if ($gift == 1) { $condition[]=array('goods.is_have_gift','=',1); } if (isset($goods_param['goodsid_array'])) { $condition[]=array('goods.goods_id','in', $goods_param['goodsid_array']); } $priceMin = intval(input('param.priceMin')); if ($priceMin > 0) { $condition[]=array('goodscommon.goods_price','>=', $priceMin); } $priceMax = intval(input('param.priceMax')); if ($priceMax > 0) { $condition[]=array('goodscommon.goods_price','<=', $priceMax); } if ($priceMin > 0 && $priceMax > 0) { $condition[] = array('goodscommon.goods_price','between', array($priceMin, $priceMax)); } $condition[] = array('goods.gc_id_1','=',765); $goods_list = $goods_model->getGoodsUnionList($condition, $fields, $order,'goodscommon.goods_commonid', self::PAGESIZE); // } View::assign('show_page', is_object($goods_model->page_info)?$goods_model->page_info->render():""); // 商品多图 if (!empty($goods_list)) { $commonid_array = array(); // 商品公共id数组 foreach ($goods_list as $value) { $commonid_array[] = $value['goods_commonid']; } $commonid_array = array_unique($commonid_array); // 商品多图 $goodsimage_more = model('goods')->getGoodsImageList(array(array('goods_commonid','in', $commonid_array))); //搜索的关键字 $search_keyword = $keyword; foreach ($goods_list as $key => $value) { if(!$value['goods_storage']){ $goods_info=$goods_model->getGoodsStorageByCommonId($value['goods_commonid']); if($goods_info){ $value['goods_id']=$goods_info['goods_id']; } } // 商品多图 //商品列表主图限制不越过5个 $n = 0; foreach ($goodsimage_more as $v) { if ($value['goods_commonid'] == $v['goods_commonid'] && $value['color_id'] == $v['color_id']) { $n++; $goods_list[$key]['image'][] = $v; if ($n >= 5) break; } } //将关键字置红 if ($search_keyword) { $goods_list[$key]['goods_name_highlight'] = str_replace($search_keyword, '' . $search_keyword . '', $value['goods_name']); } else { $goods_list[$key]['goods_name_highlight'] = $value['goods_name']; } } } // var_dump($goods_list);die; View::assign('goods_list', $goods_list); if ($keyword != '') { View::assign('show_keyword', $keyword); } else { View::assign('show_keyword', isset($goods_param['class']['gc_name']) ? $goods_param['class']['gc_name'] : ''); } $goodsclass_model = model('goodsclass'); //查看项目 $classId = array_unique(array_column($goods_list, 'gc_id')); $class = []; foreach ($classId as $val) { $class[] = $goodsclass_model->getGoodsclassList(['gc_id' => $val], '*')[0] ?? []; } View::assign('class', $class); // SEO if ($keyword == '') { $seo_class_name = isset($goods_param['class']['gc_name'])?$goods_param['class']['gc_name']:''; if (is_numeric($cate_id) && empty($keyword)) { $seo_info = $goodsclass_model->getKeyWords($cate_id); if (empty($seo_info[1])) { $seo_info[1] = config('ds_config.site_name') . ' - ' . $seo_class_name; } $seo = model('seo')->type('program')->param(array('name' => $seo_class_name))->show(); $this->_assign_seo($seo); } } elseif ($keyword != '') { $keyword=urldecode($keyword); View::assign('html_title', (empty($keyword) ? '' : $keyword . ' - ') . config('ds_config.site_name') . lang('ds_search')); } // 当前位置导航 $nav_link_list = $goodsclass_model->getGoodsclassnav($cate_id); View::assign('nav_link_list', $nav_link_list); // 得到自定义导航信息 $nav_id = intval(input('param.nav_id')); View::assign('index_sign', $nav_id); // 地区 $province_array = model('area')->getTopLevelAreas(); View::assign('province_array', $province_array); /* 引用搜索相关函数 */ require_once(base_path() . '/home/common_search.php'); // 浏览过的商品 $viewed_goods = model('goodsbrowse')->getViewedGoodsList(session('member_id'), 20); View::assign('viewed_goods', $viewed_goods); return View::fetch($this->template_dir . 'index'); } }