InvitegiftController.class.php 6.6 KB

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