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