过滤TD数据
This commit is contained in:
parent
1e942e0486
commit
1663548147
@ -13,7 +13,7 @@ class ImportService extends Service
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
public static function load(UploadedFile $file, $columns = null)
|
||||
public static function load(UploadedFile $file, $columns = null, $sheetIndex = 0)
|
||||
{
|
||||
if ($columns !== null) {
|
||||
if (!is_array($columns)) {
|
||||
@ -23,7 +23,7 @@ class ImportService extends Service
|
||||
$columns = array_map('strtolower', $columns);
|
||||
}
|
||||
|
||||
$array = self::toArray($file);
|
||||
$array = self::toArray($file, $sheetIndex);
|
||||
|
||||
$title = [];
|
||||
$data = [];
|
||||
@ -39,13 +39,13 @@ class ImportService extends Service
|
||||
if ($columns === null || in_array($column, $columns)) {
|
||||
$row[$column] = trim($value);
|
||||
|
||||
if(!empty($row[$column])){
|
||||
if (!empty($row[$column])) {
|
||||
$emptyRow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$emptyRow){
|
||||
if (!$emptyRow) {
|
||||
array_push($data, $row);
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ class ImportService extends Service
|
||||
* @param UploadedFile $file
|
||||
* @return void
|
||||
*/
|
||||
public static function toArray(UploadedFile $file)
|
||||
public static function toArray(UploadedFile $file, $sheetIndex = 0)
|
||||
{
|
||||
if (!$file) {
|
||||
throw new InvalidArgumentException('文件不存在');
|
||||
@ -78,7 +78,7 @@ class ImportService extends Service
|
||||
|
||||
$spreadsheet = $reader->load($file->getPathname());
|
||||
|
||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, false);
|
||||
$sheetData = $spreadsheet->getSheet($sheetIndex)->toArray(null, true, true, false);
|
||||
|
||||
return $sheetData;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
39
tests/TdFilter.php
Normal file
39
tests/TdFilter.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Real\OrderCardPartition;
|
||||
use App\Domains\Export\Services\ImportService;
|
||||
|
||||
echo 'started.' . PHP_EOL;
|
||||
|
||||
$file = new UploadedFile(__DIR__ . '/数据不进vd.xlsx', '数据不进vd.xlsx');
|
||||
|
||||
$data = ImportService::load($file, null, 0);
|
||||
|
||||
echo 'loaded.' . PHP_EOL;
|
||||
|
||||
$simArray = array_pluck($data, 'sim');
|
||||
unset($data);
|
||||
deleteOrderCard($simArray);
|
||||
|
||||
$data = ImportService::load($file, null, 1);
|
||||
|
||||
echo 'loaded.' . PHP_EOL;
|
||||
|
||||
$simArray = array_pluck($data, 'sim');
|
||||
unset($data);
|
||||
deleteOrderCard($simArray);
|
||||
|
||||
|
||||
function deleteOrderCard($simArray)
|
||||
{
|
||||
foreach (array_chunk($simArray, 1000) as $key => $value) {
|
||||
OrderCardPartition::whereIn('sim', $value)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
dd($data);
|
BIN
tests/数据不进vd.xlsx
Normal file
BIN
tests/数据不进vd.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user