Brand.php 11 KB

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