6
0
Fork 0

完成首页会员统计

release
vine_liutk 2021-12-31 15:32:00 +08:00
parent 811db428e5
commit ae3daf122f
1 changed files with 55 additions and 30 deletions

View File

@ -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(
<<<HTML
<div class="col-12 d-flex flex-column flex-wrap text-center" style="max-width: 220px">
<div class="chart-info d-flex justify-content-between mb-1 mt-2" >
<div class="chart-info d-flex justify-content-between mt-1">
<div class="series-info d-flex align-items-center">
<span class="text-bold-600 ml-50">会员总数</span>
</div>
<div class="product-result">
<span>{$totalNum}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1 mt-1" >
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-primary"></i>
<span class="text-bold-600 ml-50">粉丝</span>
</div>
<div class="product-result">
<span>{$finished}</span>
<span>{$civilian}</span>
</div>
</div>
@ -97,7 +122,7 @@ class Users extends Donut
<span class="text-bold-600 ml-50">店铺</span>
</div>
<div class="product-result">
<span>{$pending}</span>
<span>{$vip}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
@ -106,36 +131,36 @@ class Users extends Donut
<span class="text-bold-600 ml-50">社区</span>
</div>
<div class="product-result">
<span>{$rejected}</span>
<span>{$community}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1" >
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-primary"></i>
<i class="fa fa-circle-o text-bold-700 text-info"></i>
<span class="text-bold-600 ml-50">区级</span>
</div>
<div class="product-result">
<span>{$finished}</span>
<span>{$district}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-warning"></i>
<i class="fa fa-circle-o text-bold-700 text-primary"></i>
<span class="text-bold-600 ml-50">市级</span>
</div>
<div class="product-result">
<span>{$pending}</span>
<span>{$city}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-danger"></i>
<i class="fa fa-circle-o text-bold-700 text-warning"></i>
<span class="text-bold-600 ml-50">省级</span>
</div>
<div class="product-result">
<span>{$rejected}</span>
<span>{$province}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
@ -144,16 +169,16 @@ class Users extends Donut
<span class="text-bold-600 ml-50">分公司</span>
</div>
<div class="product-result">
<span>{$rejected}</span>
<span>{$branch}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-danger"></i>
<i class="fa fa-circle-o text-bold-700 text-info"></i>
<span class="text-bold-600 ml-50">董事</span>
</div>
<div class="product-result">
<span>{$rejected}</span>
<span>{$director}</span>
</div>
</div>
</div>