/
home
/
henzagold
/
server
/
app
/
Models
/
File Upload :
llllll
Current File: //home/henzagold/server/app/Models/ProductVariant.php
<?php namespace App\Models; use App\Models\SingleCustomer\PromotionUsed; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; class ProductVariant extends Model { use HasFactory; use SoftDeletes; //protected $connection = 'pgsql'; protected $table = 'products_productvarient'; //static Color_ = 'color as caj'; protected $fillable=[ 'title', 'qty', 'grams', 'percentage_pay', 'product_id_id', 'barcode', 'color', 'width', 'length', 'height', 'rial_pay',//اجرت ریالی (مثلا قیمت سنگ) 'inventory', 'details', 'description', 'meta', 'position', 'requires_shipping', 'taxable', 'is_pre_order', 'is_active', ]; public static $COLOR_STR=[ /* 1=>'سفید', 2=>'زرد', 3=>'شکلاتی', 4=>'رزگلد'*/ [ 'id'=>0, 'title'=>'#d3d2d2/سفید' ], [ 'id'=>1, 'title'=>'#f9daad/زرد' ], [ 'id'=>2, 'title'=>'#e1b69e/شکلاتی' ], [ 'id'=>3, 'title'=>'#bd6845/رزگلد' ], ]; // public static $COLOR_STR=[ // /* 1=>'سفید', // 2=>'زرد', // 3=>'شکلاتی', // 4=>'رزگلد'*/ // [ // 'id'=>0, // 'title'=>'سفید' // ], // [ // 'id'=>1, // 'title'=>'زرد' // ], // [ // 'id'=>2, // 'title'=>'شکلاتی' // ], // [ // 'id'=>3, // 'title'=>'رزگلد' // ], // ]; public static $COLORS=[ 0=>'#d3d2d2/سفید', 1=>'#f9daad/زرد', 2=>'#e1b69e/شکلاتی', 3=>'#bd6845/رزگلد' ]; // public static $COLORS=[ // 0=>'سفید', // 1=>'زرد', // 2=>'شکلاتی', // 3=>'رزگلد' // ]; protected $appends=[ 'price', 'color_str', 'price_with_discount' ]; protected $casts=[ 'is_pre_order'=>'boolean', 'is_active'=>'boolean', 'rial_pay'=>'double', 'percentage_pay'=>'double', 'grams'=>'double' ]; public static $goldPrice=0; public static $dis_product = []; // public static $discount_price=0; // public static $discount_percent=0; public function getColorStrAttribute(){ return Arr::get(self::$COLORS,$this->color, 'نامشخص'); //return "sdfgsdgdfg"; //return Crypt::encrypt($this->product_id); } /* public function __construct() { Log::info("this is Product varient"); }*/ /* public function __construct(array $attributes=[]) { parent::__construct($attributes); Log::info("this is Product varient"); // Not sure if this makes things better //$this->attributeRanks = attribute_ranks(); }*/ public function getPriceAttribute() { //old method /*$temp=($this->percentage_pay+4)/100; $x=self::$goldPrice+(self::$goldPrice* $temp); $price=$x+ ($x * 0.07); $price=$price*$this->grams; $price=$price+$this->rial_pay; return floor($price/1000)*1000;*/ //old method 2 /*$price=$this->grams * self::$goldPrice; $percent_pay=($this->percentage_pay+2+3) / 100; $price = $price + ( $price * $percent_pay); $price = $price + ($price*0.07); $price = $price + ($price*0.09); return floor($price/1000)*1000;*/ //old method /*$price=self::$goldPrice + (self::$goldPrice * ($this->percentage_pay/100)); $price= $price + ( $price * 0.07); $price= $price + ( $price * 0.09); $price = $price * $this->grams; return floor($price/1000)*1000;*/ //new method $price=self::$goldPrice + (self::$goldPrice * ( ($this->percentage_pay+6 ) /100)); $price += ( $price * 0.07); $temp= $price - self::$goldPrice; $temp+= ( $temp * 0.09); $price = self::$goldPrice + $temp; $price *= $this->grams; return floor($price/1000)*1000; /* $temp=($this->percentage_pay+4)/100; $x=self::$goldPrice+(self::$goldPrice*$temp); $y=$x+($x * 0.07); $price=($x+$y)*$this->grams; $price=$price+$this->rial_pay; if($this->qty==0 && $this->is_pre_order) { $percent=$price*0.3; return ceil($percent); } return ceil($price);*/ /*if($this->qty==0 && $this->is_pre_order) { $percent=$price*0.3; return floor($percent/1000)*1000; //return ceil($percent); }*/ } // public function getPriceWithDiscountAttribute() ////// { ////// ////// $dis = PromotionProduct::where('product_id',$this->product_id_id) ////// ->where('active',true) ////// ->where('start_at','<=',now()) ////// ->where('end_at','>=',now()) ////// ->orderBy('discount','desc') ////// ->first(); ////// if (!is_null($dis)){ ////// $used = PromotionUsed::where('customer_id',auth()->id()) ////// ->where('promotion_id',$dis->promotion_id)->first(); ////// if ($dis->use_only && !is_null($used)){ ////// $discount_percent = 0; ////// $discount_price = 0; ////// }else{ ////// if ($dis->type == 1){ ////// $discount_percent = $dis->discount; ////// $discount_price = 0; ////// }else{ ////// $discount_price = $dis -> discount; ////// $discount_percent = 0; ////// } ////// } ////// }else{ ////// $discount_percent = 0; ////// $discount_price = 0; ////// } ////// $price=self::$goldPrice + (self::$goldPrice * ($this->percentage_pay/100)); ////// $price= $price + ( $price * (0.07 - ($discount_percent/100))); ////// $price= $price + ( $price * 0.09); ////// $price = $price * $this->grams; ////// $price -= $price*($discount_price/100); ////// return floor($price/1000)*1000; ////// ////// } public function getPriceWithDiscountAttribute() { $column = array_column(self::$dis_product,'product_id'); $key = array_search($this->product_id_id,$column); if (in_array($this->product_id_id,$column)){ $dis = self::$dis_product[$key]; $used = PromotionUsed::where('customer_id',auth()->id()) ->where('promotion_id',$dis['promotion_id'])->first(); if ($dis['use_only'] && !is_null($used)){ $discount_percent = 0; $discount_price = 0; }else{ if ($dis['type'] == 1){ $discount_percent = $dis['discount']; $discount_price = 0; }else{ $discount_price = $dis['discount']; $discount_percent = 0; } } }else{ $discount_percent = 0; $discount_price = 0; } $price=self::$goldPrice + (self::$goldPrice * ( ($this->percentage_pay+6 ) /100)); $price += ( $price * (0.07 - ($discount_percent/100))); $temp= $price - self::$goldPrice; $temp+= ( $temp * 0.09); $price = self::$goldPrice + $temp; $price *= $this->grams; $price -= $price*($discount_price/100); return floor($price/1000)*1000; // $price=self::$goldPrice + (self::$goldPrice * ($this->percentage_pay/100)); // $price= $price + ( $price * (0.07 - ($discount_percent/100))); // $price= $price + ( $price * 0.09); // $price = $price * $this->grams; // $price -= $price*($discount_price/100); // return floor($price/1000)*1000; /*$price=$this->grams * self::$goldPrice; $percent_pay=($this->percentage_pay) / 100; $price = $price + ( $price * $percent_pay); $price = $price + ($price*0.07); $price = $price + ($price*0.09); return floor($price/1000)*1000;*/ } // public function discount(){ // $dis = PromotionProduct::where('product_variant_id',$this->id)->orderBy('discount_percent','desc') // ->orderBy('discount_price','desc')->first(); // if ($dis->discount_percent >0){ // self::$discount_percent = $dis->discount_percent; // }else{ // self::$discount_price = $dis -> discount_price; // } // } /* public function getColorAttribute($value) { return Arr::get(self::$COLOR_STR, $value, 'Undefined'); }*/ public function product() { return $this->belongsTo('App\Models\Product', 'product_id_id');//->select(['id' , 'image' , Image::$SELECT_FULL]); } public function promotion() { return $this->hasOne('App\Models\PromotionProduct', 'product_variant_id') ->where('active',true) ->where('start_at','<=',now()) ->where('end_at','>=',now()) ->orderBy('discount','desc'); } public function inventory() { return $this->hasMany(InventoryTransaction::class); } public function inventory_branch() { return $this->hasMany(InventoryBranch::class); } }
Copyright ©2k19 -
Hexid
|
Tex7ure