bug fixed
This commit is contained in:
@@ -430,16 +430,44 @@ class Controller extends BaseController
|
||||
return 'گرم';
|
||||
}
|
||||
|
||||
/** مطابق ادمین: وزن «دارد» => amount != 1 ؛ «ندارد» => amount = 1 */
|
||||
/** مطابق ادمین: وزن «دارد» => amount > 0 ؛ «ندارد» => amount = 0 */
|
||||
public static function isMeltedTradeGroup(?string $groupType): bool
|
||||
{
|
||||
$group = trim((string) $groupType);
|
||||
|
||||
return in_array($group, ['آبشده', 'کاتد مس'], true);
|
||||
}
|
||||
|
||||
public static function hasProductUnitWeight(?array $product): bool
|
||||
{
|
||||
if (!$product || !isset($product['amount'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$amount = (float) $product['amount'];
|
||||
if (self::isMeltedTradeGroup($product['group_type'] ?? null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $amount > 0 && $amount !== 1.0;
|
||||
return (float) $product['amount'] > 0;
|
||||
}
|
||||
|
||||
/** ضریب قیمت محصول — بدون وزن قطعه همیشه ۱ */
|
||||
public static function productPriceMultiplier($product): float
|
||||
{
|
||||
$payload = is_array($product) ? $product : [
|
||||
'amount' => is_object($product) ? ($product->amount ?? null) : null,
|
||||
'unit' => is_object($product) ? ($product->unit ?? null) : null,
|
||||
'direct_price' => is_object($product) ? ($product->direct_price ?? null) : null,
|
||||
'group_type' => is_object($product) ? ($product->group_type ?? null) : null,
|
||||
];
|
||||
|
||||
if (!self::hasProductUnitWeight($payload)) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
$amount = (float) ($payload['amount'] ?? 0);
|
||||
|
||||
return $amount > 0 ? $amount : 1.0;
|
||||
}
|
||||
|
||||
public function jibitNcode($nationalCode, $mobile)
|
||||
|
||||
@@ -102,13 +102,13 @@ class CustomerController extends Controller
|
||||
if (!($walletSingle->product->group_type == "سکه")) {
|
||||
$count_silver += self::productLineWeightToGrams($walletSingle->product, $walletSingle->gold);
|
||||
}
|
||||
$count_cash_from_silver += ($walletSingle->product->price * $walletSingle->product->amount) * $walletSingle->gold;
|
||||
$count_cash_from_silver += ($walletSingle->product->price * self::productPriceMultiplier($walletSingle->product)) * $walletSingle->gold;
|
||||
$count_product += $walletSingle->gold;
|
||||
} elseif ($walletSingle->product->metal_id == 3) {
|
||||
if (!($walletSingle->product->group_type == "سکه")) {
|
||||
$count_copper += self::productLineWeightToGrams($walletSingle->product, $walletSingle->gold);
|
||||
}
|
||||
$count_cash_from_copper += ($walletSingle->product->price * $walletSingle->product->amount) * $walletSingle->gold;
|
||||
$count_cash_from_copper += ($walletSingle->product->price * self::productPriceMultiplier($walletSingle->product)) * $walletSingle->gold;
|
||||
$count_product += $walletSingle->gold;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user