From fe7df1b394d320fe3ff22adaa67608a84260c700 Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 3 Jun 2026 19:41:00 +0330 Subject: [PATCH] fix order error --- .../Single/SingleOrderController.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index bbf5bf7..4787d47 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -123,6 +123,8 @@ class SingleOrderController extends Controller else if ($data['method'] == "gold") { $response['buy'] = $this->processBuyTransactionProductByGold($data, $wallet, $wallet_interface); + } else { + throw new UnprocessableEntityHttpException('روش پرداخت نامعتبر است.'); } } // Check if the user wants to sell else if ($data['direction'] == 2) { @@ -138,6 +140,8 @@ class SingleOrderController extends Controller } // Check if the method is gold else if ($data['method'] == "gold") { $response['sell'] = $this->processSellTransactionProductByGold($data, $wallet, $wallet_interface); + } else { + throw new UnprocessableEntityHttpException('روش پرداخت نامعتبر است.'); } } } else { @@ -173,7 +177,9 @@ class SingleOrderController extends Controller } } // $response['reward'] = $this->give_order_reward($data, $wallet, $wallet_interface); - $response['Notifications'] = $this->sendTransactionNotifications($data, $transactionType); + if (isset($data['order'])) { + $response['Notifications'] = $this->sendTransactionNotifications($data, $transactionType); + } return response()->json([$response, $data]); } @@ -461,17 +467,24 @@ class SingleOrderController extends Controller { $customer = Customer::findOrFail($data['customer_id']); $companyName = $this->Config('name_fa'); + $amount = $data['amount'] ?? ( + isset($data['number'], $data['product']['amount']) + ? $data['number'] * $data['product']['amount'] + : 0 + ); + $totalPrice = $data['total_price'] ?? ($data['payment_amount'] ?? 0); + $productTitle = $data['product']['title'] ?? 'آبشده'; - $message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType {$data['product']['title']} به مقدار " . - "{$data['amount']} گرم به مبلغ " . number_format($data['total_price']) . + $message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType {$productTitle} به مقدار " . + "{$amount} گرم به مبلغ " . number_format($totalPrice) . " ریال کرد. با تشکر، $companyName"; User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) { $this->send($admin->mobile, $message); }); $wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first(); -// $pricePerGram = $data['total_price'] / $data['amount']; - $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$data['amount']}\n" . - "مبلغ کل: " . number_format($data['total_price']) . "\n\n" . +// $pricePerGram = $totalPrice / $amount; + $customerMessage = "$companyName\n$transactionType آبشده\nگرم: {$amount}\n" . + "مبلغ کل: " . number_format($totalPrice) . "\n\n" . "موجودی طلایی: {$wallet->gold}\n" . "مانده ریالی: " . number_format($wallet->cash) . "\n" . $this->Config('app_url');