Files
sam-manage/app/Models/System/AiPricingConfig.php
김보곤 8291cdc39b feat: [database] codebridge DB 분리 - 118개 MNG 전용 테이블 connection 설정
- config/database.php에 codebridge connection 추가
- 78개 MNG 전용 모델에 $connection = 'codebridge' 설정
  - Admin (15): PM, 로드맵, API Explorer
  - Sales (16): 영업파트너, 수수료, 가망고객
  - Finance (9): 법인카드, 자금관리, 홈택스
  - Barobill (12): 은행/카드 동기화 관리
  - Interview (1), ESign (6), Equipment (2)
  - AI (3), Audit (3), 기타 (11)
2026-03-07 11:31:27 +09:00

69 lines
1.8 KiB
PHP

<?php
namespace App\Models\System;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class AiPricingConfig extends Model
{
protected $connection = 'codebridge';
protected $table = 'ai_pricing_configs';
protected $fillable = [
'provider',
'model_name',
'input_price_per_million',
'output_price_per_million',
'unit_price',
'unit_description',
'exchange_rate',
'is_active',
'description',
];
protected $casts = [
'input_price_per_million' => 'decimal:4',
'output_price_per_million' => 'decimal:4',
'unit_price' => 'decimal:6',
'exchange_rate' => 'decimal:2',
'is_active' => 'boolean',
];
/**
* 활성 단가 설정 조회 (캐시 적용)
*/
public static function getActivePricing(string $provider): ?self
{
return Cache::remember("ai_pricing_{$provider}", 3600, function () use ($provider) {
return self::where('provider', $provider)
->where('is_active', true)
->first();
});
}
/**
* 환율 조회 (첫 번째 활성 레코드 기준)
*/
public static function getExchangeRate(): float
{
return Cache::remember('ai_pricing_exchange_rate', 3600, function () {
$config = self::where('is_active', true)->first();
return $config ? (float) $config->exchange_rate : 1400.0;
});
}
/**
* 캐시 초기화
*/
public static function clearCache(): void
{
$providers = ['gemini', 'claude', 'google-stt', 'google-gcs'];
foreach ($providers as $provider) {
Cache::forget("ai_pricing_{$provider}");
}
Cache::forget('ai_pricing_exchange_rate');
}
}