title('订单状态统计'); $this->chartLabels(['Finished', 'Pending', 'Rejected']); $this->dropdown([ //'day' => '本日', 'week' => '本周', 'month' => '本月', 'year' => '今年', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $orders = Order::query() ->where('agent_id', Admin::user()->id) ->whereIn('status',[ OrderStatus::PAY_EARNEST, OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::SUCCESS ]); switch ($request->get('option')) { case 'day': $orders->whereDate('created_at', Carbon::today()); break; case 'week': $time = DataTime::beginAndEnd('week'); $orders->whereBetween('created_at', $time); break; case 'month': $orders->whereMonth('created_at', Carbon::now()->month); break; case 'year': $orders->whereYear('created_at', Carbon::now()->year); break; default: $time = DataTime::beginAndEnd('week'); $orders->whereBetween('created_at', $time); } $orders = $orders->pluck('status')->toArray(); $payEarnest = $pay = $success = 0; $arr = [ OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, ]; $count = count($orders); if ($orders > 0) { foreach ($orders as $status) { if ($status == OrderStatus::PAY_EARNEST) { $payEarnest++; } elseif (in_array($status,$arr)) { $pay++; } elseif ($status == OrderStatus::SUCCESS) { $success++; } } } // 卡片内容 $this->withContent($payEarnest, $pay, $success); $payEarnestPer = $count > 0 ? bcdiv($payEarnest,$count,2) * 100 : 0; $payPer = $count > 0 ? bcdiv($pay,$count,2) * 100 : 0; $successPer = $count > 0 ? bcdiv($success,$count,2) * 100 : 0; // 图表数据 $this->withChart([$payEarnestPer, $payPer, $successPer]); // 总数 $this->chartTotal('总计', $count); } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * 卡片内容. * * @param int $finished * @param int $pending * @param int $rejected * * @return $this */ public function withContent($finished, $pending, $rejected) { return $this->content( <<