MarketingController.class.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 MarketingController extends CommonController {
  16. public function get_special()
  17. {
  18. $_GPC = I('request.');
  19. $token = $_GPC['token'];
  20. $id = $_GPC['id'];
  21. $head_id = $_GPC['head_id'];
  22. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  23. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  24. {
  25. //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  26. //die();
  27. }
  28. $member_id = $weprogram_token['member_id'];
  29. $data = M('lionfish_comshop_special')->where( array('id' => $id ) )->find();
  30. $goodsids = $data['goodsids'];
  31. $list = array();
  32. if(!empty($data)) {
  33. if($data['enabled']==0){
  34. echo json_encode( array('code' => 1, 'msg' => '专题已关闭') );
  35. die();
  36. }
  37. if($data['begin_time'] > time()){
  38. echo json_encode( array('code' => 1, 'msg' => '活动未开始') );
  39. die();
  40. }
  41. if($data['end_time'] <= time()){
  42. echo json_encode( array('code' => 1, 'msg' => '活动已结束') );
  43. die();
  44. }
  45. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  46. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  47. // 满减
  48. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  49. $full_money = D('Home/Front')->get_config_by_name('full_money');
  50. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  51. if(empty($full_reducemoney) || $full_reducemoney <= 0) $is_open_fullreduction = 0;
  52. if($goodsids) {
  53. $goodsids = rtrim($goodsids, ",");
  54. $now_time = time();
  55. $where = ' g.grounding = 1 ';
  56. $where .= " and g.id in ({$goodsids})";
  57. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  58. $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 ', $where, 0, 1000);
  59. foreach ($community_goods as $key => $value) {
  60. if($value['is_all_sale']==1){
  61. $list[] = $this->change_goods_form($value, $head_id, $token, $is_open_fullreduction);
  62. } else {
  63. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id,'goods_id' => $value['id'] ) )->order('id desc')->select();
  64. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value, $head_id, $token , $is_open_fullreduction);
  65. }
  66. }
  67. }
  68. } else {
  69. echo json_encode( array('code' => 1, 'msg' => '无此专题') );
  70. die();
  71. }
  72. $ishow_special_share_btn = D('Home/Front')->get_config_by_name('ishow_special_share_btn');
  73. echo json_encode( array(
  74. 'code' => 0,
  75. 'data' => $data,
  76. 'list' => $list,
  77. 'ishow_special_share_btn' => $ishow_special_share_btn,
  78. 'full_reducemoney' => $full_reducemoney,
  79. 'full_money' => $full_money,
  80. 'is_open_fullreduction' => $is_open_fullreduction
  81. ));
  82. die();
  83. }
  84. private function change_goods_form ($val, $head_id='', $token='' , $is_open_fullreduction=0){
  85. $_GPC = I('request.');
  86. $tmp_data = array();
  87. $tmp_data['actId'] = $val['id'];
  88. $goodsname = htmlspecialchars_decode($val['goodsname']);
  89. $tmp_data['spuName'] = $goodsname;
  90. $tmp_data['spuCanBuyNum'] = $val['total'];
  91. $tmp_data['spuDescribe'] = $val['subtitle'];
  92. $tmp_data['end_time'] = $val['end_time'];
  93. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  94. $productprice = $val['productprice'];
  95. $tmp_data['marketPrice'] = explode('.', $productprice);
  96. $time = time();
  97. $tmp_data['actEnd'] = time()>$val['end_time'] ? true : false;
  98. if( !empty($val['big_img']) )
  99. {
  100. $tmp_data['bigImg'] = tomedia($val['big_img']);
  101. }
  102. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  103. if( !empty($good_image) )
  104. {
  105. $tmp_data['skuImage'] = tomedia($good_image['image']);
  106. }
  107. $token = $_GPC['token'];
  108. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  109. $member_id = $weprogram_token['member_id'];
  110. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  111. $price = $price_arr['price'];
  112. $tmp_data['actPrice'] = explode('.', $price);
  113. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  114. if( !empty($tmp_data['skuList']) )
  115. {
  116. $tmp_data['car_count'] = 0;
  117. }else{
  118. $car_count = D('Home/Car')->get_wecart_goods($val['id'],"",$head_id ,$token);
  119. if( empty($car_count) )
  120. {
  121. $tmp_data['car_count'] = 0;
  122. }else{
  123. $tmp_data['car_count'] = $car_count;
  124. }
  125. }
  126. if($is_open_fullreduction == 0)
  127. {
  128. $tmp_data['is_take_fullreduction'] = 0;
  129. }else if($is_open_fullreduction == 1){
  130. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  131. }
  132. // 商品角标
  133. $label_id = unserialize($val['labelname']);
  134. if($label_id){
  135. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  136. if($label_info){
  137. if($label_info['type'] == 1){
  138. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  139. } else {
  140. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  141. }
  142. }
  143. $tmp_data['label_info'] = $label_info;
  144. }
  145. return $tmp_data;
  146. }
  147. public function get_special_list()
  148. {
  149. $_GPC = I('request.');
  150. $head_id = $_GPC['head_id'];
  151. $token = $_GPC['token'];
  152. $id = $_GPC['id'];
  153. // $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  154. // if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  155. // {
  156. // //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  157. // //die();
  158. // }
  159. if($id) {
  160. $condition = " id=".$id;
  161. } else {
  162. $now_time = time();
  163. $condition = 'enabled = 1 and is_index = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  164. }
  165. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition.' order by displayorder desc ');
  166. if(!empty($special_list)) {
  167. foreach ($special_list as &$data) {
  168. $list = array();
  169. $goodsids = $data['goodsids'];
  170. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  171. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  172. if($goodsids && $data['type']==1) {
  173. $where = ' g.grounding = 1 ';
  174. $where .= " and g.id in ({$goodsids})";
  175. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  176. $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 ', $where, 0, 1000);
  177. foreach ($community_goods as $key => $value) {
  178. if($value['is_all_sale']==1){
  179. $list[] = $this->change_goods_form($value);
  180. } else {
  181. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('goods_id' => $value['id'],'head_id' => $head_id ) )->order('id desc')->select();
  182. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  183. }
  184. }
  185. }
  186. $data['list'] = $list;
  187. }
  188. } else {
  189. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  190. die();
  191. }
  192. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  193. die();
  194. }
  195. /**
  196. * 专题列表
  197. * @return @return [json] [list]
  198. */
  199. public function get_special_page_list()
  200. {
  201. $_GPC = I('request.');
  202. $head_id = $_GPC['head_id'];
  203. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  204. $pre_page = 10;
  205. $offset = ($page -1) * $pre_page;
  206. $token = $_GPC['token'];
  207. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  208. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  209. {
  210. //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  211. //die();
  212. }
  213. $now_time = time();
  214. $condition = 'enabled = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  215. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition." order by displayorder desc limit {$offset},{$pre_page} ");
  216. if(!empty($special_list)) {
  217. foreach ($special_list as &$data) {
  218. $list = array();
  219. $goodsids = $data['goodsids'];
  220. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  221. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  222. if($goodsids) {
  223. $where = ' g.grounding = 1 ';
  224. $where .= " and g.id in ({$goodsids})";
  225. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  226. $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 ', $where, 0, 1000);
  227. foreach ($community_goods as $key => $value) {
  228. if($value['is_all_sale']==1){
  229. $list[] = $this->change_goods_form($value);
  230. } else {
  231. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id, 'goods_id' => $value['id']) )->order('id desc')->select();
  232. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  233. }
  234. }
  235. }
  236. $data['list'] = $list;
  237. }
  238. } else {
  239. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  240. die();
  241. }
  242. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  243. die();
  244. }
  245. }