- config/services.php에 barobill 설정 등록 (운영/테스트 모드 분기 정상화) - BarobillSetting 모델에 BelongsToTenant 적용 및 use_* 필드 casts 추가 - BarobillService API URL을 baroservice.com(SOAP)으로 수정 - BarobillService callApi 메서드 경로 하드코딩 제거 (서비스별 분기) - BarobillService 예외 이중 래핑 문제 수정 - BarobillController URL 메서드 중복 코드 제거 - 누락 모델 16개 생성 (MNG 패턴 준수, BelongsToTenant 적용) - 바로빌 전 테이블 options JSON 컬럼 추가 마이그레이션
83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Barobill;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class BarobillPricingPolicy extends Model
|
|
{
|
|
protected $table = 'barobill_pricing_policies';
|
|
|
|
public const TYPE_CARD = 'card';
|
|
|
|
public const TYPE_TAX_INVOICE = 'tax_invoice';
|
|
|
|
public const TYPE_BANK_ACCOUNT = 'bank_account';
|
|
|
|
protected $fillable = [
|
|
'service_type',
|
|
'name',
|
|
'description',
|
|
'free_quota',
|
|
'free_quota_unit',
|
|
'additional_unit',
|
|
'additional_unit_label',
|
|
'additional_price',
|
|
'is_active',
|
|
'sort_order',
|
|
];
|
|
|
|
protected $casts = [
|
|
'free_quota' => 'integer',
|
|
'additional_unit' => 'integer',
|
|
'additional_price' => 'integer',
|
|
'is_active' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
];
|
|
|
|
// =========================================================================
|
|
// 스코프
|
|
// =========================================================================
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
// =========================================================================
|
|
// 헬퍼 메서드
|
|
// =========================================================================
|
|
|
|
public static function getByServiceType(string $serviceType): ?self
|
|
{
|
|
return static::active()->where('service_type', $serviceType)->first();
|
|
}
|
|
|
|
public static function getAllActive()
|
|
{
|
|
return static::active()->orderBy('sort_order')->get();
|
|
}
|
|
|
|
public function getServiceTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->service_type) {
|
|
self::TYPE_CARD => '카드조회',
|
|
self::TYPE_TAX_INVOICE => '전자세금계산서',
|
|
self::TYPE_BANK_ACCOUNT => '계좌조회',
|
|
default => $this->service_type,
|
|
};
|
|
}
|
|
|
|
public function calculateBilling(int $usageCount): int
|
|
{
|
|
if ($usageCount <= $this->free_quota) {
|
|
return 0;
|
|
}
|
|
|
|
$excess = $usageCount - $this->free_quota;
|
|
$units = (int) ceil($excess / max($this->additional_unit, 1));
|
|
|
|
return $units * $this->additional_price;
|
|
}
|
|
}
|