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)
This commit is contained in:
130
app/Models/Rd/AiQuotation.php
Normal file
130
app/Models/Rd/AiQuotation.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Rd;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class AiQuotation extends Model
|
||||
{
|
||||
use BelongsToTenant, SoftDeletes;
|
||||
|
||||
protected $table = 'ai_quotations';
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'title',
|
||||
'input_type',
|
||||
'input_text',
|
||||
'input_file_path',
|
||||
'ai_provider',
|
||||
'ai_model',
|
||||
'analysis_result',
|
||||
'quotation_result',
|
||||
'status',
|
||||
'linked_quote_id',
|
||||
'total_dev_cost',
|
||||
'total_monthly_fee',
|
||||
'created_by',
|
||||
'options',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'analysis_result' => 'array',
|
||||
'quotation_result' => 'array',
|
||||
'options' => 'array',
|
||||
'total_dev_cost' => 'decimal:0',
|
||||
'total_monthly_fee' => 'decimal:0',
|
||||
];
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_PROCESSING = 'processing';
|
||||
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
public const STATUS_FAILED = 'failed';
|
||||
|
||||
public static function getStatuses(): array
|
||||
{
|
||||
return [
|
||||
self::STATUS_PENDING => '대기',
|
||||
self::STATUS_PROCESSING => '분석중',
|
||||
self::STATUS_COMPLETED => '완료',
|
||||
self::STATUS_FAILED => '실패',
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
self::STATUS_PENDING => '대기',
|
||||
self::STATUS_PROCESSING => '분석중',
|
||||
self::STATUS_COMPLETED => '완료',
|
||||
self::STATUS_FAILED => '실패',
|
||||
default => $this->status,
|
||||
};
|
||||
}
|
||||
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
self::STATUS_PENDING => 'badge-warning',
|
||||
self::STATUS_PROCESSING => 'badge-info',
|
||||
self::STATUS_COMPLETED => 'badge-success',
|
||||
self::STATUS_FAILED => 'badge-error',
|
||||
default => 'badge-ghost',
|
||||
};
|
||||
}
|
||||
|
||||
public function isCompleted(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
public function isProcessing(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_PROCESSING;
|
||||
}
|
||||
|
||||
// Relations
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(AiQuotationItem::class, 'ai_quotation_id')->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public function getFormattedDevCostAttribute(): string
|
||||
{
|
||||
return number_format((int) $this->total_dev_cost).'원';
|
||||
}
|
||||
|
||||
public function getFormattedMonthlyFeeAttribute(): string
|
||||
{
|
||||
return number_format((int) $this->total_monthly_fee).'원';
|
||||
}
|
||||
}
|
||||
64
app/Models/Rd/AiQuotationItem.php
Normal file
64
app/Models/Rd/AiQuotationItem.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Rd;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AiQuotationItem extends Model
|
||||
{
|
||||
protected $table = 'ai_quotation_items';
|
||||
|
||||
protected $fillable = [
|
||||
'ai_quotation_id',
|
||||
'module_id',
|
||||
'module_code',
|
||||
'module_name',
|
||||
'is_required',
|
||||
'reason',
|
||||
'dev_cost',
|
||||
'monthly_fee',
|
||||
'sort_order',
|
||||
'options',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_required' => 'boolean',
|
||||
'options' => 'array',
|
||||
'dev_cost' => 'decimal:0',
|
||||
'monthly_fee' => 'decimal:0',
|
||||
];
|
||||
|
||||
public function quotation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AiQuotation::class, 'ai_quotation_id');
|
||||
}
|
||||
|
||||
public function module(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(AiQuotationModule::class, 'module_id');
|
||||
}
|
||||
|
||||
public function getFormattedDevCostAttribute(): string
|
||||
{
|
||||
return number_format((int) $this->dev_cost).'원';
|
||||
}
|
||||
|
||||
public function getFormattedMonthlyFeeAttribute(): string
|
||||
{
|
||||
return number_format((int) $this->monthly_fee).'원';
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
88
app/Models/Rd/AiQuotationModule.php
Normal file
88
app/Models/Rd/AiQuotationModule.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user