2026-01-27 00:24:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-27 16:23:12 +00:00
|
|
|
namespace Core\Mod\Commerce\Models;
|
2026-01-27 00:24:22 +00:00
|
|
|
|
|
|
|
|
use Core\Mod\Tenant\Models\Workspace;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CouponUsage model for tracking coupon redemptions.
|
|
|
|
|
*
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int $coupon_id
|
|
|
|
|
* @property int $workspace_id
|
|
|
|
|
* @property int $order_id
|
|
|
|
|
* @property float $discount_amount
|
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
|
*/
|
|
|
|
|
class CouponUsage extends Model
|
|
|
|
|
{
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'coupon_id',
|
|
|
|
|
'workspace_id',
|
|
|
|
|
'order_id',
|
|
|
|
|
'discount_amount',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'discount_amount' => 'decimal:2',
|
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
|
|
|
|
|
public function coupon(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Coupon::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function workspace(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Workspace::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function order(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Order::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Boot
|
|
|
|
|
|
|
|
|
|
protected static function boot()
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
|
static::creating(function ($usage) {
|
|
|
|
|
$usage->created_at = now();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|