{
$data = [];
$customers = Customer::all(['id', 'customer_type', 'created_at']);
#今天数据
$data['customer_today'] = Customer::where('customer_type', 1)->where('created_at', Carbon::today())->count();
$data['teacher_today'] = Customer::where('customer_type', 2)->where('created_at', Carbon::today())->count();
#昨天数据
$data['customer_yesterday'] = Customer::where('customer_type', 1)->where('created_at', Carbon::yesterday())->count();
$data['teacher_yesterday'] = Customer::where('customer_type', 2)->where('created_at', Carbon::yesterday())->count();
$data['today'] = $data['customer_today'] + $data['teacher_today'];
$data['yesterday'] = $data['customer_yesterday'] + $data['teacher_yesterday'];
// 本周数据
$this_week = [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
$data['customer_this_week'] = Customer::where('customer_type', 1)->whereBetween('created_at', $this_week)->count();
$data['teacher_this_week'] = Customer::where('customer_type', 2)->whereBetween('created_at', $this_week)->count();
// 上周数据
$last_week = [Carbon::now()->startOfWeek()->subWeek(), Carbon::now()->endOfWeek()->subWeek()];
$data['customer_last_week'] = Customer::where('customer_type', 1)->whereBetween('created_at', $last_week)->count();
$data['teacher_last_week'] = Customer::where('customer_type', 2)->whereBetween('created_at', $last_week)->count();
$data['this_week'] = $data['customer_this_week'] + $data['teacher_this_week'];
$data['last_week'] = $data['customer_last_week'] + $data['teacher_last_week'];
// 本月数据
$data['customer_this_month'] = Customer::where('customer_type', 1)->whereMonth('created_at', Carbon::now()->month)->count();
$data['teacher_this_month'] = Customer::where('customer_type', 2)->whereMonth('created_at', Carbon::now()->month)->count();
// 上月数据
$data['customer_last_month'] = Customer::where('customer_type', 1)->whereMonth('created_at', Carbon::now()->subMonth()->month)->count();
$data['teacher_last_month'] = Customer::where('customer_type', 2)->whereMonth('created_at', Carbon::now()->subMonth()->month)->count();
$data['this_month'] = $data['customer_this_month'] + $data['teacher_this_month'];
$data['last_month'] = $data['customer_last_month'] + $data['teacher_last_month'];
// 本年数据
$data['customer_this_year'] = Customer::where('customer_type', 1)->whereYear('created_at', Carbon::now()->year)->count();
$data['teacher_this_year'] = Customer::where('customer_type', 2)->whereYear('created_at', Carbon::now()->year)->count();
$data['today_login_users'] = LoginLog::whereDate('created_at', '=', Carbon::today())
->groupBy('customer_id')
->orderBy('customer_id')
->count();
$data['yesterday_login_users'] = LoginLog::whereDate('created_at', '=', Carbon::yesterday())
->groupBy('customer_id')
->orderBy('customer_id')
->count();
$data['this_month_login_users'] = LoginLog::whereMonth('created_at', Carbon::now()->month)
->groupBy('customer_id')
->orderBy('customer_id')
->count();
$data['last_month_login_users'] = LoginLog::whereMonth('created_at', Carbon::now()->subMonth()->month)
->groupBy('customer_id')
->orderBy('customer_id')
->count();
return $data;
}
|