From ae3daf122fe72eeab0716eb5af357f6b8a2d3c9d Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 31 Dec 2021 15:32:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A6=96=E9=A1=B5=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Metrics/Users.php | 85 ++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/app/Admin/Metrics/Users.php b/app/Admin/Metrics/Users.php index 8e40deca..805db470 100644 --- a/app/Admin/Metrics/Users.php +++ b/app/Admin/Metrics/Users.php @@ -3,8 +3,10 @@ namespace App\Admin\Metrics; use App\Models\UserInfo; +use Dcat\Admin\Admin; use Dcat\Admin\Widgets\Metrics\Donut; use Illuminate\Http\Request; +use Illuminate\Support\Arr; class Users extends Donut { @@ -16,11 +18,25 @@ class Users extends Donut parent::init(); $this->title('累计会员'); - $this->contentWidth(4, 8); + $this->contentWidth(5, 7); $this->chartLabels(UserInfo::$agentLevelTexts); $this->chartHeight(300); $this->chartOption('chart.width', '300'); + $this->chartOption('dataLabels.enabled', true); + $this->chartMarginBottom(50); $this->chart->style('float: none;'); + $color = Admin::color(); + $dark35 = $color->dark35(); + $this->chartColors([ + $color->primary(), + $color->warning(), + $color->danger(), + $color->info(), + $color->primary(), + $color->warning(), + $color->danger(), + $color->info(), + ]); } /** @@ -32,21 +48,12 @@ class Users extends Donut */ 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); - } + // 卡片内容 + $nums = UserInfo::selectRaw('count(1) as num, agent_level')->groupBy('agent_level')->pluck('num', 'agent_level')->toArray(); + $this->withContent($nums); + // dd($nums); + // 图表数据 + $this->withChart(array_merge($nums, [])); } /** @@ -76,18 +83,36 @@ class Users extends Donut * * @return $this */ - public function withContent($finished, $pending, $rejected) + public function withContent($userCount) { + $civilian = Arr::get($userCount, UserInfo::AGENT_LEVEL_CIVILIAN, 0); + $vip = Arr::get($userCount, UserInfo::AGENT_LEVEL_VIP, 0); + $community = Arr::get($userCount, UserInfo::AGENT_LEVEL_COMMUNITY, 0); + $district = Arr::get($userCount, UserInfo::AGENT_LEVEL_DISTRICT, 0); + $city = Arr::get($userCount, UserInfo::AGENT_LEVEL_CITY, 0); + $province = Arr::get($userCount, UserInfo::AGENT_LEVEL_PROVINCE, 0); + $branch = Arr::get($userCount, UserInfo::AGENT_LEVEL_BRANCH, 0); + $director = Arr::get($userCount, UserInfo::AGENT_LEVEL_DIRECTOR, 0); + $totalNum = array_sum($userCount); + return $this->content( << -
+
+
+ 会员总数 +
+
+ {$totalNum} +
+
+
粉丝
- {$finished} + {$civilian}
@@ -97,7 +122,7 @@ class Users extends Donut 店铺
- {$pending} + {$vip}
@@ -106,36 +131,36 @@ class Users extends Donut 社区
- {$rejected} + {$community}
- + 区级
- {$finished} + {$district}
- + 市级
- {$pending} + {$city}
- + 省级
- {$rejected} + {$province}
@@ -144,16 +169,16 @@ class Users extends Donut 分公司
- {$rejected} + {$branch}
- + 董事
- {$rejected} + {$director}