InvitegiftController.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 cy(694418550@qq.com) 2021-03-11
  12. *
  13. */
  14. namespace Home\Controller;
  15. /**
  16. * 邀新有礼
  17. * Class InvitegiftController
  18. * @package Home\Controller
  19. */
  20. class InvitegiftController extends CommonController {
  21. protected function _initialize(){
  22. parent::_initialize();
  23. }
  24. /**
  25. * @author cy 2021-03-11
  26. * @desc 邀新有礼页面
  27. */
  28. public function index(){
  29. $_GPC = I('request.');
  30. $token = $_GPC['token'];
  31. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  32. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  33. {
  34. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  35. die();
  36. }
  37. $member_id = $weprogram_token['member_id'];
  38. $data = array();
  39. $data = D('Home/Invitegift')->getInvitegiftInfo($member_id);
  40. echo json_encode( array('code' => 0, 'data' => $data) );
  41. }
  42. /**
  43. * @author cy 2021-03-11
  44. * @desc 邀请好友列表
  45. */
  46. public function getInvitegiftRecord(){
  47. $_GPC = I('request.');
  48. $token = $_GPC['token'];
  49. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  50. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  51. {
  52. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  53. die();
  54. }
  55. $member_id = $weprogram_token['member_id'];
  56. $page = !empty($_GPC['page']) ? $_GPC['page'] : 1;
  57. $type = !empty($_GPC['type']) ? $_GPC['type'] : 'invite';//invite 已邀请好友,success 邀请成功好友
  58. $record_list = D('Home/Invitegift')->getInvitegiftRecordList( $member_id , $type, $page, 10 );
  59. echo json_encode( array('code' => 0, 'data' => $record_list) );
  60. }
  61. /**
  62. * @author cy 2021-03-11
  63. * @desc 新用户推荐有礼页面
  64. */
  65. public function invitegiftIndex(){
  66. $_GPC = I('request.');
  67. $token = $_GPC['token'];
  68. $member_id = 0;
  69. if(!empty($token)){
  70. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  71. $member_id = $weprogram_token['member_id'];
  72. }
  73. $suid = $_GPC['suid'];
  74. if(empty($suid)){
  75. echo json_encode( array('code' => 2, 'msg' => '参数不能为空') );
  76. die();
  77. }
  78. $member_info = M('lionfish_comshop_member')->where(array('member_id'=>$suid))->find();
  79. if(empty($member_info)){
  80. echo json_encode( array('code' => 3, 'msg' => '邀请人不存在') );
  81. die();
  82. }
  83. $need_data = D('Home/Invitegift')->getInvitegiftIndex();
  84. if(empty($need_data)){
  85. echo json_encode( array('code' => 4, 'msg' => '活动不存在') );
  86. die();
  87. }
  88. //老用户保存邀新记录
  89. if(!empty($member_id)){
  90. $members = M('lionfish_comshop_member')->where(array('member_id'=>$member_id))->find();
  91. if (empty($members['share_id'])) {
  92. if (intval($suid) > 0 && $suid != $member_id) {
  93. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save(array('share_id'=>$suid));
  94. D('Home/Invitegift')->insertInvitegiftRecord($suid, $member_id, 1);
  95. }
  96. }
  97. }
  98. $need_data['suid'] = $suid;
  99. echo json_encode( array('code' => 0, 'data' => $need_data) );
  100. }
  101. /**
  102. * @author cy 2021-03-12
  103. * @desc 新用户领取礼包
  104. * @return mixed
  105. */
  106. public function collectInvitegift(){
  107. $_GPC = I('request.');
  108. $token = $_GPC['token'];
  109. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  110. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  111. {
  112. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  113. die();
  114. }
  115. $member_id = $weprogram_token['member_id'];
  116. $data = D('Home/Invitegift')->collectInvitegift( $member_id );
  117. if($data['code'] == 0){
  118. echo json_encode( array('code' => 0, 'data' => $data) );
  119. }else{
  120. echo json_encode( array('code' => 2, 'msg' => $data['message']) );
  121. }
  122. }
  123. /**
  124. * @author cy 2021-03-12
  125. * @desc 立即邀请判断
  126. */
  127. public function checkInvitegift(){
  128. $_GPC = I('request.');
  129. $token = $_GPC['token'];
  130. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  131. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  132. {
  133. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  134. die();
  135. }
  136. $member_id = $weprogram_token['member_id'];
  137. $data = D('Home/Invitegift')->checkInvitegift( $member_id );
  138. if($data['code'] == 0){
  139. echo json_encode( array('code' => 0) );
  140. }else{
  141. echo json_encode( array('code' => 2, 'msg' => $data['message']) );
  142. }
  143. }
  144. /**
  145. * @author cy 2021-03-12
  146. * @desc 邀请优惠券列表
  147. */
  148. public function getInvitegiftCouponList(){
  149. $_GPC = I('request.');
  150. $token = $_GPC['token'];
  151. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  152. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  153. {
  154. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  155. die();
  156. }
  157. $member_id = $weprogram_token['member_id'];
  158. $page = !empty($_GPC['page']) ? $_GPC['page'] : 1;
  159. $coupon_list = D('Home/Invitegift')->getInvitegiftCouponList( $member_id , $page, 10 );
  160. echo json_encode( array('code' => 0, 'data'=>$coupon_list) );
  161. }
  162. /**
  163. * @author cy 2021-03-12
  164. * @desc 邀请积分数记录
  165. * @return mixed
  166. */
  167. public function getInvitegiftPoints(){
  168. $_GPC = I('request.');
  169. $token = $_GPC['token'];
  170. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  171. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  172. {
  173. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  174. die();
  175. }
  176. $member_id = $weprogram_token['member_id'];
  177. //总积分
  178. $total_points = D('Home/Invitegift')->getInvitegiftPointsTotal($member_id);
  179. $need_data['total_points'] = $total_points;
  180. echo json_encode( array('code' => 0, 'data'=>$need_data) );
  181. }
  182. /**
  183. * @author cy 2021-03-12
  184. * @desc 邀请积分明细列表
  185. */
  186. public function getInvitegiftPointsList(){
  187. $_GPC = I('request.');
  188. $token = $_GPC['token'];
  189. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  190. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  191. {
  192. echo json_encode( array('code' => 1, 'msg' => '未登录') );
  193. die();
  194. }
  195. $member_id = $weprogram_token['member_id'];
  196. $page = !empty($_GPC['page']) ? $_GPC['page'] : 1;
  197. $point_list = D('Home/Invitegift')->getInvitegiftPointsList( $member_id , $page, 10 );
  198. echo json_encode( array('code' => 0, 'data'=>$point_list) );
  199. }
  200. }