CaiWuXiTong/app/Console/Commands/ResolvePinduoduoOpeningBalances.php

61 lines
1.8 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 Illuminate\Console\Command;
use Modules\EcommerceFinance\Services\PinduoduoOpeningBalanceAutoResolver;
use Throwable;
class ResolvePinduoduoOpeningBalances extends Command
{
protected $signature = 'pinduoduo-opening-balances:import
{--store=* : 只补指定店铺,可重复传入}
{--dry-run : 只读取和校验,不写入数据库}';
protected $description = '从聚水潭平台资金账户余额自动补齐拼多多店铺期初余额';
public function handle(PinduoduoOpeningBalanceAutoResolver $resolver): int
{
$stores = array_values(array_filter(array_map(
static fn (mixed $value): string => trim((string) $value),
(array) $this->option('store'),
)));
try {
$result = $resolver->resolve($stores === [] ? null : $stores, (bool) $this->option('dry-run'));
} catch (Throwable $exception) {
report($exception);
$this->error('拼多多店铺期初自动补录失败,详细原因已记录到受保护日志。');
return self::FAILURE;
}
$this->table([
'状态',
'检查店铺',
'自动补齐',
'仍待处理',
'发送提醒',
'处理月份',
], [[
$result['dry_run'] ? 'validated' : 'succeeded',
$result['checked'],
$result['resolved'],
$result['pending'],
$result['alerted'],
implode('、', $result['months']),
]]);
foreach ($result['issues'] as $issue) {
$this->line(sprintf(
'%s(%s):%s',
$issue['store_name'],
$issue['month'],
$issue['reason'],
));
}
return self::SUCCESS;
}
}