Brand.php 10 KB

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