command->warn('WX_DEFAULT_APP_CODE / WX_APP_ID 未配置,跳过 WxAppSeeder。'); return; } // 用 firstOrCreate 防重复:已存在相同 code 的记录就只更新 AppID/名称,不动密钥 // 不直接写 app_secret —— 密钥必须经后台加密入库 $row = WxAppModel::where('code', $code)->where('deleted_at', 0)->first(); if (!empty($row)) { $row->update([ 'app_id' => $appId, 'name' => $name !== '' ? $name : $row->name, 'updated_at' => time(), ]); $this->command->info("已更新品牌 [{$code}] 的 AppID 为 {$appId},AppSecret 未改动。"); return; } WxAppModel::create([ 'code' => $code, 'name' => $name, 'app_id' => $appId, 'status' => 0, 'created_at' => time(), 'updated_at' => time(), ]); $this->command->info("已新增品牌 [{$code}] 应用记录,请进后台「小程序应用配置」填写 AppSecret。"); } }