ProductWidget.class.php 8.0 KB

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