added merge wallet 2

This commit is contained in:
2026-06-10 17:31:38 +03:30
parent 285767fcd3
commit 95ee496df0
6 changed files with 180 additions and 22 deletions
@@ -275,7 +275,19 @@ class WalletController extends Controller
if (!$data['wallets'][$key]['wallet']['product']) {
return response()->json(['message' => 'محصولی در ولت مورد نظر یافت نشد.'], 422);
}
if ($data['wallets'][$key]['value'] > $data['wallets'][$key]['wallet']['gold']){
// محصول متصل به کیف اصلی (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);
}
if ($data['wallets'][$key]['value'] > $availableGold){
return response()->json([
'message' => "شما به اندازه کافی از {$data['wallets'][$key]['wallet']['product']['title']} ندارید"
], 422);
@@ -288,7 +300,7 @@ class WalletController extends Controller
}
$data['wallets'][$key]['wallet_interface'] = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data['wallets'][$key]['wallet']["product_id"]);
$data['wallets'][$key]['wallet_interface'] = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $effectiveProductId);
}
$data['withdraw'] = new Withdraw(); // Create a new instance of the Withdraw model
$data['withdraw']->note = "برداشت فیزیکی"; // 50 for phisicals