Update
This commit is contained in:
16
app/Models/PaymentWebhookProcessedLog.php
Normal file
16
app/Models/PaymentWebhookProcessedLog.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentWebhookProcessedLog extends Model
|
||||
{
|
||||
protected $table = 'payment_webhook_processed_logs';
|
||||
|
||||
protected $fillable = [
|
||||
'provider',
|
||||
'log_id',
|
||||
'log_type',
|
||||
];
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class User extends Authenticatable
|
||||
protected function ids(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value, $attributes) => hashids_encode($attributes['id']),
|
||||
get: fn ($value, $attributes) => hashids_encode($attributes['id']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
39
app/Models/UserCredit.php
Normal file
39
app/Models/UserCredit.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class UserCredit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
const TYPE_SUBSCRIPTION = 'subscription';
|
||||
|
||||
const TYPE_ALACARTE = 'alacarte';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'subscription_credits',
|
||||
'alacarte_credits',
|
||||
'spend_subscription_first',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'spend_subscription_first' => 'boolean',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function transactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserCreditTransaction::class, 'user_id', 'user_id')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
}
|
||||
57
app/Models/UserCreditTransaction.php
Normal file
57
app/Models/UserCreditTransaction.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserCreditTransaction extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'credit_type',
|
||||
'operation',
|
||||
'amount',
|
||||
'subscription_balance_after',
|
||||
'alacarte_balance_after',
|
||||
'description',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function userCredit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserCredit::class, 'user_id', 'user_id');
|
||||
}
|
||||
|
||||
public function scopeDeposits($query)
|
||||
{
|
||||
return $query->where('operation', 'deposit');
|
||||
}
|
||||
|
||||
public function scopeSpending($query)
|
||||
{
|
||||
return $query->where('operation', 'spend');
|
||||
}
|
||||
|
||||
public function isCredit(): bool
|
||||
{
|
||||
return $this->amount > 0;
|
||||
}
|
||||
|
||||
public function isDebit(): bool
|
||||
{
|
||||
return $this->amount < 0;
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ class UserUsage extends Model
|
||||
protected function ids(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value, $attributes) => hashids_encode($attributes['id']),
|
||||
get: fn ($value, $attributes) => hashids_encode($attributes['id']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user