title(admin_trans('admin-home.New_Report')); $this->dropdown([ '7' => admin_trans('admin-home.Last_7_days'), '30' => admin_trans('admin-home.Last_month'), // '180' => admin_trans('admin-home.Last_half_year'), // '365' => admin_trans('admin-home.Last_year'), ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $generator = function ($len, $min = 10, $max = 300) { for ($i = 0; $i <= $len; $i++) { yield mt_rand($min, $max); } }; switch ($request->get('option')) { case '365': $user = $this->new_user("365"); // 卡片内容 $this->withContent($user['num']); // 图表数据 $this->withChart($user['num_arr']); break; case '30': $user = $this->new_user("30"); // 卡片内容 $this->withContent($user['num']); // 图表数据 $this->withChart($user['num_arr']); break; case '180': $user = $this->new_user("180"); // 卡片内容 $this->withContent($user['num']); // 图表数据 $this->withChart($user['num_arr']); break; case '7': default: $user = $this->new_user("7"); // 卡片内容 $this->withContent($user['num']); // 图表数据 $this->withChart($user['num_arr']); break; } } /** * 新用户 一年 * write by wanglas */ public function new_user($kind){ if ($kind=='365'){ $t_last = date('Y-m-d H:i:s',strtotime('-1 year')); $t_time = 86400*12; $count = 31; }elseif ($kind=='180'){ $t_last = date('Y-m-d H:i:s',strtotime('-180 day')); $t_time = 86400*6; $count = 31; }elseif ($kind=='30'){ $t_last = date('Y-m-d',strtotime('-30 day')); $t_time = 86400; $count = 30; }elseif ($kind=='7'){ $t_last = date('Y-m-d',strtotime('-7 day')); $t_time = 86400; $count = 8; } //统计会员总数 $t_now = date('Y-m-d'); $num = ReportLog::query()->whereBetween('created_at',array($t_last,$t_now))->count(); //计算会员增长数量 for ($i=1 ; $i < $count; $i++) { $today=strtotime(date('Ymd')); $start_time = date('Y-m-d',$today-$t_time*$i); $end_time = date('Y-m-d',$today-$t_time*($i-1)); $inc_num = ReportLog::query()->whereBetween('created_at',[$start_time,$end_time])->count(); //$arr_t[]=$now; $arr_n[]=$inc_num; } //逆序输出数组 //$arr_t=array_reverse($arr_t); //时间 $arr_n=array_reverse($arr_n); //数量 return array('num'=>$num,'num_arr'=>$arr_n); } /** * 设置图表数据. * * @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( <<

{$content}

{$this->title} HTML ); } }