brand.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * 前台品牌分类
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class brandControl extends BaseHomeControl {
  10. public function indexOp(){
  11. //读取语言包
  12. Language::read('home_brand_index');
  13. //分类导航
  14. $nav_link = array(
  15. 0=>array(
  16. 'title'=>Language::get('homepage'),
  17. 'link'=>SHOP_SITE_URL
  18. ),
  19. 1=>array(
  20. 'title'=>Language::get('brand_index_all_brand')
  21. )
  22. );
  23. Tpl::output('nav_link_list',$nav_link);
  24. //获得品牌列表
  25. $model = Model();
  26. $brand_c_list = $model->table('brand')->where(array('brand_apply'=>'1'))->order('brand_sort asc')->select();
  27. $brands = $this->_tidyBrand($brand_c_list);
  28. extract($brands);
  29. Tpl::output('brand_c',$brand_listnew);
  30. Tpl::output('brand_class',$brand_class);
  31. Tpl::output('brand_r',$brand_r_list);
  32. Tpl::output('html_title',Language::get('brand_index_brand_list'));
  33. //页面输出
  34. Tpl::output('index_sign','brand');
  35. Model('seo')->type('brand')->show();
  36. Tpl::showpage('brand');
  37. }
  38. /**
  39. * 整理品牌
  40. * 所有品牌全部显示在一级类目下,不显示二三级类目
  41. * @param array $brand_c_list
  42. * @return array
  43. */
  44. private function _tidyBrand($brand_c_list) {
  45. $brand_listnew = array();
  46. $brand_class = array();
  47. $brand_r_list = array();
  48. if (!empty($brand_c_list) && is_array($brand_c_list)){
  49. $goods_class = Model('goods_class')->getGoodsClassForCacheModel();
  50. foreach ($brand_c_list as $key=>$brand_c){
  51. $gc_array = $this->_getTopClass($goods_class, $brand_c['class_id']);
  52. if (empty($gc_array)) {
  53. if ($brand_c['show_type'] == 1){
  54. $brand_listnew[0]['text'][] = $brand_c;
  55. } else {
  56. $brand_listnew[0]['image'][] = $brand_c;
  57. }
  58. $brand_class[0]['brand_class'] = '其他';
  59. } else {
  60. if ($brand_c['show_type'] == 1){
  61. $brand_listnew[$gc_array['gc_id']]['text'][] = $brand_c;
  62. } else {
  63. $brand_listnew[$gc_array['gc_id']]['image'][] = $brand_c;
  64. }
  65. $brand_class[$gc_array['gc_id']]['brand_class'] = $gc_array['gc_name'];
  66. }
  67. //推荐品牌
  68. if ($brand_c['brand_recommend'] == 1){
  69. $brand_r_list[] = $brand_c;
  70. }
  71. }
  72. }
  73. krsort($brand_class);
  74. krsort($brand_listnew);
  75. return array('brand_listnew' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r_list' => $brand_r_list);
  76. }
  77. /**
  78. * 获取顶级商品分类
  79. * 递归调用
  80. * @param array $goods_class
  81. * @param int $gc_id
  82. * @return array
  83. */
  84. private function _getTopClass($goods_class, $gc_id) {
  85. if (!isset($goods_class[$gc_id])) {
  86. return null;
  87. }
  88. return $goods_class[$gc_id]['gc_parent_id'] == 0 ? $goods_class[$gc_id] : $this->_getTopClass($goods_class, $goods_class[$gc_id]['gc_parent_id']);
  89. }
  90. /**
  91. * 品牌商品列表
  92. */
  93. public function listOp(){
  94. Language::read('home_brand_index');
  95. $lang = Language::getLangContent();
  96. /**
  97. * 验证品牌
  98. */
  99. $model_brand = Model('brand');
  100. $brand_info = $model_brand->getBrandInfo(array('brand_id' => intval($_GET['brand'])));
  101. if(!$brand_info){
  102. showMessage($lang['wrong_argument'],'index.php','html','error');
  103. }
  104. /**
  105. * 获得推荐品牌
  106. */
  107. $brand_r_list = Model('brand')->getBrandPassedList(array('brand_recommend'=>1) ,'brand_id,brand_name,brand_pic', 0, 'brand_sort asc, brand_id desc', 10);
  108. Tpl::output('brand_r',$brand_r_list);
  109. // 得到排序方式
  110. $order = 'is_own_shop desc,goods_id desc';
  111. if (!empty($_GET['key'])) {
  112. $order_tmp = trim($_GET['key']);
  113. $sequence = $_GET['order'] == 1 ? 'asc' : 'desc';
  114. switch ($order_tmp) {
  115. case '1' : // 销量
  116. $order = 'goods_salenum' . ' ' . $sequence;
  117. break;
  118. case '2' : // 浏览量
  119. $order = 'goods_click' . ' ' . $sequence;
  120. break;
  121. case '3' : // 价格
  122. $order = 'goods_promotion_price' . ' ' . $sequence;
  123. break;
  124. }
  125. }
  126. // 字段
  127. $fieldstr = "goods_id,goods_commonid,goods_name,goods_jingle,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_fcode,is_appoint,is_presell,have_gift";
  128. // 条件
  129. $where = array();
  130. $where['brand_id'] = $brand_info['brand_id'];
  131. if (intval($_GET['area_id']) > 0) {
  132. $where['areaid_1'] = intval($_GET['area_id']);
  133. }
  134. if ($_GET['type'] == 1) {
  135. $where['is_own_shop'] = 1;
  136. }
  137. if ($_GET['gift'] == 1) {
  138. $where['have_gift'] = 1;
  139. }
  140. $model_goods = Model('goods');
  141. $goods_list = $model_goods->getGoodsListByColorDistinct($where, $fieldstr, $order, 24);
  142. Tpl::output('show_page1', $model_goods->showpage(4));
  143. Tpl::output('show_page', $model_goods->showpage(5));
  144. // 商品多图
  145. if (!empty($goods_list)) {
  146. $commonid_array = array(); // 商品公共id数组
  147. $storeid_array = array(); // 店铺id数组
  148. foreach ($goods_list as $value) {
  149. $commonid_array[] = $value['goods_commonid'];
  150. $storeid_array[] = $value['store_id'];
  151. }
  152. $commonid_array = array_unique($commonid_array);
  153. $storeid_array = array_unique($storeid_array);
  154. // 商品多图
  155. $goodsimage_more = $model_goods->getGoodsImageList(array('goods_commonid' => array('in', $commonid_array)));
  156. // 店铺
  157. $store_list = Model('store')->getStoreMemberIDList($storeid_array);
  158. foreach ($goods_list as $key => $value) {
  159. // 商品多图
  160. foreach ($goodsimage_more as $v) {
  161. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  162. $goods_list[$key]['image'][] = $v;
  163. }
  164. }
  165. // 店铺的开店会员编号
  166. $store_id = $value['store_id'];
  167. $goods_list[$key]['member_id'] = $store_list[$store_id]['member_id'];
  168. $goods_list[$key]['store_domain'] = $store_list[$store_id]['store_domain'];
  169. //将关键字置红
  170. $goods_list[$key]['goods_name_highlight'] = $value['goods_name'];
  171. }
  172. }
  173. Tpl::output('goods_list', $goods_list);
  174. // 地区
  175. $province_array = Model('area')->getTopLevelAreas();
  176. Tpl::output('province_array', $province_array);
  177. loadfunc('search');
  178. /**
  179. * 取浏览过产品的cookie(最大四组)
  180. */
  181. $viewed_goods = Model('goods_browse')->getViewedGoodsList($_SESSION['member_id'],20);
  182. Tpl::output('viewed_goods',$viewed_goods);
  183. /**
  184. * 分类导航
  185. */
  186. $nav_link = array(
  187. 0=>array(
  188. 'title'=>$lang['homepage'],
  189. 'link'=>SHOP_SITE_URL
  190. ),
  191. 1=>array(
  192. 'title'=>$lang['brand_index_all_brand'],
  193. 'link'=>urlShop('brand', 'index')
  194. ),
  195. 2=>array(
  196. 'title'=>$brand_info['brand_name']
  197. )
  198. );
  199. Tpl::output('nav_link_list',$nav_link);
  200. /**
  201. * 页面输出
  202. */
  203. Tpl::output('index_sign','brand');
  204. Model('seo')->type('brand_list')->param(array('name'=>$brand_info['brand_name']))->show();
  205. Tpl::showpage('brand_goods');
  206. }
  207. }