From 50db77fc848c97de89c3d6f43edfa3720a841248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Tue, 6 Feb 2024 17:13:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=A8=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exports/WeekDataExport.php | 25 +++++++++---------- .../Controllers/Goods/GoodsSkusController.php | 5 +++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Exports/WeekDataExport.php b/app/Exports/WeekDataExport.php index 49d9090..7642c5e 100644 --- a/app/Exports/WeekDataExport.php +++ b/app/Exports/WeekDataExport.php @@ -3,23 +3,21 @@ namespace App\Exports; use App\Models\DailyReport; -use App\Models\DailyStockRecord; -use App\Models\Log; use App\Models\Shop; -use App\Utils\ArrayUtils; -use App\Utils\DateTimeUtils; -use Carbon\Carbon; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\ShouldAutoSize; -use App\Models\GoodsSku; use Illuminate\Support\Collection; class WeekDataExport implements FromCollection, ShouldAutoSize { + private $startDate; + private $endDate; private $data; - public function __construct() + public function __construct($startDate, $endDate) { + $this->startDate = $startDate; + $this->endDate = $endDate; $this->data = $this->createData(); } @@ -42,12 +40,13 @@ class WeekDataExport implements FromCollection, ShouldAutoSize '成本', '销售数量', ]; - $shops = Shop::query()->orderBy('id')->pluck('name', 'id')->toArray(); + $shops = Shop::query() + ->whereNotIn('id', [9, 10, 11, 17, 18]) + ->orderBy('id') + ->pluck('name', 'id') + ->toArray(); $headTitle = array_merge($headTitle, array_values($shops)); - $startDate = Carbon::now()->subWeek()->startOfWeek()->toDateString(); - $endDate = Carbon::now()->subWeek()->endOfWeek()->toDateString(); - $dailyReports = DailyReport::query() ->with([ 'goods:id,title', @@ -55,8 +54,8 @@ class WeekDataExport implements FromCollection, ShouldAutoSize 'goodsSku:id,title', 'goodsBrand:id,name', ]) -// ->where('date', '>=', $startDate) -// ->where('date', '<=', $endDate) + ->where('date', '>=', $this->startDate) + ->where('date', '<=', $this->endDate) ->get(); if ($dailyReports->isEmpty()) { return [$headTitle]; diff --git a/app/Http/Controllers/Goods/GoodsSkusController.php b/app/Http/Controllers/Goods/GoodsSkusController.php index d7229bb..5d7096c 100644 --- a/app/Http/Controllers/Goods/GoodsSkusController.php +++ b/app/Http/Controllers/Goods/GoodsSkusController.php @@ -18,6 +18,7 @@ use App\Models\Log; use App\Models\Log as LogModel; use App\Utils\ArrayUtils; use App\Utils\DateTimeUtils; +use Carbon\Carbon; use Illuminate\Http\Request; use App\Models\GoodsSku; use App\Http\Resources\GoodsSkuResource; @@ -525,7 +526,9 @@ class GoodsSkusController extends Controller $type = $request->get('exportType'); ob_end_clean(); if ('week_data' === $type) { - return Excel::download(new WeekDataExport(), $type . '.xlsx'); + $startDate = Carbon::now()->subWeek()->startOfWeek()->toDateString(); + $endDate = Carbon::now()->subWeek()->endOfWeek()->toDateString(); + return Excel::download(new WeekDataExport($startDate, $endDate), $startDate . '~' . $endDate . '.xlsx'); } return Excel::download(new GoodsSkusExport($type), $type . '.xlsx'); }