/
home
/
henzagold
/
server
/
app
/
Models
/
File Upload :
llllll
Current File: /home/henzagold/server/app/Models/Order.php
<?php namespace App\Models; use App\DB\Selector; use App\Models\Major\Cash; 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; use Morilog\Jalali\Jalalian; use Mpdf\Cache; use Ramsey\Uuid\Type\Decimal; class Order extends Model { use HasFactory; use Selector; use SoftDeletes; //protected $dateFormat = 'U'; // protected $dateFormat = "d.m.Y H:i"; public static $SELECT_COLOR = 'sts as color'; public static $SELECT_IMG = 'sts as img'; protected $fillable = [ 'customer_id', 'reagent_id', 'type', 'input', 'output', 'remain', 'w', 'wage', 'city_id', 'price', 'percent', 'sts', 'confirmed', 'rial_input', 'discount', ]; /* protected $casts = [ 'address' => , ];*/ public static $TYPES = [ 1 => 'ثبت سفارش توسط مسئول فروش', 2 => 'ثبت مشتری', ]; /*public static $STS = [ -2 => 'وصول نشده', -1 => 'ثبت سفارش', 1 => 'تایید حسابدار', 3 => 'وصول شده', 4=>'معلق', 5=>'تایید مشتری نشده' ];*/ public static $CONFIRMED = [ 1 => 'تایید شده', 2 => 'در انتظار تایید', ]; public static $STS = [ 0=>"معلق", 1=>"ثبت سفارش", 2=>"تایید مدیر سیستم", 3=>"درحال تامین", 4=>"درحال آماده سازی", 5=>"تحویل مسئول فروش", 6=>"تحویل مشتری", // 7=>"کنسل شده" ]; public static $STS_TAB = [ [ 'id'=>-1, 'title'=>'همگی' ], [ 'id'=>0, 'title'=>'معلق' ], [ 'id'=>1, 'title'=>'ثبت سفارش' ], [ 'id'=>2, 'title'=>'تایید مدیر سیستم' ], [ 'id'=>3, 'title'=>'درحال تامین' ], [ 'id'=>4, 'title'=>'درحال آماده سازی' ], [ 'id'=>5, 'title'=>'تحویل مسئول فروش' ], [ 'id'=>6, 'title'=>'تحویل مشتری' ] ]; public static $STS_COLOR = [ 0=>"#FF5252", 1=>"#f5cb83", 2=>"#f5cb83", 3=>"#f5cb83", 4=>"#f5cb83", 5=>"#f5cb83", 6=>"#4CAF50", ]; protected $appends =[ 'time', 'confirmed_str' ]; public static $STS_IMG = [ 0=>'img/order/order-fail.png', 1=>"img/order/order-open.png", 2=>"img/order/order-open.png", 3=>"img/order/order-open.png", 4=>"img/order/order-open.png", 5=>"img/order/order-open.png", 6=>"img/order/order-closed.png", ]; protected $hidden = [ 'password', 'remember_token', ]; protected $casts = [ //'email_verified_at' => 'datetime', //'created_at' => "datetime:Y-m-d\TH:iPZ", ]; public function items() { return $this->hasMany('App\Models\OrderItem', 'order_id')->with('product'); } public function customer() { return $this->belongsTo('App\Models\Customer', 'customer_id'); } public function scopeMe($query) { return $query->where(function ($qq) { return $qq->where('customer_id', auth()->id()); }); } public function parent() { return $this->belongsTo('App\Models\Customer', 'reagent_id')->with('city'); } public function activity() { return $this->hasMany('App\Models\OrderActivity', 'order_id')->select(['*', OrderActivity::$SELECT_CAJ,OrderActivity::$SELECT_UAJ]); } public function getConfirmedStrAttribute($value) { //if (is_null($value)) return $value; return Arr::get(self::$CONFIRMED, $this->confirmed, ''); } public function getColorAttribute($value) { if (is_null($value)) return $value; return Arr::get(self::$STS_COLOR, $value, '#f5cb83'); } public function getImgAttribute($value) { if (is_null($value)) return $value; return url(Arr::get(self::$STS_IMG, $value, 'img/order/order-open.png')); } public function getInputAttribute($value) { return Utility::round($value); } public function getPercentAttribute($value) { return Utility::round($value); } public function getWageAttribute($value) { return Utility::round($value); } public static function safeDelete($orderID){ Order::findOrFail($orderID)->delete(); OrderItem::where('order_id',$orderID)->delete(); Cash::where('order_id',$orderID)->delete(); OrderActivity::where('order_id',$orderID)->delete(); } public function getWAttribute($value) { return Utility::round($value); } public function getTimeAttribute() { return Jalalian::forge($this->created_at)->format('H:i'); } public function cashe() { return $this->hasOne(Cash::class, 'order_id')->select(['*',Cash::$SELECT_CAJ,Cash::$SELECT_TYPE_STR]); } }
Copyright ©2k19 -
Hexid
|
Tex7ure