From a8dd0071e2cb9d71a9a84d123a2bce4694fa7b50 Mon Sep 17 00:00:00 2001 From: adonis Date: Tue, 9 Jun 2026 11:17:07 +0330 Subject: [PATCH] fix amount 4 --- app/Http/Controllers/Controller.php | 38 +++++++++++++++++-- .../Controllers/Customer/WalletController.php | 14 ++++++- .../Single/SingleOrderController.php | 4 +- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index b92acc5..4dded41 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -270,6 +270,31 @@ class Controller extends BaseController return 'فروش ' . $productTitle; } + public static function mainMetalBuyTitle(): string + { + return self::productBuyTitle(self::metalTypeLabel()); + } + + public static function mainMetalSellTitle(): string + { + return self::productSellTitle(self::metalTypeLabel()); + } + + /** واحد وزن معاملات فلز اصلی — مس: کیلوگرم، طلا: گرم */ + public static function tradeWeightUnit(): string + { + $label = self::metalTypeLabel(); + + return str_contains($label, 'مس') ? 'کیلوگرم' : 'گرم'; + } + + public static function isWeightBasedProductUnit(?string $unit): bool + { + $unit = trim((string) $unit); + + return in_array($unit, ['کیلوگرم', 'گرم'], true); + } + public static function meltedGoldBuyTitle(): string { return 'خرید ' . self::meltedGoldLabel(); @@ -296,6 +321,10 @@ class Controller extends BaseController return false; } + if (self::isWeightBasedProductUnit($product['unit'] ?? null)) { + return false; + } + if (isset($product['direct_price']) && (int) $product['direct_price'] !== 0) { return true; } @@ -310,13 +339,16 @@ class Controller extends BaseController public static function productQuantityUnit(?array $product): string { + $unit = trim((string) ($product['unit'] ?? '')); + if ($unit !== '') { + return $unit; + } + if (self::isCountBasedProduct($product)) { return 'عدد'; } - $unit = trim((string) ($product['unit'] ?? '')); - - return $unit !== '' ? $unit : 'گرم'; + return 'گرم'; } /** مطابق ادمین: وزن «دارد» => amount != 1 ؛ «ندارد» => amount = 1 */ diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index 58ac749..60280d8 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -113,7 +113,11 @@ class WalletController extends Controller } else { $record->title = ($record->gold > 0 ? self::productBuyTitle($wallet->product->title) : self::productSellTitle($wallet->product->title)); } - $record->unit = "عدد"; + $record->unit = self::productQuantityUnit([ + 'unit' => $wallet->product->unit ?? null, + 'direct_price' => $wallet->product->direct_price ?? null, + 'group_type' => $wallet->product->group_type ?? null, + ]); } else { $record->title = $this->resolveMainWalletTransactionTitle($record); } @@ -400,8 +404,10 @@ class WalletController extends Controller $expectedBuy = self::productBuyTitle($productTitle); $expectedSell = self::productSellTitle($productTitle); + $metalBuy = self::mainMetalBuyTitle(); + $metalSell = self::mainMetalSellTitle(); - if ($record->title === $expectedBuy || $record->title === $expectedSell) { + if (in_array($record->title, [$expectedBuy, $expectedSell, $metalBuy, $metalSell], true)) { return; } @@ -470,6 +476,10 @@ class WalletController extends Controller { $product = $record->wallet->product ?? $record->product ?? null; if (!$product) { + if (!empty($record->gold) && empty($record->wallet?->product)) { + $record->unit = self::tradeWeightUnit(); + } + return; } diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index 5afec7a..6848d74 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -336,7 +336,7 @@ class SingleOrderController extends Controller 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, - 'title' => self::productBuyTitle($data['product']['title'] ?? '') + 'title' => self::mainMetalSellTitle(), ], 12, false, true); $wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]); $wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold); @@ -453,7 +453,7 @@ class SingleOrderController extends Controller 'expire_at' => now(), 'active' => true, 'order_id' => $order->id, - 'title' => self::productSellTitle($data['product']['title'] ?? '') + 'title' => self::mainMetalBuyTitle(), ], 12, true, false); $wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold); $wallet_interface_product->wallet->save();