Invite.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace App\Http\Controllers\Fpdx;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Managers\SharePairManager;
  6. use App\Models\Fpdx\PairModel;
  7. use App\Models\Fpdx\ActivityModel;
  8. use App\Models\Fpdx\InviteModel;
  9. use App\Models\User\UserModel;
  10. use App\Models\User\AuthKey;
  11. use Illuminate\Http\Request;
  12. use Tymon\JWTAuth\Exceptions\JWTException;
  13. class Invite extends Controller
  14. {
  15. /**
  16. * 检验邀请
  17. * @param int $invite_id
  18. * @param Request $request
  19. * @return array
  20. * @throws \App\Exceptions\AlertException
  21. * @throws \Throwable
  22. */
  23. public function invite(int $invite_id, Request $request)
  24. {
  25. $platform = $request->header('platform');
  26. if ('qq' == $platform) {
  27. $this->validate($request, ['openid' => 'required']);
  28. $openid = $request->get('openid');
  29. } else {
  30. $uid = Auth::auth();
  31. $auth = AuthKey::where(array(['uid', $uid], ['auth_type', config("miniprogram.public_id")]))->firstOrFail();
  32. $openid = $auth->auth_key;
  33. }
  34. $ps = new SharePairManager();
  35. $data = $ps->check($openid, $invite_id);
  36. return array(
  37. 'code' => 200,
  38. 'message' => 'success',
  39. 'data' => $data
  40. );
  41. }
  42. /**
  43. * 会员助力提升成功率
  44. * @param int $invite_id
  45. * @return array
  46. * @throws \App\Exceptions\AlertException
  47. * @throws \Throwable
  48. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  49. * @deprecated Share/PairVipCheck
  50. */
  51. public function vipCheck(int $invite_id)
  52. {
  53. $uid = Auth::auth();
  54. $ps = new SharePairManager();
  55. $data = $ps->vipCheck($uid, $invite_id);
  56. return array(
  57. 'code' => 200,
  58. 'message' => 'success',
  59. 'data' => $data
  60. );
  61. }
  62. /**
  63. * 邀请进度
  64. * @param int $invite_id
  65. * @return float(2, 2)
  66. */
  67. public function progressInvite(int $invite_id)
  68. {
  69. $dis_score = InviteModel::where([
  70. ['id', $invite_id],
  71. ['state', '!=', 2]
  72. ])->sum('dis_score');
  73. return sprintf('%.2f', $dis_score / 100);
  74. }
  75. /**
  76. * 获取邀请信息
  77. * @param int $invite_id
  78. * @return array
  79. */
  80. public function get(int $invite_id)
  81. {
  82. $pair = PairModel::find($invite_id);
  83. if (collect($pair)->isEmpty()) {
  84. return array(
  85. 'code' => 101,
  86. 'message' => '参数错误'
  87. );
  88. } else {
  89. return array(
  90. 'code' => 200,
  91. 'message' => 'success',
  92. 'data' => $pair
  93. );
  94. }
  95. }
  96. /**
  97. * @return array
  98. * @throws \ApiException
  99. * @api 获取最近三个人的报名气泡
  100. * @deprecated Invite/LastInvite
  101. */
  102. public function lastInvite()
  103. {
  104. try {
  105. $ings = ActivityModel::getActivitys();
  106. $invites = InviteModel::where([
  107. ['stage_id', $ings['next']],
  108. ['state', '!=', 2]
  109. ])->take(30)->groupBy('pair_id')->get(['uid', 'pair_id']);
  110. foreach ($invites as &$invite) {
  111. $invite->user = UserModel::find(
  112. $invite->uid,
  113. ['uid', 'headimgurl', 'nickname', 'sex', 'address', 'home']
  114. );
  115. $refund = InviteModel::where([
  116. ['state', 1],
  117. ['pair_id', $invite->pair_id]
  118. ])->count();
  119. if ($refund > 0) {
  120. $invite->invite = array(
  121. 'type' => 1,
  122. 'count' => $refund,
  123. 'dis_count' => InviteModel::where([
  124. ['state', 1],
  125. ['pair_id', $invite->pair_id]
  126. ])->sum('dis_score')
  127. );
  128. } else {
  129. $invite->invite = array(
  130. 'type' => 0,
  131. 'count' => InviteModel::where([
  132. ['state', 0],
  133. ['pair_id', $invite->pair_id]
  134. ])->count(),
  135. 'dis_score' => InviteModel::where([
  136. ['state', 0],
  137. ['pair_id', $invite->pair_id]
  138. ])->sum('dis_score')
  139. );
  140. }
  141. }
  142. return array(
  143. 'code' => 200,
  144. 'message' => 'success',
  145. 'data' => $invites
  146. );
  147. } catch (\Exception $e) {
  148. dump($e);
  149. throw new \ApiException($e->getMessage(), $e->getCode());
  150. }
  151. }
  152. }