75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class CustomersSetting extends Model
|
||
|
|
{
|
||
|
|
use HasFactory,Selector;
|
||
|
|
protected $appends = ['title',];
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
"agent_id",
|
||
|
|
"customer_id",
|
||
|
|
"group",
|
||
|
|
"product_id",
|
||
|
|
"profit_buy",
|
||
|
|
"profit_sell",
|
||
|
|
"credit_buy",
|
||
|
|
"credit_sell",
|
||
|
|
"auto_buy",
|
||
|
|
"auto_sell",
|
||
|
|
"title",
|
||
|
|
"is_active",
|
||
|
|
];
|
||
|
|
protected $casts = [
|
||
|
|
"customer_id" => "integer", // or "string" depending on your needs
|
||
|
|
"group" => "string", // or "integer" if it's a numeric group ID
|
||
|
|
"product_id" => "integer", // or "string"
|
||
|
|
"profit_buy" => "float", // or "decimal:2" for monetary values
|
||
|
|
"profit_sell" => "float", // or "decimal:2"
|
||
|
|
"credit_buy" => "integer", // assuming these are true/false flags
|
||
|
|
"credit_sell" => "integer",
|
||
|
|
"auto_buy" => "boolean",
|
||
|
|
"auto_sell" => "boolean",
|
||
|
|
"is_active" => "boolean",
|
||
|
|
];
|
||
|
|
public function customer()
|
||
|
|
{
|
||
|
|
return $this->hasOne(Customer::class,'id','customer_id');
|
||
|
|
} public function product()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Product::class);
|
||
|
|
}
|
||
|
|
public function agent()
|
||
|
|
{
|
||
|
|
return $this->hasOne(Customer::class,'id','agent_id');
|
||
|
|
}
|
||
|
|
public function getTitleAttribute()
|
||
|
|
{
|
||
|
|
if (array_key_exists('title', $this->attributes) && !is_null($this->attributes['title'])) {
|
||
|
|
return $this->attributes['title'];
|
||
|
|
}
|
||
|
|
|
||
|
|
$t = "نامشخص";
|
||
|
|
|
||
|
|
if (is_null($this->customer_id) && is_null($this->group) && is_null($this->product_id)) {
|
||
|
|
$t = "تنظیمات اصلی برای همه کاربران";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!is_null($this->group)) {
|
||
|
|
$t = "تنظیمات برای گروه " . $this->group;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!is_null($this->customer_id)) {
|
||
|
|
$t = "تنظیمات برای " . ($this->customer->name ?? 'نامشخص');
|
||
|
|
}
|
||
|
|
|
||
|
|
return $t;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|