获取七天以前到现在的数据:
$days = Input::get('days', 7); $range = \Carbon\Carbon::now()->subDays($days); $stats = User::where('created_at', '>=', $range) ->groupBy('date') ->orderBy('date', 'DESC') ->get([ DB::raw('Date(created_at) as date'), DB::raw('COUNT(*) as value') ]);
SELECT sum(case when `EmailSource`='FM' then 1 else 0 end) as FM_Statistic, sum(case when `EmailSource`='UOC' then 1 else 0 end) as UOC_Statistic, sum(case when `EmailSource`='OC' then 1 else 0 end) as OC_Statistic, DATE_FORMAT(Date,'%Y-%m-%d') AS `DateTime` FROM `user_performance` WHERE Email != '' AND Email != 'TOTAL' AND (DATE_FORMAT(Date,'%Y-%m-%d') >= DATE_FORMAT('2011-02-5','%Y-%m-%d')) AND (DATE_FORMAT(Date,'%Y-%m-%d') <= DATE_FORMAT('2011-03-07','%Y-%m-%d')) GROUP BY `Date`
public function getNumber() { $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; }
public function numberCount() { $days = request('days', 7); $range = Carbon::today()->subDays($days); $day_stats = Customer::where('created_at', '>=', $range) ->groupBy('date') ->orderBy('date', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y-%m-%d\') as date,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer,SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); $week_stats = Customer::groupBy('week') ->orderBy('week', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y W%u\') as week,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer, SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); // dd($week_stats); // \DB::enableQueryLog(); $month_stats = Customer::groupBy('month') ->orderBy('month', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y-%m\') as month,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer,SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); // dd(\DB::getQueryLog()); // dd($week_stats, $month_stats); $data = $this->getNumber(); // dd($day_stats, $week_stats, $month_stats, $data); return view('admin.numberCount', compact('day_stats', 'week_stats', 'month_stats', 'data')); }
效果图:
以上这篇Laravel统计一段时间间隔的数据方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年11月17日
2024年11月17日
- 【雨果唱片】中国管弦乐《鹿回头》WAV
- APM亚流新世代《一起冒险》[FLAC/分轨][106.77MB]
- 崔健《飞狗》律冻文化[WAV+CUE][1.1G]
- 罗志祥《舞状元 (Explicit)》[320K/MP3][66.77MB]
- 尤雅.1997-幽雅精粹2CD【南方】【WAV+CUE】
- 张惠妹.2007-STAR(引进版)【EMI百代】【WAV+CUE】
- 群星.2008-LOVE情歌集VOL.8【正东】【WAV+CUE】
- 罗志祥《舞状元 (Explicit)》[FLAC/分轨][360.76MB]
- Tank《我不伟大,至少我能改变我。》[320K/MP3][160.41MB]
- Tank《我不伟大,至少我能改变我。》[FLAC/分轨][236.89MB]
- CD圣经推荐-夏韶声《谙2》SACD-ISO
- 钟镇涛-《百分百钟镇涛》首批限量版SACD-ISO
- 群星《继续微笑致敬许冠杰》[低速原抓WAV+CUE]
- 潘秀琼.2003-国语难忘金曲珍藏集【皇星全音】【WAV+CUE】
- 林东松.1997-2039玫瑰事件【宝丽金】【WAV+CUE】