/
home
/
old_henza
/
server
/
app
/
Models
/
Major
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Models/Major/Promotion.php
<?php namespace App\Models\Major; use App\DB\Selector; use App\Models\PromotionProduct; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Morilog\Jalali\Jalalian; use Illuminate\Support\Facades\Log; class Promotion extends Model { use HasFactory; use Selector; use SoftDeletes; protected $table = 'major_promotion'; public function scopeActive($query){ return $query->where('is_active',true)->where('type_customer',2)->where('start_at', '<=',Carbon::now())->where('end_at', '>=',Carbon::now()); } public function scopeWeb($query){ return $query->where('is_active',true)->where('type_customer',1)->where('start_at', '<=',Carbon::now())->where('end_at', '>=',Carbon::now()); } protected $fillable=[ 'title', 'description', 'start_at', 'end_at', 'type', 'type_customer', 'discount_percent', 'discount_price', 'is_active', 'use_only', 'show', ]; static $TYPES = [ 1=>"محصول", 2=>"دسته بندی", 3=>"مشتری", 4=>"برند" ]; static $TYPE_CUSTOMER = [ 1=>"تکی", 2=>"عمده", ]; protected $casts=[ 'is_active' => 'boolean', 'use_only' => 'boolean', 'show' => 'boolean' ]; protected $appends=[ 'start_atj', 'end_atj', 'items', ]; public function getStartAtjAttribute() { return Jalalian::forge($this->start_at)->format('Y/n/j', true); } public function getEndAtjAttribute() { return Jalalian::forge($this->end_at)->format('Y/n/j', true); } public static function safeDelete($promotionID){ Promotion::findOrFail($promotionID)->delete(); PromotionItem::where('promotion_id',$promotionID)->delete(); PromotionProduct::where('promotion_id',$promotionID)->delete(); return true; } public function items() { return $this->hasMany('App\Models\Major\PromotionItem','promotion_id'); } public function getItemsAttribute(){ $items=PromotionItem::where('promotion_id',$this->id); if($this->type==3) { $items=$items->where('item_id',auth()->id()); } if($this->use_only==1) { $promtion_item_used=PromotionUsed::where('customer_id',auth()->id()) ->where('promotion_id',$this->id) ->pluck('promotion_item_id'); $items=$items->whereNotIn('id',$promtion_item_used); } return $items->get(); } }
Copyright ©2k19 -
Hexid
|
Tex7ure