fix bug
This commit is contained in:
@@ -319,6 +319,7 @@ class WalletController extends Controller
|
||||
if (!$data['adress'] || $data['adress']->customer_id != $data['customer']->id) {
|
||||
return response()->json(['message' => 'آدرس معتبر نیست یا متعلق به شما نمیباشد'], 403);
|
||||
}
|
||||
$assetSummaryService = app(AssetSummaryService::class);
|
||||
foreach ($data['wallets'] as $key => $wallet) {
|
||||
$data['wallets'][$key]['wallet'] = Wallet::with(["product"])->find($wallet['wallet_id']);
|
||||
if (!$data['wallets'][$key]['wallet']) {
|
||||
@@ -332,16 +333,15 @@ class WalletController extends Controller
|
||||
return response()->json(['message' => 'محصولی در ولت مورد نظر یافت نشد.'], 422);
|
||||
}
|
||||
|
||||
// محصول متصل به کیف اصلی (main_wallet_products): موجودی و تراکنش روی کیف اصلی است
|
||||
$effectiveProductId = self::effectiveProductWalletId((int) $data['wallets'][$key]['wallet']['product_id']);
|
||||
$availableGold = $data['wallets'][$key]['wallet']['gold'];
|
||||
if ($effectiveProductId === null) {
|
||||
$mainWallet = Wallet::where('owner', auth('customer')->id())
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->first();
|
||||
$availableGold = (float) ($mainWallet->gold ?? 0);
|
||||
}
|
||||
$productId = (int) $data['wallets'][$key]['wallet']['product_id'];
|
||||
$customerId = (int) $data['customer']['id'];
|
||||
$ownerType = (int) auth('customer')->user()->type;
|
||||
|
||||
// موجودی و کیف مؤثر — همسان با assets-summary و صفحهٔ اصلی
|
||||
$effectiveProductId = $assetSummaryService
|
||||
->effectiveProductWalletIdForCustomer($customerId, $ownerType, $productId);
|
||||
$availableGold = $assetSummaryService
|
||||
->productDisplayQuantity($customerId, $ownerType, $productId);
|
||||
|
||||
if ($data['wallets'][$key]['value'] > $availableGold){
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user