From e4a50063249e6783f9c827586eb73cca3e259726 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Mon, 6 Sep 2021 14:54:10 +0800
Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E7=BB=9F=E8=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ProductStatisticsController.php | 102 +++++++++++++
.../Metrics/Examples/ProductStatistics.php | 134 ++++++++++++++++++
app/AdminAgent/routes.php | 1 +
3 files changed, 237 insertions(+)
create mode 100755 app/AdminAgent/Controllers/ProductStatisticsController.php
create mode 100644 app/AdminAgent/Metrics/Examples/ProductStatistics.php
diff --git a/app/AdminAgent/Controllers/ProductStatisticsController.php b/app/AdminAgent/Controllers/ProductStatisticsController.php
new file mode 100755
index 0000000..412df87
--- /dev/null
+++ b/app/AdminAgent/Controllers/ProductStatisticsController.php
@@ -0,0 +1,102 @@
+body(
+ <<
+
+
+ HTML
+
+ )
+
+ ->body(function (Row $row){
+
+ $row->column(4, function (Column $column) {
+ $column->row(Card::make('总数', function () {
+ $count = AgentProduct::query()->where('agent_id',Admin::user()->id)->count();
+ return <<
+
$count
+
+HTML;
+ }));
+ });
+
+ $row->column(4, function (Column $column) {
+ $column->row(Card::make('上架', function () {
+ $profit = AgentProduct::query()->where('agent_id',Admin::user()->id)->where('status',ProductStatus::ON_SALE)->count();
+ return <<
+ $profit
+
+HTML;
+ }));
+
+ });
+
+ $row->column(4, function (Column $column) {
+ $column->row(Card::make('下架', function () {
+ $unSale = AgentProduct::query()
+ ->where('agent_id',Admin::user()->id)
+ ->where('status',ProductStatus::SOLD_OUT)
+ ->count();
+ return <<
+ $unSale
+
+HTML;
+ }));
+
+ });
+
+ })
+ ->body(function (Row $row){
+ $row->column(12,new ProductStatistics()
+ );
+ });
+ }
+}
diff --git a/app/AdminAgent/Metrics/Examples/ProductStatistics.php b/app/AdminAgent/Metrics/Examples/ProductStatistics.php
new file mode 100644
index 0000000..947d08d
--- /dev/null
+++ b/app/AdminAgent/Metrics/Examples/ProductStatistics.php
@@ -0,0 +1,134 @@
+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->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('statistics_time')
+ ->get();
+
+ $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 99fdbeb..eee2007 100644
--- a/app/AdminAgent/routes.php
+++ b/app/AdminAgent/routes.php
@@ -40,4 +40,5 @@ Route::group([
$router->resource('finance_statistics', 'FinanceStatisticsController');
$router->resource('order_statistics', 'OrderStatisticsController');
$router->resource('user_statistics', 'UserStatisticsController');
+ $router->resource('product_statistics', 'ProductStatisticsController');
});