You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
904 B

<?php
namespace App\Services;
use App\Models\WechatUser;
use App\Models\WechatUserHomeVisit;
use Illuminate\Support\Carbon;
class WechatHomeVisitService
{
public function record(WechatUser $user): void
{
WechatUserHomeVisit::query()->create([
'wechat_user_id' => $user->id,
'visited_at' => now(),
]);
}
public function totalVisits(): int
{
return (int) WechatUserHomeVisit::query()->count();
}
public function todayVisits(): int
{
$tz = (string) config('app.timezone');
$start = Carbon::now($tz)->startOfDay();
$end = Carbon::now($tz)->endOfDay();
return (int) WechatUserHomeVisit::query()
->whereBetween('visited_at', [$start, $end])
->count();
}
public function totalWechatUsers(): int
{
return (int) WechatUser::query()->count();
}
}