diff --git a/app/AdminAgent/Controllers/OrderStatisticsController.php b/app/AdminAgent/Controllers/OrderStatisticsController.php new file mode 100755 index 0000000..14d7fd5 --- /dev/null +++ b/app/AdminAgent/Controllers/OrderStatisticsController.php @@ -0,0 +1,84 @@ +body( + << + + + HTML + + ) + ->body(function (Row $row) { + $orders = Order::query()->where('agent_id',Admin::user()->id)->select('*')->selectRaw("count(id) as count_id")->groupBy('status')->get(); + $count = Order::query()->where('agent_id',Admin::user()->id)->count(); + + $row->column(3, function (Column $column) use ($count) { + $column->row(Card::make('总数', function () use ($count) { + return << +

$count

+ +HTML; + })); + }); + + $arr = OrderStatus::array(); + foreach ($orders as $order) { + $row->column(3, function (Column $column) use ($order,$arr) { + $column->row(Card::make($arr[$order->status], function () use ($order) { + return << +

$order->count_id

+ +HTML; + })); + }); + } + + }) + ->body(function (Row $row){ + $row->column(12,new OrderStatistics() + ); + }); + } +} diff --git a/app/AdminAgent/Metrics/Examples/OrderStatistics.php b/app/AdminAgent/Metrics/Examples/OrderStatistics.php new file mode 100644 index 0000000..09326cb --- /dev/null +++ b/app/AdminAgent/Metrics/Examples/OrderStatistics.php @@ -0,0 +1,133 @@ +contentWidth(0, 12); + // 标题 + //$this->title('财务统计'); + $this->chartHeight = 500; + // 设置下拉选项 + $this->dropdown([ + '1' => '日', + '30' => '月', + '365' => '年', + ]); + // 设置图表颜色 + $this->chartColors([ + $color->green(), + ]); + } + + /** + * 处理请求 + * + * @param Request $request + * + * @return mixed|void + */ + public function handle(Request $request) + { + $query = Order::query() + ->where('agent_id',Admin::user()->id) + ->select('*'); + switch ($request->get('option')) { + case '1': + $query->selectRaw("count(id) as sum_price,date(created_at) AS statistics_time"); + break; + case '30': + $query->selectRaw("count(id) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at)) AS statistics_time"); + break; + case '365': + $query->selectRaw("count(id) as sum_price,CONCAT(YEAR(created_at)) AS statistics_time"); + break; + default: + $query->selectRaw("count(id) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"); + } + $order = $query->groupBy('statistics_time') + ->orderBy('created_at') + ->get() + ->toArray(); + $this->withChart( + Arr::pluck($order,'sum_price') + ); + $this->chartLabels( + Arr::pluck($order,'statistics_time') + ); + } + + /** + * 设置图表数据. + * + * @param array $data + * + * @return $this + */ + public function withChart(array $data) + { + return $this->chart([ + 'series' => [[ + 'name' => '订单数', + 'data' => $data + ]], + 'chart' => [ + //'width' => '180%', + 'type' => 'bar', + 'events' => [ + ], + 'toolbar' => ['show' => false], + ], + 'colors' => $this->colors, + 'plotOptions' => [ + 'bar' => [ + //'columnWidth' => '45%', + 'distributed' => true, + ] + ], + 'dataLabels' => [ + 'enabled' => false + ], + 'legend' => [ + 'show' => false + ], + 'xaxis' => [ + //'categories' => + // [75, 125, 225, 175, 125, 75, 25] + //, + 'labels' => [ + 'show' => true, + 'style' => [ + 'colors' => $this->colors, + 'fontSize' => '12px' + ] + ], + ], + 'yaxis' => [ + 'show' => true + ], + 'tooltip' => [ + 'x' => ['show' => true], + ], + + ]); + } +} diff --git a/app/AdminAgent/routes.php b/app/AdminAgent/routes.php index c375c7d..b01d436 100644 --- a/app/AdminAgent/routes.php +++ b/app/AdminAgent/routes.php @@ -38,4 +38,5 @@ Route::group([ $router->resource('channel/list', 'ChannelController'); $router->resource('group_order/list', 'GroupOrderController'); $router->resource('finance_statistics', 'FinanceStatisticsController'); + $router->resource('order_statistics', 'OrderStatisticsController'); });