NASER add settings to me api

This commit is contained in:
gholak tala
2026-01-31 09:09:32 +00:00
parent b6e8040d82
commit b7705c2c95
3 changed files with 99 additions and 1 deletions
@@ -17,6 +17,7 @@ use Rooyesh\Wallet\models\Wallet;
use Rooyesh\Wallet\models\Transaction;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Http;
use App\Models\Setting;
//use App\Models\Price;
@@ -27,7 +28,8 @@ class CustomerController extends Controller
{
public function me()
{
$user = Customer::findOrFail(auth('customer')->id());
$select = ['*',Customer::$SELECT_CAJ,Customer::$SELECT_TYPE_STR];
$user = Customer::with(['customer_settings.customer',"agent"])->select($select)->findOrFail(auth('customer')->id());
$wallet = Wallet::where('owner', $user->id)
->where('owner_type', $user->type)
@@ -75,6 +77,14 @@ class CustomerController extends Controller
->whereNotNull('product_id') // Filters wallets that have a non-null product_id
->get() ?? new Wallet(); // If no wallet is found, assigns a new Wallet instance to the attribute
$forbiddenWords = ['tahesab', 'token']; // کلمات ممنوعه
$query = Setting::query();
// حذف رکوردهایی که key شامل کلمات ممنوعه است
foreach ($forbiddenWords as $word) {
$query->where('key', 'not like', "%{$word}%");
}$settings = $query->get();
$user->settings= $settings;
return response()->json($user);
}
+14
View File
@@ -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');
}
}
+74
View File
@@ -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;
}
}