CategoryController.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class CategoryController extends CommonController {
  16. public function info(){
  17. $pre_page = 10;
  18. $page = I('post.page',1);
  19. $id = I('get.gid',0);
  20. if(empty($id))
  21. {
  22. $id = I('post.gid',0);
  23. }
  24. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$id} or class_id2 ={$id} or class_id3 = {$id} ")->field('goods_id')->select();
  25. $ids_arr = array();
  26. foreach($goods_ids_arr as $val){
  27. $ids_arr[] = $val['goods_id'];
  28. }
  29. $ids_str = implode(',',$ids_arr);
  30. $condition = array('goods_id' => array('in',$ids_str), 'status'=>1,'quantity' =>array('gt',0) );
  31. $condition['type'] = 'normal';
  32. $condition['lock_type'] = 'normal';
  33. $offset = ($page -1) * $pre_page;
  34. $list = M('goods')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  35. $goods_model = D('Home/goods');
  36. if(!empty($list)) {
  37. foreach($list as $key => $v){
  38. if(empty($v['fan_image'])){
  39. $list[$key]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  40. }
  41. }
  42. }
  43. foreach($list as $key => $val)
  44. {
  45. $val['seller_count'] += $val['virtual_count'];
  46. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  47. $val['pinprice'] = $price_arr['price'];
  48. $list[$key] = $val;
  49. }
  50. $this->list = $list;
  51. $this->gid = $id;
  52. if($page > 1) {
  53. $result = array('code' => 0);
  54. if(!empty($list)) {
  55. $result['code'] = 1;
  56. $result['html'] = $this->fetch('Widget:category_ajax_goods_list_fetch');
  57. }
  58. echo json_encode($result);
  59. die();
  60. }
  61. //pid
  62. $goods_category = M('goods_category')->field('pid')->where(array('id' => $id) )->find();
  63. $child_category = array();
  64. if($goods_category['pid'] == 0)
  65. {
  66. $goods_category_list = M('goods_category')->field('id,name,logo')->where( array('pid' => $id) )->limit(8)->select();
  67. if( !empty($goods_category_list) )
  68. {
  69. foreach($goods_category_list as $key => $val)
  70. {
  71. $val['logo']=resize($val['logo'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  72. $goods_category_list[$key] = $val;
  73. }
  74. $child_category = $goods_category_list;
  75. }
  76. }
  77. $this->child_category = $child_category;
  78. $this->display();
  79. }
  80. public function index(){
  81. $pre_page = 10;
  82. $page = I('post.page',1);
  83. $sort = I('get.sort','default');
  84. $condition = array('status'=>1,'quantity' =>array('gt',0) );
  85. $keyword = '';
  86. if( !empty($_GET['keyword']) || !empty($_GET['keyword']))
  87. {
  88. //condition["FromAddress"] = array(“like”, “%”.$rname);
  89. //name
  90. $keyword = htmlspecialchars($_POST['keyword']);
  91. if(empty($keyword))
  92. {
  93. $keyword = htmlspecialchars($_GET['keyword']);
  94. }
  95. $condition['name'] = array( 'like',"%".$keyword.'%' );
  96. }else{
  97. if(isset($_POST['keyword']))
  98. {
  99. $keyword = htmlspecialchars($_POST['keyword']);
  100. $condition['name'] = array( 'like',"%".$keyword.'%' );
  101. }
  102. }
  103. $this->keyword = $keyword;
  104. $offset = ($page -1) * $pre_page;
  105. $orderby = '';
  106. switch($sort)
  107. {
  108. case 'default' :
  109. $orderby = 'seller_count desc,goods_id asc';
  110. break;
  111. case 'new':
  112. $orderby = 'goods_id desc';
  113. break;
  114. case 'hot':
  115. $orderby = 'seller_count desc';
  116. break;
  117. }
  118. $goods_model = D('Home/goods');
  119. $list = M('goods')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  120. if(!empty($list)) {
  121. foreach($list as $key => $v){
  122. $list[$key]['seller_count'] = $v['seller_count'] + $v['virtual_count'];
  123. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  124. $list[$key]['pinprice'] = $price_arr['price'];
  125. //
  126. if(!empty($v['fan_image'])){
  127. $list[$key]['image']=resize($v['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  128. }else {
  129. $list[$key]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  130. }
  131. }
  132. }
  133. $this->list = $list;
  134. if($page > 1) {
  135. $result = array('code' => 0);
  136. if(!empty($list)) {
  137. $result['code'] = 1;
  138. $result['html'] = $this->fetch('Widget:category_ajax_goods_list_fetch');
  139. }
  140. echo json_encode($result);
  141. die();
  142. }
  143. $this->display();
  144. }
  145. }