feat: Reimplement order and invoice management with new service and repository layers, introduce compression middleware, and update database schema.
This commit is contained in:
+29
-38
@@ -10,62 +10,53 @@ class Order extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'order';
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
// protected $fillable = [
|
||||
// 'order_num',
|
||||
// 'customer_id',
|
||||
// 'date',
|
||||
// 'payment_id',
|
||||
// 'discount_id',
|
||||
// 'discount_value',
|
||||
// 'invoice_id',
|
||||
// 'user_id',
|
||||
// 'amount',
|
||||
// 'note',
|
||||
// 'client_ip',
|
||||
// 'status'
|
||||
// ];
|
||||
protected $table = 'orders';
|
||||
|
||||
protected $guarded = [];
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Customer::class);
|
||||
}
|
||||
public function discount()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Discount::class);
|
||||
}
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Invoice::class, 'invoice_id', 'id');
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Payment::class, 'payment_method', 'id');
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class);
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function orderItem()
|
||||
public function discount()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\InvoiceItem::class, 'order_items', 'order_id', 'invoice_item_id');
|
||||
return $this->belongsTo(Discount::class);
|
||||
}
|
||||
|
||||
/** Line items that make up this order. */
|
||||
public function orderItems()
|
||||
{
|
||||
return $this->hasMany(OrderItem::class, 'order_id');
|
||||
}
|
||||
|
||||
public function vmWare()
|
||||
/** Invoice generated from this order. */
|
||||
public function invoice()
|
||||
{
|
||||
return $this->hasMany(\App\Models\ModuleVmware::class, 'order_id', 'id');
|
||||
return $this->hasOne(Invoice::class, 'order_id');
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'pending' => 'Chờ xử lý',
|
||||
'processing' => 'Đang xử lý',
|
||||
'completed' => 'Hoàn tất',
|
||||
'cancelled' => 'Đã hủy',
|
||||
default => ucfirst($this->status),
|
||||
};
|
||||
}
|
||||
|
||||
public function payment()
|
||||
{
|
||||
return $this->belongsTo(Payment::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user