From b7705c2c955c8b31763006cfc85f59e4447e3237 Mon Sep 17 00:00:00 2001 From: gholak tala Date: Sat, 31 Jan 2026 09:09:32 +0000 Subject: [PATCH] NASER add settings to me api --- .../Customer/CustomerController.php | 12 ++- app/Models/Customer.php | 14 ++++ app/Models/CustomersSetting.php | 74 +++++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 app/Models/CustomersSetting.php diff --git a/app/Http/Controllers/Customer/CustomerController.php b/app/Http/Controllers/Customer/CustomerController.php index 9429bf4..6b50af1 100755 --- a/app/Http/Controllers/Customer/CustomerController.php +++ b/app/Http/Controllers/Customer/CustomerController.php @@ -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); } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 856f04c..682dee9 100755 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -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'); + } } diff --git a/app/Models/CustomersSetting.php b/app/Models/CustomersSetting.php new file mode 100644 index 0000000..ce40d0a --- /dev/null +++ b/app/Models/CustomersSetting.php @@ -0,0 +1,74 @@ + "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; + } + + +}