chinh sua theo tieu chuan phan mem BDS_1
This commit is contained in:
@@ -42,4 +42,25 @@ class Product extends Model
|
||||
{
|
||||
return $this->hasMany(Appendix::class);
|
||||
}
|
||||
|
||||
public function salesPhases()
|
||||
{
|
||||
return $this->belongsToMany(SalesPhase::class, 'sales_phase_products')
|
||||
->using(SalesPhaseProduct::class)
|
||||
->withPivot('id', 'sale_price', 'land_value', 'foundation_value', 'discount_details', 'status')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function activeSalesPhase()
|
||||
{
|
||||
return $this->salesPhases()
|
||||
->wherePivot('status', 'Còn hàng')
|
||||
->where('sales_phases.status', 'Đang mở bán')
|
||||
->whereDate('sales_phases.start_date', '<=', now())
|
||||
->where(function ($q) {
|
||||
$q->whereNull('sales_phases.end_date')
|
||||
->orWhereDate('sales_phases.end_date', '>=', now());
|
||||
})
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user