- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt - Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder - Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway - Backfill payment_method và ngày đơn hàng còn thiếu - Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\LogsActivity;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Models\ModuleVmware;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, LogsActivity;
|
|
|
|
protected $table = 'orders';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'date' => 'date',
|
|
'paid_at' => 'datetime',
|
|
];
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function discount()
|
|
{
|
|
return $this->belongsTo(Discount::class);
|
|
}
|
|
|
|
/** Line items that make up this order. */
|
|
public function orderItems()
|
|
{
|
|
return $this->hasMany(OrderItem::class, 'order_id');
|
|
}
|
|
|
|
/** First/primary invoice generated from this order (kept for backward compat — an order can have many). */
|
|
public function invoice()
|
|
{
|
|
return $this->hasOne(Invoice::class, 'order_id');
|
|
}
|
|
|
|
/** All invoices billed against this order (initial + renewals) — an order can have many. */
|
|
public function invoices()
|
|
{
|
|
return $this->hasMany(Invoice::class, 'order_id');
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Helpers
|
|
// -------------------------------------------------------------------------
|
|
|
|
/**
|
|
* orders.status là tinyInteger (OrderStatus), không phải chuỗi — bản cũ match 'pending'/
|
|
* 'completed'… nên mọi giá trị đều rơi vào default và hiển thị ra "0", "1", "2".
|
|
*/
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return \App\Enums\Order\OrderStatus::tryFrom((int) $this->status)?->label() ?? 'Không xác định';
|
|
}
|
|
|
|
public function payment()
|
|
{
|
|
return $this->belongsTo(Payment::class, 'payment_method', 'id');
|
|
}
|
|
|
|
public function moduleVmwares()
|
|
{
|
|
return $this->hasMany(ModuleVmware::class, 'order_id');
|
|
}
|
|
|
|
public function vmWare()
|
|
{
|
|
return $this->hasMany(ModuleVmware::class, 'order_id');
|
|
}
|
|
}
|