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); } }