diff --git a/app/AdminAgent/Controllers/OrderStatisticsController.php b/app/AdminAgent/Controllers/OrderStatisticsController.php
index dbfa4e1..1963d2b 100755
--- a/app/AdminAgent/Controllers/OrderStatisticsController.php
+++ b/app/AdminAgent/Controllers/OrderStatisticsController.php
@@ -58,14 +58,11 @@ class OrderStatisticsController extends AdminController
})
->body(function (Row $row) {
- $orders = Order::query()->where('agent_id',Admin::user()->id)->select('*')->selectRaw("count(id) as count_id")->groupBy('status');
$count = Order::query()->where('agent_id',Admin::user()->id);
$dateTime = request('created_at', 0);
if ($dateTime) {
- $orders->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',$dateTime);
}
- $orders = $orders->get();
$count = $count->count();
$row->column(3, function (Column $column) use ($count) {
$column->row(Card::make('总数', function () use ($count) {
@@ -76,20 +73,29 @@ class OrderStatisticsController extends AdminController
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) {
+ [$keys, $values] = Arr::divide($arr);
+ foreach ($keys as $v){
+ $orders = Order::query()->where('agent_id',Admin::user()->id)->where('status',$v);
+
+ if ($dateTime) {
+ $orders->whereBetween('created_at',$dateTime);
+ }
+ $orders = $orders->count();
+
+ $row->column(3, function (Column $column) use ($arr,$orders,$v) {
+ $column->row(Card::make($arr[$v], function () use ($orders) {
return <<
-
$order->count_id
+ $orders
HTML;
}));
});
}
+ //
+
})
->body(function (Row $row){
// 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
diff --git a/app/AdminSupplier/Controllers/OrderStatisticsController.php b/app/AdminSupplier/Controllers/OrderStatisticsController.php
new file mode 100755
index 0000000..28acbbd
--- /dev/null
+++ b/app/AdminSupplier/Controllers/OrderStatisticsController.php
@@ -0,0 +1,141 @@
+body(
+ <<
+
+
+ HTML
+
+ )
+ ->body(function (Row $row){
+ $row->column(6,function (Column $column){
+ $column->row(new \App\AdminAgent\Tools\DataReportDate('data_report'));
+ });
+
+ })
+ ->body(function (Row $row) {
+
+ $count = OrderProductItem::query()->where('supplier_id',Admin::user()->id);
+ $dateTime = request('created_at', 0);
+ if ($dateTime) {
+ $count->whereBetween('created_at',$dateTime);
+ }
+ $count = $count->count();
+ $row->column(3, function (Column $column) use ($count) {
+ $column->row(Card::make('总数', function () use ($count) {
+ return <<
+ $count
+
+HTML;
+ }));
+ });
+ $arr = OrderStatus::array();
+ [$keys, $values] = Arr::divide($arr);
+ foreach ($keys as $v){
+ $orders = OrderProductItem::query()
+ ->where('supplier_id',Admin::user()->id)
+ ->whereHas('order',function ($query) use ($v){
+ $query->where('status',$v);
+ });
+ if ($dateTime) {
+ $orders->whereBetween('created_at',$dateTime);
+ }
+ $orders = $orders->count();
+
+ $row->column(3, function (Column $column) use ($arr,$orders,$v) {
+ $column->row(Card::make($arr[$v], function () use ($orders) {
+ return <<
+ $orders
+
+HTML;
+ }));
+ });
+ }
+
+ })
+ ->body(function (Row $row){
+ // 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
+ $menu = [
+ '1' => '日',
+ '30' => '月',
+ '365' => '年',
+ ];
+ $buttonName = '日';
+ if (Arr::exists($menu, \request()->input('time_key', ''))) {
+ $buttonName = $menu[\request()->input('time_key')];
+ }
+
+ $dropdown = Dropdown::make($menu)
+ ->button(current($menu))
+ ->button($buttonName)
+ ->click()
+ ->map(function ($v, $k) {
+ $querys = \request()->all();
+ $querys['time_key'] = $k;
+ $queryString = http_build_query($querys);
+ $str = Str::replaceFirst('admin-agent/','',request()->path());
+ $url = admin_url($str.'?'.$queryString);
+ // 此处设置的 data-xxx 属性会作为post数据发送到后端api
+ return "{$v}";
+ });
+
+ // 传递自定义参数
+
+ $bar = OrderStatistics::make()
+ ->fetching('$("#my-box").loading()') // 设置loading效果
+ ->fetched('$("#my-box").loading(false)') // 移除loading效果
+ ->click('.switch-bar'); // 设置图表点击菜单则重新发起请求,且被点击的目标元素上的 data-xxx 属性会被作为post数据发送到后端API
+
+ $box = Box::make('成本总额图表', $bar)
+ ->id('my-box') // 设置盒子的ID
+ ->tool($dropdown); // 设置下拉菜单按钮
+
+ $row->column(12, $box);
+ });
+ }
+}
diff --git a/app/AdminSupplier/Metrics/Examples/OrderStatistics.php b/app/AdminSupplier/Metrics/Examples/OrderStatistics.php
new file mode 100644
index 0000000..36a9e40
--- /dev/null
+++ b/app/AdminSupplier/Metrics/Examples/OrderStatistics.php
@@ -0,0 +1,142 @@
+setUpOptions();
+ }
+
+ /**
+ * 初始化图表配置
+ */
+ protected function setUpOptions()
+ {
+ $this->options([
+ 'chart' => [
+ //'width' => '180%',
+ 'type' => 'bar',
+ 'events' => [
+ ],
+ 'toolbar' => ['show' => false],
+ ],
+ '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' => [
+ 'fontSize' => '12px'
+ ]
+ ],
+ ],
+ 'yaxis' => [
+ 'show' => true
+ ],
+ 'tooltip' => [
+ 'x' => ['show' => true],
+ ],
+ ]);
+ }
+
+ /**
+ * 处理图表数据
+ */
+ protected function buildData()
+ {
+ $query = OrderProductItem::query()
+ ->where('supplier_id',Admin::user()->id)
+ ->select('*');
+
+ $dateTime = request('created_at', 0);
+ if ($dateTime) {
+ $query->whereBetween('created_at',$dateTime);
+ }
+
+ switch (request('time_key', 0)) {
+ case '1':
+ $query->addSelect(DB::raw("count(id) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"));
+ break;
+ case '30':
+ $query->addSelect(DB::raw("count(id) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at)) AS statistics_time"));
+ break;
+ case '365':
+ $query->addSelect(DB::raw("count(id) as sum_price,CONCAT(YEAR(created_at)) AS statistics_time"));
+ break;
+ default:
+ $query->addSelect(DB::raw("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->withData([
+ [
+ 'name' => '订单数',
+ 'data' => Arr::pluck($order,'sum_price')
+ ],
+ ]
+ );
+ $this->withCategories(
+ Arr::pluck($order,'statistics_time')
+ );
+
+ }
+
+ public function withData(array $data)
+ {
+ return $this->option('series', $data);
+ }
+
+ /**
+ * 设置图表类别.
+ *
+ * @param array $data
+ *
+ * @return $this
+ */
+ public function withCategories(array $data)
+ {
+ return $this->option('xaxis.categories', $data);
+ }
+
+ /**
+ * 渲染图表
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $this->buildData();
+
+ return parent::render();
+ }
+}