diff --git a/app/AdminAgent/Controllers/HomeController.php b/app/AdminAgent/Controllers/HomeController.php index 58396c1..495802c 100644 --- a/app/AdminAgent/Controllers/HomeController.php +++ b/app/AdminAgent/Controllers/HomeController.php @@ -4,7 +4,7 @@ namespace App\AdminAgent\Controllers; use App\AdminAgent\Metrics\Examples; use App\Http\Controllers\Controller; -use Dcat\Admin\Http\Controllers\Dashboard; +use Dcat\Admin\Admin; use Dcat\Admin\Layout\Column; use Dcat\Admin\Layout\Content; use Dcat\Admin\Layout\Row; @@ -13,13 +13,19 @@ class HomeController extends Controller { public function index(Content $content) { + Admin::style( + <<header('仪表盘') + ->header('代理商后台') ->description('数据详情') ->body(function (Row $row) { $row->column(6, function (Column $column) { - $column->row(Dashboard::title()); - $column->row(new Examples\Tickets()); + $column->row(Examples\Dashboard::title()); + $column->row(new Examples\OrderExamples()); }); $row->column(6, function (Column $column) { diff --git a/app/AdminAgent/Metrics/Examples/Dashboard.php b/app/AdminAgent/Metrics/Examples/Dashboard.php new file mode 100755 index 0000000..a406343 --- /dev/null +++ b/app/AdminAgent/Metrics/Examples/Dashboard.php @@ -0,0 +1,13 @@ + Admin::user()]); + } +} diff --git a/app/AdminAgent/Metrics/Examples/OrderExamples.php b/app/AdminAgent/Metrics/Examples/OrderExamples.php new file mode 100644 index 0000000..1e59e26 --- /dev/null +++ b/app/AdminAgent/Metrics/Examples/OrderExamples.php @@ -0,0 +1,160 @@ +title('订单统计'); + $this->height(400); + $this->chartHeight(300); + } + + /** + * 处理请求 + * + * @param Request $request + * + * @return mixed|void + */ + public function handle(Request $request) + { + //总订单数 + $count = Order::query()->where('agent_id',Admin::user()->id)->count(); + // 卡片内容 + $this->withContent($count); + // 卡片底部 + //今日订单 + $countToday = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::today())->count(); + $countYesterday = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::yesterday())->count(); + $price = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::today())->sum('price'); + $this->withFooter($countToday, $countYesterday, $price); + $order = Order::query() + ->select('*') + ->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time")) + ->where('agent_id',Admin::user()->id) + ->limit(30) + ->orderBy('created_at', 'asc') + ->groupBy('statistics_time') + ->get() + ->toArray(); + + $categories = Arr::pluck($order,'statistics_time'); + // 图表数据 + $data = Arr::pluck($order,'count_id'); + $this->withChart($data,$categories); + + } + + /** + * 设置图表数据. + * + * @param int $data + * + * @return $this + */ + public function withChart(array $data,array $categories) + { + return $this->chart([ + 'series' => [ + [ + 'name' => '订单量', + 'data' => $data + ] + ], + 'chart' => [ + 'type' => 'line', + 'zoom' => [ + 'enabled' => false + ], + 'toolbar' => [ + 'show' => false + ], + ], + 'colors' => [ + Admin::color()->green(), + ], + 'dataLabels' => [ + 'enabled' => false + ], + 'stroke' => [ + 'curve' => 'smooth' + ], + 'legend' => [ + 'position' =>'top', + //'horizontalAlign' => 'right' + ], + 'fill' => [ + 'opacity' => 1, + 'type' => 'solid', + ], + 'xaxis' => [ + 'categories' => $categories, + ] + ]); + } + + /** + * 卡片内容 + * + * @param string $content + * + * @return $this + */ + public function withContent($content) + { + return $this->content( + << +

{$content}

+ 总订单数 + +HTML + ); + } + + /** + * 卡片底部内容. + * + * @param string $new + * @param string $open + * @param string $response + * + * @return $this + */ + public function withFooter($new, $open, $response) + { + return $this->footer( + << +
+

今日订单

+ {$new} +
+
+

昨日订单

+ {$open} +
+
+

今日成交(元)

+ {$response} +
+ +HTML + ); + } +} diff --git a/config/database.php b/config/database.php index b42d9b3..aeabec6 100644 --- a/config/database.php +++ b/config/database.php @@ -56,7 +56,7 @@ return [ 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, - 'strict' => true, + 'strict' => false, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), diff --git a/resources/views/admin/pages/agent-home.blade.php b/resources/views/admin/pages/agent-home.blade.php new file mode 100755 index 0000000..29800e5 --- /dev/null +++ b/resources/views/admin/pages/agent-home.blade.php @@ -0,0 +1,43 @@ + + +
+
+
+ + +
+

{{$admin->name}}

+ +
+
+
+