mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-10-11 03:13:30 -04:00
56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
namespace Modules\WTIALaCarte\Entities;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Modules\WTIJobBoard\Entities\JobRequestCategory;
|
|
|
|
class Alacarte extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = "alacarte";
|
|
protected $guarded = ["id"];
|
|
protected $dates = ['deleted_at'];
|
|
|
|
protected $casts = [
|
|
'price' => 'float',
|
|
'stock' => 'integer',
|
|
'status' => 'boolean',
|
|
];
|
|
|
|
protected $appends = [
|
|
'image_url',
|
|
'final_price'
|
|
];
|
|
|
|
public function category() {
|
|
return $this->belongsTo(JobRequestCategory::class, 'category_id', 'id');
|
|
}
|
|
|
|
public function getImageUrlAttribute()
|
|
{
|
|
return "/public/storage/{$this->image}";
|
|
}
|
|
|
|
public function getFinalPriceAttribute()
|
|
{
|
|
$currentSubscription = auth()->user()->currentSubscription();
|
|
if($currentSubscription) {
|
|
if($currentSubscription->status == 'active'){
|
|
return ($this->price - ($this->price * ($currentSubscription->planPrice->plan->discount / 100) ));
|
|
}
|
|
|
|
if($currentSubscription->status == 'cancelled'){
|
|
$subscription_expired = $currentSubscription->expired_at != null ? \Carbon\Carbon::now()->gt(\Carbon\Carbon::parse($currentSubscription->expired_at)) : true;
|
|
if(!$subscription_expired) {
|
|
return ($this->price - ($this->price * ($currentSubscription->planPrice->plan->discount / 100) ));
|
|
}
|
|
}
|
|
|
|
}
|
|
return $this->price;
|
|
}
|
|
|
|
}
|