diff --git a/app/Admin/Controllers/HomeController.php b/app/Admin/Controllers/HomeController.php index 4960a87..ddccd9e 100644 --- a/app/Admin/Controllers/HomeController.php +++ b/app/Admin/Controllers/HomeController.php @@ -125,11 +125,11 @@ class HomeController extends Controller ->description('欢迎回到懒族后台') ->body(function (Row $row) { $row->column(4, function (Column $column) { - $column->row(new Examples\Order\OrderData('订单数')); + $column->row(new Examples\Order\OrderData('number','订单数')); }); $row->column(4, function (Column $column) { - $column->row(new Examples\Community\TotalAmount(Admin::user()->id, 3)); + $column->row(new Examples\Order\OrderData('amount','订单金额')); }); }); } diff --git a/app/Admin/Metrics/Examples/Order/OrderData.php b/app/Admin/Metrics/Examples/Order/OrderData.php index ab74cef..3da40a2 100644 --- a/app/Admin/Metrics/Examples/Order/OrderData.php +++ b/app/Admin/Metrics/Examples/Order/OrderData.php @@ -11,11 +11,11 @@ use Illuminate\Http\Request; class OrderData extends Card { protected $title; - - - public function __construct($title = null, $icon = null) + protected $data_type; + public function __construct($data_type=null,$title = null, $icon = null) { $this->title = $title; + $this->data_type = $data_type; parent::__construct($title, $icon); } @@ -34,11 +34,12 @@ class OrderData extends Card public function handle(Request $request) { - $type = $request->get('option'); - $this->content($this->orderNum('',$type)); + $type = $request->get('option');//数据选项 + $data_type = $request->get('data_type');//数据类型 + $this->content($this->orderNum($data_type,$type)); } - public function orderNum($marketId=null,$type=null) + public function orderNumBuild($marketId=null,$type=null) { $where = []; @@ -73,16 +74,36 @@ class OrderData extends Card $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; break; } - $count = ImsCjdcOrderMain + $build = ImsCjdcOrderMain ::whereBetween('created_at',[$beginTime,$endTime]) ->whereIn('state',[3,4,5,10]) - ->where($where) - ->count(); + ->where($where); + return $build; + } - return $count; + + public function orderNum($data_type,$type) + { + $build = $this->orderNumBuild($marketId=null,$type); + if ($data_type=='number'){ + $result = $build->count(); + }elseif ($data_type=='amount'){ + $result = $build->sum('money'); + }else{ + $result = 0; + } + return $result; } + // 传递自定义参数到 handle 方法 + public function parameters() : array + { + return [ + 'data_type'=>$this->data_type + ]; + } + /** * 渲染卡片内容 * @return string