プロフィールトップに最近のシコ草を移動

This commit is contained in:
shibafu
2020-05-24 19:03:15 +09:00
parent 8ac65f1cc6
commit 8fb8677406
4 changed files with 60 additions and 10 deletions

View File

@@ -62,7 +62,18 @@ SQL
->limit(10)
->get();
return view('user.profile')->with(compact('user', 'ejaculations', 'tags'));
// シコ草
$countByDayQuery = $this->countEjaculationByDay($user)
->where('ejaculated_date', '>=', now()->startOfMonth()->subMonths(9))
->where('ejaculated_date', '<', now()->addMonth()->startOfMonth())
->get();
$countByDay = [];
foreach ($countByDayQuery as $data) {
$date = Carbon::createFromFormat('Y/m/d', $data->date);
$countByDay[$date->timestamp] = $data->count;
}
return view('user.profile')->with(compact('user', 'ejaculations', 'tags', 'countByDay'));
}
public function stats($name)
@@ -223,16 +234,8 @@ SQL
$dateCondition[] = ['ejaculated_date', '>=', $dateSince];
}
$groupByDay = Ejaculation::select(DB::raw(
<<<'SQL'
to_char(ejaculated_date, 'YYYY/MM/DD') AS "date",
count(*) AS "count"
SQL
))
->where('user_id', $user->id)
$groupByDay = $this->countEjaculationByDay($user)
->where($dateCondition)
->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"))
->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"))
->get();
$groupByHour = Ejaculation::select(DB::raw(
@@ -287,4 +290,17 @@ SQL
'hourlySum' => array_values($hourlySum),
];
}
private function countEjaculationByDay(User $user)
{
return Ejaculation::select(DB::raw(
<<<'SQL'
to_char(ejaculated_date, 'YYYY/MM/DD') AS "date",
count(*) AS "count"
SQL
))
->where('user_id', $user->id)
->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"))
->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"));
}
}