Files
sam-manage/app/Models/Sales/SalesProspectScenario.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

70 lines
1.7 KiB
PHP

<?php
namespace App\Models\Sales;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SalesProspectScenario extends Model
{
protected $connection = 'codebridge';
protected $table = 'sales_prospect_scenarios';
protected $fillable = [
'prospect_id',
'scenario_type',
'step_id',
'checkpoint_index',
'is_checked',
];
protected $casts = [
'step_id' => 'integer',
'checkpoint_index' => 'integer',
'is_checked' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 가망고객
*/
public function prospect(): BelongsTo
{
return $this->belongsTo(SalesProspect::class, 'prospect_id');
}
/**
* 시나리오 유형 라벨
*/
public function getScenarioTypeLabelAttribute(): string
{
return match ($this->scenario_type) {
'sales' => '영업 시나리오',
'manager' => '매니저 시나리오',
default => $this->scenario_type,
};
}
/**
* 특정 가망고객의 시나리오 진행률 계산
*/
public static function getProgressRate(int $prospectId, string $scenarioType): float
{
$total = self::where('prospect_id', $prospectId)
->where('scenario_type', $scenarioType)
->count();
if ($total === 0) {
return 0;
}
$checked = self::where('prospect_id', $prospectId)
->where('scenario_type', $scenarioType)
->where('is_checked', true)
->count();
return round(($checked / $total) * 100, 1);
}
}