CaiWuXiTong/app/Console/Commands/SyncKukaPostingMaterialMap.php
chenxi 6dff7620b6 feat(顾家过账): 按款式编码匹配品牌货号 (#1195)
品牌货号改为按款式编码匹配,物料编号继续按聚水潭原始货号匹配;同一款式下多个货号共享品牌货号。
2026-11-16 15:30:20 +08:00

59 lines
2.1 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\Business\KukaPostingBase\KukaPostingMaterialMapSynchronizer;
use Illuminate\Console\Command;
use InvalidArgumentException;
class SyncKukaPostingMaterialMap extends Command
{
protected $signature = 'business-mirror:sync-kuka-posting-material-map
{--company=1 : 公司 ID}
{--period= : 只匹配指定账期,格式 YYYY-MM}
{--dry-run : 只读取和校验,不覆盖镜像}
{--json : 输出 JSON}';
protected $description = '按货号匹配物料编号,并按款式编码匹配品牌货号及货号回退';
public function handle(KukaPostingMaterialMapSynchronizer $synchronizer): int
{
$companyId = (int) $this->option('company');
if ($companyId <= 0) {
throw new InvalidArgumentException('公司 ID 必须为正整数。');
}
$period = trim((string) $this->option('period'));
if ($period !== '' && preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $period) !== 1) {
throw new InvalidArgumentException('账期格式必须为 YYYY-MM。');
}
$result = $synchronizer->sync(
$companyId,
$period === '' ? null : $period,
(bool) $this->option('dry-run'),
);
if ((bool) $this->option('json')) {
$this->line(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
} else {
$this->info(sprintf(
'物料映射%s完成:货号 %d,唯一匹配 %d,未匹配 %d,冲突 %d;直接物料编号 %d,档案条码 %d,品牌SKU %d;页面货号映射 %d(品牌 %d,档案回退 %d)。',
$result['dry_run'] ? '校验' : '同步',
$result['items'],
$result['matched'],
$result['unmatched'],
$result['ambiguous'],
$result['direct'],
$result['archive'],
$result['brand_sku'],
$result['brand_item_mappings'],
$result['brand_sku_mappings'],
$result['archive_item_mappings'],
));
}
return self::SUCCESS;
}
}