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.
179 lines
4.7 KiB
179 lines
4.7 KiB
<?php
|
|
|
|
namespace App\Admin\Widgets\Charts;
|
|
|
|
use App\Admin\Repositories\v3\GoodsActivityReport;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Support\JavaScript;
|
|
use Dcat\Admin\Widgets\Metrics\Bar;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OrderGoodsActivityTotalChart extends Bar
|
|
{
|
|
/**
|
|
* 活动商品总数
|
|
*/
|
|
protected $categories = [];
|
|
protected $data = [];
|
|
protected $total = [];
|
|
protected $id;
|
|
protected $option;
|
|
protected $GoodsActivityReport = null;
|
|
protected $valueData = [];
|
|
|
|
public function __construct($data = [])
|
|
{
|
|
$this->GoodsActivityReport = new GoodsActivityReport();
|
|
$this->option = $this->id = 7;
|
|
|
|
// 分页的时候不重复查询数据
|
|
$currentPage = request()->input('page', 1);
|
|
if($currentPage == 1){
|
|
$data = $this->GoodsActivityReport->getCountData();
|
|
if(!empty($data) && is_array($data)){
|
|
$total = 0;
|
|
$subsidyTotal = 0;
|
|
foreach($data as $key => $value){
|
|
if($key < 10){
|
|
$this->data[] = $value['total'];
|
|
$this->categories[] = $value['dtime'];
|
|
|
|
$this->valueData[] = $value['subsidy_total'];
|
|
}
|
|
$total += $value['total'];
|
|
$subsidyTotal += $value['subsidy_total'];
|
|
}
|
|
$this->total['number_total'] = $total;
|
|
$this->total['subsidy_total'] = $subsidyTotal;
|
|
}
|
|
}
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
$color = Admin::color();
|
|
// 设置标题
|
|
$this->title('');
|
|
// 设置下拉菜单
|
|
// $this->dropdown([]);
|
|
|
|
// $this->chartBarColumnWidth('50%');
|
|
// $this->style('display:block');
|
|
|
|
// 设置图表颜色
|
|
$this->chartColors([$color->primary()]);
|
|
|
|
$this->chartOption(
|
|
'tooltip.x',
|
|
['show' => true]
|
|
);
|
|
|
|
// $this->chartOption(
|
|
// 'tooltip.y.formatter',
|
|
// JavaScript::make("function (params) {
|
|
// return params;
|
|
// }")
|
|
// );
|
|
$this->chartOption(
|
|
'tooltip.trigger',
|
|
'axis'
|
|
);
|
|
$this->chartOption(
|
|
'tooltip.formatter',
|
|
JavaScript::make("function (params) {
|
|
return 'ff';
|
|
}")
|
|
);
|
|
$this->chartOption(
|
|
'xaxis.type',
|
|
'category'
|
|
);
|
|
$this->chartOption(
|
|
'xaxis.categories',
|
|
$this->categories
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 处理请求
|
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求
|
|
*
|
|
* @param Request $request
|
|
* @return mixed|void
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
// dd($request);
|
|
// 数据查询逻辑
|
|
$data = $this->data;
|
|
$categories = $this->categories;
|
|
$chartData = [
|
|
[
|
|
'name' => '销量',
|
|
'data' => $data,
|
|
]
|
|
];
|
|
$this->withContent($this->total);
|
|
$this->withChart($chartData);
|
|
$this->withCategories($categories);
|
|
}
|
|
|
|
/**
|
|
* 这里返回需要异步传递到 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($total = [])
|
|
{
|
|
$numberTotal = $this->total['number_total'] ?? 0;
|
|
$subsidyTotal = $this->total['subsidy_total'] ?? 0;//d-flex
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="justify-content-between align-items-center mt-1">
|
|
<div class="ml-2">
|
|
<div class="card" style="background-color:#4e9876; color:#ffffff;">
|
|
<div class="card-header"><span>销售总数量(单)</span></div>
|
|
<div class="card-body ml-1"><span>{$numberTotal}</span></div>
|
|
</div>
|
|
</div>
|
|
<div class="ml-2">
|
|
<div class="card" style="background-color:#4e9876; color:#ffffff">
|
|
<div class="card-header"><span>总补贴金额(元)</span></div>
|
|
<div class="card-body ml-1"><span>{$subsidyTotal}</span></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
|
|
}
|