diff --git a/app/Http/Controllers/Api/Admin/Barobill/BarobillConfigController.php b/app/Http/Controllers/Api/Admin/Barobill/BarobillConfigController.php index c19ac817..690639d7 100644 --- a/app/Http/Controllers/Api/Admin/Barobill/BarobillConfigController.php +++ b/app/Http/Controllers/Api/Admin/Barobill/BarobillConfigController.php @@ -235,13 +235,15 @@ public function toggleActive(int $id): JsonResponse /** * barobill_companies에서 barobill_members로 동기화 + * chandj DB(sales 레거시)에서 데이터를 가져와 samdb(MNG)로 동기화 */ public function syncCompanies(): JsonResponse { DB::beginTransaction(); try { - // barobill_companies 테이블에서 데이터 조회 - $companies = DB::table('barobill_companies') + // chandj DB의 barobill_companies 테이블에서 데이터 조회 + $companies = DB::connection('chandj') + ->table('barobill_companies') ->where('is_active', 1) ->whereNotNull('barobill_user_id') ->get(); @@ -300,18 +302,29 @@ public function syncCompanies(): JsonResponse } /** - * barobill_companies 목록 조회 + * barobill_companies 목록 조회 (chandj DB) */ public function getCompanies(): JsonResponse { - $companies = DB::table('barobill_companies') - ->select('id', 'company_name', 'corp_num', 'barobill_user_id', 'ceo_name', 'is_active', 'memo', 'created_at') - ->orderBy('id') - ->get(); + try { + $companies = DB::connection('chandj') + ->table('barobill_companies') + ->select('id', 'company_name', 'corp_num', 'barobill_user_id', 'ceo_name', 'is_active', 'memo', 'created_at') + ->orderBy('id') + ->get(); - return response()->json([ - 'success' => true, - 'data' => $companies, - ]); + return response()->json([ + 'success' => true, + 'data' => $companies, + ]); + } catch (\Exception $e) { + Log::error('chandj DB 연결 실패', ['error' => $e->getMessage()]); + + return response()->json([ + 'success' => false, + 'message' => 'chandj DB 연결에 실패했습니다: ' . $e->getMessage(), + 'data' => [], + ]); + } } } diff --git a/config/database.php b/config/database.php index 53dcae02..138eeb3a 100644 --- a/config/database.php +++ b/config/database.php @@ -63,6 +63,23 @@ ]) : [], ], + // sales 레거시 시스템 DB (chandj) + 'chandj' => [ + 'driver' => 'mysql', + 'host' => env('CHANDJ_DB_HOST', 'sam-mysql-1'), + 'port' => env('CHANDJ_DB_PORT', '3306'), + 'database' => env('CHANDJ_DB_DATABASE', 'chandj'), + 'username' => env('CHANDJ_DB_USERNAME', 'root'), + 'password' => env('CHANDJ_DB_PASSWORD', 'root'), + 'unix_socket' => '', + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => false, + 'engine' => null, + ], + 'mariadb' => [ 'driver' => 'mariadb', 'url' => env('DB_URL'),