title('订单状态统计'); $this->chartLabels(['已付定金', '已付款', '已完成']); $this->dropdown([ //'day' => '本日', 'week' => '本周', 'month' => '本月', 'year' => '今年', ]); } /** * 处理请求 * * @param Request $request * * @return mixed|void */ public function handle(Request $request) { $orders = OrderProductItem::query() ->with('product') ->where('supplier_id', Admin::user()->id); 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); } $count = clone $orders; $payEarnest = clone $orders; $pay = clone $orders; $success = clone $orders; $payEarnest = $payEarnest->whereHas('order', function ($query) { $query->whereIn('status', [ OrderStatus::PAY_EARNEST ]); }) ->count(); $pay = $pay->whereHas('order', function ($query) { $query->whereIn('status',[ OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, ]); }) ->count(); $success = $success->whereHas('order', function ($query) { $query->whereIn('status', [ OrderStatus::SUCCESS ]); }) ->count(); $count = $count->whereHas('order', function ($query) { $query->whereIn('status', [ OrderStatus::PAY_EARNEST, OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::SUCCESS ]); }) ->count(); // 卡片内容 $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 \App\AdminSupplier\Metrics\Examples\ProductOrders */ 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( <<
已付定金
{$finished}
已付款
{$pending}
已完成
{$rejected}
HTML ); } }