36 lines
851 B
PHP
36 lines
851 B
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\TodayPrice;
|
|
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
|
use Maatwebsite\Excel\Concerns\ToArray;
|
|
use Maatwebsite\Excel\Concerns\WithStartRow;
|
|
|
|
class TodayPriceImport implements ToArray, SkipsEmptyRows, WithStartRow
|
|
{
|
|
public function startRow(): int
|
|
{
|
|
return 2;
|
|
}
|
|
|
|
public function array(array $array)
|
|
{
|
|
$data = [];
|
|
$day = date('Y-m-d');
|
|
foreach ($array as $row) {
|
|
$row = array_map(function ($value) {
|
|
return trim($value);
|
|
}, $row);
|
|
$data[] = [
|
|
'day' => $day,
|
|
'external_sku_id' => $row[0],
|
|
'price' => $row[1],
|
|
];
|
|
}
|
|
TodayPrice::query()->delete();
|
|
$model = new TodayPrice();
|
|
$model->batchInsert($data);
|
|
}
|
|
}
|