initial: bootstrap from BukidBountyApp base
This commit is contained in:
54
app/Models/Subscription/Subscription.php
Normal file
54
app/Models/Subscription/Subscription.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Subscription;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class Subscription extends Model
|
||||
{
|
||||
protected ?string $table = 'subscriptions';
|
||||
|
||||
public bool $incrementing = true;
|
||||
|
||||
protected array $fillable = [
|
||||
'hashkey',
|
||||
'user_id',
|
||||
'plan_id',
|
||||
'status',
|
||||
'starts_at',
|
||||
'expires_at',
|
||||
'payment_method',
|
||||
'additional_details',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'starts_at' => 'datetime',
|
||||
'expires_at' => 'datetime',
|
||||
'additional_details' => 'array',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function plan()
|
||||
{
|
||||
return $this->belongsTo(SubscriptionPlan::class, 'plan_id');
|
||||
}
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(SubscriptionInvoice::class, 'subscription_id');
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->status === 'active' && $this->expires_at && $this->expires_at->isFuture();
|
||||
}
|
||||
}
|
||||
45
app/Models/Subscription/SubscriptionInvoice.php
Normal file
45
app/Models/Subscription/SubscriptionInvoice.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Subscription;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class SubscriptionInvoice extends Model
|
||||
{
|
||||
protected ?string $table = 'subscription_invoices';
|
||||
|
||||
public bool $incrementing = true;
|
||||
|
||||
protected array $fillable = [
|
||||
'hashkey',
|
||||
'subscription_id',
|
||||
'user_id',
|
||||
'amount',
|
||||
'status',
|
||||
'paid_at',
|
||||
'payment_method',
|
||||
'payment_reference',
|
||||
'additional_details',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'amount' => 'float',
|
||||
'paid_at' => 'datetime',
|
||||
'additional_details' => 'array',
|
||||
];
|
||||
|
||||
public function subscription()
|
||||
{
|
||||
return $this->belongsTo(Subscription::class, 'subscription_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
45
app/Models/Subscription/SubscriptionPlan.php
Normal file
45
app/Models/Subscription/SubscriptionPlan.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Subscription;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class SubscriptionPlan extends Model
|
||||
{
|
||||
protected ?string $table = 'subscription_plans';
|
||||
|
||||
public bool $incrementing = true;
|
||||
|
||||
protected array $fillable = [
|
||||
'hashkey',
|
||||
'name',
|
||||
'description',
|
||||
'price',
|
||||
'duration_days',
|
||||
'expiry_action',
|
||||
'active',
|
||||
'additional_details',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'active' => 'boolean',
|
||||
'price' => 'float',
|
||||
'duration_days' => 'integer',
|
||||
'additional_details' => 'array',
|
||||
];
|
||||
|
||||
public function subscriptions()
|
||||
{
|
||||
return $this->hasMany(Subscription::class, 'plan_id');
|
||||
}
|
||||
|
||||
public function creator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user