ProductWidget.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /**
  3. * 狮子鱼社区团购系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Widget;
  10. use Think\Controller;
  11. /**
  12. * 商品
  13. */
  14. class ProductWidget extends Controller{
  15. /**
  16. *
  17. */
  18. function index_ajax_goods_list()
  19. {
  20. $page = I('get.page',1);
  21. $pre_page = 10;
  22. //'seller_count' =>
  23. $condition = array('status'=>1,'quantity' =>array('gt',0) );
  24. $offset = ($page -1) * $pre_page;
  25. $list = M('goods')->where($condition)->order('seller_count desc,goods_id asc')->limit($offset,$pre_page)->select();
  26. //M('') $map['id'] = array('gt',100);
  27. $this->list = $list;
  28. //$content = $this->fetch('Widget:index_ajax_goods_list');
  29. $this->display('Widget:index_ajax_goods_list');
  30. }
  31. /**
  32. 商品详情底部状态
  33. **/
  34. public function goods_button_html()
  35. {
  36. $id=I('get.id');
  37. $pin_id = I('get.pin_id',0);
  38. $this->id = $id;
  39. $this->pin_id = $pin_id;
  40. $this->display('Widget:goods_button_info');
  41. }
  42. /**
  43. * 首页的商品
  44. *
  45. */
  46. function home_goods_list($title,$order_by,$limit){
  47. $key='home_goods_cache'.$order_by;
  48. if (!$home_goods_cache = S($key)) {
  49. $sql='SELECT goods_id,image,price,name FROM '.C('DB_PREFIX').'goods WHERE status=1 ORDER BY '.$order_by.' LIMIT 0,'.$limit;
  50. $list=M()->query($sql);
  51. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  52. foreach ($list as $k => $v) {
  53. $list[$k]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  54. $list[$k]['goods_id']=$hashids->encode($v['goods_id']);
  55. }
  56. S($key, $list);
  57. $home_goods_cache=$list;
  58. }
  59. $this->products=$home_goods_cache;
  60. $this->title=$title;
  61. $this->display('Widget:home_goods_list');
  62. }
  63. //详情页热门产品
  64. function hot_goods_list($title,$order_by,$limit){
  65. $key='hot_goods_cache'.$order_by;
  66. if (!$hot_goods_cache = S($key)) {
  67. $sql='SELECT goods_id,image,price,name FROM '.C('DB_PREFIX').'goods WHERE status=1 ORDER BY '.$order_by.' LIMIT 0,'.$limit;
  68. $list=M()->query($sql);
  69. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  70. foreach ($list as $k => $v) {
  71. $list[$k]['image']=resize($v['image'], C('goods_cart_thumb_width'), C('goods_cart_thumb_height'));
  72. $list[$k]['goods_id']=$hashids->encode($v['goods_id']);
  73. }
  74. S($key, $list);
  75. $hot_goods_cache=$list;
  76. }
  77. $this->products=$hot_goods_cache;
  78. $this->title=$title;
  79. $this->display('Widget:goods_show_hot_goods_list');
  80. }
  81. /**
  82. 拼团详情页 关联拼团活动
  83. **/
  84. function relapin_goods_list($goods_id)
  85. {
  86. $goods_info = M('goods')->where( array('goods_id' =>$goods_id) )->find();
  87. $goods_model = D('Home/Goods');
  88. if(!empty($goods_info))
  89. {
  90. //begin_time end_time
  91. $now_time = time();
  92. $where_time = " and pg.begin_time < {$now_time} and pg.end_time > {$now_time} ";
  93. $goods_cate = M('goods_to_category')->where( array('goods_id' =>$goods_id) )->find();
  94. $sql='SELECT g.goods_id,g.image,g.seller_count,g.virtual_count,g.fan_image,pg.pin_price,g.danprice,g.name FROM '.C('DB_PREFIX').'goods as g,
  95. '.C('DB_PREFIX').'pin_goods as pg,
  96. '.C('DB_PREFIX').'goods_to_category as gtc
  97. WHERE g.goods_id = pg.goods_id and gtc.goods_id=g.goods_id and gtc.class_id1='.$goods_cate['class_id1'].'
  98. and g.goods_id != '.$goods_id.' '.$where_time.' and g.status=1 and g.quantity >0 and g.type="pintuan" ORDER BY rand() LIMIT 0,20';
  99. }else{
  100. $now_time = time();
  101. $where_time = " and pg.begin_time < {$now_time} and pg.end_time > {$now_time} ";
  102. $sql='SELECT g.goods_id,g.image,g.seller_count,g.virtual_count,g.fan_image,pg.pin_price,g.danprice,g.name FROM '.C('DB_PREFIX').'goods as g,
  103. '.C('DB_PREFIX').'pin_goods as pg
  104. WHERE g.goods_id = pg.goods_id '.$where_time.'
  105. and g.status=1 and g.quantity >0 ORDER BY rand() LIMIT 0,20';
  106. }
  107. $list=M()->query($sql);
  108. foreach ($list as $k => $v) {
  109. // $list[$k]['image']=resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  110. //pin_price
  111. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  112. $list[$k]['pin_price'] = $price_arr['pin_price'];
  113. $list[$k]['seller_count'] = $list[$k]['seller_count'] + $list[$k]['virtual_count'];
  114. if(!empty($v['fan_image'])){
  115. $list[$k]['image']=resize($v['fan_image'], 480,480);
  116. //$list[$k]['image']='/Uploads/image/'.$v['fan_image'];
  117. }else {
  118. $list[$k]['image']=resize($v['image'], 480,480);
  119. //$list[$k]['image']='/Uploads/image/'.$v['image'];
  120. }
  121. }
  122. $this->related_goods=$list;
  123. $this->display('Widget:relapin_goods_list');
  124. }
  125. //详情页推荐的关联产品
  126. function related_goods_list($goods_id ){
  127. //var_dump($goods_id);die(); type != "integral" and type != "bargain"
  128. $goods_model = D('Home/Goods');
  129. $goods_cate = M('goods_to_category')->where( array('goods_id' =>$goods_id) )->find();
  130. $sql='SELECT g.goods_id,g.image,g.fan_image,g.danprice,g.name FROM '.C('DB_PREFIX').'goods as g,'.C('DB_PREFIX').'goods_to_category as gtc WHERE gtc.goods_id=g.goods_id and gtc.class_id1='.$goods_cate['class_id1'].' and g.type != "integral" and g.type != "bargain" and g.status=1 ORDER BY rand() LIMIT 0,20';
  131. $list=M()->query($sql);
  132. foreach($list as $k =>$v)
  133. {
  134. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  135. $list[$k]['danprice'] = $price_arr['danprice'];
  136. //$val['danprice'] = $price_arr['price'];
  137. }
  138. $member_id = is_login();
  139. $goods_model = D('Home/Goods');
  140. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  141. foreach ($list as $k => $v) {
  142. //$list[$k]['image']=resize($v['image'], 468, 658);
  143. $list[$k]['image']=resize($v['image'], 400, 400);
  144. }
  145. $this->related_goods=$list;
  146. $this->display('Widget:related_goods_list');
  147. }
  148. function related_usecenter_goods_list()
  149. {
  150. $sql='SELECT goods_id,image,fan_image,danprice,name FROM '.C('DB_PREFIX').'goods WHERE status=1 and type != "integral" and type != "bargain" and quantity>0 ORDER BY rand() LIMIT 0,12';
  151. $list=M()->query($sql);
  152. $goods_model = D('Home/Goods');
  153. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  154. foreach ($list as $k => $v) {
  155. //$list[$k]['image']=resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  156. $price_arr = $goods_model->get_goods_price($v['goods_id']);
  157. $list[$k]['danprice'] = $price_arr['danprice'];
  158. //$val['danprice'] = $price_arr['price'];
  159. if(!empty($v['fan_image'])){
  160. $list[$k]['image']=resize($v['fan_image'], 480,480);
  161. //$list[$k]['image']='/Uploads/image/'.$v['fan_image'];
  162. }else {
  163. $list[$k]['image']=resize($v['image'], 480,480);
  164. //$list[$k]['image']='/Uploads/image/'.$v['image'];
  165. }
  166. }
  167. $this->related_goods=$list;
  168. $this->display('Widget:related_usercenter_goods_list');
  169. }
  170. //拼团详情页推荐的关联产品
  171. function related_group_goods_list()
  172. {
  173. $sql='SELECT goods_id,image,fan_image,price,name,pinprice FROM '.C('DB_PREFIX').'goods WHERE status=1 ORDER BY rand() LIMIT 0,9';
  174. $list=M()->query($sql);
  175. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  176. foreach ($list as $k => $v) {
  177. $list[$k]['image']=resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  178. if(!empty($v['fan_image'])){
  179. $list[$k]['image']=resize($v['fan_image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  180. }else {
  181. $list[$k]['image']=resize($v['image'], C('goods_related_thumb_width'), C('goods_related_thumb_height'));
  182. }
  183. //$list[$k]['goods_id']=$hashids->encode($v['goods_id']);
  184. }
  185. $this->related_goods=$list;
  186. $this->display('Widget:related_group_goods_list');
  187. }
  188. }