added percent in product price 4

This commit is contained in:
2026-07-05 13:04:00 +03:30
parent 3373bc82ca
commit 694fddc909
4 changed files with 45 additions and 25 deletions
@@ -15,6 +15,7 @@ use App\Models\Price;
use App\Models\Setting;
use App\Http\Controllers\Admin\TahesabController;
use App\Services\AssetSummaryService;
use App\Services\WalletBalanceService;
use App\Services\ZaarboxPriceService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
@@ -38,25 +39,28 @@ class WalletController extends Controller
return response()->json($records);
}
public function walletMe()
public function walletMe(WalletBalanceService $balanceService)
{
$customerId = auth('customer')->id();
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
$customer = auth('customer')->user();
$customerId = (int) $customer->id;
$ownerType = (int) $customer->type;
$wallets = Wallet::query()
->where('owner', $customerId)
->whereNull('product_id')
->whereNull('fund_id')
->first();
->where('owner_type', $ownerType)
->get();
if (!$wallet) {
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
->where('owner', $customerId)
->whereNull('fund_id')
->first() ?? new Wallet();
}
$mainWallet = $wallets->first(
fn (Wallet $row) => $row->fund_id === null && $row->product_id === null
);
$wallet['gold_sum'] = round(Wallet::where('owner', $customerId)->where('product_id', null)->sum('gold'), 2);
return response()->json($wallet);
return response()->json([
'owner' => $customerId,
'id' => $mainWallet?->id,
'gold' => $balanceService->mainWalletGold($wallets),
'cash' => $balanceService->mainWalletCash($wallets),
'gold_sum' => round($balanceService->totalGoldWeight($wallets), 2),
]);
}
public function assetsSummary(AssetSummaryService $assetSummaryService)