38 lines
1.6 KiB
PHP
38 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Modules\EcommerceFinance\Services\JdWalletBillImporter;
|
||
use Throwable;
|
||
|
||
class ImportJdWalletBills extends Command
|
||
{
|
||
protected $signature = 'business-mirror:import-jd-wallet
|
||
{path : 胜算京东钱包指定月份月初至截止日期 UTF-8 CSV} {month : YYYY-MM}
|
||
{--through= : 截止日期 YYYY-MM-DD,默认月末} {--count= : 核对笔数} {--income= : 核对收入} {--expense= : 核对支出}';
|
||
|
||
protected $description = '核对并启用胜算京东钱包月份镜像,保留旧版本';
|
||
|
||
public function handle(JdWalletBillImporter $importer): int
|
||
{
|
||
$lock = Cache::lock('jd-wallet-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']);
|
||
return self::SUCCESS;
|
||
} catch (Throwable $e) {
|
||
$this->error('京东钱包未启用,保留上一版本。' . ($e instanceof \InvalidArgumentException ? $e->getMessage() : '请检查文件、重复记录及镜像连接。'));
|
||
return self::FAILURE;
|
||
} finally {
|
||
$lock->release();
|
||
}
|
||
}
|
||
}
|