Browse Source

订单卡片数据

master
lanzu_qinsheng 5 years ago
parent
commit
d2d284f636
  1. 4
      app/Admin/Controllers/HomeController.php
  2. 41
      app/Admin/Metrics/Examples/Order/OrderData.php

4
app/Admin/Controllers/HomeController.php

@ -125,11 +125,11 @@ class HomeController extends Controller
->description('欢迎回到懒族后台') ->description('欢迎回到懒族后台')
->body(function (Row $row) { ->body(function (Row $row) {
$row->column(4, function (Column $column) { $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) { $row->column(4, function (Column $column) {
$column->row(new Examples\Community\TotalAmount(Admin::user()->id, 3));
$column->row(new Examples\Order\OrderData('amount','订单金额'));
}); });
}); });
} }

41
app/Admin/Metrics/Examples/Order/OrderData.php

@ -11,11 +11,11 @@ use Illuminate\Http\Request;
class OrderData extends Card class OrderData extends Card
{ {
protected $title; 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->title = $title;
$this->data_type = $data_type;
parent::__construct($title, $icon); parent::__construct($title, $icon);
} }
@ -34,11 +34,12 @@ class OrderData extends Card
public function handle(Request $request) 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 = []; $where = [];
@ -73,16 +74,36 @@ class OrderData extends Card
$endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1; $endTime=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
break; break;
} }
$count = ImsCjdcOrderMain
$build = ImsCjdcOrderMain
::whereBetween('created_at',[$beginTime,$endTime]) ::whereBetween('created_at',[$beginTime,$endTime])
->whereIn('state',[3,4,5,10]) ->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 * @return string

Loading…
Cancel
Save