diff --git a/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php b/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php index d8051b3..056f227 100644 --- a/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php +++ b/app/Admin/Actions/Grid/v3/GoodsActivitySetting.php @@ -36,7 +36,7 @@ class GoodsActivitySetting extends AbstractTool */ // public function href() // { - // return admin_url('category/tie'); + // return admin_url('/'); // } /** diff --git a/app/Admin/Actions/Grid/v3/OrderReportLastMonth.php b/app/Admin/Actions/Grid/v3/OrderReportLastMonth.php new file mode 100644 index 0000000..1ff2557 --- /dev/null +++ b/app/Admin/Actions/Grid/v3/OrderReportLastMonth.php @@ -0,0 +1,78 @@ +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 <<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 <<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 <<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 <<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); + } +} diff --git a/app/Admin/Controllers/v3/OrderReportController.php b/app/Admin/Controllers/v3/OrderReportController.php index 306dd23..fc2394e 100644 --- a/app/Admin/Controllers/v3/OrderReportController.php +++ b/app/Admin/Controllers/v3/OrderReportController.php @@ -2,16 +2,19 @@ namespace App\Admin\Controllers\v3; +use App\Admin\Actions\Grid\v3\OrderReportLastMonth; +use App\Admin\Actions\Grid\v3\OrderReportLastWeek; +use App\Admin\Actions\Grid\v3\OrderReportToday; +use App\Admin\Actions\Grid\v3\OrderReportYesterday; 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; class OrderReportController extends AdminController { - + // public static $searchTime = []; /** * Make a grid builder. * @@ -20,15 +23,15 @@ class OrderReportController extends AdminController protected function grid() { return Grid::make(new OrderReport(), function (Grid $grid) { - + $marketList = MarketModel::getMarketArray(); - $grid->combine('默认统计今天的数据【'.date('Y-m-d').'】', ['name', 'value'])->responsive()->help('如果未选择时间,则默认只统计当天的所有市场的数据,特殊:现存用户默认统计所有的数据'); + $grid->combine('默认统计今天的数据', ['name', 'value'])->responsive()->help('如果未选择时间,则默认只统计当天的所有市场的数据,特殊:现存用户默认统计所有的数据'); $grid->column('name'); $grid->column('value'); - $grid->filter(function (Grid\Filter $filter) use($marketList){ + $grid->filter(function (Filter $filter) use($marketList) { // 更改为 panel 布局 $filter->panel(); @@ -37,6 +40,8 @@ class OrderReportController extends AdminController $filter->equal('end_time','结束时间')->date(); }); + $grid->tools([new OrderReportToday(), new OrderReportYesterday(), new OrderReportLastWeek(), new OrderReportLastMonth()]); + // 每页1条 $grid->paginate(10); $grid->disableCreateButton(); @@ -55,4 +60,56 @@ class OrderReportController extends AdminController }); } + /** + * 获取一个时间段内的日期 + */ + 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); + + // $grid->selector(function (Grid\Tools\Selector $selector) { + // $today = date('Y-m-d'); + // $selector->selectOne('time', '选择日期', ['today'=>'今日', 'yesterday'=>'昨日', 'last_week'=>'上周','last_month'=>'上月'], function($query, $value) use($today){ + // $where = []; + + // switch($value){ + // case 'today': + // $where['start_time'] = $today; + // $where['end_time'] = $today; + // break; + // case 'yesterday': + // $yesterday = date("Y-m-d",strtotime("-1 days",strtotime($today))); + // $where['start_time'] = $yesterday; + // $where['end_time'] = $yesterday; + // break; + // case 'last_week': + // //上周日 + // $lastSunday = date('Y-m-d', strtotime('-1 sunday', time())); + // // 上周一 + // $lastMonday = date('Y-m-d', strtotime('-1 monday', strtotime($lastSunday))); + // $where['start_time'] = $lastMonday; + // $where['end_time'] = $lastSunday; + // break; + // case 'last_month': + // //上月初 + // $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); + // $where['start_time'] = $lastMonthStart; + // $where['end_time'] = $lastMonthEnd; + // break; + // } + // self::$searchTime = $where; + // }); + // }); + } } diff --git a/app/Admin/Metrics/Examples/Order/OrderReportCard.php b/app/Admin/Metrics/Examples/Order/OrderReportCard.php new file mode 100644 index 0000000..892d4ba --- /dev/null +++ b/app/Admin/Metrics/Examples/Order/OrderReportCard.php @@ -0,0 +1,147 @@ +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( + " {$percent}% Increase" + ); + } + + /** + * @param int $percent + * + * @return $this + */ + public function down($percent) + { + return $this->footer( + " {$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 << +

