Files
sam-manage/app/Models/Rd/AiQuotationModule.php
김보곤 44f139f757 feat: [rd] AI 견적 엔진 Phase 1 구현
- 모델 3개: AiQuotationModule, AiQuotation, AiQuotationItem
- AiQuotationService: Gemini/Claude 2단계 AI 파이프라인
- RdController: R&D 대시보드 + AI 견적 Blade 화면
- AiQuotationController: AI 견적 API (생성/목록/상세/재분석)
- Blade 뷰: 대시보드, 목록, 생성, 상세, HTMX 테이블
- 라우트: /rd/* (web), /admin/rd/* (api)
2026-03-02 18:16:00 +09:00

89 lines
2.1 KiB
PHP

<?php
namespace App\Models\Rd;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
class AiQuotationModule extends Model
{
use BelongsToTenant;
protected $table = 'ai_quotation_modules';
protected $fillable = [
'tenant_id',
'module_code',
'module_name',
'category',
'description',
'keywords',
'dev_cost',
'monthly_fee',
'is_active',
'sort_order',
'options',
];
protected $casts = [
'keywords' => 'array',
'options' => 'array',
'is_active' => 'boolean',
'dev_cost' => 'decimal:0',
'monthly_fee' => 'decimal:0',
];
public const CATEGORY_BASIC = 'basic';
public const CATEGORY_INDIVIDUAL = 'individual';
public const CATEGORY_ADDON = 'addon';
public static function getCategories(): array
{
return [
self::CATEGORY_BASIC => '기본 패키지',
self::CATEGORY_INDIVIDUAL => '개별 모듈',
self::CATEGORY_ADDON => '부가 옵션',
];
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
/**
* AI 프롬프트에 주입할 활성 모듈 목록 조회
*/
public static function getActiveModulesForPrompt(): array
{
return self::active()
->orderBy('sort_order')
->get()
->map(fn ($m) => [
'module_code' => $m->module_code,
'module_name' => $m->module_name,
'category' => $m->category,
'description' => $m->description,
'keywords' => $m->keywords,
'dev_cost' => (int) $m->dev_cost,
'monthly_fee' => (int) $m->monthly_fee,
])
->toArray();
}
public function getOption(string $key, $default = null)
{
return data_get($this->options, $key, $default);
}
public function setOption(string $key, $value): void
{
$options = $this->options ?? [];
data_set($options, $key, $value);
$this->options = $options;
$this->save();
}
}