6 changed files with 287 additions and 4 deletions
-
28app/Admin/Common/Common.php
-
97app/Admin/Controllers/v3/OrderReportController copy.php
-
13app/Admin/Controllers/v3/OrderReportController.php
-
147app/Admin/Metrics/Examples/Order/OrderReportCard.php
-
3app/Admin/Repositories/v3/OrderReport.php
-
1app/Admin/routes.php
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace App\Admin\Common; |
|||
|
|||
|
|||
use Dcat\Admin\Controllers\AdminController; |
|||
|
|||
class Common extends AdminController |
|||
{ |
|||
|
|||
/** |
|||
* 获取一个时间段内的日期 |
|||
*/ |
|||
public static function periodDateArr($start_time,$end_time){ |
|||
$start_time = strtotime($start_time); |
|||
$end_time = strtotime($end_time); |
|||
$i=0; |
|||
$arr = []; |
|||
while ($start_time<=$end_time){ |
|||
$arr[date('Y-m-d',$start_time)]=date('Y年m月d日',$start_time); |
|||
$start_time = strtotime('+1 day',$start_time); |
|||
$i++; |
|||
} |
|||
|
|||
return array_reverse($arr); |
|||
} |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers\v3; |
|||
|
|||
use App\Admin\Repositories\v3\OrderReport; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\v3\Market as MarketModel; |
|||
use App\Admin\Metrics\Examples\Order\OrderReportCard; |
|||
use Dcat\Admin\Grid\Filter; |
|||
use Dcat\Admin\Layout\Content; |
|||
|
|||
class OrderReportController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
*/ |
|||
public function index(Content $content) |
|||
{ |
|||
return $content |
|||
->header('报表') |
|||
->description('订单统计') |
|||
->body(function ($row) { |
|||
$row->column(3, new OrderReportCard()); |
|||
$row->column(3, new OrderReportCard()); |
|||
$row->column(3, new OrderReportCard()); |
|||
$row->column(3, new OrderReportCard()); |
|||
}) |
|||
->body($this->grid()); |
|||
} |
|||
|
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return 123; |
|||
return Grid::make(new OrderReport(), function (Grid $grid) { |
|||
|
|||
$marketList = MarketModel::getMarketArray(); |
|||
|
|||
$grid->combine('默认统计今天的数据', ['name', 'value'])->responsive()->help('如果未选择时间,则默认只统计当天的所有市场的数据,特殊:现存用户默认统计所有的数据'); |
|||
|
|||
$grid->column('name'); |
|||
$grid->column('value'); |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) use($marketList){ |
|||
// 更改为 panel 布局
|
|||
$filter->panel(); |
|||
|
|||
$filter->equal('market_id','市场')->select($marketList); |
|||
$filter->equal('start_time','开始时间')->date(); |
|||
$filter->equal('end_time','结束时间')->date(); |
|||
|
|||
// $today = date('Y-m-d');
|
|||
// $monthBefore = date("Y-m-d",strtotime("-1 months",strtotime($today)));
|
|||
// $timeData = $this->periodDateArr($monthBefore,$today);
|
|||
// $filter->equal('day','日期')->select($timeData)->default($today);
|
|||
}); |
|||
|
|||
// 每页1条
|
|||
$grid->paginate(10); |
|||
$grid->disableCreateButton(); |
|||
$grid->disableBatchActions(); |
|||
$grid->disableBatchDelete(); |
|||
|
|||
$grid->toolsWithOutline(); |
|||
|
|||
$grid->disableDeleteButton(); |
|||
$grid->disableEditButton(); |
|||
$grid->disableQuickEditButton(); |
|||
$grid->disableViewButton(); |
|||
$grid->disableActions(); |
|||
|
|||
$grid->disableRowSelector(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 获取一个时间段内的日期 |
|||
*/ |
|||
public function periodDateArr($start_time,$end_time){ |
|||
$start_time = strtotime($start_time); |
|||
$end_time = strtotime($end_time); |
|||
$i=0; |
|||
$arr = []; |
|||
while ($start_time<=$end_time){ |
|||
$arr[date('Y-m-d',$start_time)]=date('Y年m月d日',$start_time); |
|||
$start_time = strtotime('+1 day',$start_time); |
|||
$i++; |
|||
} |
|||
|
|||
return array_reverse($arr); |
|||
} |
|||
} |
|||
@ -0,0 +1,147 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Metrics\Examples\Order; |
|||
|
|||
use App\Admin\Common\Common; |
|||
use Dcat\Admin\Widgets\Metrics\Card; |
|||
use Illuminate\Contracts\Support\Renderable; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class OrderReportCard extends Card |
|||
{ |
|||
/** |
|||
* 卡片底部内容. |
|||
* |
|||
* @var string|Renderable|\Closure |
|||
*/ |
|||
protected $footer; |
|||
|
|||
// 保存自定义参数
|
|||
protected $data = []; |
|||
|
|||
// 构造方法参数必须设置默认值
|
|||
public function __construct(array $data = []) |
|||
{ |
|||
$this->data = []; |
|||
|
|||
parent::__construct(); |
|||
} |
|||
|
|||
protected function init() |
|||
{ |
|||
parent::init(); |
|||
|
|||
// 设置标题
|
|||
$this->title('现存用户总数(人)'); |
|||
|
|||
// 设置下拉菜单
|
|||
$today = date('Y-m-d'); |
|||
$monthBefore = date("Y-m-d",strtotime("-1 weeks",strtotime($today))); |
|||
$timeData = Common::periodDateArr($monthBefore,$today); |
|||
|
|||
$this->dropdown($timeData); |
|||
} |
|||
|
|||
/** |
|||
* 处理请求. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
// 获取外部传递的自定义参数
|
|||
$key1 = $request->get('key1'); |
|||
|
|||
switch ($request->get('option')) { |
|||
case '365': |
|||
$this->content(mt_rand(600, 1500)); |
|||
$this->down(mt_rand(1, 30)); |
|||
break; |
|||
case '30': |
|||
$this->content(mt_rand(170, 250)); |
|||
$this->up(mt_rand(12, 50)); |
|||
break; |
|||
case '28': |
|||
$this->content(mt_rand(155, 200)); |
|||
$this->up(mt_rand(5, 50)); |
|||
break; |
|||
case '7': |
|||
default: |
|||
$this->content(143); |
|||
$this->up(15); |
|||
} |
|||
} |
|||
|
|||
// 传递自定义参数到 handle 方法
|
|||
public function parameters() : array |
|||
{ |
|||
return $this->data; |
|||
} |
|||
|
|||
/** |
|||
* @param int $percent |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function up($percent) |
|||
{ |
|||
return $this->footer( |
|||
"<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase" |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* @param int $percent |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function down($percent) |
|||
{ |
|||
return $this->footer( |
|||
"<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease" |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 设置卡片底部内容 |
|||
* |
|||
* @param string|Renderable|\Closure $footer |
|||
* |
|||
* @return $this |
|||
*/ |
|||
public function footer($footer) |
|||
{ |
|||
$this->footer = $footer; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* 渲染卡片内容. |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function renderContent() |
|||
{ |
|||
$content = parent::renderContent(); |
|||
|
|||
return <<<HTML |
|||
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
|||
<h2 class="ml-1 font-large-1">{$content}</h2> |
|||
</div> |
|||
<div class="ml-1 mt-1 font-weight-bold text-80"> |
|||
{$this->renderFooter()} |
|||
</div> |
|||
HTML; |
|||
} |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
public function renderFooter() |
|||
{ |
|||
return $this->toString($this->footer); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue