99 lines
2.2 KiB
PHP
99 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Venturecraft\Revisionable\RevisionableTrait;
|
|
|
|
class Order extends Model
|
|
{
|
|
use RevisionableTrait, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
protected $table = 'shop_orders';
|
|
protected $revisionCreationsEnabled = false;
|
|
protected $keepRevisionOf = ['customer_address_id', 'delivery_id', 'payment_type', 'status'];
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function address()
|
|
{
|
|
return $this->belongsTo(CustomerAddress::class, 'customer_address_id');
|
|
}
|
|
|
|
public function delivery_address()
|
|
{
|
|
return $this->belongsTo(CustomerAddress::class, 'customer_delivery_id');
|
|
}
|
|
|
|
public function delivery()
|
|
{
|
|
return $this->belongsTo(Delivery::class);
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
return $this->hasMany(OrderDetail::class);
|
|
}
|
|
|
|
public function invoice()
|
|
{
|
|
return $this->hasOne(Invoice::class);
|
|
}
|
|
|
|
public function sale_channel()
|
|
{
|
|
return $this->belongsTo(SaleChannel::class);
|
|
}
|
|
|
|
public function scopeByUUID($query, $uuid)
|
|
{
|
|
return $query->where('uuid', $uuid);
|
|
}
|
|
|
|
public function scopeByCustomer($query, $customer_id)
|
|
{
|
|
return $query->where('customer_id', $customer_id);
|
|
}
|
|
|
|
public function scopeByDelivery($query, $delivery_id)
|
|
{
|
|
return $query->where('delivery_id', $delivery_id);
|
|
}
|
|
|
|
public function scopePreparation($query)
|
|
{
|
|
return $query->byStatus(1);
|
|
}
|
|
|
|
public function scopeSended($query)
|
|
{
|
|
return $query->byStatus(2);
|
|
}
|
|
|
|
public function scopeReceived($query)
|
|
{
|
|
return $query->byStatus(3);
|
|
}
|
|
|
|
public function scopeByStatus($query, $status)
|
|
{
|
|
return $query->where('status', $status);
|
|
}
|
|
|
|
public function scopeByPaymentType($query, $payment_type)
|
|
{
|
|
return $query->where('payment_type', $payment_type);
|
|
}
|
|
|
|
public function scopeByPeriod($query, $start, $end, $field = 'created_at')
|
|
{
|
|
return $query->whereBetween($field, [$start, $end]);
|
|
}
|
|
}
|