周数据导出
This commit is contained in:
parent
4928479795
commit
50db77fc84
@ -3,23 +3,21 @@
|
|||||||
namespace App\Exports;
|
namespace App\Exports;
|
||||||
|
|
||||||
use App\Models\DailyReport;
|
use App\Models\DailyReport;
|
||||||
use App\Models\DailyStockRecord;
|
|
||||||
use App\Models\Log;
|
|
||||||
use App\Models\Shop;
|
use App\Models\Shop;
|
||||||
use App\Utils\ArrayUtils;
|
|
||||||
use App\Utils\DateTimeUtils;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
use App\Models\GoodsSku;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class WeekDataExport implements FromCollection, ShouldAutoSize
|
class WeekDataExport implements FromCollection, ShouldAutoSize
|
||||||
{
|
{
|
||||||
|
private $startDate;
|
||||||
|
private $endDate;
|
||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct($startDate, $endDate)
|
||||||
{
|
{
|
||||||
|
$this->startDate = $startDate;
|
||||||
|
$this->endDate = $endDate;
|
||||||
$this->data = $this->createData();
|
$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));
|
$headTitle = array_merge($headTitle, array_values($shops));
|
||||||
|
|
||||||
$startDate = Carbon::now()->subWeek()->startOfWeek()->toDateString();
|
|
||||||
$endDate = Carbon::now()->subWeek()->endOfWeek()->toDateString();
|
|
||||||
|
|
||||||
$dailyReports = DailyReport::query()
|
$dailyReports = DailyReport::query()
|
||||||
->with([
|
->with([
|
||||||
'goods:id,title',
|
'goods:id,title',
|
||||||
@ -55,8 +54,8 @@ class WeekDataExport implements FromCollection, ShouldAutoSize
|
|||||||
'goodsSku:id,title',
|
'goodsSku:id,title',
|
||||||
'goodsBrand:id,name',
|
'goodsBrand:id,name',
|
||||||
])
|
])
|
||||||
// ->where('date', '>=', $startDate)
|
->where('date', '>=', $this->startDate)
|
||||||
// ->where('date', '<=', $endDate)
|
->where('date', '<=', $this->endDate)
|
||||||
->get();
|
->get();
|
||||||
if ($dailyReports->isEmpty()) {
|
if ($dailyReports->isEmpty()) {
|
||||||
return [$headTitle];
|
return [$headTitle];
|
||||||
|
|||||||
@ -18,6 +18,7 @@ use App\Models\Log;
|
|||||||
use App\Models\Log as LogModel;
|
use App\Models\Log as LogModel;
|
||||||
use App\Utils\ArrayUtils;
|
use App\Utils\ArrayUtils;
|
||||||
use App\Utils\DateTimeUtils;
|
use App\Utils\DateTimeUtils;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\GoodsSku;
|
use App\Models\GoodsSku;
|
||||||
use App\Http\Resources\GoodsSkuResource;
|
use App\Http\Resources\GoodsSkuResource;
|
||||||
@ -525,7 +526,9 @@ class GoodsSkusController extends Controller
|
|||||||
$type = $request->get('exportType');
|
$type = $request->get('exportType');
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
if ('week_data' === $type) {
|
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');
|
return Excel::download(new GoodsSkusExport($type), $type . '.xlsx');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user