547 lines
20 KiB
PHP
547 lines
20 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 品牌管理
|
|
*/
|
|
|
|
namespace app\home\controller;
|
|
use think\facade\View;
|
|
use think\facade\Lang;
|
|
|
|
class Brand extends BaseMall {
|
|
|
|
//每页显示商品数
|
|
const PAGESIZE = 10;
|
|
|
|
public function initialize() {
|
|
Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/brand.lang.php');
|
|
parent::initialize(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
|
|
private function getCate($cid)
|
|
{
|
|
$data = [
|
|
'name' => '',
|
|
'aid' => 0,
|
|
'seo' => 'subject',
|
|
];
|
|
|
|
if ($cid == 766) {
|
|
$name = "艺术学";
|
|
$aid = 5;
|
|
$seo = 'arts';
|
|
}
|
|
if ($cid == 767) {
|
|
$name = "商科";
|
|
$aid = 6;
|
|
$seo = 'business';
|
|
}
|
|
if ($cid == 768) {
|
|
$name = "通讯和媒体";
|
|
$aid = 7;
|
|
$seo = 'communication';
|
|
}
|
|
if ($cid == 774) {
|
|
$name = "计算机科学";
|
|
$aid = 8;
|
|
$seo = 'computer';
|
|
}
|
|
if ($cid == 775) {
|
|
$name = "教育学";
|
|
$aid = 9;
|
|
$seo = 'education';
|
|
}
|
|
if ($cid == 776) {
|
|
$name = "工程学";
|
|
$aid = 36;
|
|
$seo = 'engineering';
|
|
}
|
|
if ($cid == 777) {
|
|
$name = "英文-写作";
|
|
$aid = 37;
|
|
$seo = 'english';
|
|
}
|
|
if ($cid == 778) {
|
|
$name = "全球观";
|
|
$aid = 38;
|
|
$seo = 'global';
|
|
}
|
|
if ($cid == 780) {
|
|
$name = "人文学";
|
|
$aid = 39;
|
|
$seo = 'human';
|
|
}
|
|
if ($cid == 781) {
|
|
$name = "数学和统计学";
|
|
$aid = 40;
|
|
$seo = 'math';
|
|
}
|
|
if ($cid == 783) {
|
|
$name = "自然科学";
|
|
$aid = 41;
|
|
$seo = 'natural';
|
|
}
|
|
if ($cid == 784) {
|
|
$name = "其他学科";
|
|
$aid = 42;
|
|
$seo = 'others';
|
|
}
|
|
if ($cid == 785) {
|
|
$name = "社会学";
|
|
$aid = 43;
|
|
$seo = 'social';
|
|
}
|
|
if ($cid == 790) {
|
|
$name = "法学";
|
|
$aid = 53;
|
|
$seo = 'law';
|
|
}
|
|
|
|
$data = [
|
|
'name' => $name,
|
|
'aid' => $aid,
|
|
'seo' => $seo,
|
|
];
|
|
|
|
return $data;
|
|
}
|
|
public function index() {
|
|
|
|
/* //分类导航
|
|
$nav_link = array(
|
|
0 => array(
|
|
'title' => lang('ds_index'),
|
|
'link' => HOME_SITE_URL
|
|
),
|
|
1 => array(
|
|
'title' => lang('brand_index_all_brand')
|
|
)
|
|
);
|
|
View::assign('nav_link_list', $nav_link);
|
|
|
|
$brand_mod=model('brand');
|
|
$brand_c_list = $brand_mod->getBrandList(array());
|
|
$brands = $this->_tidyBrand($brand_c_list);
|
|
extract($brands);
|
|
View::assign('brand_c', $brand_listnew);
|
|
View::assign('brand_class', $brand_class);
|
|
View::assign('brand_r', $brand_r_list);
|
|
|
|
//页面输出
|
|
View::assign('index_sign', 'brand');
|
|
$seo = model('seo')->type('brand')->show();
|
|
$this->_assign_seo($seo);
|
|
*/
|
|
|
|
$this->_model_search = model('search');
|
|
$goodsclass_model = model('goodsclass');
|
|
|
|
$header_title = '所有课程';
|
|
$header_title_eng = 'All Courses';
|
|
$header_image = '/static/home/new/images/course.png';
|
|
//分类页过来
|
|
$c_id = input('param.c_id');
|
|
$a_id = 0;
|
|
|
|
$page_size = input('param.page_size', self::PAGESIZE);
|
|
View::assign('page_size', $page_size);
|
|
|
|
|
|
if (!empty($c_id)) {
|
|
$rst = $this->getCate($c_id);
|
|
|
|
$a_id = $rst['aid'];
|
|
|
|
$a2 = input('param.a_id');
|
|
if (!empty($a2)) {
|
|
$a_array = [5=>766,6=>767,7=>768,8=>774,9=>775,36=>776,37=>777,
|
|
38=>778,39=>780,40=>781,41=>783,42=>784,43=>785,53=>790];
|
|
|
|
|
|
$arr2 = explode('_', $a2);
|
|
foreach ($arr2 as $val) {
|
|
if (isset($a_array[$val])) {
|
|
header("Location:/Brand.html?c_id=".$a_array[$val]);exit();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$cate = $goodsclass_model->getGoodsclassInfoById($c_id);
|
|
|
|
$header_title = $rst['name'];
|
|
$header_title_eng = $cate['gc_name'];
|
|
$header_image = '/uploads/home/common/'. $cate['gc_image'];
|
|
|
|
//seo
|
|
$seo = model('seo')->type($rst['seo'])->param([])->show();
|
|
$this->_assign_seo($seo);
|
|
View::assign('show_type', 2);
|
|
View::assign('pro_desc', $cate['pro_desc']);
|
|
} else {
|
|
|
|
// SEO
|
|
$seo = model('seo')->type('course')->param([])->show();
|
|
$this->_assign_seo($seo);
|
|
View::assign('show_type', 1);
|
|
}
|
|
|
|
View::assign('header_title', $header_title);
|
|
View::assign('header_title_eng', $header_title_eng);
|
|
View::assign('header_image', $header_image);
|
|
|
|
//显示左侧分类
|
|
//默认分类,从而显示相应的属性和品牌
|
|
$cate_id = $default_classid = intval(input('param.cate_id', 766));
|
|
$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, $a_id);
|
|
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);
|
|
// var_dump($attr_array);die;
|
|
//处理排序
|
|
$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','=',764);
|
|
$goods_list = $goods_model->getGoodsUnionList($condition, $fields, $order,'goodscommon.goods_commonid',$page_size);
|
|
// }
|
|
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, '<font style="color:#f00;">' . $search_keyword . '</font>', $value['goods_name']);
|
|
} else {
|
|
$goods_list[$key]['goods_name_highlight'] = $value['goods_name'];
|
|
}
|
|
}
|
|
}
|
|
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'] : '');
|
|
}
|
|
|
|
|
|
|
|
|
|
// 当前位置导航
|
|
$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);
|
|
|
|
View::assign('hot_search', @explode(',', config('ds_config.hot_search'))); //热门搜索
|
|
|
|
|
|
//全部科目
|
|
$recommend = model('goodsclass')->getGoodsclassList(['gc_parent_id' => 764]);
|
|
View::assign('recommend', $recommend);
|
|
|
|
|
|
|
|
// 商品详细信息
|
|
$goods_model = model('goods');
|
|
$goods_detail = $goods_model->getGoodsDetail(rand(14906,19161));
|
|
|
|
$goods_info = $goods_detail['goods_info'];
|
|
View::assign('goodss', $goods_info);
|
|
|
|
return View::fetch($this->template_dir . 'index');
|
|
}
|
|
|
|
/**
|
|
* 所有品牌全部显示在一级类目下,不显示二三级类目
|
|
* @param type $brand_c_list
|
|
* @return type
|
|
*/
|
|
private function _tidyBrand($brand_c_list) {
|
|
$brand_listnew = array();#品怕分类下对应的品牌
|
|
$brand_class = array();#品牌分类
|
|
$brand_r_list = array();#推荐品牌
|
|
if (!empty($brand_c_list) && is_array($brand_c_list)) {
|
|
$goods_class = model('goodsclass')->getGoodsclassForCacheModel();
|
|
foreach ($brand_c_list as $key => $brand_c) {
|
|
$gc_array = $this->_getTopClass($goods_class, $brand_c['gc_id']);
|
|
if (empty($gc_array)) {
|
|
if ($brand_c['brand_showtype'] == 1) {
|
|
$brand_listnew[0]['text'][] = $brand_c;
|
|
} else {
|
|
$brand_listnew[0]['image'][] = $brand_c;
|
|
}
|
|
$brand_class[0]['brand_class'] = lang('ds_other');
|
|
} else {
|
|
if ($brand_c['brand_showtype'] == 1) {
|
|
$brand_listnew[$gc_array['gc_id']]['text'][] = $brand_c;
|
|
} else {
|
|
$brand_listnew[$gc_array['gc_id']]['image'][] = $brand_c;
|
|
}
|
|
$brand_class[$gc_array['gc_id']]['brand_class'] = $gc_array['gc_name'];
|
|
}
|
|
//推荐品牌
|
|
if ($brand_c['brand_recommend'] == 1) {
|
|
$brand_r_list[] = $brand_c;
|
|
}
|
|
}
|
|
}
|
|
krsort($brand_class);
|
|
krsort($brand_listnew);
|
|
return array('brand_listnew' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r_list' => $brand_r_list);
|
|
}
|
|
|
|
/**
|
|
* 获取顶级商品分类\递归调用
|
|
* @param type $goods_class
|
|
* @param type $gc_id
|
|
* @return type
|
|
*/
|
|
private function _getTopClass($goods_class, $gc_id) {
|
|
if (!isset($goods_class[$gc_id])) {
|
|
return null;
|
|
}
|
|
if($goods_class[$gc_id]['gc_parent_id']==$gc_id){//自身ID等于父ID
|
|
return null;
|
|
}
|
|
if(isset($goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id']) && $goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id']==$gc_id){//父分类的父ID等于自身ID
|
|
return null;
|
|
}
|
|
return $goods_class[$gc_id]['gc_parent_id'] == 0 ? $goods_class[$gc_id] : $this->_getTopClass($goods_class, $goods_class[$gc_id]['gc_parent_id']);
|
|
}
|
|
|
|
/**
|
|
* 品牌商品列表
|
|
*/
|
|
//原方法 function list
|
|
public function brand_goods() {
|
|
/**
|
|
* 验证品牌
|
|
*/
|
|
$brand_model = model('brand');
|
|
$brand_id = intval(input('param.brand_id'));
|
|
$brand_info = $brand_model->getBrandInfo(array('brand_id' => $brand_id));
|
|
if (!$brand_info) {
|
|
$this->error(lang('param_error'));
|
|
}
|
|
|
|
/**
|
|
* 获得推荐品牌
|
|
*/
|
|
$brand_r_list = model('brand')->getBrandPassedList(array('brand_recommend' => 1), 'brand_id,brand_name,brand_pic',10, 'brand_sort asc, brand_id desc');
|
|
View::assign('brand_r', $brand_r_list);
|
|
|
|
// 得到排序方式
|
|
$order = 'goods_id desc';
|
|
|
|
$key = input('param.key');
|
|
|
|
if (!empty($key)) {
|
|
$order_tmp = trim($key);
|
|
$sequence = input('param.order') == 1 ? 'asc' : 'desc';
|
|
switch ($order_tmp) {
|
|
case '1' : // 销量
|
|
$order = 'goods_salenum' . ' ' . $sequence;
|
|
break;
|
|
case '2' : // 浏览量
|
|
$order = 'goods_click' . ' ' . $sequence;
|
|
break;
|
|
case '3' : // 价格
|
|
$order = 'goods_promotion_price' . ' ' . $sequence;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 字段
|
|
$fieldstr = "goods_id,goods_commonid,goods_name,goods_advword,goods_price,goods_promotion_price,goods_promotion_type,goods_marketprice,goods_storage,goods_image,goods_freight,goods_salenum,color_id,evaluation_good_star,evaluation_count,is_virtual,is_goodsfcode,is_appoint,is_presell,is_have_gift";
|
|
// 条件
|
|
$where = array();
|
|
$where[]=array('brand_id','=',$brand_info['brand_id']);
|
|
$area_id = intval(input('param.area_id'));
|
|
if ($area_id > 0) {
|
|
$where[]=array('areaid_1','=',$area_id);
|
|
}
|
|
if (input('param.gift') == 1) {
|
|
$where[]=array('is_have_gift','=',1);
|
|
}
|
|
$goods_model = model('goods');
|
|
|
|
$goods_list = $goods_model->getGoodsListByColorDistinct($where, $fieldstr, $order, 24);
|
|
|
|
View::assign('show_page', !empty($goods_list)?$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 = $goods_model->getGoodsImageList(array(array('goods_commonid','in', $commonid_array)));
|
|
|
|
foreach ($goods_list as $key => $value) {
|
|
// 商品多图
|
|
foreach ($goodsimage_more as $v) {
|
|
if ($value['goods_commonid'] == $v['goods_commonid'] && $value['color_id'] == $v['color_id']) {
|
|
$goods_list[$key]['image'][] = $v;
|
|
}
|
|
}
|
|
//将关键字置红
|
|
$goods_list[$key]['goods_name_highlight'] = $value['goods_name'];
|
|
}
|
|
}
|
|
View::assign('goods_list', $goods_list);
|
|
|
|
// 地区
|
|
$province_array = model('area')->getTopLevelAreas();
|
|
View::assign('province_array', $province_array);
|
|
|
|
/* 引用搜索相关函数 */
|
|
require_once(base_path() . '/home/common_search.php');
|
|
|
|
/**
|
|
* 取浏览过产品的cookie(最大四组)
|
|
*/
|
|
$viewed_goods = model('goodsbrowse')->getViewedGoodsList(session('member_id'), 20);
|
|
View::assign('viewed_goods', $viewed_goods);
|
|
|
|
/**
|
|
* 分类导航
|
|
*/
|
|
$nav_link = array(
|
|
0 => array(
|
|
'title' => lang('ds_index'),
|
|
'link' => HOME_SITE_URL
|
|
),
|
|
1 => array(
|
|
'title' => lang('brand_index_all_brand'),
|
|
'link' => url('Brand/index')
|
|
),
|
|
2 => array(
|
|
'title' => $brand_info['brand_name']
|
|
)
|
|
);
|
|
View::assign('nav_link_list', $nav_link);
|
|
/**
|
|
* 页面输出
|
|
*/
|
|
View::assign('index_sign', 'brand');
|
|
|
|
//SEO 设置
|
|
$seo = model('seo')->type('brand_list')->param(array('name' => $brand_info['brand_name']))->show();
|
|
$this->_assign_seo($seo);
|
|
|
|
return View::fetch($this->template_dir.'brand_goods');
|
|
}
|
|
|
|
} |