Browse Source

可视化报表

master
lanzu_qinsheng 5 years ago
parent
commit
17bc5c20a1
  1. 118
      app/Admin/Actions/Metrics/Market.php
  2. 4
      app/Admin/Actions/Metrics/Shipping.php
  3. 20
      app/Admin/Common/Order.php
  4. 13
      app/Admin/Controllers/v3/DataReport.php

118
app/Admin/Actions/Metrics/Market.php

@ -0,0 +1,118 @@
<?php
namespace App\Admin\Actions\Metrics;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut;
class Market extends Donut
{
protected $labels = ['东沟岭市场', '铜鼓岭市场', '华园菜市', '平西市场'];
protected $market;
public function __construct($market)
{
$this->market = $market;
parent::__construct($title = null, $icon = null);
}
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
$color = Admin::color();
$colors = [$color->primary(), $color->alpha('blue2', 0.5),$color->warning(),'rebeccapurple'];
//$this->title('<small>配送数据</small>');
$this->height = 153;
$this->chartLabels($this->labels);
// 设置图表颜色
$this->chartColors($colors);
}
/**
* 渲染模板
*
* @return string
*/
public function render()
{
$this->fill();
return parent::render(); // TODO: Change the autogenerated stub
}
/**
* 写入数据.
*
* @return void
*/
public function fill()
{
$total = array_sum($this->market);
// 图表数据
$this->withChart($this->market);
$this->withContent($this->market[0], $this->market[1], $this->market[2], $this->market[3]);
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
return $this->chart([
'series' => $data
]);
}
/**
* 设置卡片头部内容.
*
* @param mixed $desktop
* @param mixed $mobile
*
* @return $this
*/
protected function withContent($s1, $s2, $s3, $s4)
{
$blue = Admin::color()->alpha('blue2', 0.5);
$style = 'margin-bottom: 8px';
$labelWidth = 120;
return $this->content(
<<<HTML
<div class="d-flex pl-1 pr-1 " style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
</div>
<div>{$s1}</div>
</div>
<div class="d-flex pl-1 pr-1" style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
</div>
<div>{$s2}</div>
</div>
<div class="d-flex pl-1 pr-1 " style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle text-warning"></i> {$this->labels[2]}
</div>
<div>{$s3}</div>
</div>
<div class="d-flex pl-1 pr-1" style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle" style="color: rebeccapurple"></i> {$this->labels[3]}
</div>
<div>{$s4}</div>
</div>
HTML
);
}
}

4
app/Admin/Actions/Metrics/Shipping.php

@ -23,7 +23,7 @@ class Shipping extends Donut
$color = Admin::color();
$colors = [$color->primary(), $color->alpha('blue2', 0.5)];
//$this->title('<small>配送数据</small>');
$this->height = 150;
$this->height = 152;
$this->chartLabels($this->labels);
// 设置图表颜色
$this->chartColors($colors);
@ -88,7 +88,7 @@ class Shipping extends Donut
return $this->content(
<<<HTML
<div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
<div class="d-flex pl-1 pr-1 " style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
</div>

20
app/Admin/Common/Order.php

@ -84,8 +84,26 @@ class Order
if ($result){
$result = $result->toArray();
}
}elseif ($params['data_type']=='market'){
$data = $buildData
->selectRaw("count(*) as num,case market_id when 2 then 'dg' when 3 then 'tg' when 4 then 'hy' when 5 then 'px' end 'name'")
->groupBy('market_id')
->orderBy('market_id')
->get()->toArray();
$arr = ['dg','tg','hy','px'];
$result = [];
foreach ($arr as $key=>$item){
foreach ($data as $val){
if ($item==$val['name']){
$result[$key] = $val['num'];
break;
}
}
if (!isset($result[$key])){
$result[$key] = 0;
}
}
}
return $result;
}

13
app/Admin/Controllers/v3/DataReport.php

@ -31,6 +31,7 @@ class DataReport
protected $_shipping;
protected $_distance;
protected $_order_count_user;
protected $_market;
public function __construct()
{
$option = request()->get('option',1);
@ -71,6 +72,13 @@ class DataReport
'condition'=>1,//取数据维度 condition
'user_ids'=>null
],$option);
$this->_market = Order::getOrderData([
'user_type'=>'market_service',//谁取数据 user_type 用户类型
'data_type'=>'market',//取什么数据 data_type 数据类型
'market_id'=>$marketId,//取哪个市场数据
'condition'=>1,//取数据维度 condition
'user_ids'=>null
],$option);
}
public function index(Content $content)
@ -169,9 +177,8 @@ class DataReport
$row->column(4,function (Column $column){
$column->row(new Shipping($this->_shipping));
$column->row(new Distance($this->_distance,count($this->_number)));
$card3 = Card::make('送达时间(暂无)');
$card3->style("height:155px");
$column->row($card3);
$column->row(new \App\Admin\Actions\Metrics\Market($this->_market));
});
});
}

Loading…
Cancel
Save