MarketingController.class.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. //mead
  114. $tmp_data['levelprice'] = $price_arr['levelprice']; // 会员等级价格
  115. $tmp_data['is_mb_level_buy'] = $price_arr['is_mb_level_buy']; //是否 会员等级 可享受
  116. $tmp_data['levelPrice'] = explode('.', $tmp_data['levelprice']);
  117. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  118. if( !empty($tmp_data['skuList']) )
  119. {
  120. $tmp_data['car_count'] = 0;
  121. }else{
  122. $car_count = D('Home/Car')->get_wecart_goods($val['id'],"",$head_id ,$token);
  123. if( empty($car_count) )
  124. {
  125. $tmp_data['car_count'] = 0;
  126. }else{
  127. $tmp_data['car_count'] = $car_count;
  128. }
  129. }
  130. if($is_open_fullreduction == 0)
  131. {
  132. $tmp_data['is_take_fullreduction'] = 0;
  133. }else if($is_open_fullreduction == 1){
  134. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  135. }
  136. // 商品角标
  137. $label_id = unserialize($val['labelname']);
  138. if($label_id){
  139. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  140. if($label_info){
  141. if($label_info['type'] == 1){
  142. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  143. } else {
  144. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  145. }
  146. }
  147. $tmp_data['label_info'] = $label_info;
  148. }
  149. return $tmp_data;
  150. }
  151. public function get_special_list()
  152. {
  153. $_GPC = I('request.');
  154. $head_id = $_GPC['head_id'];
  155. $token = $_GPC['token'];
  156. $id = $_GPC['id'];
  157. // $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  158. // if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  159. // {
  160. // //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  161. // //die();
  162. // }
  163. if($id) {
  164. $condition = " id=".$id;
  165. } else {
  166. $now_time = time();
  167. $condition = 'enabled = 1 and is_index = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  168. }
  169. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition.' order by displayorder desc ');
  170. if(!empty($special_list)) {
  171. foreach ($special_list as &$data) {
  172. $list = array();
  173. $goodsids = $data['goodsids'];
  174. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  175. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  176. if($goodsids && $data['type']==1) {
  177. $where = ' g.grounding = 1 ';
  178. $where .= " and g.id in ({$goodsids})";
  179. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  180. $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);
  181. foreach ($community_goods as $key => $value) {
  182. if($value['is_all_sale']==1){
  183. $list[] = $this->change_goods_form($value);
  184. } else {
  185. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('goods_id' => $value['id'],'head_id' => $head_id ) )->order('id desc')->select();
  186. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  187. }
  188. }
  189. }
  190. $data['list'] = $list;
  191. }
  192. } else {
  193. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  194. die();
  195. }
  196. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  197. die();
  198. }
  199. /**
  200. * 专题列表
  201. * @return @return [json] [list]
  202. */
  203. public function get_special_page_list()
  204. {
  205. $_GPC = I('request.');
  206. $head_id = $_GPC['head_id'];
  207. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  208. $pre_page = 10;
  209. $offset = ($page -1) * $pre_page;
  210. $token = $_GPC['token'];
  211. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  212. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  213. {
  214. //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  215. //die();
  216. }
  217. $now_time = time();
  218. $condition = 'enabled = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  219. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition." order by displayorder desc limit {$offset},{$pre_page} ");
  220. if(!empty($special_list)) {
  221. foreach ($special_list as &$data) {
  222. $list = array();
  223. $goodsids = $data['goodsids'];
  224. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  225. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  226. if($goodsids) {
  227. $where = ' g.grounding = 1 ';
  228. $where .= " and g.id in ({$goodsids})";
  229. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  230. $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);
  231. foreach ($community_goods as $key => $value) {
  232. if($value['is_all_sale']==1){
  233. $list[] = $this->change_goods_form($value);
  234. } else {
  235. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id, 'goods_id' => $value['id']) )->order('id desc')->select();
  236. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  237. }
  238. }
  239. }
  240. $data['list'] = $list;
  241. }
  242. } else {
  243. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  244. die();
  245. }
  246. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  247. die();
  248. }
  249. }