142 lines
3.4 KiB
PHP
142 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
|
use App\Traits\Model\HasComments;
|
|
|
|
class Offer extends Model
|
|
{
|
|
use BelongsToThrough, HasComments;
|
|
|
|
protected $guarded = ['id'];
|
|
protected $table = 'shop_offers';
|
|
|
|
public function article()
|
|
{
|
|
return $this->belongsTo(Article::class);
|
|
}
|
|
|
|
public function article_nature()
|
|
{
|
|
return $this->belongsToThrough(ArticleNature::class, Article::class, null, '', [
|
|
'App\Models\Shop\Article' => 'article_id',
|
|
'App\Models\Shop\ArticleNature' => 'article_nature_id',
|
|
]);
|
|
}
|
|
|
|
public function tariff()
|
|
{
|
|
return $this->belongsTo(Tariff::class);
|
|
}
|
|
|
|
public function variation()
|
|
{
|
|
return $this->belongsTo(Variation::class);
|
|
}
|
|
|
|
public function price_lists()
|
|
{
|
|
return $this->hasManyThrough(PriceList::class, Tariff::class, 'id', 'tariff_id', 'id', 'id');
|
|
}
|
|
|
|
public function categories()
|
|
{
|
|
return $this->article->categories();
|
|
}
|
|
|
|
public function tags()
|
|
{
|
|
return $this->article->tags();
|
|
}
|
|
|
|
public function get_price_lists()
|
|
{
|
|
return $this->tariff->price_lists();
|
|
}
|
|
|
|
public function get_price_list_values()
|
|
{
|
|
return $this->tariff->price_lists->price_list_values();
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->byStatus(1)->byTariffActive();
|
|
}
|
|
|
|
public function scopeByArticle($query, $id)
|
|
{
|
|
return $query->where($this->table . '.article_id', $id);
|
|
}
|
|
|
|
public function scopeByArticles($query, $ids)
|
|
{
|
|
return $query->whereIn($this->table . '.article_id', $ids);
|
|
}
|
|
|
|
public function scopeByID($query, $id)
|
|
{
|
|
return $query->where($this->table . '.id', $id);
|
|
}
|
|
|
|
public function scopeByOffer($query, $id)
|
|
{
|
|
return $query->where($this->table . '.id', $id);
|
|
}
|
|
|
|
public function scopeByStatus($query, $id)
|
|
{
|
|
return $query->where($this->table . '.status_id', $id);
|
|
}
|
|
|
|
public function scopeByVariation($query, $id)
|
|
{
|
|
return $query->where($this->table . '.variation_id', $id);
|
|
}
|
|
|
|
public function scopeByArticleNature($query, $article_nature_id)
|
|
{
|
|
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
|
|
$query->byArticleNature($article_nature_id);
|
|
});
|
|
}
|
|
|
|
public function scopeByCategory($query, $category_id)
|
|
{
|
|
return $query->whereHas('article.categories', function ($query) use ($category_id) {
|
|
$query->where('category_id', $category_id);
|
|
});
|
|
}
|
|
|
|
public function scopeByPackage($query, $package_id)
|
|
{
|
|
return $query->whereHas('variation', function ($query) use ($package_id) {
|
|
$query->byPackage($package_id);
|
|
});
|
|
}
|
|
|
|
public function scopeByTag($query, $tag_id)
|
|
{
|
|
return $query->whereHas('article.tags', function ($query) use ($tag_id) {
|
|
$query->where('tag_id', $tag_id);
|
|
});
|
|
}
|
|
|
|
public function scopeByTags($query, $tags)
|
|
{
|
|
return $query->whereHas('article.tags', function ($query) use ($tags) {
|
|
$query->whereIn('tag_id', $tags);
|
|
});
|
|
}
|
|
|
|
public function scopeByTariffActive($query)
|
|
{
|
|
return $query->whereHas('tariff', function ($query) {
|
|
$query->active();
|
|
});
|
|
}
|
|
}
|