InviteService.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Services\V1;
  3. use App\Generated\V1\Messages\Invite\LastInviteMessage;
  4. use App\Models\Fpdx\ActivityModel;
  5. use App\Models\Fpdx\InviteModel;
  6. use App\Models\User\UserModel;
  7. class InviteService
  8. {
  9. public function lastInvite(LastInviteMessage $message)
  10. {
  11. $ings = ActivityModel::getActivitys();
  12. $invites = InviteModel::where([
  13. ['stage_id', $ings['next']],
  14. ['state', '!=', 2]
  15. ])->take(30)->groupBy('pair_id')->get(['uid', 'pair_id']);
  16. foreach ($invites as &$invite) {
  17. $invite->user = UserModel::find($invite->uid, ['uid', 'headimgurl', 'nickname', 'sex', 'address', 'home']);
  18. $refund = InviteModel::where([
  19. ['state', 1],
  20. ['pair_id', $invite->pair_id]
  21. ])->count();
  22. if ($refund > 0) {
  23. $invite->invite = array(
  24. 'type' => 1,
  25. 'count' => $refund,
  26. 'dis_count' => InviteModel::where([
  27. ['state', 1],
  28. ['pair_id', $invite->pair_id]
  29. ])->sum('dis_score')
  30. );
  31. } else {
  32. $invite->invite = array(
  33. 'type' => 0,
  34. 'count' => InviteModel::where([
  35. ['state', 0],
  36. ['pair_id', $invite->pair_id]
  37. ])->count(),
  38. 'dis_score' => InviteModel::where([
  39. ['state', 0],
  40. ['pair_id', $invite->pair_id]
  41. ])->sum('dis_score')
  42. );
  43. }
  44. }
  45. $message->setResponse($invites);
  46. }
  47. }