commit
7f1220ceb3
@ -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];
|
||||
|
||||
@ -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');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user