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.
182 lines
5.0 KiB
182 lines
5.0 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\Line;
|
|
use Illuminate\Http\Request;
|
|
use App\Admin\Common\Auth;
|
|
|
|
class OrderGoodsActivityCountChart extends Line
|
|
{
|
|
/**
|
|
* 活动商品总数
|
|
*/
|
|
protected $categories = [];
|
|
protected $data = [];
|
|
protected $total = [];
|
|
protected $valueData = [];
|
|
protected $chartData = [];
|
|
protected $GoodsActivityReport = null;
|
|
protected $showNumber = 7;
|
|
|
|
public function __construct($params = [])
|
|
{
|
|
parent::__construct();
|
|
|
|
$data = $params['list'] ?? [];
|
|
|
|
if(!empty($data) && is_array($data)){
|
|
$subsidyTotal = 0;
|
|
foreach($data as $key => $value){
|
|
|
|
if($key < $this->showNumber){
|
|
$this->data[] = $value['subsidy_total'];
|
|
$this->categories[] = $value['dtime'];
|
|
}
|
|
$subsidyTotal += $value['subsidy_total'];
|
|
}
|
|
$this->total['subsidy_total'] = $subsidyTotal;
|
|
}
|
|
|
|
$this->chartData = [
|
|
[
|
|
'name' => '金额',
|
|
'data' => $this->data,
|
|
]
|
|
];
|
|
|
|
$color = Admin::color();
|
|
// 设置标题
|
|
$this->title('总补贴金额(元)');
|
|
$this->subTitle('其中'.$this->showNumber.'天每天总补贴金额');
|
|
$this->chartHeight(140);
|
|
|
|
// 设置图表颜色
|
|
$this->chartColors([$color->primary()]);
|
|
|
|
$this->chartOption(
|
|
'tooltip.x',
|
|
['show' => true]
|
|
);
|
|
|
|
$this->chartOption(
|
|
'tooltip.y.formatter',
|
|
JavaScript::make("function (params,index) {
|
|
return params ;
|
|
}")
|
|
);
|
|
|
|
$this->chartOption(
|
|
'xaxis.type',
|
|
'category'
|
|
);
|
|
$this->chartOption(
|
|
'xaxis.categories',
|
|
$this->categories
|
|
);
|
|
$this->withContent($this->total);
|
|
$this->withChart($this->chartData);
|
|
$this->withCategories($this->categories);
|
|
}
|
|
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
}
|
|
|
|
/**
|
|
* 处理请求
|
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求
|
|
*
|
|
* @param Request $request
|
|
* @return mixed|void
|
|
*/
|
|
public function handleBar(Request $request)
|
|
{
|
|
// $this->GoodsActivityReport = new GoodsActivityReport($data);
|
|
|
|
// 数据查询逻辑
|
|
// 分页的时候不重复查询数据
|
|
$currentPage = request()->input('page', 1);
|
|
if($currentPage == 1){
|
|
$params = $this->parameters();
|
|
$data = $this->GoodsActivityReport->getCountData($params);
|
|
if(!empty($data) && is_array($data)){
|
|
$subsidyTotal = 0;
|
|
foreach($data as $key => $value){
|
|
if($key < $this->showNumber){
|
|
$this->data[] = $value['subsidy_total'];
|
|
$this->categories[] = $value['dtime'];
|
|
}
|
|
$subsidyTotal += $value['subsidy_total'];
|
|
}
|
|
$this->total['subsidy_total'] = $subsidyTotal;
|
|
}
|
|
}
|
|
|
|
$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
|
|
{
|
|
$this->marketId = Auth::getMarket();
|
|
return [
|
|
'page' => request()->input('page', 1),
|
|
'name' => request()->input('name', ''),
|
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0),
|
|
'store_id' => request()->input('store_id',0),
|
|
'start_time' => request()->input('start_time',''),
|
|
'end_time' => request()->input('end_time',''),
|
|
];
|
|
}
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @param array $data
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withChart(array $data)
|
|
{
|
|
return $this->chart([
|
|
'series' => $data,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 渲染卡片内容.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function withContent($total = [])
|
|
{
|
|
$content = $total['subsidy_total'] ??0;
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
|
|
<h2 class="ml-1 font-lg-1">{$content}</h2>
|
|
<!-- <span class="mb-0 mr-1 text-80">{$this->title}</span> -->
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
|
|
}
|