title('统计预览'); $this->height(300); $this->contentWidth(12, 0); // 设置下拉选项 $this->dropdown([ '1' => '当天', '7' => '最近7天', '30' => '最近30天', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { switch ($request->get('option')) { case '30': $start_time = Carbon::now()->subDays(29)->startOfDay(); $end_time = Carbon::now()->endOfDay(); break; case '7': $start_time = Carbon::now()->subDays(6)->startOfDay(); $end_time = Carbon::now()->endOfDay(); break; default: $start_time = Carbon::now()->startOfDay(); $end_time = Carbon::now()->endOfDay(); break; } $order = Order::whereBetween('created_at', [$start_time, $end_time])->whereNotIn('status', [Order::STATUS_PENDING, Order::STATUS_CANCELLED])->sum('total_amount'); // 卡片内容 $this->withContent([ 'total_points'=> bcdiv(UserInfo::sum('points'), 100, 2), 'order_money' => bcdiv($order, 100, 2) ]); } /** * 卡片内容 * * @param string $content * * @return $this */ public function withContent($content) { return $this->content( <<

{$content['total_points']}

总积分

{$content['order_money']}

销售额
HTML ); } /** * 卡片底部内容. * * @param string $new * @param string $open * @param string $response * * @return $this */ public function withFooter($new, $open, $response) { return $this->footer( <<

New Tickets

{$new}

Open Tickets

{$open}

Response Time

{$response}
HTML ); } }