CaiWuXiTong/app/Console/Commands/ImportJdDailyBills.php
qiuxiang 37b9a17b65 修复原始账单更新后自动重算业绩明细
京东、京喜、抖音原始账单导入后自动排队重算业绩明细;补齐 10 月最新数据。
2026-11-26 11:53:47 +08:00

58 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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();
}
}
}