fix bug 22/4 2
This commit is contained in:
@@ -417,7 +417,7 @@ class WalletController extends Controller
|
||||
return response()->json($Withdraw);
|
||||
}
|
||||
|
||||
private function formatGramsNumber(float $value): string
|
||||
private function formatDeliveryQuantity(float $value): string
|
||||
{
|
||||
$rounded = round($value, 3);
|
||||
if (fmod($rounded, 1.0) === 0.0) {
|
||||
@@ -466,7 +466,7 @@ class WalletController extends Controller
|
||||
$availableGold = $assetSummaryService
|
||||
->productDisplayQuantity($customerId, $ownerType, $productId);
|
||||
|
||||
// گیت تحویل فیزیکی per-product — سوییچ محصول و حداقل گرم
|
||||
// گیت تحویل فیزیکی per-product — سوییچ محصول و حداقل مقدار (به واحد خود محصول)
|
||||
$walletProduct = $data['wallets'][$key]['wallet']['product'];
|
||||
if (Product::hasPhysicalDeliveryColumns() && !$walletProduct->physicalDeliveryEnabled()) {
|
||||
return response()->json([
|
||||
@@ -474,20 +474,22 @@ class WalletController extends Controller
|
||||
], 422);
|
||||
}
|
||||
|
||||
$minDeliveryGrams = Product::hasPhysicalDeliveryColumns()
|
||||
? $walletProduct->minPhysicalDeliveryGrams()
|
||||
$minDeliveryQuantity = Product::hasPhysicalDeliveryColumns()
|
||||
? $walletProduct->minPhysicalDeliveryQuantity()
|
||||
: 0.0;
|
||||
if ($minDeliveryGrams > 0) {
|
||||
if ($minDeliveryQuantity > 0) {
|
||||
// موجودی و حداقل هر دو با واحد خود محصول سنجیده میشوند:
|
||||
// تعدادی → عدد، وزنی → گرم/کیلوگرم (همسان با inventory_cards)
|
||||
$card = $assetSummaryService->productInventoryCard($customerId, $ownerType, $productId);
|
||||
$isCount = ($card['display_type'] ?? null) === 'count';
|
||||
$unitWeight = (float) ($walletProduct['amount'] ?? 0);
|
||||
$availableGrams = $isCount ? $availableGold * $unitWeight : $availableGold;
|
||||
$unitLabel = $card['unit'] ?? Controller::productQuantityUnit(
|
||||
Controller::productUnitPayload($walletProduct)
|
||||
);
|
||||
|
||||
if ($availableGrams + 0.0001 < $minDeliveryGrams) {
|
||||
$remaining = max(0, $minDeliveryGrams - $availableGrams);
|
||||
if ($availableGold + 0.0001 < $minDeliveryQuantity) {
|
||||
$remaining = max(0, $minDeliveryQuantity - $availableGold);
|
||||
return response()->json([
|
||||
'message' => $this->formatGramsNumber($remaining)
|
||||
. " گرم مانده تا رسیدن به حداقل تحویل فیزیکی "
|
||||
'message' => $this->formatDeliveryQuantity($remaining)
|
||||
. " {$unitLabel} مانده تا رسیدن به حداقل تحویل فیزیکی "
|
||||
. "{$walletProduct['title']}"
|
||||
], 422);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user