2021-11-10 23:01:50 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Http\Request;
|
2021-11-11 18:49:09 +09:00
|
|
|
use App\Models\Meeting;
|
2021-11-10 23:01:50 +09:00
|
|
|
use App\Models\MeetingApprovals;
|
|
|
|
|
|
|
|
class NoticeIncomplete
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 未完了ミーティング通知(親向け)
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle(Request $request, Closure $next)
|
|
|
|
{
|
2021-11-11 18:49:09 +09:00
|
|
|
$response = $next($request);
|
|
|
|
$count = 0;
|
|
|
|
|
2021-11-17 13:09:21 +09:00
|
|
|
if (is_null(session()->get('fathers'))) {
|
|
|
|
session()->forget('fathers');
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2021-11-13 15:33:48 +09:00
|
|
|
if (null !== ($list = Meeting::select('id')->where('father_id', (int)session()->get('fathers')['id'])->get())) {
|
|
|
|
foreach ($list as $i => $l) {
|
2021-11-16 19:24:36 +09:00
|
|
|
if (null === ($apr = MeetingApprovals::select('id')->where('meeting_id', (int)$l->id)->get())) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-17 19:42:21 +09:00
|
|
|
|
|
|
|
$cnt = MeetingApprovals::select('id')->whereNotNull('approval_at')->where('meeting_id', (int)$l->id)->count();
|
|
|
|
$apr = count($apr);
|
2021-11-16 19:24:36 +09:00
|
|
|
|
2021-11-17 19:42:21 +09:00
|
|
|
if ($apr != 0 && $apr == $cnt) {
|
2021-11-16 19:24:36 +09:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count++;
|
2021-11-13 15:33:48 +09:00
|
|
|
}
|
2021-11-11 10:02:28 +09:00
|
|
|
}
|
2021-11-11 18:49:09 +09:00
|
|
|
|
|
|
|
$content = json_decode($response->content(), true);
|
|
|
|
if (json_last_error() == JSON_ERROR_NONE) {
|
2021-11-15 17:18:04 +09:00
|
|
|
$response->setContent(json_encode(array_merge($content, ['notice' => $count])));
|
2021-11-11 18:49:09 +09:00
|
|
|
}
|
|
|
|
|
2021-11-15 17:18:04 +09:00
|
|
|
return $response;
|
2021-11-10 23:01:50 +09:00
|
|
|
}
|
|
|
|
}
|