option('company')); $month = trim((string) $this->option('month')); if ($month === '') { $month = now('Asia/Shanghai')->subMonthNoOverflow()->format('Y-m'); } if (preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $month) !== 1) { $this->error('账期格式必须为 YYYY-MM。'); return self::FAILURE; } $suppliers = array_values(array_filter(array_map( static fn (mixed $supplier): string => trim((string) $supplier), (array) $this->option('supplier'), ))); if ($suppliers === []) { $suppliers = $statements->uploadedSuppliers($companyId); } $suppliers = array_values(array_unique($suppliers)); sort($suppliers, SORT_NATURAL | SORT_FLAG_CASE); if ($suppliers === []) { $this->info('没有找到已上传对账单的厂家。'); return self::SUCCESS; } $dryRun = (bool) $this->option('dry-run'); $force = (bool) $this->option('force'); $rows = []; $pushed = 0; $failed = 0; $skipped = 0; foreach ($suppliers as $supplier) { if ($dryRun) { $assessment = $zeroDifferenceConfirmations->assess($supplier, $companyId, $month); $status = $assessment['eligible'] ? '可推送' : '不推送'; $reason = $assessment['reason']; $qty = $assessment['qty']; $amount = $assessment['amount']; } else { $result = $zeroDifferenceConfirmations->pushMonth( $supplier, $companyId, $month, null, ! $force, ); $status = match ($result['status']) { 'pushed' => '已推送', 'failed' => '失败', default => '跳过', }; $reason = $result['reason']; $qty = $result['qty']; $amount = $result['amount']; if ($result['status'] === 'pushed') { $pushed++; } elseif ($result['status'] === 'failed') { $failed++; } else { $skipped++; } } $rows[] = [ $supplier, $status, rtrim(rtrim(number_format($qty, 2, '.', ''), '0'), '.'), rtrim(rtrim(number_format($amount, 2, '.', ''), '0'), '.'), $reason, ]; } $this->table(['厂家', '状态', '件数', '货款金额', '说明'], $rows); if ($dryRun) { $this->info("{$month} 检查完成,共 " . count($suppliers) . ' 家;未发送任何消息。'); } else { $this->info("{$month} 处理完成:已推送 {$pushed} 家,跳过 {$skipped} 家,失败 {$failed} 家。"); } return $failed > 0 ? self::FAILURE : self::SUCCESS; } }