12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Http\Services\V1;
- use App\Generated\V1\Messages\Invite\LastInviteMessage;
- use App\Models\Fpdx\ActivityModel;
- use App\Models\Fpdx\InviteModel;
- use App\Models\User\UserModel;
- class InviteService
- {
- public function lastInvite(LastInviteMessage $message)
- {
- $ings = ActivityModel::getActivitys();
- $invites = InviteModel::where([
- ['stage_id', $ings['next']],
- ['state', '!=', 2]
- ])->take(30)->groupBy('pair_id')->get(['uid', 'pair_id']);
- foreach ($invites as &$invite) {
- $invite->user = UserModel::find($invite->uid, ['uid', 'headimgurl', 'nickname', 'sex', 'address', 'home']);
- $refund = InviteModel::where([
- ['state', 1],
- ['pair_id', $invite->pair_id]
- ])->count();
- if ($refund > 0) {
- $invite->invite = array(
- 'type' => 1,
- 'count' => $refund,
- 'dis_count' => InviteModel::where([
- ['state', 1],
- ['pair_id', $invite->pair_id]
- ])->sum('dis_score')
- );
- } else {
- $invite->invite = array(
- 'type' => 0,
- 'count' => InviteModel::where([
- ['state', 0],
- ['pair_id', $invite->pair_id]
- ])->count(),
- 'dis_score' => InviteModel::where([
- ['state', 0],
- ['pair_id', $invite->pair_id]
- ])->sum('dis_score')
- );
- }
- }
- $message->setResponse($invites);
- }
- }
|