ScekillController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 ScekillController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function get_scekill_info()
  21. {
  22. //秒杀设置begin
  23. $seckill_is_open = D('Home/Front')->get_config_by_name('seckill_is_open');
  24. $seckill_is_show_index = D('Home/Front')->get_config_by_name('seckill_is_show_index');
  25. $scekill_show_time = D('Home/Front')->get_config_by_name('scekill_show_time');
  26. if( empty($seckill_is_open) )
  27. {
  28. $seckill_is_open = 0;
  29. }
  30. if( empty($seckill_is_show_index) )
  31. {
  32. $seckill_is_show_index = 0;
  33. }
  34. $scekill_time_arr = array();
  35. if( isset($scekill_show_time) && !empty($scekill_show_time) )
  36. {
  37. $scekill_show_time_arr = unserialize($scekill_show_time);
  38. foreach($scekill_show_time_arr as $vv)
  39. {
  40. if( $vv != 25 )
  41. {
  42. $scekill_time_arr[] = $vv;
  43. }
  44. }
  45. }
  46. //秒杀主页标题
  47. $seckill_page_title = D('Home/Front')->get_config_by_name('seckill_page_title');
  48. if( empty($seckill_page_title) )
  49. {
  50. $seckill_page_title = '商品秒杀';
  51. }
  52. //首页秒杀活动背景色
  53. $seckill_bg_color = D('Home/Front')->get_config_by_name('seckill_bg_color');
  54. //秒杀活动分享标题
  55. $seckill_share_title = D('Home/Front')->get_config_by_name('seckill_share_title');
  56. $seckill_share_image = D('Home/Front')->get_config_by_name('seckill_share_image');
  57. if( !empty($seckill_share_image) )
  58. {
  59. $seckill_share_image = tomedia( $seckill_share_image );
  60. }
  61. //整点秒杀结束
  62. $need_data = array();
  63. $need_data['seckill_is_open'] = $seckill_is_open;
  64. $need_data['seckill_is_show_index'] = $seckill_is_show_index;
  65. $need_data['scekill_time_arr'] = $scekill_time_arr;
  66. $need_data['seckill_page_title'] = $seckill_page_title;
  67. $need_data['seckill_bg_color'] = $seckill_bg_color;
  68. $need_data['seckill_share_title'] = $seckill_share_title;
  69. $need_data['seckill_share_image'] = $seckill_share_image;
  70. echo json_encode( array('code' => 0 ,'data' => $need_data ) );
  71. die();
  72. }
  73. public function load_gps_goodslist()
  74. {
  75. $_GPC = I('request.');
  76. $head_id = $_GPC['head_id'];
  77. if($head_id == 'undefined') $head_id = '';
  78. $pageNum = $_GPC['pageNum'];
  79. $gid = $_GPC['gid'];
  80. $keyword = $_GPC['keyword'];
  81. $is_random = isset($_GPC['is_random']) ? $_GPC['is_random'] : 0;
  82. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  83. $cate_info = '';
  84. if($gid == 'undefined' || $gid =='')
  85. {
  86. $gid = 0;
  87. } else {
  88. $cate_info = M('lionfish_comshop_goods_category')->field('banner,name')->where( array('id' => $gid ) )->find();
  89. if(!empty($cate_info['banner'])) $cate_info['banner'] = tomedia($cate_info['banner']);
  90. }
  91. if(!$keyword){
  92. $gids = D('Home/GoodsCategory')->get_index_goods_category($gid);
  93. $gidArr = array();
  94. $gidArr[] = $gid;
  95. foreach ($gids as $key => $val) {
  96. $gidArr[] = $val['id'];
  97. }
  98. $gid = implode(',', $gidArr);
  99. }
  100. $offset = ($pageNum - 1) * $per_page;
  101. $limit = "{$offset},{$per_page}";
  102. $token = $_GPC['token'];
  103. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token ) )->find();
  104. $is_member_level_buy = 0;
  105. $is_vip_card_member = 0;
  106. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  107. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  108. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  109. {
  110. // echo json_encode( array('code' => 2) );
  111. // die();
  112. }else{
  113. $member_id = $weprogram_token['member_id'];
  114. //member_id
  115. if( $member_id > 0 )
  116. {
  117. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  118. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  119. {
  120. $now_time = time();
  121. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  122. {
  123. $is_vip_card_member = 1;//还是会员
  124. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  125. $is_vip_card_member = 2;//已过期
  126. }
  127. }
  128. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  129. {
  130. $is_member_level_buy = 1;
  131. }
  132. }
  133. }
  134. $now_time = time();
  135. $where = " g.grounding =1 and g.type ='normal' ";
  136. //head_id
  137. if( !empty($head_id) && $head_id >0 )
  138. {
  139. if(!empty($keyword)) {
  140. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg,"
  141. .C('DB_PREFIX')."lionfish_comshop_goods as g
  142. where pg.goods_id = g.id and g.goodsname like '%{$keyword}%' and pg.head_id = {$head_id} order by pg.id desc ";
  143. $goods_ids_arr = M()->query($sql_goods_ids);
  144. } else {
  145. if($gid == 0){
  146. $goods_ids_arr = M()->query('SELECT goods_id FROM ' . C('DB_PREFIX'). "lionfish_community_head_goods
  147. WHERE head_id=".$head_id." order by id desc " );
  148. } else {
  149. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg,"
  150. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  151. where pg.goods_id = g.goods_id and g.cate_id in ({$gid}) and pg.head_id = {$head_id} order by pg.id desc ";
  152. $goods_ids_arr = M()->query($sql_goods_ids);
  153. }
  154. }
  155. $ids_arr = array();
  156. foreach($goods_ids_arr as $val){
  157. $ids_arr[] = $val['goods_id'];
  158. }
  159. if(!empty($keyword)) {
  160. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  161. WHERE is_all_sale=1 and goodsname like '%{$keyword}%' " );
  162. } else {
  163. if($gid == 0){
  164. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX') . "lionfish_comshop_goods
  165. WHERE is_all_sale=1 " );
  166. } else {
  167. $goods_ids_nolimit_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  168. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  169. where pg.id = g.goods_id and g.cate_id in ({$gid}) and pg.is_all_sale=1 ";
  170. $goods_ids_nolimit_arr = M()->query($goods_ids_nolimit_sql);
  171. }
  172. }
  173. if( !empty($goods_ids_nolimit_arr) )
  174. {
  175. foreach($goods_ids_nolimit_arr as $val){
  176. $ids_arr[] = $val['id'];
  177. }
  178. }
  179. $ids_str = implode(',',$ids_arr);
  180. if( !empty($ids_str) )
  181. {
  182. $where .= " and g.id in ({$ids_str})";
  183. } else{
  184. $where .= " and 0 ";
  185. }
  186. }else{
  187. //echo json_encode( array('code' => 1) );
  188. // die();
  189. if(!empty($keyword)) {
  190. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  191. WHERE goodsname like '%{$keyword}%' and type='normal' " );
  192. } else {
  193. if($gid == 0){
  194. $goods_ids_nohead_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  195. WHERE type='normal' " );
  196. } else {
  197. $goods_ids_nohead_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  198. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g where pg.id = g.goods_id and g.cate_id in ({$gid}) and type='normal' ";
  199. $goods_ids_nohead_arr = M()->query($goods_ids_nohead_sql);
  200. }
  201. }
  202. $ids_arr = array();
  203. if( !empty($goods_ids_nohead_arr) )
  204. {
  205. foreach($goods_ids_nohead_arr as $val){
  206. $ids_arr[] = $val['id'];
  207. }
  208. }
  209. $ids_str = implode(',',$ids_arr);
  210. if( !empty($ids_str) )
  211. {
  212. $where .= " and g.id in ({$ids_str})";
  213. } else{
  214. $where .= " and 0 ";
  215. }
  216. }
  217. if($gid == 0 && $keyword == ''){
  218. $where .= " and g.is_index_show = 1 and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  219. // $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  220. } else {
  221. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  222. }
  223. $where .= " and gc.is_new_buy=0 and gc.is_spike_buy = 0 ";
  224. //$is_random $order='g.istop DESC, g.settoptime DESC,g.index_sort desc,g.id desc '
  225. if($is_random == 1)
  226. {
  227. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video ', $where,$offset,$per_page,' rand() ');
  228. }else{
  229. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video ', $where,$offset,$per_page);
  230. }
  231. if( !empty($community_goods) )
  232. {
  233. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  234. $full_money = D('Home/Front')->get_config_by_name('full_money');
  235. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  236. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  237. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1:0;
  238. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  239. {
  240. $is_open_fullreduction = 0;
  241. }
  242. $cart= D('Home/Car');
  243. $list = array();
  244. $copy_text_arr = array();
  245. foreach($community_goods as $val)
  246. {
  247. $tmp_data = array();
  248. $tmp_data['actId'] = $val['id'];
  249. $tmp_data['spuName'] = $val['goodsname'];
  250. $tmp_data['spuCanBuyNum'] = $val['total'];
  251. $tmp_data['spuDescribe'] = $val['subtitle'];
  252. $tmp_data['end_time'] = $val['end_time'];
  253. $tmp_data['is_take_vipcard'] = $val['is_take_vipcard'];
  254. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  255. $productprice = $val['productprice'];
  256. $tmp_data['marketPrice'] = explode('.', $productprice);
  257. if( !empty($val['big_img']) )
  258. {
  259. $tmp_data['bigImg'] = tomedia($val['big_img']);
  260. }
  261. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  262. if( !empty($good_image) )
  263. {
  264. $tmp_data['skuImage'] = tomedia($good_image['image']);
  265. }
  266. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  267. $price = $price_arr['price'];
  268. if( $pageNum == 1 )
  269. {
  270. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  271. }
  272. $tmp_data['actPrice'] = explode('.', $price);
  273. $tmp_data['card_price'] = $price_arr['card_price'];
  274. $tmp_data['levelprice'] = $price_arr['levelprice']; // 会员等级价格
  275. $tmp_data['is_mb_level_buy'] = $price_arr['is_mb_level_buy']; //是否 会员等级 可享受
  276. //card_price
  277. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  278. if( !empty($tmp_data['skuList']) )
  279. {
  280. $tmp_data['car_count'] = 0;
  281. }else{
  282. $car_count = $cart->get_wecart_goods($val['id'],"",$head_id ,$token);
  283. if( empty($car_count) )
  284. {
  285. $tmp_data['car_count'] = 0;
  286. }else{
  287. $tmp_data['car_count'] = $car_count;
  288. }
  289. }
  290. if($is_open_fullreduction == 0)
  291. {
  292. $tmp_data['is_take_fullreduction'] = 0;
  293. }else if($is_open_fullreduction == 1){
  294. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  295. }
  296. // 商品角标
  297. $label_id = unserialize($val['labelname']);
  298. if($label_id){
  299. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  300. if($label_info){
  301. if($label_info['type'] == 1){
  302. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  303. } else {
  304. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  305. }
  306. }
  307. $tmp_data['label_info'] = $label_info;
  308. }
  309. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  310. $list[] = $tmp_data;
  311. }
  312. $is_show_list_timer = D('Home/Front')->get_config_by_name('is_show_list_timer');
  313. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  314. echo json_encode(array('code' => 0, 'list' => $list ,'is_vip_card_member' => $is_vip_card_member,'is_member_level_buy' => $is_member_level_buy ,'copy_text_arr' => $copy_text_arr, 'cur_time' => time() ,'full_reducemoney' => $full_reducemoney,'full_money' => $full_money,'is_open_vipcard_buy' => $is_open_vipcard_buy,'is_open_fullreduction' => $is_open_fullreduction,'is_show_list_timer'=>$is_show_list_timer, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar ));
  315. die();
  316. }else{
  317. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  318. echo json_encode( array('code' => 1, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar) );
  319. die();
  320. }
  321. }
  322. }