From c0f6df7065cda894107065023350c9ec2585b4ee Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Wed, 21 Oct 2020 17:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81--=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BF=AB=E6=8D=B7=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Actions/Grid/v3/DataReportOption.php | 113 ++++++++++++++++++ .../v3/GoodsActivityReportController.php | 26 ++-- .../Controllers/v3/OrderReportController.php | 6 +- 3 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 app/Admin/Actions/Grid/v3/DataReportOption.php diff --git a/app/Admin/Actions/Grid/v3/DataReportOption.php b/app/Admin/Actions/Grid/v3/DataReportOption.php new file mode 100644 index 0000000..36f7253 --- /dev/null +++ b/app/Admin/Actions/Grid/v3/DataReportOption.php @@ -0,0 +1,113 @@ +option = $option; + $this->url = $url; + $this->title = $title; + } + + /** + * Handle the action request. + * + * @param Request $request + * + * @return Response + */ + public function handle(Request $request) + { + // $date = $this->getDataByOption($this->option); + // $startTime = $date['start'] ?? ''; + // $endTime = $date['end'] ?? ''; + return $this->response() + ->success('查询中~'); + // ->redirect('/'.$this->url.'?start_time='.$startTime.'&end_time='.$endTime); + } + + /** + * @return string + */ + protected function html() + { + $date = $this->getDataByOption($this->option); + $startTime = $date['start'] ?? ''; + $endTime = $date['end'] ?? ''; + $url = 'admin/'.$this->url.'?start_time='.$startTime.'&end_time='.$endTime; + $this->defaultHtmlAttribute('href', url($url)); + + return <<formatHtmlAttributes()}>{$this->title()} +HTML; + } + + public function getDataByOption($option) + { + $date = ['start','end']; + $today = date('Y-m-d'); + switch($option){ + case 'today': + $date['start'] = $today; + $date['end'] = $today; + break; + case 'yesterday': + $yesterday = date("Y-m-d",strtotime("-1 days",time())); + $date['start'] = $yesterday; + $date['end'] = $yesterday; + break; + case 'this_week': + $first=1; + //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 + $w=date('w',strtotime($today)); + //获取本周开始日期,如果$w是0,则表示周日,减去 6 天 + $week_start=date('Y-m-d',strtotime("$today -".($w ? $w - $first : 6).' days')); + //本周结束日期 + $week_end=date('Y-m-d',strtotime("$week_start +6 days")); + $date['start'] = $week_start; + $date['end'] = $week_end; + break; + case 'last_week': + // 上周日 + $lastSunday = date('Y-m-d', strtotime('-1 sunday', time())); + // 上周一 + $lastMonday = date('Y-m-d', strtotime('-1 monday', strtotime($lastSunday))); + + $date['start'] = $lastMonday; + $date['end'] = $lastSunday; + break; + case 'this_month': + $thisMonthStart = date('Y-m-01', strtotime($today)); + $thisMonthEnd = date('Y-m-d', strtotime($today)); + + $date['start'] = $thisMonthStart; + $date['end'] = $thisMonthEnd; + 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); + + $date['start'] = $lastMonthStart; + $date['end'] = $lastMonthEnd; + break; + default: + break; + } + + return $date; + } + +} diff --git a/app/Admin/Controllers/v3/GoodsActivityReportController.php b/app/Admin/Controllers/v3/GoodsActivityReportController.php index c959d7d..d534c72 100644 --- a/app/Admin/Controllers/v3/GoodsActivityReportController.php +++ b/app/Admin/Controllers/v3/GoodsActivityReportController.php @@ -2,12 +2,8 @@ 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\Actions\Grid\v3\DataReportOption; -use Dcat\Admin\Grid\Model as GridModel; use App\Admin\Repositories\v3\GoodsActivityReport; use App\Admin\Widgets\Charts\OrderGoodsActivityColumnChart; use Dcat\Admin\Grid; @@ -54,15 +50,21 @@ class GoodsActivityReportController extends AdminController $grid->filter(function (Filter $filter) use($marketList,$storeList) { // 更改为 panel 布局 $filter->panel(); - - $filter->equal('name','商品名称'); - $filter->equal('market_id','市场')->select($marketList); - $filter->equal('store_id','店铺')->select($storeList); - $filter->equal('start_time','开始时间')->date(); - $filter->equal('end_time','结束时间')->date(); + $filter->equal('start_time','开始时间')->date()->width(2); + $filter->equal('end_time','结束时间')->date()->width(2); + $filter->equal('name','商品名称')->width(3); + $filter->equal('market_id','市场')->select($marketList)->width(2); + $filter->equal('store_id','店铺')->select($storeList)->width(3); }); - // $grid->tools([new OrderReportToday(), new OrderReportYesterday(), new OrderReportLastWeek(), new OrderReportLastMonth()]); + $grid->tools([ + new DataReportOption('today','goods_activity_report','今日'), + new DataReportOption('yesterday','goods_activity_report','昨日'), + new DataReportOption('this_week','goods_activity_report','本周'), + new DataReportOption('last_week','goods_activity_report','上周'), + new DataReportOption('this_month','goods_activity_report','本月'), + new DataReportOption('last_month','goods_activity_report','上月') + ]); // 每页1条 $grid->paginate(10); diff --git a/app/Admin/Controllers/v3/OrderReportController.php b/app/Admin/Controllers/v3/OrderReportController.php index fc2394e..082b23c 100644 --- a/app/Admin/Controllers/v3/OrderReportController.php +++ b/app/Admin/Controllers/v3/OrderReportController.php @@ -35,9 +35,9 @@ class OrderReportController extends AdminController // 更改为 panel 布局 $filter->panel(); - $filter->equal('market_id','市场')->select($marketList); - $filter->equal('start_time','开始时间')->date(); - $filter->equal('end_time','结束时间')->date(); + $filter->equal('market_id','市场')->select($marketList)->width(3); + $filter->equal('start_time','开始时间')->date()->width(2); + $filter->equal('end_time','结束时间')->date()->width(2); }); $grid->tools([new OrderReportToday(), new OrderReportYesterday(), new OrderReportLastWeek(), new OrderReportLastMonth()]);