Brand.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * 品牌管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Brand extends BaseMall
  16. {
  17. public function initialize()
  18. {
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/brand.lang.php');
  20. parent::initialize();
  21. }
  22. public function index()
  23. {
  24. //分类导航
  25. $nav_link = array(
  26. 0 => array(
  27. 'title' => lang('homepage'),
  28. 'link' => HOME_SITE_URL
  29. ),
  30. 1 => array(
  31. 'title' => lang('brand_index_all_brand')
  32. )
  33. );
  34. View::assign('nav_link_list', $nav_link);
  35. $brand_mod = model('brand');
  36. $brand_c_list = $brand_mod->getBrandList(array('brand_apply' => '1'));
  37. $brands = $this->_tidyBrand($brand_c_list);
  38. extract($brands);
  39. View::assign('brand_c', $brand_listnew);
  40. View::assign('brand_class', $brand_class);
  41. View::assign('brand_r', $brand_r_list);
  42. //页面输出
  43. View::assign('index_sign', 'brand');
  44. $seo = model('seo')->type('brand')->show();
  45. $this->_assign_seo($seo);
  46. return View::fetch($this->template_dir . 'index');
  47. }
  48. /**
  49. * 所有品牌全部显示在一级类目下,不显示二三级类目
  50. * @param type $brand_c_list
  51. * @return type
  52. */
  53. private function _tidyBrand($brand_c_list)
  54. {
  55. $brand_listnew = array(); #品怕分类下对应的品牌
  56. $brand_class = array(); #品牌分类
  57. $brand_r_list = array(); #推荐品牌
  58. if (!empty($brand_c_list) && is_array($brand_c_list)) {
  59. $goods_class = model('goodsclass')->getGoodsclassForCacheModel();
  60. foreach ($brand_c_list as $key => $brand_c) {
  61. $gc_array = $this->_getTopClass($goods_class, $brand_c['gc_id']);
  62. if (empty($gc_array)) {
  63. if ($brand_c['brand_showtype'] == 1) {
  64. $brand_listnew[0]['text'][] = $brand_c;
  65. } else {
  66. $brand_listnew[0]['image'][] = $brand_c;
  67. }
  68. $brand_class[0]['brand_class'] = lang('ds_other');
  69. } else {
  70. if ($brand_c['brand_showtype'] == 1) {
  71. $brand_listnew[$gc_array['gc_id']]['text'][] = $brand_c;
  72. } else {
  73. $brand_listnew[$gc_array['gc_id']]['image'][] = $brand_c;
  74. }
  75. $brand_class[$gc_array['gc_id']]['brand_class'] = $gc_array['gc_name'];
  76. }
  77. //推荐品牌
  78. if ($brand_c['brand_recommend'] == 1) {
  79. $brand_r_list[] = $brand_c;
  80. }
  81. }
  82. }
  83. krsort($brand_class);
  84. krsort($brand_listnew);
  85. return array('brand_listnew' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r_list' => $brand_r_list);
  86. }
  87. /**
  88. * 获取顶级商品分类\递归调用
  89. * @param type $goods_class
  90. * @param type $gc_id
  91. * @return type
  92. */
  93. private function _getTopClass($goods_class, $gc_id)
  94. {
  95. if (!isset($goods_class[$gc_id])) {
  96. return null;
  97. }
  98. if ($goods_class[$gc_id]['gc_parent_id'] == $gc_id) { //自身ID等于父ID
  99. return null;
  100. }
  101. 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
  102. return null;
  103. }
  104. return $goods_class[$gc_id]['gc_parent_id'] == 0 ? $goods_class[$gc_id] : $this->_getTopClass($goods_class, $goods_class[$gc_id]['gc_parent_id']);
  105. }
  106. /**
  107. * 品牌商品列表
  108. */
  109. //原方法 function list
  110. public function brand_goods()
  111. {
  112. /**
  113. * 验证品牌
  114. */
  115. $brand_model = model('brand');
  116. $brand_id = intval(input('param.brand_id'));
  117. $brand_info = $brand_model->getBrandInfo(array('brand_id' => $brand_id));
  118. if (!$brand_info) {
  119. $this->error(lang('param_error'));
  120. }
  121. /**
  122. * 获得推荐品牌
  123. */
  124. $brand_r_list = model('brand')->getBrandPassedList(array(array('brand_recommend', '=', 1)), 'brand_id,brand_name,brand_pic', 10, 'brand_sort asc, brand_id desc');
  125. View::assign('brand_r', $brand_r_list);
  126. // 得到排序方式
  127. $order = 'is_platform_store desc,goods_id desc';
  128. $key = input('param.key');
  129. if (!empty($key)) {
  130. $order_tmp = trim($key);
  131. $sequence = input('param.order') == 1 ? 'asc' : 'desc';
  132. switch ($order_tmp) {
  133. case '1': // 销量
  134. $order = 'goods_salenum' . ' ' . $sequence;
  135. break;
  136. case '2': // 浏览量
  137. $order = 'goods_click' . ' ' . $sequence;
  138. break;
  139. case '3': // 价格
  140. $order = 'goods_promotion_price' . ' ' . $sequence;
  141. break;
  142. }
  143. }
  144. // 字段
  145. $fieldstr = "goods_id,goods_commonid,goods_name,goods_advword,store_id,store_name,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_have_gift";
  146. // 条件
  147. $where = array();
  148. $where[] = array('brand_id', '=', $brand_info['brand_id']);
  149. $area_id = intval(input('param.area_id'));
  150. if ($area_id > 0) {
  151. $where[] = array('areaid_1', '=', $area_id);
  152. }
  153. if (input('param.type') == 1) {
  154. $where[] = array('is_platform_store', '=', 1);
  155. }
  156. if (input('param.gift') == 1) {
  157. $where[] = array('is_have_gift', '=', 1);
  158. }
  159. $goods_model = model('goods');
  160. $goods_list = $goods_model->getGoodsListByColorDistinct($where, $fieldstr, $order, 24);
  161. View::assign('show_page', !empty($goods_list) ? $goods_model->page_info->render() : '');
  162. // 商品多图
  163. if (!empty($goods_list)) {
  164. $commonid_array = array(); // 商品公共id数组
  165. $storeid_array = array(); // 店铺id数组
  166. foreach ($goods_list as $value) {
  167. $commonid_array[] = $value['goods_commonid'];
  168. $storeid_array[] = $value['store_id'];
  169. }
  170. $commonid_array = array_unique($commonid_array);
  171. $storeid_array = array_unique($storeid_array);
  172. // 商品多图
  173. $goodsimage_more = $goods_model->getGoodsImageList(array(array('goods_commonid', 'in', $commonid_array)));
  174. // 店铺
  175. $store_list = model('store')->getStoreMemberIDList($storeid_array);
  176. foreach ($goods_list as $key => $value) {
  177. //预售
  178. $goods_list[$key]['presell_info'] = model('presell')->getPresellInfoByGoodsID($value['goods_id']);
  179. // 商品多图
  180. foreach ($goodsimage_more as $v) {
  181. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  182. $goods_list[$key]['image'][] = $v;
  183. }
  184. }
  185. // 店铺的开店会员编号
  186. $store_id = $value['store_id'];
  187. $goods_list[$key]['member_id'] = $store_list[$store_id]['member_id'];
  188. //将关键字置红
  189. $goods_list[$key]['goods_name_highlight'] = $value['goods_name'];
  190. }
  191. }
  192. View::assign('goods_list', $goods_list);
  193. // 地区
  194. $area_condition = array();
  195. $area_condition[] = array('area_parent_id', '=', 0);
  196. $area_array = model('area')->getAreaList($area_condition, 'area_name,area_initial,area_id');
  197. $province_array = array();
  198. foreach ($area_array as $k => $v) {
  199. $province_array[$v['area_initial']][$k]['area_name'] = $v['area_name'];
  200. $province_array[$v['area_initial']][$k]['area_id'] = $v['area_id'];
  201. }
  202. foreach ($province_array as $k => $v) {
  203. $edition[] = $k;
  204. }
  205. array_multisort($edition, SORT_ASC, $province_array);
  206. View::assign('province_array', $province_array);
  207. //当前选中地区
  208. if ($area_id > 0) {
  209. $area_name = model('area')->getAreaInfoById($area_id);
  210. View::assign('area_name', $area_name);
  211. }
  212. /* 引用搜索相关函数 */
  213. require_once(base_path() . '/home/common_search.php');
  214. /**
  215. * 取浏览过产品的cookie(最大四组)
  216. */
  217. $viewed_goods = model('goodsbrowse')->getViewedGoodsList(session('member_id'), 20);
  218. View::assign('viewed_goods', $viewed_goods);
  219. /**
  220. * 分类导航
  221. */
  222. $nav_link = array(
  223. 0 => array(
  224. 'title' => lang('homepage'),
  225. 'link' => HOME_SITE_URL
  226. ),
  227. 1 => array(
  228. 'title' => lang('brand_index_all_brand'),
  229. 'link' => (string)url('Brand/index')
  230. ),
  231. 2 => array(
  232. 'title' => $brand_info['brand_name']
  233. )
  234. );
  235. View::assign('nav_link_list', $nav_link);
  236. /**
  237. * 页面输出
  238. */
  239. View::assign('index_sign', 'brand');
  240. //SEO 设置
  241. $seo = model('seo')->type('brand_list')->param(array('name' => $brand_info['brand_name']))->show();
  242. $this->_assign_seo($seo);
  243. return View::fetch($this->template_dir . 'brand_goods');
  244. }
  245. }