77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class OrderItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'order_items';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'addons_meta' => 'array',
|
|
];
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Relationships
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class, 'order_id');
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Product::class, 'product_id');
|
|
}
|
|
|
|
public function getProductAttribute(): ?Product
|
|
{
|
|
if ($this->relationLoaded('product')) {
|
|
return $this->getRelation('product');
|
|
}
|
|
|
|
return $this->product()->first();
|
|
}
|
|
|
|
public function pricing()
|
|
{
|
|
return $this->belongsTo(ProductPricings::class, 'product_pricing_id');
|
|
}
|
|
|
|
public function os()
|
|
{
|
|
return $this->belongsTo(Os::class, 'os_id');
|
|
}
|
|
|
|
/** The provisioned service spawned from this order line. */
|
|
public function service()
|
|
{
|
|
return $this->hasOne(Service::class, 'order_item_id');
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Helpers
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function getBillingLabelAttribute(): string
|
|
{
|
|
return match ((int) $this->months) {
|
|
0 => 'Một lần',
|
|
1 => 'Hàng tháng',
|
|
3 => 'Hàng quý',
|
|
6 => 'Nửa năm',
|
|
12 => 'Hàng năm',
|
|
24 => '2 năm',
|
|
36 => '3 năm',
|
|
default => $this->months . ' tháng',
|
|
};
|
|
}
|
|
}
|