title('新增用户'); $this->dropdown([ //'day' => '本日', 'week' => '本周', 'month' => '本月', //'year' => '今年', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $count = User::query(); $user = User::query() ->select('*') ->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time")); switch ($request->get('option')) { case 'day': $count->whereDate('created_at', Carbon::today()); $user->whereDate('created_at', Carbon::today()); break; case 'week': $time = DataTime::beginAndEnd('week'); $count->whereBetween('created_at', $time); $user->whereBetween('created_at', $time); break; case 'month': $count->whereMonth('created_at', Carbon::now()->month); $user->whereMonth('created_at', Carbon::now()->month); break; case 'year': $count->whereYear('created_at', Carbon::now()->year); $user->whereYear('created_at', Carbon::now()->year); break; default: $time = DataTime::beginAndEnd('week'); $count->whereBetween('created_at', $time); $user->whereBetween('created_at', $time); } $user = $user->where('agent_id', Admin::user()->id) ->limit(30) ->groupBy('statistics_time') ->get() ->toArray(); $count = $count->count(); $this->withContent($count); // 图表数据 $this->chartLabels(Arr::pluck($user, 'statistics_time')); $this->withChart(Arr::pluck($user, 'count_id')); } /** * 设置图表数据. * * @param array $data * * @return \App\Admin\Metrics\Examples\NewUsers */ public function withChart(array $data) { return $this->chart([ 'series' => [ [ 'name' => $this->title, 'data' => $data, ], ], ]); } /** * 设置卡片内容. * * @param string $content * * @return $this */ public function withContent($content) { return $this->content( <<