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
@@ -160,7 +160,13 @@ class ProductController extends SuperController
$products = Product::with(['file'])->where('active', 1)->get();
if (str_contains(request()->path(), '/customer/')) {
app(ProductDisplayPriceService::class)->enrichForApi($products);
$displayPriceService = app(ProductDisplayPriceService::class);
$displayPriceService->enrichForApi($products);
$products->each(function (Product $product) use ($displayPriceService) {
if (!$displayPriceService->hasCustomerDisplayPrice($product)) {
$product->setAttribute('show', false);
}
});
}
if (Product::hasPriceOffsetColumn() && str_contains(request()->path(), '/customer/')) {
@@ -132,6 +132,8 @@ class CustomerController extends Controller
$wallet->cash_from_silver = $count_cash_from_silver;
$wallet->cash_from_copper = $count_cash_from_copper;
$wallet->count_cash_total = $count_cash_total;
// cash در پاسخ = موجودی ریالی کیف اصلی (نه کیف legacy محصولات main_wallet_products)
$wallet->cash = $count_cash_pure;
// جمع واقعی طلا از کیف‌ها — هم‌تراز wallet/me و کارت محصول (بدون دوباره‌شماری customers.gold)
$wallet->gold_sum = round((float) $wallet->count_gold, 2);
@@ -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);
}