7 changed files with 345 additions and 40 deletions
-
137app/Admin/Actions/Metrics/Distance.php
-
99app/Admin/Actions/Metrics/Shipping.php
-
45app/Admin/Actions/Tools/DataReportDate.php
-
3app/Admin/Actions/Tools/DataReportOption.php
-
12app/Admin/Actions/Tools/DataReportOrder.php
-
21app/Admin/Common/Order.php
-
68app/Admin/Controllers/v3/DataReport.php
@ -0,0 +1,137 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Admin\Actions\Metrics; |
|||
|
|||
|
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Widgets\Metrics\Round; |
|||
|
|||
class Distance extends Round |
|||
{ |
|||
protected $distance; |
|||
protected $number; |
|||
public function __construct($distance, $number) |
|||
{ |
|||
$this->distance = $distance; |
|||
$this->number = $number; |
|||
parent::__construct($title=null, $icon=null); |
|||
} |
|||
|
|||
/** |
|||
* 初始化卡片内容 |
|||
*/ |
|||
protected function init() |
|||
{ |
|||
parent::init(); |
|||
$this->height = 160; |
|||
$this->style('padding-top:0'); |
|||
$this->chartLabels(['1km以内', '1-3km', '3km以上']); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 渲染模板 |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function render() |
|||
{ |
|||
$this->fill(); |
|||
Admin::script($this->script()); |
|||
return parent::render(); |
|||
} |
|||
|
|||
public function script() |
|||
{ |
|||
return <<<JS |
|||
$('#shipping').parent().parent().parent().parent().prev().addClass('pt-0'); |
|||
JS; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 写入数据. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function fill() |
|||
{ |
|||
$this->withContent($this->distance[0], $this->distance[1],$this->distance[2]); |
|||
// 图表数据
|
|||
$this->withChart([ |
|||
$this->distance[0]>0?sprintf("%.2f",($this->distance[0]/$this->number)*100):0, |
|||
$this->distance[0]>0?sprintf("%.2f",($this->distance[1]/$this->number)*100):0, |
|||
$this->distance[0]>0?sprintf("%.2f",($this->distance[2]/$this->number)*100):0, |
|||
]); |
|||
|
|||
// 总数
|
|||
$this->chartTotal('总数', $this->number); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 设置图表数据. |
|||
* |
|||
* @param array $data |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function withChart(array $data) |
|||
{ |
|||
return $this->chart([ |
|||
'series' => $data, |
|||
]); |
|||
} |
|||
|
|||
/** |
|||
* 卡片内容. |
|||
* |
|||
* @param int $finished |
|||
* @param int $pending |
|||
* @param int $rejected |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function withContent($d1, $d2, $d3) |
|||
{ |
|||
return $this->content( |
|||
<<<HTML |
|||
<div class="col-12 d-flex flex-column flex-wrap text-center" id="shipping" style="max-width: 220px;"> |
|||
<div class="chart-info d-flex justify-content-between mb-1 mt-2"> |
|||
<div class="series-info d-flex align-items-center"> |
|||
<i class="fa fa-circle-o text-bold-700 text-primary"></i> |
|||
<span class="text-bold-600 ml-50">1km以内</span> |
|||
</div> |
|||
<div class="product-result"> |
|||
<span>{$d1}</span> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="chart-info d-flex justify-content-between mb-1"> |
|||
<div class="series-info d-flex align-items-center"> |
|||
<i class="fa fa-circle-o text-bold-700 text-warning"></i> |
|||
<span class="text-bold-600 ml-50">1-3km</span> |
|||
</div> |
|||
<div class="product-result"> |
|||
<span>{$d2}</span> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="chart-info d-flex justify-content-between mb-1"> |
|||
<div class="series-info d-flex align-items-center"> |
|||
<i class="fa fa-circle-o text-bold-700 text-danger"></i> |
|||
<span class="text-bold-600 ml-50">3km以上</span> |
|||
</div> |
|||
<div class="product-result"> |
|||
<span>{$d3}</span> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
HTML |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
<?php |
|||
namespace App\Admin\Actions\Metrics; |
|||
|
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Widgets\Metrics\Donut; |
|||
|
|||
class Shipping extends Donut |
|||
{ |
|||
protected $labels = ['站内配送','用户自提']; |
|||
protected $shipping; |
|||
public function __construct($shipping) |
|||
{ |
|||
|
|||
$this->shipping = $shipping; |
|||
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)]; |
|||
//$this->title('<small>配送数据</small>');
|
|||
$this->height = 150; |
|||
$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() |
|||
{ |
|||
// 图表数据
|
|||
$this->withChart($this->shipping); |
|||
$this->withContent($this->shipping[0], $this->shipping[1]); |
|||
} |
|||
|
|||
/** |
|||
* 设置图表数据. |
|||
* |
|||
* @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) |
|||
{ |
|||
$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 pt-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> |
|||
HTML |
|||
); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue