11 changed files with 672 additions and 10 deletions
-
2app/Admin/Actions/Grid/v3/GoodsActivitySetting.php
-
78app/Admin/Actions/Grid/v3/OrderReportLastMonth.php
-
79app/Admin/Actions/Grid/v3/OrderReportLastWeek.php
-
77app/Admin/Actions/Grid/v3/OrderReportToday.php
-
78app/Admin/Actions/Grid/v3/OrderReportYesterday.php
-
28app/Admin/Common/Common.php
-
97app/Admin/Controllers/v3/OrderReportController copy.php
-
67app/Admin/Controllers/v3/OrderReportController.php
-
147app/Admin/Metrics/Examples/Order/OrderReportCard.php
-
28app/Admin/Repositories/v3/OrderReport.php
-
1app/Admin/routes.php
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class OrderReportLastMonth extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '上月'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
//上月初
|
|||
$lastMonthStart = date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01'))); |
|||
// 上月底
|
|||
$lastMonthEnd = date('Y-m-d', strtotime(date('Y-m', time()) . '-01') - 86400); |
|||
return $this->response() |
|||
->success('查询中~') |
|||
->redirect('/order_report?start_time='.$lastMonthStart.'&end_time='.$lastMonthEnd); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('/');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class OrderReportLastWeek extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '上周'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
// 上周日
|
|||
$lastSunday = date('Y-m-d', strtotime('-1 sunday', time())); |
|||
// 上周一
|
|||
$lastMonday = date('Y-m-d', strtotime('-1 monday', strtotime($lastSunday))); |
|||
|
|||
return $this->response() |
|||
->success('查询中~') |
|||
->redirect('/order_report?start_time='.$lastMonday.'&end_time='.$lastSunday); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('/');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class OrderReportToday extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '今日'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
$today = date('Y-m-d'); |
|||
$startTime = $today; |
|||
$endTime = $today; |
|||
return $this->response() |
|||
->success('查询中~') |
|||
->redirect('/order_report?start_time='.$startTime.'&end_time='.$endTime); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('/');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Grid\v3; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class OrderReportYesterday extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '昨日'; |
|||
|
|||
/** |
|||
* Handle the action request. |
|||
* |
|||
* @param Request $request |
|||
* |
|||
* @return Response |
|||
*/ |
|||
public function handle(Request $request) |
|||
{ |
|||
$today = date('Y-m-d'); |
|||
$yesterday = date("Y-m-d",strtotime("-1 days",strtotime($today))); |
|||
$startTime = $yesterday; |
|||
$endTime = $yesterday; |
|||
return $this->response() |
|||
->success('查询中~') |
|||
->redirect('/order_report?start_time='.$startTime.'&end_time='.$endTime); |
|||
} |
|||
|
|||
/** |
|||
* @return string|void |
|||
*/ |
|||
// public function href()
|
|||
// {
|
|||
// return admin_url('/');
|
|||
// }
|
|||
|
|||
/** |
|||
* @return string|array|void |
|||
*/ |
|||
public function confirm() |
|||
{ |
|||
// return ['Confirm?', 'contents'];
|
|||
} |
|||
|
|||
// protected function actionScript()
|
|||
// {
|
|||
|
|||
// return <<<JS
|
|||
// function (data, target, action) {
|
|||
// console.log('发起请求之前', data, target, action);
|
|||
|
|||
// // return false; 在这里return false可以终止执行后面的操作
|
|||
|
|||
// // 更改传递到接口的主键值
|
|||
// action.options.key = 123;
|
|||
// }
|
|||
// JS;
|
|||
// }
|
|||
|
|||
/** |
|||
* @param Model|Authenticatable|HasPermissions|null $user |
|||
* |
|||
* @return bool |
|||
*/ |
|||
protected function authorize($user): bool |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -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