{$content}

+ +
+ {$this->renderFooter()} +
+HTML; + } + + /** + * @return string + */ + public function renderFooter() + { + return $this->toString($this->footer); + } +} \ No newline at end of file diff --git a/app/Admin/Repositories/v3/OrderReport.php b/app/Admin/Repositories/v3/OrderReport.php index fb73c57..91eb627 100644 --- a/app/Admin/Repositories/v3/OrderReport.php +++ b/app/Admin/Repositories/v3/OrderReport.php @@ -32,9 +32,16 @@ class OrderReport extends EloquentRepository public function get(GridModel $model) { $marketId = request()->input('market_id'); + $time = date('Y-m-d',time()); $startTime = request()->input('start_time'); $endTime = request()->input('end_time'); - + + // $searchTime = OrderReportController::$searchTime; + // if(!empty($searchTime) && !($startTime || $endTime)){ + // $startTime = $searchTime['start_time']; + // $endTime = $searchTime['end_time']; + // } + $orderMainOnline = OrderMainModel::select(DB::raw('COUNT(id) AS total_num, SUM(money) AS total_money'))->whereIn('state',[4,5])->where('type',OrderMainModel::ORDER_TYPE_ONLINE); $orderMainOffline = OrderMainModel::select(DB::raw('COUNT(id) AS total_num, SUM(money) AS total_money'))->whereIn('state',[4,5])->where('type',OrderMainModel::ORDER_TYPE_OFFLINE); // 旧商户流水 @@ -70,8 +77,9 @@ class OrderReport extends EloquentRepository $storeNewUserNewFour->whereIn('user_id',$userIdsArr)->where('user_type',5); } if($startTime){ + $date = $startTime; $startTime = $startTime.' 00:00:00'; - + $orderMainOnline->where([['created_at','>=',strtotime($startTime)]]); $orderMainOffline->where([['created_at','>=',strtotime($startTime)]]); @@ -82,10 +90,13 @@ class OrderReport extends EloquentRepository $storeNewUserNewThree->where([['created_at','>=',strtotime($startTime)]]); $storeNewUserNewFour->where([['created_at','>=',strtotime($startTime)]]); // $newUser->where([['created_at','>=',strtotime($startTime)]]); + }else{ + $date = '2020-06-01'; } if($endTime){ + $date = $date.' 至 '.$endTime; $endTime = $endTime.' 23:59:59'; - + $orderMainOnline->where([['created_at','<=',strtotime($endTime)]]); $orderMainOffline->where([['created_at','<=',strtotime($endTime)]]); @@ -96,9 +107,12 @@ class OrderReport extends EloquentRepository $storeNewUserNewThree->where([['created_at','<=',strtotime($endTime)]]); $storeNewUserNewFour->where([['created_at','<=',strtotime($endTime)]]); // $newUser->where([['created_at','<=',strtotime($endTime)]]); + }else{ + $date .= ' 至 '.$time; } if(empty($startTime) && empty($endTime)){ - $time = date('Y-m-d',time()); + + $date = $time; $todayStart = $time.' 00:00:00'; $todayEnd = $time.' 23:59:59'; @@ -122,6 +136,7 @@ class OrderReport extends EloquentRepository $storeNewUserNewThree->where([['created_at','<=',strtotime($todayEnd)]]); $storeNewUserNewFour->where([['created_at','<=',strtotime($todayEnd)]]); } + // 订单总额 $orderReportOnline = $orderMainOnline->get()->toArray(); $orderReportOffline = $orderMainOffline->get()->toArray(); @@ -206,6 +221,11 @@ class OrderReport extends EloquentRepository 'key' => 'store_user_total_money', 'name' => '店铺用户每日首单补贴(元)', 'value' => $query['store_user_total_money'] + $query['store_user_total_new_money_zero'] + $query['store_user_total_new_money_one'] + $query['store_user_total_new_money_two'] + $query['store_user_total_new_money_three'] + $query['store_user_total_new_money_four'] + ], + [ + 'key' => 'day', + 'name' => '统计日期', + 'value' => $date ] ]; diff --git a/app/Admin/routes.php b/app/Admin/routes.php index a729727..b79a123 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -85,5 +85,6 @@ Route::group([ // 订单统计 $router->resource('/order_report', 'v3\OrderReportController'); + // $router->any('/order_report', 'v3\OrderReportController@index'); });