title('用户统计(伞下)'); // 卡片内容宽度 $this->contentWidth(8, 4); // $this->height(150); // $this->dropdown([ // '7' => '最近7天', // '30' => '最近30天', // '365' => '最近一年', // ]); $this->request('POST', $this->getRequestUrl(), ['referrer' => request()->input('key')]); // 设置API请求地址 携带参数 } /** * 处理请求. * * @param Request $request * * @return void */ public function handle(Request $request) { $referrer = $request->get('referrer', null); $base_ids = collect(User::getChilds($referrer)) ->pluck("user_id")->toArray(); $today_date = Carbon::today()->format('Y-m-d'); $total = User::query()->whereIn('user_id', $base_ids)->count(); $total_auth = User::query()->whereIn('user_id', $base_ids)->where('user_auth_level', User::user_auth_level_top)->count(); $today = User::query()->whereIn('user_id', $base_ids)->whereDate('created_at', $today_date)->count(); $today_auth = User::query()->whereIn('user_id', $base_ids)->whereDate('created_at', $today_date)->where('user_auth_level', User::user_auth_level_top)->count(); $this->withContent($referrer, $total, $total_auth, $today, $today_auth); // 图表数据 $this->withChart([$total, $total_auth, $today_auth]); // 总数 $this->chartTotal('Total', $total); } /** * 设置卡片底部内容. * * @param string|Renderable|\Closure $footer * * @return $this */ public function footer($footer) { $this->footer = $footer; return $this; } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * 卡片内容. * * @param int $referrer * @param int $total * @param int $total_auth * @param int $today * @param int $today_auth * * @return $this */ public function withContent($referrer, $total, $total_auth, $today, $today_auth) { $minHeight = '183px'; $admin_url = admin_url(); return $this->content( <<