From 041e7307b7a213850cae9a658a431d5fc8b163f2 Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 24 May 2026 12:30:39 +0330 Subject: [PATCH] wallet controller withdraw and transactions handled --- .../Controllers/Customer/WalletController.php | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index 652b007..23ed179 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -84,36 +84,44 @@ class WalletController extends Controller } foreach ($records['rows'] as &$record) { - if (empty($record->title) or $record->title == "تعریف نشده"){ - $record->title = $record->type_str ; - $record->unit = "گرم"; - if (isset($record->wallet)) { - $wallet = Wallet::with('product')->where('id',$record->wallet)->first(); - if (isset($wallet->product)) { - if ($record->gold > 0){ - $record->title = " خرید " ; - }else{ - $record->title = " فروش " ; + // اولویت اول: واریز توسط ادمین + // حتی اگر title قبلاً برداشت ریالی ذخیره شده باشد، باید اصلاح شود + if ( + isset($record->withdraw) && + (int) $record->withdraw->sts === 4 + ) { + $record->title = "واریز ریالی"; - } - $record->title .= $wallet->product->title ; - $record->unit = "عدد"; - - } - } - if ( - (int) $record->type === 4 && - isset($record->withdraw) && - (int) $record->withdraw->sts === 4 - ) { - $record->title = "واریز ریالی"; - } else { - $record->title = $record->type_str; - } + // اگر می‌خوای تو دیتابیس هم اصلاح بشه $record->save(); + + continue; } + // بقیه رکوردها فقط اگر title ندارند یا تعریف نشده هستند اصلاح شوند + if (empty($record->title) || $record->title == "تعریف نشده") { + + $record->title = $record->type_str; + $record->unit = "گرم"; + + if (isset($record->wallet)) { + $wallet = Wallet::with('product')->where('id', $record->wallet)->first(); + + if (isset($wallet->product)) { + if ($record->gold > 0) { + $record->title = " خرید "; + } else { + $record->title = " فروش "; + } + + $record->title .= $wallet->product->title; + $record->unit = "عدد"; + } + } + + $record->save(); + } } return response()->json($records);