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