Merge pull request !215 from 赵世界/feat/2024
This commit is contained in:
赵世界 2024-02-06 09:13:58 +00:00 committed by Gitee
commit 7f1220ceb3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 16 additions and 14 deletions

View File

@ -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];

View File

@ -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');
}