From 17bc5c20a1fffdf806c0c36c3be6505b0e61d59e Mon Sep 17 00:00:00 2001
From: lanzu_qinsheng <334039090@qq.com>
Date: Fri, 23 Oct 2020 18:03:55 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E6=8A=A5=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Actions/Metrics/Market.php | 118 ++++++++++++++++++++++++
app/Admin/Actions/Metrics/Shipping.php | 4 +-
app/Admin/Common/Order.php | 20 +++-
app/Admin/Controllers/v3/DataReport.php | 13 ++-
4 files changed, 149 insertions(+), 6 deletions(-)
create mode 100644 app/Admin/Actions/Metrics/Market.php
diff --git a/app/Admin/Actions/Metrics/Market.php b/app/Admin/Actions/Metrics/Market.php
new file mode 100644
index 0000000..b393ae4
--- /dev/null
+++ b/app/Admin/Actions/Metrics/Market.php
@@ -0,0 +1,118 @@
+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('配送数据');
+ $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(
+ <<
+
+ {$this->labels[0]}
+
+ {$s1}
+
+
+
+ {$this->labels[1]}
+
+
{$s2}
+
+
+
+
+ {$this->labels[2]}
+
+
{$s3}
+
+
+
+ {$this->labels[3]}
+
+
{$s4}
+
+HTML
+ );
+ }
+}
diff --git a/app/Admin/Actions/Metrics/Shipping.php b/app/Admin/Actions/Metrics/Shipping.php
index a22079d..15ec76f 100644
--- a/app/Admin/Actions/Metrics/Shipping.php
+++ b/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('配送数据');
- $this->height = 150;
+ $this->height = 152;
$this->chartLabels($this->labels);
// 设置图表颜色
$this->chartColors($colors);
@@ -88,7 +88,7 @@ class Shipping extends Donut
return $this->content(
<<
+
{$this->labels[0]}
diff --git a/app/Admin/Common/Order.php b/app/Admin/Common/Order.php
index fd0dc3b..77255ad 100644
--- a/app/Admin/Common/Order.php
+++ b/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;
}
diff --git a/app/Admin/Controllers/v3/DataReport.php b/app/Admin/Controllers/v3/DataReport.php
index 88fe3ef..b7e02da 100644
--- a/app/Admin/Controllers/v3/DataReport.php
+++ b/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));
});
});
}