fix bug 2

This commit is contained in:
2026-06-11 21:17:40 +03:30
parent 2636df99ad
commit a21dbcf3e1
5 changed files with 95 additions and 4 deletions
@@ -40,11 +40,22 @@ class WalletController extends Controller
public function walletMe()
{
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])->where('owner', auth('customer')->id())
$customerId = auth('customer')->id();
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
->where('owner', $customerId)
->whereNull('product_id')
->whereNull('fund_id')
->first();
// $wallet['gold_sum'] = Wallet::where('owner', auth('customer')->id())->get();
$wallet['gold_sum'] = round(Wallet::where('owner', auth('customer')->id())->where('product_id', null)->sum('gold'), 2);
if (!$wallet) {
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
->where('owner', $customerId)
->whereNull('fund_id')
->first() ?? new Wallet();
}
$wallet['gold_sum'] = round(Wallet::where('owner', $customerId)->where('product_id', null)->sum('gold'), 2);
return response()->json($wallet);
}