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.
153 lines
4.1 KiB
153 lines
4.1 KiB
<?php
|
|
|
|
namespace App\Admin\Widgets\Charts;
|
|
|
|
use App\Admin\Common\Auth;
|
|
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 $valueData = [];
|
|
protected $GoodsActivityReport = null;
|
|
protected $showNumber = 7;
|
|
|
|
public function __construct($data = [])
|
|
{
|
|
$this->GoodsActivityReport = new GoodsActivityReport($data);
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
$color = Admin::color();
|
|
// 设置标题
|
|
$this->title('销售总数量(单)');
|
|
$this->subTitle('其中'.$this->showNumber.'天每天的销量');
|
|
// 设置图表颜色
|
|
$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
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 处理请求
|
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求
|
|
*
|
|
* @param Request $request
|
|
* @return mixed|void
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
// 数据查询逻辑
|
|
// 分页的时候不重复查询数据
|
|
$currentPage = request()->input('page', 1);
|
|
if($currentPage == 1){
|
|
$params = $this->parameters();
|
|
$data = $this->GoodsActivityReport->getCountData($params);
|
|
if(!empty($data) && is_array($data)){
|
|
$total = 0;
|
|
foreach($data as $key => $value){
|
|
if($key < $this->showNumber){
|
|
$this->data[] = $value['total'];
|
|
$this->categories[] = $value['dtime'];
|
|
}
|
|
$total += $value['total'];
|
|
}
|
|
$this->total['number_total'] = $total;
|
|
}
|
|
}
|
|
$categories = $this->categories;
|
|
$chartData = [
|
|
[
|
|
'name' => '销量',
|
|
'data' => $this->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 = [])
|
|
{
|
|
$value = $total['number_total'] ?? 0;
|
|
$minHeight = '113px';
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex p-1 flex-column justify-content-between" style="padding-top: 0;width: 100%;height: 100%;min-height: {$minHeight}">
|
|
<div class="text-left">
|
|
<h2 class="ml-1 font-lg-1">{$value}</h2>
|
|
</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
|
|
}
|