NASER add settings to me api
This commit is contained in:
@@ -119,5 +119,19 @@ class Customer extends Authenticatable implements JWTSubject
|
||||
return $this->hasMany(Tahesab::class, 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function customer_settings()
|
||||
{
|
||||
return $this->hasMany(CustomersSetting::class, 'agent_id');
|
||||
}
|
||||
|
||||
public function package()
|
||||
{
|
||||
return $this->belongsTo(Package::class);
|
||||
}
|
||||
|
||||
public function agent()
|
||||
{
|
||||
return $this->belongsTo(Customer::class, 'agent_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user