title('新用户统计'); $this->dropdown([ '1' => '今日', '7' => '7天内', '30' => '30天内', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { // $start_time = Carbon::now()->subDays(7)->startOfDay(); // $end_time = Carbon::now()->subDays(1)->endOfDay(); // $this->withContent($this->getUserCount($start_time, $end_time).'人'); // // 图表数据 // $this->withChart($this->getUserGenerator($start_time, $end_time, 7)); switch ($request->get('option')) { case '1': // 卡片内容 $start_time = Carbon::now()->startOfDay(); $end_time = Carbon::now()->endOfDay(); $this->withContent($this->getUserCount($start_time, $end_time).'人'); $start_time = Carbon::now()->subDays(7)->startOfDay(); // 图表数据 $this->withChart($this->getUserGenerator($start_time, $end_time, 7)); break; case '7': // 卡片内容 $start_time = Carbon::now()->subDays(7)->startOfDay(); $end_time = Carbon::now()->subDays(1)->endOfDay(); $this->withContent($this->getUserCount($start_time, $end_time).'人'); // 图表数据 $this->withChart($this->getUserGenerator($start_time, $end_time, 7)); break; case '30': // 卡片内容 $start_time = Carbon::now()->subDays(30)->startOfDay(); $end_time = Carbon::now()->subDays(1)->endOfDay(); $this->withContent($this->getUserCount($start_time, $end_time).'人'); // 图表数据 $this->withChart($this->getUserGenerator($start_time, $end_time, 30)); break; default: // 卡片内容 $start_time = Carbon::now()->startOfDay(); $end_time = Carbon::now()->endOfDay(); $this->withContent($this->getUserCount($start_time, $end_time).'人'); $start_time = Carbon::now()->subDays(7)->startOfDay(); // 图表数据 $this->withChart($this->getUserGenerator($start_time, $end_time, 7)); } } /** * 设置图表数据. * * @param array $data * * @return $this */ 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( <<