title('现金流水'); $this->dropdown([ //'day' => '本日', 'week' => '本周', 'month' => '本月', //'year' => '今年', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $order = OrderProductItem::query() ->where('supplier_id',Admin::user()->id); switch ($request->get('option')) { case 'day': $order->whereDate('created_at', Carbon::today()); break; case 'week': $time = DataTime::beginAndEnd('week'); $order->whereBetween('created_at', $time); break; case 'month': $order->whereMonth('created_at', Carbon::now()->month); break; case 'year': $order->whereYear('created_at', Carbon::now()->year); break; default: $time = DataTime::beginAndEnd('week'); $order->whereBetween('created_at', $time); } $countOrder = clone $order; $count = $order->sum('price'); $this->withContent($count); $countOrder = $countOrder->select('*') ->addSelect(DB::raw("sum(price) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time")) ->limit(30) ->groupBy('statistics_time') ->get() ->toArray(); // 图表数据 $this->chartLabels(Arr::pluck($countOrder, 'statistics_time')); $this->withChart(Arr::pluck($countOrder, 'sum_price')); } /** * 设置图表数据. * * @param array $data * * @return \App\AdminSupplier\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( <<