From cd182d2f87a20de3cdadc66db7152f5f3e800ac4 Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 9 Jun 2026 13:28:02 +0330 Subject: [PATCH] fix amount 6 --- .../Single/SingleOrderController.php | 62 +++++++++++++++---- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index 6848d74..1ce3d90 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -241,15 +241,19 @@ class SingleOrderController extends Controller throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است'); } $data['order'] = $order = Order::create($data); - new TransactionInterface($wallet_interface, [ + $buyTransaction = [ "cash" => $data['payment_amount'], "gold" => $data['amount'], 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, 'start_at' => now(), - 'title' => self::meltedGoldBuyTitle(), - ], 1, true, false); + 'title' => $this->meltedOrProductBuyTitle($data), + ]; + if (!empty($data['product_id'])) { + $buyTransaction['product_id'] = $data['product_id']; + } + new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false); $response['1'] = 2; //send to provider $this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']); @@ -368,14 +372,18 @@ class SingleOrderController extends Controller throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data)); } $data['order'] = $order = Order::create($data); - new TransactionInterface($wallet_interface, [ + $sellTransaction = [ "gold" => $data['amount'], "cash" => $data['total_price'], 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, - 'title' => self::meltedGoldSellTitle(), - ], 2, false, true); + 'title' => $this->meltedOrProductSellTitle($data), + ]; + if (!empty($data['product_id'])) { + $sellTransaction['product_id'] = $data['product_id']; + } + new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true); //send to Goldir $this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']); @@ -749,18 +757,50 @@ class SingleOrderController extends Controller return null; } + private function productTitleFromData(array $data): ?string + { + $product = $data['product'] ?? null; + if (!$product) { + return null; + } + + if (is_array($product)) { + $title = $product['title'] ?? null; + } else { + $title = $product->title ?? null; + } + + $title = trim((string) $title); + + return $title !== '' ? $title : null; + } + private function isProductOrder(array $data): bool { - return !empty($data['product_id']) && !empty($data['product']['title']); + return !empty($data['product_id']) && $this->productTitleFromData($data) !== null; } private function transactionSubjectTitle(array $data): string { - if ($this->isProductOrder($data)) { - return $data['product']['title']; - } + return $this->productTitleFromData($data) ?? self::meltedGoldLabel(); + } - return self::meltedGoldLabel(); + private function meltedOrProductBuyTitle(array $data): string + { + $productTitle = $this->productTitleFromData($data); + + return $productTitle !== null + ? self::productBuyTitle($productTitle) + : self::meltedGoldBuyTitle(); + } + + private function meltedOrProductSellTitle(array $data): string + { + $productTitle = $this->productTitleFromData($data); + + return $productTitle !== null + ? self::productSellTitle($productTitle) + : self::meltedGoldSellTitle(); } private function insufficientGoldBalanceMessage(array $data): string