- Pending
+ 已付款
{$pending}
@@ -101,7 +168,7 @@ class ProductOrders extends Round
- Rejected
+ 已完成
{$rejected}
@@ -109,6 +176,6 @@ class ProductOrders extends Round
HTML
- );
- }
+ );
+ }
}
diff --git a/app/AdminSupplier/Metrics/Examples/SalesExamples.php b/app/AdminSupplier/Metrics/Examples/SalesExamples.php
new file mode 100644
index 0000000..17a4c69
--- /dev/null
+++ b/app/AdminSupplier/Metrics/Examples/SalesExamples.php
@@ -0,0 +1,180 @@
+colors = [$color->green(), $color->red(), $color->yellow(), $color->orange1(), $color->dark90(), $color->dark70(), $color->custom()];
+ $this->contentWidth(3, 9);
+ $this->title('销售排行');
+ //$this->chartPullRight = false;
+ //$this->subTitle('Last 30 days');
+ $this->height = 280;
+ $this->chartHeight = 250;
+ // 设置图表颜色
+ $this->chartColors($this->colors);
+ }
+
+ /**
+ * 渲染模板
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $this->fill();
+
+ return parent::render();
+ }
+
+ /**
+ * 写入数据.
+ *
+ * @return void
+ */
+ public function fill()
+ {
+ $warehouse = OrderProductItem::query()
+ ->with('product')
+ ->select('*')
+ ->addSelect(DB::raw('count(id) as count_id'))
+ ->whereHas('order',function ($query) {
+ $query->where('status',OrderStatus::SUCCESS);
+ })
+ ->where('supplier_id',Admin::user()->id)
+ ->orderByDesc('count_id')
+ ->groupBy('product_id')
+ ->limit(5)
+ ->get();
+ //$warehouse = [];
+ $data = $categories = [];
+ foreach ($warehouse as $v) {
+ array_push($this->labels, $v->product->title);
+ array_push($data, $v->count_id);
+ $categories[] = [$v->product->title];
+ }
+
+ $this->withChart($data, $categories);
+ //$this->chartLabels($this->labels);
+
+ $count = OrderProductItem::query()
+ ->where('supplier_id',Admin::user()->id)
+ ->whereHas('order',function ($query) {
+ $query->where('status',OrderStatus::SUCCESS);
+ })
+ ->count();
+ //$count = 0;
+ if ($count > 0) {
+ array_unshift($data, $count);
+ array_unshift($this->labels, '总销售量');
+ $color = Admin::color();
+ array_unshift($this->colors, $color->primary());
+ }
+ $this->withContent($data);
+ }
+
+ /**
+ * 设置图表数据.
+ *
+ * @param array $data
+ *
+ * @return $this
+ */
+ public function withChart($data, $categories)
+ {
+ 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' =>
+ $categories
+ ,
+ 'labels' => [
+ 'show' => false,
+ 'style' => [
+ 'colors' => $this->colors,
+ 'fontSize' => '12px'
+ ]
+ ],
+ ],
+ 'yaxis' => [
+ 'show' => false
+ ],
+ 'tooltip' => [
+ 'x' => ['show' => true],
+ ],
+
+ ]);
+ }
+
+ /**
+ * 设置卡片头部内容.
+ *
+ * @param mixed $desktop
+ * @param mixed $mobile
+ *
+ * @return $this
+ */
+ protected function withContent($data)
+ {
+ $content = '';
+ foreach ($data as $k => $v) {
+ $content .= '
+
+
+
' . $this->labels[$k] . '
+
' . $v . '
+
+
+
+ ';
+ }
+ return $this->content(
+ <<timestamps = false;
+ //$this->timestamps = false;
+ }
+
+ function order()
+ {
+ return $this->belongsTo(Order::class,'order_id','id');
+ }
+
+ function product()
+ {
+ return $this->belongsTo(Product::class,'product_id','id');
}
}
diff --git a/resources/views/admin/pages/agent-home.blade.php b/resources/views/admin/pages/agent-home.blade.php
index 29800e5..f7b3808 100755
--- a/resources/views/admin/pages/agent-home.blade.php
+++ b/resources/views/admin/pages/agent-home.blade.php
@@ -32,7 +32,7 @@
{{$admin->name}}
-
用户管理
+
用户管理
订单管理
广告管理
产品管理
diff --git a/resources/views/admin/pages/supplier-home.blade.php b/resources/views/admin/pages/supplier-home.blade.php
new file mode 100755
index 0000000..29d95c9
--- /dev/null
+++ b/resources/views/admin/pages/supplier-home.blade.php
@@ -0,0 +1,43 @@
+
+
+
+
+
+
.'/'.$admin->avatar}})
+
+
+
+
+
From c25d489dff4290cdf7d79561c819cacc7f12edaa Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Thu, 2 Sep 2021 19:05:33 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/HomeController.php | 18 +-
app/Admin/Metrics/Examples/Dashboard.php | 13 ++
app/Admin/Metrics/Examples/NewUsers.php | 189 ++++++++--------
app/Admin/Metrics/Examples/OrderExamples.php | 160 ++++++++++++++
app/Admin/Metrics/Examples/ProductOrders.php | 203 +++++++++++-------
app/Admin/Metrics/Examples/SalesExamples.php | 177 +++++++++++++++
.../views/admin/pages/admin-home.blade.php | 43 ++++
7 files changed, 635 insertions(+), 168 deletions(-)
create mode 100755 app/Admin/Metrics/Examples/Dashboard.php
create mode 100644 app/Admin/Metrics/Examples/OrderExamples.php
create mode 100644 app/Admin/Metrics/Examples/SalesExamples.php
create mode 100755 resources/views/admin/pages/admin-home.blade.php
diff --git a/app/Admin/Controllers/HomeController.php b/app/Admin/Controllers/HomeController.php
index 0697d73..4660bd1 100644
--- a/app/Admin/Controllers/HomeController.php
+++ b/app/Admin/Controllers/HomeController.php
@@ -4,7 +4,7 @@ namespace App\Admin\Controllers;
use App\Admin\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,23 @@ class HomeController extends Controller
{
public function index(Content $content)
{
+ Admin::style(
+ <<
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) {
@@ -28,7 +38,7 @@ class HomeController extends Controller
$row->column(6, new Examples\NewDevices());
});
- $column->row(new Examples\Sessions());
+ $column->row(new Examples\SalesExamples());
$column->row(new Examples\ProductOrders());
});
});
diff --git a/app/Admin/Metrics/Examples/Dashboard.php b/app/Admin/Metrics/Examples/Dashboard.php
new file mode 100755
index 0000000..c489a3e
--- /dev/null
+++ b/app/Admin/Metrics/Examples/Dashboard.php
@@ -0,0 +1,13 @@
+ Admin::user()]);
+ }
+}
diff --git a/app/Admin/Metrics/Examples/NewUsers.php b/app/Admin/Metrics/Examples/NewUsers.php
index 66798bf..7068b4d 100644
--- a/app/Admin/Metrics/Examples/NewUsers.php
+++ b/app/Admin/Metrics/Examples/NewUsers.php
@@ -2,107 +2,118 @@
namespace App\Admin\Metrics\Examples;
+use App\Common\DataTime;
+use App\Models\User;
+use Carbon\Carbon;
+use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Line;
use Illuminate\Http\Request;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\DB;
class NewUsers extends Line
{
- /**
- * 初始化卡片内容
- *
- * @return void
- */
- protected function init()
- {
- parent::init();
+ /**
+ * 初始化卡片内容
+ *
+ * @return void
+ */
+ protected function init()
+ {
+ parent::init();
- $this->title('New Users');
- $this->dropdown([
- '7' => 'Last 7 Days',
- '28' => 'Last 28 Days',
- '30' => 'Last Month',
- '365' => 'Last Year',
- ]);
- }
+ $this->title('新增用户');
+ $this->dropdown([
+ //'day' => '本日',
+ 'week' => '本周',
+ 'month' => '本月',
+ //'year' => '今年',
+ ]);
+ }
- /**
- * 处理请求
- *
- * @param Request $request
- *
- * @return mixed|void
- */
- public function handle(Request $request)
- {
- $generator = function ($len, $min = 10, $max = 300) {
- for ($i = 0; $i <= $len; $i++) {
- yield mt_rand($min, $max);
- }
- };
+ /**
+ * 处理请求
+ *
+ * @param Request $request
+ *
+ * @return mixed|void
+ */
+ public function handle(Request $request)
+ {
+ $count = User::query();
+ $user = User::query()
+ ->select('*')
+ ->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"));
+ switch ($request->get('option')) {
+ case 'day':
+ $count->whereDate('created_at', Carbon::today());
+ $user->whereDate('created_at', Carbon::today());
+ break;
+ case 'week':
+ $time = DataTime::beginAndEnd('week');
+ $count->whereBetween('created_at', $time);
+ $user->whereBetween('created_at', $time);
+ break;
+ case 'month':
+ $count->whereMonth('created_at', Carbon::now()->month);
+ $user->whereMonth('created_at', Carbon::now()->month);
+ break;
+ case 'year':
+ $count->whereYear('created_at', Carbon::now()->year);
+ $user->whereYear('created_at', Carbon::now()->year);
+ break;
+ default:
+ $time = DataTime::beginAndEnd('week');
+ $count->whereBetween('created_at', $time);
+ $user->whereBetween('created_at', $time);
+ }
+ $user = $user->where('agent_id', Admin::user()->id)
+ ->limit(30)
+ ->groupBy('statistics_time')
+ ->get()
+ ->toArray();
+ $count = $count->count();
+ $this->withContent($count);
+ // 图表数据
+ $this->chartLabels(Arr::pluck($user, 'statistics_time'));
+ $this->withChart(Arr::pluck($user, 'count_id'));
+ }
- switch ($request->get('option')) {
- case '365':
- // 卡片内容
- $this->withContent(mt_rand(1000, 5000).'k');
- // 图表数据
- $this->withChart(collect($generator(30))->toArray());
- break;
- case '30':
- // 卡片内容
- $this->withContent(mt_rand(400, 1000).'k');
- // 图表数据
- $this->withChart(collect($generator(30))->toArray());
- break;
- case '28':
- // 卡片内容
- $this->withContent(mt_rand(400, 1000).'k');
- // 图表数据
- $this->withChart(collect($generator(28))->toArray());
- break;
- case '7':
- default:
- // 卡片内容
- $this->withContent('89.2k');
- // 图表数据
- $this->withChart([28, 40, 36, 52, 38, 60, 55,]);
- }
- }
+ /**
+ * 设置图表数据.
+ *
+ * @param array $data
+ *
+ * @return \App\Admin\Metrics\Examples\NewUsers
+ */
+ public function withChart(array $data)
+ {
+ return $this->chart([
+ 'series' => [
+ [
+ 'name' => $this->title,
+ 'data' => $data,
+ ],
+ ],
+ ]);
+ }
- /**
- * 设置图表数据.
- *
- * @param array $data
- *
- * @return $this
- */
- public function withChart(array $data)
- {
- return $this->chart([
- 'series' => [
- [
- 'name' => $this->title,
- 'data' => $data,
- ],
- ],
- ]);
- }
-
- /**
- * 设置卡片内容.
- *
- * @param string $content
- *
- * @return $this
- */
- public function withContent($content)
- {
- return $this->content(
- <<content(
+ <<
{$content}
{$this->title}
HTML
- );
- }
+ );
+ }
}
diff --git a/app/Admin/Metrics/Examples/OrderExamples.php b/app/Admin/Metrics/Examples/OrderExamples.php
new file mode 100644
index 0000000..434dd74
--- /dev/null
+++ b/app/Admin/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()->count();
+ // 卡片内容
+ $this->withContent($count);
+ // 卡片底部
+ //今日订单
+ $countToday = Order::query()->whereDate('created_at',Carbon::today())->count();
+ $countYesterday = Order::query()->whereDate('created_at',Carbon::yesterday())->count();
+ $price = Order::query()->where('status',OrderStatus::SUCCESS)->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"))
+ ->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(
+ <<
+
+
+
+
今日成交(元)
+
{$response}
+
+
+HTML
+ );
+ }
+}
diff --git a/app/Admin/Metrics/Examples/ProductOrders.php b/app/Admin/Metrics/Examples/ProductOrders.php
index d7c10bb..bcd52d3 100644
--- a/app/Admin/Metrics/Examples/ProductOrders.php
+++ b/app/Admin/Metrics/Examples/ProductOrders.php
@@ -2,86 +2,139 @@
namespace App\Admin\Metrics\Examples;
+use App\Common\DataTime;
+use App\Common\OrderStatus;
+use App\Models\Order;
+use Carbon\Carbon;
+use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Round;
use Illuminate\Http\Request;
class ProductOrders extends Round
{
- /**
- * 初始化卡片内容
- */
- protected function init()
- {
- parent::init();
-
- $this->title('Product Orders');
- $this->chartLabels(['Finished', 'Pending', 'Rejected']);
- $this->dropdown([
- '7' => 'Last 7 Days',
- '28' => 'Last 28 Days',
- '30' => 'Last Month',
- '365' => 'Last Year',
- ]);
- }
-
- /**
- * 处理请求
- *
- * @param Request $request
- *
- * @return mixed|void
- */
- public function handle(Request $request)
- {
- switch ($request->get('option')) {
- case '365':
- case '30':
- case '28':
- case '7':
- default:
- // 卡片内容
- $this->withContent(23043, 14658, 4758);
-
- // 图表数据
- $this->withChart([70, 52, 26]);
-
- // 总数
- $this->chartTotal('Total', 344);
- }
- }
-
- /**
- * 设置图表数据.
- *
- * @param array $data
- *
- * @return $this
- */
- 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(
- <<title('订单状态统计');
+ $this->chartLabels(['Finished', 'Pending', 'Rejected']);
+ $this->dropdown([
+ //'day' => '本日',
+ 'week' => '本周',
+ 'month' => '本月',
+ 'year' => '今年',
+ ]);
+ }
+
+ /**
+ * 处理请求
+ *
+ * @param Request $request
+ *
+ * @return mixed|void
+ */
+ public function handle(Request $request)
+ {
+ $orders = Order::query()
+ ->whereIn('status',[
+ OrderStatus::PAY_EARNEST,
+ OrderStatus::PAID,
+ OrderStatus::PAID_RETAINAGE,
+ OrderStatus::OFFLINE_PAID,
+ OrderStatus::SUCCESS
+ ]);
+
+ 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);
+ }
+ $orders = $orders->pluck('status')->toArray();
+ $payEarnest = $pay = $success = 0;
+
+ $arr = [
+ OrderStatus::PAID,
+ OrderStatus::PAID_RETAINAGE,
+ OrderStatus::OFFLINE_PAID,
+ ];
+
+ $count = count($orders);
+ if ($orders > 0) {
+ foreach ($orders as $status) {
+ if ($status == OrderStatus::PAY_EARNEST) {
+ $payEarnest++;
+ } elseif (in_array($status,$arr)) {
+ $pay++;
+ } elseif ($status == OrderStatus::SUCCESS) {
+ $success++;
+ }
+ }
+ }
+
+ // 卡片内容
+ $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\Admin\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
+ 已付定金
{$finished}
@@ -91,7 +144,7 @@ class ProductOrders extends Round
- Pending
+ 已付款
{$pending}
@@ -101,7 +154,7 @@ class ProductOrders extends Round
- Rejected
+ 已完成
{$rejected}
@@ -109,6 +162,6 @@ class ProductOrders extends Round
HTML
- );
- }
+ );
+ }
}
diff --git a/app/Admin/Metrics/Examples/SalesExamples.php b/app/Admin/Metrics/Examples/SalesExamples.php
new file mode 100644
index 0000000..36c36fa
--- /dev/null
+++ b/app/Admin/Metrics/Examples/SalesExamples.php
@@ -0,0 +1,177 @@
+colors = [$color->green(), $color->red(), $color->yellow(), $color->orange1(), $color->dark90(), $color->dark70(), $color->custom()];
+ $this->contentWidth(3, 9);
+ $this->title('销售排行');
+ //$this->chartPullRight = false;
+ //$this->subTitle('Last 30 days');
+ $this->height = 280;
+ $this->chartHeight = 250;
+ // 设置图表颜色
+ $this->chartColors($this->colors);
+ }
+
+ /**
+ * 渲染模板
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $this->fill();
+
+ return parent::render();
+ }
+
+ /**
+ * 写入数据.
+ *
+ * @return void
+ */
+ public function fill()
+ {
+ $warehouse = Order::query()
+ ->with('agentProduct')
+ ->select('*')
+ ->addSelect(DB::raw('count(id) as count_id'))
+ ->where([
+ 'status' => OrderStatus::SUCCESS,
+ ])
+ ->orderByDesc('count_id')
+ ->groupBy('agent_product_id')
+ ->limit(5)
+ ->get();
+ //$warehouse = [];
+ $data = $categories = [];
+ foreach ($warehouse as $v) {
+ array_push($this->labels, $v->title);
+ array_push($data, $v->count_id);
+ $categories[] = [$v->title];
+ }
+
+ $this->withChart($data, $categories);
+ //$this->chartLabels($this->labels);
+
+ $count = Order::query()
+ ->where([
+ 'status' => OrderStatus::SUCCESS,
+ ])
+ ->count();
+ //$count = 0;
+ if ($count > 0) {
+ array_unshift($data, $count);
+ array_unshift($this->labels, '总销售量');
+ $color = Admin::color();
+ array_unshift($this->colors, $color->primary());
+ }
+ $this->withContent($data);
+ }
+
+ /**
+ * 设置图表数据.
+ *
+ * @param array $data
+ *
+ * @return $this
+ */
+ public function withChart($data, $categories)
+ {
+ 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' =>
+ $categories
+ ,
+ 'labels' => [
+ 'show' => false,
+ 'style' => [
+ 'colors' => $this->colors,
+ 'fontSize' => '12px'
+ ]
+ ],
+ ],
+ 'yaxis' => [
+ 'show' => false
+ ],
+ 'tooltip' => [
+ 'x' => ['show' => true],
+ ],
+
+ ]);
+ }
+
+ /**
+ * 设置卡片头部内容.
+ *
+ * @param mixed $desktop
+ * @param mixed $mobile
+ *
+ * @return $this
+ */
+ protected function withContent($data)
+ {
+ $content = '';
+ foreach ($data as $k => $v) {
+ $content .= '
+
+
+
' . $this->labels[$k] . '
+
' . $v . '
+
+
+
+ ';
+ }
+ return $this->content(
+ <<
+ .dashboard-title .links {
+ text-align: center;
+ margin-bottom: 2.5rem;
+ }
+ .dashboard-title .links > a {
+ padding: 0 25px;
+ font-size: 12px;
+ font-weight: 600;
+ letter-spacing: .1rem;
+ text-decoration: none;
+ text-transform: uppercase;
+ color: #fff;
+ }
+ .dashboard-title h1 {
+ font-weight: 200;
+ font-size: 2.5rem;
+ }
+ .dashboard-title .avatar {
+ background: #fff;
+ border: 2px solid #fff;
+ width: 70px;
+ height: 70px;
+ }
+
+
+
+
+
+
.'/'.$admin->avatar}})
+
+
+
+
+
From 6c99394a567c301e9a32128fe812249e93e92083 Mon Sep 17 00:00:00 2001
From: lemon <15040771@qq.com>
Date: Thu, 2 Sep 2021 19:10:00 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E5=85=A5=E9=A9=BB=E6=AF=94=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Metrics/Examples/NewDevices.php | 145 ++++++++++++----------
1 file changed, 78 insertions(+), 67 deletions(-)
diff --git a/app/Admin/Metrics/Examples/NewDevices.php b/app/Admin/Metrics/Examples/NewDevices.php
index 3406d9d..8b873df 100644
--- a/app/Admin/Metrics/Examples/NewDevices.php
+++ b/app/Admin/Metrics/Examples/NewDevices.php
@@ -2,86 +2,91 @@
namespace App\Admin\Metrics\Examples;
+use App\Models\Agent;
+use App\Models\Guide;
+use App\Models\Supplier;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut;
class NewDevices extends Donut
{
- protected $labels = ['Desktop', 'Mobile'];
+ protected $labels = ['代理商', '供应商', '地接'];
- /**
- * 初始化卡片内容
- */
- protected function init()
- {
- parent::init();
+ /**
+ * 初始化卡片内容
+ */
+ protected function init()
+ {
+ parent::init();
- $color = Admin::color();
- $colors = [$color->primary(), $color->alpha('blue2', 0.5)];
+ $color = Admin::color();
+ $colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()];
- $this->title('New Devices');
- $this->subTitle('Last 30 days');
- $this->chartLabels($this->labels);
- // 设置图表颜色
- $this->chartColors($colors);
- }
+ $this->title('入驻比例');;
+ $this->chartLabels($this->labels);
+ // 设置图表颜色
+ $this->chartColors($colors);
+ }
- /**
- * 渲染模板
- *
- * @return string
- */
- public function render()
- {
- $this->fill();
+ /**
+ * 渲染模板
+ *
+ * @return string
+ */
+ public function render()
+ {
+ $this->fill();
- return parent::render();
- }
+ return parent::render();
+ }
- /**
- * 写入数据.
- *
- * @return void
- */
- public function fill()
- {
- $this->withContent(44.9, 28.6);
+ /**
+ * 写入数据.
+ *
+ * @return void
+ */
+ public function fill()
+ {
+ $agent = Agent::query()->count();
+ $supplier = Supplier::query()->count();
+ $guide = Guide::query()->count();
+ $this->withContent($agent, $supplier, $guide);
- // 图表数据
- $this->withChart([44.9, 28.6]);
- }
+ // 图表数据
+ $this->withChart([$agent, $supplier, $guide]);
+ }
- /**
- * 设置图表数据.
- *
- * @param array $data
- *
- * @return $this
- */
- public function withChart(array $data)
- {
- return $this->chart([
- 'series' => $data
- ]);
- }
+ /**
+ * 设置图表数据.
+ *
+ * @param array $data
+ *
+ * @return $this
+ */
+ public function withChart(array $data)
+ {
+ return $this->chart([
+ 'series' => $data
+ ]);
+ }
- /**
- * 设置卡片头部内容.
- *
- * @param mixed $desktop
- * @param mixed $mobile
- *
- * @return $this
- */
- protected function withContent($desktop, $mobile)
- {
- $blue = Admin::color()->alpha('blue2', 0.5);
+ /**
+ * 设置卡片头部内容.
+ *
+ * @param mixed $desktop
+ * @param mixed $mobile
+ *
+ * @return $this
+ */
+ protected function withContent($desktop, $mobile, $unkonw)
+ {
+ $blue = Admin::color()->alpha('blue2', 0.5);
+ $yellow = Admin::color()->yellow();
+ $style = 'margin-bottom: 8px';
+ $labelWidth = 120;
- $style = 'margin-bottom: 8px';
- $labelWidth = 120;
-
- return $this->content(
- <<content(
+ <<
{$this->labels[0]}
@@ -94,7 +99,13 @@ class NewDevices extends Donut
{$mobile}
+
+
+ {$this->labels[2]}
+
+
{$unkonw}
+
HTML
- );
- }
+ );
+ }
}