diff --git a/app/Console/Commands/ImportStoreViolationRules.php b/app/Console/Commands/ImportStoreViolationRules.php index 18fb67d2..bd5d234d 100644 --- a/app/Console/Commands/ImportStoreViolationRules.php +++ b/app/Console/Commands/ImportStoreViolationRules.php @@ -54,8 +54,20 @@ class ImportStoreViolationRules extends Command } try { - $sheet = IOFactory::load($file)->getActiveSheet(); - $matrix = $sheet->toArray(null, true, true, false); + $reader = IOFactory::createReaderForFile($file); + if (method_exists($reader, 'setReadDataOnly')) { + $reader->setReadDataOnly(true); + } + if (method_exists($reader, 'setReadFilter')) { + // 字典文件通常只有几十行;部分导出文件带巨大空白维度,限制读取范围。 + $reader->setReadFilter(new class implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter { + public function readCell($columnAddress, $row, $worksheetName = ''): bool + { + return $row <= 5000; + } + }); + } + $matrix = $reader->load($file)->getActiveSheet()->toArray(null, true, true, false); } catch (Throwable $exception) { $this->error('无法读取文件:' . $exception->getMessage()); @@ -137,18 +149,16 @@ class ImportStoreViolationRules extends Command 'updated_at' => now(), ]; - if ($this->option('dry-run')) { - $skipped += 0; - $updated += 0; - $created += 0; - continue; - } - $exists = $connection->table(StoreViolationRuleRepository::TABLE) ->where('platform', $platform) ->where('violation_type', $payload['violation_type']) ->exists(); + if ($this->option('dry-run')) { + $exists ? $updated++ : $created++; + continue; + } + if ($exists) { $connection->table(StoreViolationRuleRepository::TABLE) ->where('platform', $platform) diff --git a/modules/EcommerceFinance/Repositories/StoreViolationRecordRepository.php b/modules/EcommerceFinance/Repositories/StoreViolationRecordRepository.php index 458d4f5e..c11c7dd0 100644 --- a/modules/EcommerceFinance/Repositories/StoreViolationRecordRepository.php +++ b/modules/EcommerceFinance/Repositories/StoreViolationRecordRepository.php @@ -202,6 +202,7 @@ class StoreViolationRecordRepository if (! empty($filters['overdue'])) { $query->whereNotIn('handling_status', self::FINAL_HANDLING_STATUSES) + ->where('needs_alert', true) ->whereNotNull('handling_deadline') ->where('handling_deadline', '<', now()); } @@ -311,6 +312,7 @@ class StoreViolationRecordRepository $grouped = $this->connection->table(self::TABLE) ->selectRaw('platform, COUNT(*) AS aggregate') + ->where('needs_alert', true) ->whereNotIn('handling_status', self::FINAL_HANDLING_STATUSES) ->whereNotNull('handling_deadline') ->where('handling_deadline', '<', now())