import( (string) $this->argument('path'), $this->option('balance-date') === null ? null : (string) $this->option('balance-date'), (string) $this->option('scope'), (bool) $this->option('dry-run'), ); } catch (Throwable $exception) { report($exception); $this->error($exception->getMessage()); return self::FAILURE; } $this->info(sprintf( '%s:%s 共 %d 条,替换原有 %d 条。', $result['dry_run'] ? '校验完成' : '导入完成', $result['balance_date'], $result['total'], $result['replaced'], )); $financeFallbackFailed = false; try { $fallback = $financeFallback->fillMissing( $result['balance_date'], (string) $this->option('scope'), (bool) $result['dry_run'], ); if (! $fallback['supported']) { $this->warn('账单余额回填:当前来源的店铺收款账户账单没有累计账户余额字段,跳过回填。'); } elseif ($fallback['missing'] === 0) { $this->info('账单余额回填:聚水潭余额没有缺失店铺。'); } else { $this->info(sprintf( '账单余额回填:缺失 %d 家,匹配 %d 家,写入 %d 条,仍有 %d 家待补。', $fallback['missing'], $fallback['resolved'], $fallback['filled'], $fallback['unresolved'], )); } } catch (Throwable $exception) { report($exception); $this->error('财务系统店铺收款账户账单余额回填失败,聚水潭余额已保留,财务回填未覆盖。'); $financeFallbackFailed = true; } if (! $result['dry_run']) { $companyIds = StoreReceivingAccount::withoutGlobalScopes() ->whereNull('deleted_at') ->distinct() ->pluck('company_id') ->filter() ->map(static fn (mixed $id): int => (int) $id) ->unique() ->values(); foreach ($companyIds as $companyId) { try { $alerts = $alertSynchronizer->syncLatest($companyId); if ($alerts['created'] > 0 || $alerts['updated'] > 0) { $this->info(sprintf( '余额预警待办:公司 %d 新增 %d 条、更新 %d 条。', $companyId, $alerts['created'], $alerts['updated'], )); } } catch (Throwable $exception) { report($exception); $this->warn("余额预警待办生成失败(公司 {$companyId}),余额快照已保留。"); } } } return $financeFallbackFailed ? self::FAILURE : self::SUCCESS; } }