From 085237364d31e0a200129f7391aff1f3e1cde979 Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 7 Jun 2026 12:25:32 +0330 Subject: [PATCH] fix deposite and withdraw --- .../Controllers/Admin/WalletController.php | 3 +- app/Http/Controllers/Auth/AuthController.php | 2 +- database/sql/fix_rial_transaction_types.sql | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 database/sql/fix_rial_transaction_types.sql diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index 467b694..854dfb7 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -110,6 +110,7 @@ class WalletController extends Controller "note" => $data['note'], 'sts' => 4, ]); + $type = $deposit ? 3 : 4; new TransactionInterface($wallet_interface, $_inp = [ 'gold' => 0, 'cash' => $data['value'], @@ -117,7 +118,7 @@ class WalletController extends Controller "note" => $data['note'], 'withdraw_id' => $Withdraw->id, 'active' => true - ], 4, true, $deposit, $gold_block); + ], $type, true, $deposit, $gold_block); if($this->Config('send_to_tahesab') == "true"){ try { diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index a25a74e..ce99ceb 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -160,7 +160,7 @@ class AuthController extends Controller if (isset($data['referral_to_id'])) { $referrer = Customer::where('referral_id', $data['referral_to_id'])->first(); if (!$referrer) { - return response()->json(['message' => 'کد نامعتبره'], 422); + return response()->json(['message' => 'کد نامعتبر می باشد'], 422); } } else { if ($this->Config('referral_id') == 'required') { diff --git a/database/sql/fix_rial_transaction_types.sql b/database/sql/fix_rial_transaction_types.sql new file mode 100644 index 0000000..df426c6 --- /dev/null +++ b/database/sql/fix_rial_transaction_types.sql @@ -0,0 +1,46 @@ +-- ============================================================================= +-- اصلاح transaction_type تراکنش‌های ریالی قبلی +-- +-- مشکل: متد charge() در WalletController همیشه type=4 (برداشت ریالی) استفاده می‌کرد +-- حتی وقتی پول مثبت (شارژ) بود. +-- +-- راه‌حل: +-- - cash > 0 و type = 4 → type = 3 (واریز ریالی) +-- - cash < 0 و type = 3 → type = 4 (برداشت ریالی) +-- +-- این اسکریپت idempotent است و چند بار اجرا مشکلی ایجاد نمی‌کند. +-- ============================================================================= + +START TRANSACTION; + +-- ۱) شارژ ریالی که اشتباه type=4 گرفته → اصلاح به type=3 +UPDATE `transactions` +SET `type` = 3, + `updated_at` = NOW() +WHERE `type` = 4 + AND `cash` > 0 + AND `fund_id` IS NULL; + +-- ۲) برداشت ریالی که اشتباه type=3 گرفته → اصلاح به type=4 +UPDATE `transactions` +SET `type` = 4, + `updated_at` = NOW() +WHERE `type` = 3 + AND `cash` < 0 + AND `fund_id` IS NULL; + +-- ۳) گزارش تعداد تغییرات (اختیاری — برای لاگ) +-- SELECT +-- (SELECT COUNT(*) FROM `transactions` WHERE `type` = 3 AND `cash` > 0 AND `fund_id` IS NULL) AS fixed_to_deposit, +-- (SELECT COUNT(*) FROM `transactions` WHERE `type` = 4 AND `cash` < 0 AND `fund_id` IS NULL) AS fixed_to_withdraw; + +COMMIT; + +-- ============================================================================= +-- بعد از اجرا، جدول transactions را چک کنید: +-- SELECT id, type, type_str, cash, note, created_at +-- FROM `transactions` +-- WHERE `fund_id` IS NULL AND `type` IN (3,4) +-- ORDER BY `created_at` DESC +-- LIMIT 20; +-- =============================================================================