4 changed files with 188 additions and 37 deletions
-
31app/Admin/Controllers/v3/GoodsActivityReportController.php
-
152app/Admin/Widgets/Charts/OrderGoodsActivityCountChart.php
-
7app/Admin/Widgets/Charts/OrderGoodsActivityMarketChart.php
-
35app/Admin/Widgets/Charts/OrderGoodsActivityTotalChart.php
@ -0,0 +1,152 @@ |
|||
<?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; |
|||
|
|||
class OrderGoodsActivityCountChart extends Line |
|||
{ |
|||
/** |
|||
* 活动商品总数 |
|||
*/ |
|||
protected $categories = []; |
|||
protected $data = []; |
|||
protected $total = []; |
|||
protected $id; |
|||
protected $option; |
|||
protected $valueData = []; |
|||
protected $GoodsActivityReport = null; |
|||
protected $showNumber = 7; |
|||
|
|||
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 < $this->showNumber){ |
|||
$this->data[] = $value['subsidy_total']; |
|||
$this->categories[] = $value['dtime']; |
|||
} |
|||
$subsidyTotal += $value['subsidy_total']; |
|||
} |
|||
$this->total['subsidy_total'] = $subsidyTotal; |
|||
} |
|||
} |
|||
|
|||
parent::__construct(); |
|||
} |
|||
|
|||
protected function init() |
|||
{ |
|||
parent::init(); |
|||
$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 |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 处理请求 |
|||
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
|||
* |
|||
* @param Request $request |
|||
* @return mixed|void |
|||
*/ |
|||
public function handle(Request $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 = []) |
|||
{ |
|||
$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 |
|||
); |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue