fix amount 4
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user