GoodsCategoryModel.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. /**
  5. * 商品分类模型
  6. * @author fish
  7. *
  8. */
  9. class GoodsCategoryModel {
  10. /**
  11. 获取首页的商品分类
  12. **/
  13. public function get_index_goods_category($pid = 0 ,$cate_type = 'normal', $is_show=1, $is_type_show=0, $show_all=0)
  14. {
  15. // and pid = {$pid}
  16. if( empty($pid) )
  17. {
  18. $pid = 0;
  19. }
  20. $where = '';
  21. if($show_all==1) {
  22. $cate_list = M('lionfish_comshop_goods_category')->where( array('pid' =>$pid,'cate_type' => $cate_type ) )->order('sort_order desc, id desc')->select();
  23. } else if($is_type_show==1) {
  24. $cate_list = M('lionfish_comshop_goods_category')->where( array('is_type_show' => 1,'pid' =>$pid,'cate_type' => $cate_type ) )
  25. ->order('sort_order desc, id desc')->select();
  26. } else {
  27. $cate_list = M('lionfish_comshop_goods_category')->where( array('is_show' => 1,'pid' =>$pid,'cate_type' => $cate_type ) )
  28. ->order('sort_order desc, id desc')->select();
  29. }
  30. $need_data = array();
  31. foreach($cate_list as $key => $cate)
  32. {
  33. $need_data[$key]['id'] = $cate['id'];
  34. $need_data[$key]['name'] = $cate['name'];
  35. $need_data[$key]['banner'] = $cate['banner'] && !empty($cate['banner']) ? tomedia($cate['banner']) : '';
  36. $need_data[$key]['logo'] = $cate['logo'] && !empty($cate['logo']) ? tomedia($cate['logo']) : '';
  37. $need_data[$key]['sort_order'] = $cate['sort_order'];
  38. $need_data[$key]['adv_info'] = [];
  39. if( $cate['pid'] == 0 )
  40. {
  41. $cate_adv_info = M('lionfish_comshop_adv_category')->where("cate_id=".$cate['id'] )->find();
  42. if( !empty($cate_adv_info) )
  43. {
  44. $cate_adv_info['image'] = tomedia($cate_adv_info['thumb']);
  45. $cate_adv_info['thumb'] = tomedia($cate_adv_info['thumb']);
  46. $cate_adv_info['link'] = htmlspecialchars_decode( $cate_adv_info['link'] );
  47. $need_data[$key]['adv_info'] = $cate_adv_info;
  48. }
  49. }
  50. $params = array();
  51. $params['pid'] = $cate['id'];
  52. if($show_all==1) {
  53. // 显示所有
  54. } else if($is_type_show==1) {
  55. $params['is_type_show'] = 1;
  56. } else {
  57. $params['is_show'] = 1;
  58. }
  59. $sub_cate = M('lionfish_comshop_goods_category')->field('id,name,sort_order')
  60. ->where($params)->order('sort_order desc, id desc')->select();
  61. $need_data[$key]['sub'] = $sub_cate;
  62. }
  63. return $need_data;
  64. }
  65. /**
  66. * 获取所有分类包括子分类
  67. * @param string $cate_type [description]
  68. * @param integer $is_show [description]
  69. * @param integer $is_type_show [description]
  70. * @return [type] [description]
  71. */
  72. public function get_all_goods_category($cate_type = 'normal', $is_show=1, $is_type_show=0)
  73. {
  74. // and pid = {$pid}
  75. if( empty($pid) )
  76. {
  77. $pid = 0;
  78. }
  79. $where = '';
  80. if($is_type_show==1) {
  81. $cate_list = M('lionfish_comshop_goods_category')->where( array('is_type_show' => 1, 'cate_type' => $cate_type ) )
  82. ->order('sort_order desc, id desc')->select();
  83. } else {
  84. $params = array();
  85. $params['cate_type'] = $cate_type;
  86. if($is_show!=-1) {
  87. $params['is_show'] = $is_show;
  88. }
  89. $cate_list = M('lionfish_comshop_goods_category')->where( $params )->order('sort_order desc, id desc')->select();
  90. }
  91. $need_data = array();
  92. foreach($cate_list as $key => $cate)
  93. {
  94. $need_data[$key]['id'] = $cate['id'];
  95. $need_data[$key]['pid'] = $cate['pid'];
  96. $need_data[$key]['name'] = $cate['name'];
  97. $need_data[$key]['banner'] = $cate['banner'] && !empty($cate['banner']) ? tomedia($cate['banner']) : '';
  98. $need_data[$key]['logo'] = $cate['logo'] && !empty($cate['logo']) ? tomedia($cate['logo']) : '';
  99. $need_data[$key]['sort_order'] = $cate['sort_order'];
  100. $need_data[$key]['is_show'] = $cate['is_show'];
  101. }
  102. return $need_data;
  103. }
  104. }