58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Console\Commands\Concerns\QueuesBillPerformanceResync;
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Modules\EcommerceFinance\Services\BillPerformanceResyncDispatcher;
|
||
use Modules\EcommerceFinance\Services\JdDailyBillImporter;
|
||
use Throwable;
|
||
|
||
class ImportJdDailyBills extends Command
|
||
{
|
||
use QueuesBillPerformanceResync;
|
||
|
||
protected $signature = 'business-mirror:import-jd-daily
|
||
{path : 胜算京东日账单指定月份月初至截止日期 UTF-8 CSV} {month : YYYY-MM}
|
||
{--through= : 截止日期 YYYY-MM-DD,默认月末} {--count= : 核对笔数} {--income= : 核对收入} {--expense= : 核对支出}';
|
||
|
||
protected $description = '核对并启用胜算京东日账单月份镜像,保留旧版本';
|
||
|
||
public function handle(
|
||
JdDailyBillImporter $importer,
|
||
BillPerformanceResyncDispatcher $performanceResync,
|
||
): int
|
||
{
|
||
$lock = Cache::lock('jd-daily-bill-import', 21600);
|
||
if (! $lock->get()) {
|
||
$this->error('京东日账单正在导入,请稍后重试。');
|
||
return self::FAILURE;
|
||
}
|
||
try {
|
||
$result = $importer->import((string) $this->argument('path'), (string) $this->argument('month'),
|
||
(int) $this->option('count'), (string) $this->option('income'), (string) $this->option('expense'), $this->option('through'));
|
||
$this->info('京东日账单已启用,笔数:' . $result['row_count']);
|
||
$queuedJd = $this->queueBillPerformanceResync(
|
||
$performanceResync,
|
||
'jd-transactions',
|
||
$result,
|
||
true,
|
||
);
|
||
$queuedJingxi = $this->queueBillPerformanceResync(
|
||
$performanceResync,
|
||
'jingxi',
|
||
$result,
|
||
true,
|
||
);
|
||
|
||
return $queuedJd && $queuedJingxi ? self::SUCCESS : self::FAILURE;
|
||
} catch (Throwable $e) {
|
||
$this->error('京东日账单未启用,保留上一版本。' . ($e instanceof \InvalidArgumentException ? $e->getMessage() : '请检查文件、重复记录及镜像连接。'));
|
||
return self::FAILURE;
|
||
} finally {
|
||
$lock->release();
|
||
}
|
||
}
|
||
}
|