VipcardController.class.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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 VipcardController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function get_vipcard_baseinfo()
  21. {
  22. $_GPC = I('request.');
  23. $token = $_GPC['token'];
  24. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  25. $member_id = $weprogram_token['member_id'];
  26. if( empty($member_id) )
  27. {
  28. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  29. die();
  30. }
  31. $member_id = $weprogram_token['member_id'];
  32. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  33. $vipcard_unopen_headbg = D('Home/Front')->get_config_by_name('vipcard_unopen_headbg');
  34. $vipcard_effect_headbg = D('Home/Front')->get_config_by_name('vipcard_effect_headbg');
  35. $vipcard_afterefect_headbg = D('Home/Front')->get_config_by_name('vipcard_afterefect_headbg');
  36. if(!empty($vipcard_unopen_headbg)) $vipcard_unopen_headbg = tomedia($vipcard_unopen_headbg);
  37. if(!empty($vipcard_effect_headbg)) $vipcard_effect_headbg = tomedia($vipcard_effect_headbg);
  38. if(!empty($vipcard_afterefect_headbg)) $vipcard_afterefect_headbg = tomedia($vipcard_afterefect_headbg);
  39. $vipcard_buy_pagenotice = D('Home/Front')->get_config_by_name('vipcard_buy_pagenotice');
  40. $vipcard_equity_notice = D('Home/Front')->get_config_by_name('vipcard_equity_notice');
  41. $vipcard_buy_pagenotice = htmlspecialchars_decode($vipcard_buy_pagenotice);
  42. $vipcard_equity_notice = htmlspecialchars_decode($vipcard_equity_notice);
  43. $card_list = M('lionfish_comshop_member_card')->select();
  44. $card_equity_list = M('lionfish_comshop_member_card_equity')->select();
  45. $result = array();
  46. //判断是否开启了 会员卡 is_open_vipcard_buy
  47. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  48. $modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
  49. $is_hide_vipcard_vipgoods = D('Home/Front')->get_config_by_name('is_hide_vipcard_vipgoods');
  50. $is_show_vipgoods = empty($is_hide_vipcard_vipgoods) || $is_hide_vipcard_vipgoods == 0 ? 1 : 0;
  51. $modify_vipcard_name = empty($modify_vipcard_name) ? '天机会员': $modify_vipcard_name;
  52. $result['is_open_vipcard_buy'] = $is_open_vipcard_buy;
  53. $result['modify_vipcard_name'] = $modify_vipcard_name;
  54. $result['is_vip_card_member'] = 0;
  55. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  56. {
  57. $now_time = time();
  58. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  59. {
  60. $result['is_vip_card_member'] = 1;//还有会员
  61. $del_day = ceil( ($member_info['card_end_time'] - $now_time) / 86400 ) ;
  62. $result['del_vip_day'] = $del_day;
  63. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  64. $result['is_vip_card_member'] = 2;//已过期
  65. }
  66. }
  67. if( !empty($card_equity_list) )
  68. {
  69. foreach($card_equity_list as $key => $val)
  70. {
  71. $val['image'] = tomedia($val['image'] );
  72. $card_equity_list[$key] = $val;
  73. }
  74. }
  75. $member_info['card_end_time'] = date('Y-m-d', $member_info['card_end_time']);
  76. $member_info['username'] = str_replace('&#039;',"'",$member_info['username']);
  77. $result['vipcard_unopen_headbg'] = $vipcard_unopen_headbg;
  78. $result['vipcard_effect_headbg'] = $vipcard_effect_headbg;
  79. $result['vipcard_afterefect_headbg'] = $vipcard_afterefect_headbg;
  80. $result['vipcard_buy_pagenotice'] = $vipcard_buy_pagenotice;
  81. $result['vipcard_equity_notice'] = $vipcard_equity_notice;
  82. $result['card_list'] = $card_list;
  83. $result['card_equity_list'] = $card_equity_list;
  84. $result['member_info'] = $member_info;
  85. $result['is_show_vipgoods'] = $is_show_vipgoods;//是否显示会员卡商品
  86. $category_list = M('lionfish_comshop_goods_category')->where( "cate_type='normal' and is_show=1 and pid=0" )->order('sort_order desc,id asc')->select();
  87. foreach( $category_list as &$val )
  88. {
  89. unset($val['uniacid']);
  90. unset($val['pid']);
  91. unset($val['is_hot']);
  92. unset($val['logo']);
  93. unset($val['banner']);
  94. unset($val['cate_type']);
  95. unset($val['sort_order']);
  96. unset($val['is_show_topic']);
  97. }
  98. $result['category_list'] = $category_list;
  99. echo json_encode( array('code' => 0, 'data' => $result) );
  100. die();
  101. }
  102. public function get_vipgoods_list()
  103. {
  104. $_GPC = I('request.');
  105. $head_id = $_GPC['head_id'];
  106. if($head_id == 'undefined') $head_id = '';
  107. $pageNum = isset($_GPC['pageNum']) && $_GPC['pageNum'] > 0 ? $_GPC['pageNum'] : 1 ;
  108. $gid = $_GPC['gid'];
  109. $keyword = '';
  110. $is_random = 0;
  111. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  112. $cate_info = '';
  113. if($gid > 0){
  114. $sub_cate_list = M('lionfish_comshop_goods_category')->where( "is_show=1 and cate_type='normal' and pid = {$gid}" )->order('sort_order desc, id desc')->select();
  115. $gidArr = array();
  116. $gidArr[] = $gid;
  117. foreach ($sub_cate_list as $key => $val) {
  118. $gidArr[] = $val['id'];
  119. }
  120. $gid = implode(',', $gidArr);
  121. }
  122. $offset = ($pageNum - 1) * $per_page;
  123. $limit = "{$offset},{$per_page}";
  124. $token = $_GPC['token'];
  125. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  126. $is_vip_card_member = 0;
  127. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  128. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  129. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  130. {
  131. }else{
  132. $member_id = $weprogram_token['member_id'];
  133. $is_vip_card_member = 0;
  134. //member_id
  135. if( $member_id > 0 )
  136. {
  137. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  138. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  139. {
  140. $now_time = time();
  141. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  142. {
  143. $is_vip_card_member = 1;//还是会员
  144. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  145. $is_vip_card_member = 2;//已过期
  146. }
  147. }
  148. }
  149. }
  150. $now_time = time();
  151. $where = " g.is_take_vipcard =1 and g.grounding =1 and g.type ='normal' ";
  152. //head_id
  153. if( !empty($head_id) && $head_id >0 )
  154. {
  155. if($gid == 0){
  156. $goods_ids_arr = M('lionfish_community_head_goods')->field('goods_id')->where( array('head_id' => $head_id ) )->select();
  157. } else {
  158. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg,"
  159. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  160. where pg.goods_id = g.goods_id and g.cate_id in ({$gid}) and pg.head_id = {$head_id} order by pg.id desc ";
  161. $goods_ids_arr = M()->query($sql_goods_ids);
  162. }
  163. $ids_arr = array();
  164. foreach($goods_ids_arr as $val){
  165. $ids_arr[] = $val['goods_id'];
  166. }
  167. if($gid == 0){
  168. $goods_ids_nolimit_arr = M('lionfish_comshop_goods')->field('id')->where( array('is_all_sale' => 1) )->select();
  169. } else {
  170. $goods_ids_nolimit_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  171. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  172. where pg.id = g.goods_id and g.cate_id in ({$gid}) and pg.is_all_sale=1 ";
  173. $goods_ids_nolimit_arr = M()->query($goods_ids_nolimit_sql);
  174. }
  175. if( !empty($goods_ids_nolimit_arr) )
  176. {
  177. foreach($goods_ids_nolimit_arr as $val){
  178. $ids_arr[] = $val['id'];
  179. }
  180. }
  181. $ids_str = implode(',',$ids_arr);
  182. if( !empty($ids_str) )
  183. {
  184. $where .= " and g.id in ({$ids_str})";
  185. } else{
  186. $where .= " and 0 ";
  187. }
  188. }else{
  189. //echo json_encode( array('code' => 1) );
  190. // die();
  191. if($gid == 0){
  192. $goods_ids_nohead_arr = M('lionfish_comshop_goods')->field('id')->where( array('type' => 'normal' ) )->select();
  193. } else {
  194. $goods_ids_nohead_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  195. .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' ";
  196. $goods_ids_nohead_arr = M()->query($goods_ids_nohead_sql);
  197. }
  198. $ids_arr = array();
  199. if( !empty($goods_ids_nohead_arr) )
  200. {
  201. foreach($goods_ids_nohead_arr as $val){
  202. $ids_arr[] = $val['id'];
  203. }
  204. }
  205. $ids_str = implode(',',$ids_arr);
  206. if( !empty($ids_str) )
  207. {
  208. $where .= " and g.id in ({$ids_str})";
  209. } else{
  210. $where .= " and 0 ";
  211. }
  212. }
  213. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  214. $where .= " and gc.is_new_buy=0 and gc.is_spike_buy = 0 ";
  215. $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);
  216. if( !empty($community_goods) )
  217. {
  218. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  219. $full_money = D('Home/Front')->get_config_by_name('full_money');
  220. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  221. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  222. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1:0;
  223. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  224. {
  225. $is_open_fullreduction = 0;
  226. }
  227. $cart= D('Home/Car');
  228. $list = array();
  229. $copy_text_arr = array();
  230. foreach($community_goods as $val)
  231. {
  232. $tmp_data = array();
  233. $tmp_data['actId'] = $val['id'];
  234. $tmp_data['spuName'] = $val['goodsname'];
  235. $tmp_data['spuCanBuyNum'] = $val['total'];
  236. $tmp_data['spuDescribe'] = $val['subtitle'];
  237. $tmp_data['end_time'] = $val['end_time'];
  238. $tmp_data['is_take_vipcard'] = $val['is_take_vipcard'];
  239. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  240. $productprice = $val['productprice'];
  241. $tmp_data['marketPrice'] = explode('.', $productprice);
  242. if( !empty($val['big_img']) )
  243. {
  244. $tmp_data['bigImg'] = tomedia($val['big_img']);
  245. }
  246. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  247. if( !empty($good_image) )
  248. {
  249. $tmp_data['skuImage'] = tomedia($good_image['image']);
  250. }
  251. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  252. $price = $price_arr['price'];
  253. if( $pageNum == 1 )
  254. {
  255. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  256. }
  257. $tmp_data['actPrice'] = explode('.', $price);
  258. $tmp_data['card_price'] = $price_arr['card_price'];
  259. //card_price
  260. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  261. if( !empty($tmp_data['skuList']) )
  262. {
  263. $tmp_data['car_count'] = 0;
  264. }else{
  265. $car_count = $cart->get_wecart_goods($val['id'],"",$head_id ,$token);
  266. if( empty($car_count) )
  267. {
  268. $tmp_data['car_count'] = 0;
  269. }else{
  270. $tmp_data['car_count'] = $car_count;
  271. }
  272. }
  273. if($is_open_fullreduction == 0)
  274. {
  275. $tmp_data['is_take_fullreduction'] = 0;
  276. }else if($is_open_fullreduction == 1){
  277. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  278. }
  279. // 商品角标
  280. $label_id = unserialize($val['labelname']);
  281. if($label_id){
  282. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  283. if($label_info){
  284. if($label_info['type'] == 1){
  285. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  286. } else {
  287. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  288. }
  289. }
  290. $tmp_data['label_info'] = $label_info;
  291. }
  292. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  293. $list[] = $tmp_data;
  294. }
  295. $is_show_list_timer = D('Home/Front')->get_config_by_name('is_show_list_timer');
  296. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  297. echo json_encode(array('code' => 0, 'list' => $list ,'is_vip_card_member' => $is_vip_card_member,'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 ));
  298. die();
  299. }else{
  300. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  301. echo json_encode( array('code' => 1, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar) );
  302. die();
  303. }
  304. }
  305. /**
  306. 微信购买会员卡
  307. **/
  308. public function wxcharge()
  309. {
  310. $data = array();
  311. $_GPC = I('request.');
  312. $token = $_GPC['token'];
  313. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  314. $member_id = $weprogram_token['member_id'];
  315. if( empty($member_id) )
  316. {
  317. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  318. die();
  319. }
  320. $rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
  321. $card_info = M('lionfish_comshop_member_card')->where( array('id' => $rech_id ) )->find();
  322. if( empty($card_info) )
  323. {
  324. echo json_encode( array('code' =>1,'msg' =>'无此会员卡') );
  325. die();
  326. }
  327. $money = $card_info['price'];
  328. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  329. $now_time = time();
  330. $order_type = 1;
  331. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  332. {
  333. $order_type = 2;
  334. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  335. $order_type = 3;
  336. }
  337. $member_charge_flow_data = array();
  338. $member_charge_flow_data['order_sn'] = build_order_no($member_id);
  339. $member_charge_flow_data['member_id'] = $member_id;
  340. $member_charge_flow_data['pay_type'] = 'weixin';
  341. $member_charge_flow_data['state'] = 0;
  342. $member_charge_flow_data['car_id'] = $card_info['id'];
  343. $member_charge_flow_data['expire_day'] = $card_info['expire_day'];
  344. $member_charge_flow_data['price'] = $card_info['price'];
  345. $member_charge_flow_data['order_type'] = $order_type; // 1,2,3
  346. $member_charge_flow_data['begin_time'] = 0;
  347. $member_charge_flow_data['end_time'] = 0;
  348. $member_charge_flow_data['pay_time'] = 0;
  349. $member_charge_flow_data['addtime'] = time();
  350. $order_id = M('lionfish_comshop_member_card_order')->add( $member_charge_flow_data );
  351. if($card_info['price'] == 0){//会员卡价格为0时
  352. D('Home/Vipcard')->member_charge_zero_card($order_id);
  353. $data['code'] = 0;
  354. $data['is_zero_pay'] = 1;//1、0元支付成功标识;0、微信支付
  355. }else{
  356. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  357. $fee = $money;
  358. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  359. $body = '会员卡购买';
  360. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  361. $nonce_str = nonce_str();
  362. $notify_url = $shop_domain.'/notify.php';
  363. $openid = $member_info['we_openid'];
  364. $out_trade_no = $order_id.'-'.time().'-buycard-'.$rech_id;
  365. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  366. $total_fee = $fee*100;
  367. $trade_type = 'JSAPI';
  368. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  369. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  370. if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  371. {
  372. //特约商户
  373. //小程序appid
  374. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  375. //特约商户商户id
  376. $mch_id = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  377. $pay_key = D('Home/Front')->get_config_by_name('sup_wepro_key');
  378. }
  379. $post['appid'] = $appid;
  380. $post['body'] = $body;
  381. $post['mch_id'] = $mch_id;
  382. $post['nonce_str'] = $nonce_str;
  383. $post['notify_url'] = $notify_url;
  384. $post['openid'] = $openid;
  385. $post['out_trade_no'] = $out_trade_no;
  386. $post['spbill_create_ip'] = $spbill_create_ip;
  387. $post['total_fee'] = $total_fee;
  388. $post['trade_type'] = $trade_type;
  389. $sign = sign($post,$pay_key);
  390. //sign()
  391. $post_xml = '<xml>
  392. <appid>'.$appid.'</appid>
  393. <body>'.$body.'</body>
  394. <mch_id>'.$mch_id.'</mch_id>
  395. <nonce_str>'.$nonce_str.'</nonce_str>
  396. <notify_url>'.$notify_url.'</notify_url>
  397. <openid>'.$openid.'</openid>
  398. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  399. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  400. <total_fee>'.$total_fee.'</total_fee>
  401. <trade_type>'.$trade_type.'</trade_type>
  402. <sign>'.$sign.'</sign>
  403. </xml> ';
  404. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  405. $xml = http_request($url,$post_xml);
  406. $array = xml($xml);
  407. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  408. $time = time();
  409. $tmp= array();
  410. $tmp['appId'] = $appid;
  411. $tmp['nonceStr'] = $nonce_str;
  412. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  413. $tmp['signType'] = 'MD5';
  414. $tmp['timeStamp'] = "$time";
  415. M('lionfish_comshop_member_card_order')->where( array('id' => $order_id) )->save( array('formid' => $array['PREPAY_ID'] ) );
  416. $data['code'] = 0;
  417. $data['timeStamp'] = "$time";
  418. $data['nonceStr'] = $nonce_str;
  419. $data['signType'] = 'MD5';
  420. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  421. $data['paySign'] = sign($tmp, $pay_key);
  422. $data['out_trade_no'] = $out_trade_no;
  423. $data['is_zero_pay'] = 0;
  424. $data['redirect_url'] = '../dan/me';
  425. }else{
  426. $data['code'] = 1;
  427. $data['text'] = "错误";
  428. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  429. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  430. }
  431. }
  432. echo json_encode($data);
  433. die();
  434. }
  435. }