5 changed files with 161 additions and 21 deletions
-
7app/Admin/Controllers/v3/GoodsActivityReportController.php
-
12app/Admin/Repositories/v3/GoodsActivityReport.php
-
14app/Admin/Widgets/Charts/OrderGoodsActivityColumnChart.php
-
129app/Admin/Widgets/Charts/OrderGoodsActivityMarketChart.php
-
20app/Admin/Widgets/Charts/OrderGoodsActivityTotalChart.php
@ -0,0 +1,129 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Widgets\Charts; |
|||
|
|||
use App\Admin\Repositories\v3\GoodsActivityReport; |
|||
use Dcat\Admin\Widgets\Metrics\Donut; |
|||
use Illuminate\Http\Request; |
|||
use App\Models\v3\Market as MarketModel; |
|||
|
|||
class OrderGoodsActivityMarketChart extends Donut |
|||
{ |
|||
/** |
|||
* 活动商品总数 |
|||
*/ |
|||
protected $labels = []; |
|||
protected $data = []; |
|||
protected $total = []; |
|||
protected $id; |
|||
protected $option; |
|||
protected $GoodsActivityReport = null; |
|||
protected $color = [ '#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B', '#2b908f', '#f9a3a4', '#90ee7e', '#f48024', '#69d2e7']; |
|||
protected $colors = []; |
|||
|
|||
public function __construct($data = []) |
|||
{ |
|||
$this->GoodsActivityReport = new GoodsActivityReport(); |
|||
$this->option = $this->id = 7; |
|||
|
|||
// 分页的时候不重复查询数据
|
|||
$currentPage = request()->input('page', 1); |
|||
if($currentPage == 1){ |
|||
$data = $this->GoodsActivityReport->getMarketData(); |
|||
$market = MarketModel::getMarketArray(); |
|||
if(!empty($data) && is_array($data)){ |
|||
$total = 0; |
|||
foreach($data as $key => $value){ |
|||
$this->data[] = (int)$value['total']; |
|||
$this->labels[] = $market[$value['market_id']]??'未知'; |
|||
$this->colors[] = $this->color[$key]; |
|||
$total += $value['total']; |
|||
} |
|||
$this->total['number_total'] = $total; |
|||
} |
|||
} |
|||
|
|||
parent::__construct(); |
|||
} |
|||
|
|||
protected function init() |
|||
{ |
|||
parent::init(); |
|||
// 设置标题
|
|||
$this->title(''); |
|||
$this->chartHeight(160); |
|||
// 设置下拉菜单
|
|||
// $this->dropdown([]);
|
|||
|
|||
$this->chartLabels($this->labels); |
|||
|
|||
// 设置图表颜色
|
|||
$this->chartColors($this->colors); |
|||
} |
|||
|
|||
/** |
|||
* 处理请求 |
|||
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
|||
* |
|||
* @param Request $request |
|||
* @return mixed|void |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
// 数据查询逻辑
|
|||
$data = $this->data; |
|||
$this->withContent($data); |
|||
$this->withChart($data); |
|||
} |
|||
|
|||
/** |
|||
* 这里返回需要异步传递到 handler 方法的参数 |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function parameters(): array |
|||
{ |
|||
return [ |
|||
'id' => $this->id, |
|||
'option' => $this->option, |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* 设置图表数据. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function withChart(array $data) |
|||
{ |
|||
return $this->chart([ |
|||
'series' => $data, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 渲染卡片内容. |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function withContent($data = []) |
|||
{ |
|||
$div = ''; |
|||
$style = 'margin-bottom: 8px'; |
|||
if(!empty($data) && is_array($data)){ |
|||
foreach($data as $key => $value){ |
|||
$div .= '<div class="d-flex pl-1 pr-1 pt-1" style="'.$style.'"><div style="width: 120px">
|
|||
<i class="fa fa-circle" style="color:'.$this->colors[$key].'"></i> '.$this->labels[$key].' |
|||
</div><div>'.$value.'</div></div>'; |
|||
} |
|||
} |
|||
return $this->content( |
|||
<<<HTML |
|||
{$div} |
|||
HTML |
|||
); |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue