You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
2.7 KiB
127 lines
2.7 KiB
<?php
|
|
|
|
namespace App\AdminSupplier\Metrics\Examples;
|
|
|
|
use App\Common\AgentType;
|
|
use App\Common\ProductStatus;
|
|
use App\Models\Agent as AgentModel;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Donut;
|
|
|
|
class NewDevices extends Donut
|
|
{
|
|
protected $labels = [];
|
|
|
|
/**
|
|
* 初始化卡片内容
|
|
*/
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
$this->labels = array_values(AgentType::array());
|
|
$color = Admin::color();
|
|
$colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()];
|
|
|
|
$this->title('代理商类型');;
|
|
$this->chartLabels($this->labels);
|
|
// 设置图表颜色
|
|
$this->chartColors($colors);
|
|
}
|
|
|
|
/**
|
|
* 渲染模板
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render()
|
|
{
|
|
$this->fill();
|
|
|
|
return parent::render();
|
|
}
|
|
|
|
/**
|
|
* 写入数据.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function fill()
|
|
{
|
|
$agent = AgentModel::whereHas('agentProduct', function($query) {
|
|
//只统计在售产品的代理商
|
|
return $query->where('status', ProductStatus::ON_SALE)
|
|
->whereHas('product', function ($query) {
|
|
return $query->where(['supplier_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
|
|
});
|
|
});
|
|
$agent = $agent->pluck('type');
|
|
$operator = $supplier = $cluster = 0;
|
|
foreach ($agent as $v) {
|
|
if ($v == AgentType::CLUSTER) {
|
|
$operator++;
|
|
} elseif ($v == AgentType::SUPPLIER) {
|
|
$supplier++;
|
|
} elseif($v == AgentType::OPERATOR) {
|
|
$cluster++;
|
|
}
|
|
}
|
|
$this->withContent($operator, $supplier, $cluster);
|
|
|
|
// 图表数据
|
|
$this->withChart([$operator,$supplier, $cluster]);
|
|
}
|
|
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @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, $unkonw)
|
|
{
|
|
$blue = Admin::color()->alpha('blue2', 0.5);
|
|
$yellow = Admin::color()->yellow();
|
|
$style = 'margin-bottom: 8px';
|
|
$labelWidth = 120;
|
|
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
|
|
</div>
|
|
<div>{$desktop}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
|
|
</div>
|
|
<div>{$mobile}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: $yellow"></i> {$this->labels[2]}
|
|
</div>
|
|
<div>{$unkonw}</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
}
|