argument('file'); if (! is_file($path) || filesize($path) > 2 * 1024 * 1024) throw new RuntimeException('配置文件不存在或超过 2MB。'); $rows = json_decode(file_get_contents($path), true, 32, JSON_THROW_ON_ERROR); if (! is_array($rows) || ! array_is_list($rows) || count($rows) > 10000) throw new RuntimeException('配置文件必须是最多 10000 条的数组。'); \App\Models\Common\Company::findOrFail((int) $this->option('company'))->makeCurrent(true); $result = $matcher->match($store->groups(), $rows); $this->line('名称匹配:' . count($result['robots']) . ';未匹配:' . count($result['unmatched']) . ';有歧义:' . count($result['ambiguous'])); foreach ($result['robots'] as $name => $robot) $this->line($name . ' → ' . ($robot['group_name'] ?: '工作平台已配置群') . '(配置 ' . $robot['source_id'] . ')'); $this->line('未匹配:' . implode('、', $result['unmatched'])); $this->line('有歧义:' . implode('、', $result['ambiguous'])); if (! $this->option('apply')) return self::SUCCESS; $backup = 'private/courier-robot-backups/' . now()->format('Ymd-His') . '-' . bin2hex(random_bytes(4)) . '.enc'; $backedUp = Storage::disk('local')->put($backup, Crypt::encryptString(json_encode([ 'company_id' => (int) $this->option('company'), 'value' => setting('supplier_reconciliation.dingtalk_robots', []), ], JSON_THROW_ON_ERROR))); if (! $backedUp || ! chmod(Storage::disk('local')->path($backup), 0600)) { throw new RuntimeException('原配置备份失败,未修改机器人配置。'); } $notifier->importCourierRobots($result['robots']); $this->info('已保存 ' . count($result['robots']) . ' 家;原配置已加密备份:' . $backup . ';未发送消息。'); return self::SUCCESS; } }