53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\EcommerceFinance\Services\DingInvoiceLocalAttachmentImporter;
|
|
use Throwable;
|
|
|
|
class ImportDingInvoiceAttachments extends Command
|
|
{
|
|
protected $signature = 'ding-invoices:import-attachments
|
|
{manifest : 附件清单 JSON 路径}
|
|
{--month= : 付款月份 YYYY-MM}
|
|
{--base-dir= : 清单中 relative_path 的基础目录}
|
|
{--scope=personal_permission : 镜像来源范围}';
|
|
|
|
protected $description = '按月导入已经下载的发票附件并保留原始截图';
|
|
|
|
public function handle(DingInvoiceLocalAttachmentImporter $importer): int
|
|
{
|
|
$month = trim((string) $this->option('month'));
|
|
$baseDirectory = trim((string) $this->option('base-dir'));
|
|
if ($baseDirectory === '') {
|
|
$this->error('必须指定 --base-dir。');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
try {
|
|
$result = $importer->import(
|
|
(string) $this->argument('manifest'),
|
|
$month,
|
|
$baseDirectory,
|
|
(string) $this->option('scope'),
|
|
);
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
$this->error($exception->getMessage());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
$this->info(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
if ($result['errors'] !== []) {
|
|
foreach (array_slice($result['errors'], 0, 20) as $error) {
|
|
$this->warn($error);
|
|
}
|
|
}
|
|
|
|
return $result['stored'] > 0 || $result['skipped'] === 0
|
|
? self::SUCCESS
|
|
: self::FAILURE;
|
|
}
|
|
}
|