InviteService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Services\V1_1;
  3. use App\Generated\V1_1\Messages\Invite\LastInviteMessage;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Controllers\Core\Auth;
  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 InviteService
  14. {
  15. public function lastInvite(LastInviteMessage $message)
  16. {
  17. $ings = ActivityModel::getActivitys();
  18. $invites = InviteModel::where([
  19. ['stage_id', $ings['next']],
  20. ['state', '!=', 2]
  21. ])->take(30)->groupBy('pair_id')->get(['uid', 'pair_id']);
  22. foreach ($invites as &$invite) {
  23. $invite->user = UserModel::find($invite->uid, ['uid', 'headimgurl', 'nickname', 'sex', 'address', 'home']);
  24. $refund = InviteModel::where([
  25. ['state', 1],
  26. ['pair_id', $invite->pair_id]
  27. ])->count();
  28. if ($refund > 0) {
  29. $invite->invite = array(
  30. 'type' => 1,
  31. 'count' => $refund,
  32. 'dis_count' => InviteModel::where([
  33. ['state', 1],
  34. ['pair_id', $invite->pair_id]
  35. ])->sum('dis_score')
  36. );
  37. } else {
  38. $invite->invite = array(
  39. 'type' => 0,
  40. 'count' => InviteModel::where([
  41. ['state', 0],
  42. ['pair_id', $invite->pair_id]
  43. ])->count(),
  44. 'dis_score' => InviteModel::where([
  45. ['state', 0],
  46. ['pair_id', $invite->pair_id]
  47. ])->sum('dis_score')
  48. );
  49. }
  50. }
  51. $message->setResponse($invites);
  52. }
  53. }