VipcardController.class.php 18 KB

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