fix some bugs 2

This commit is contained in:
2026-07-21 21:23:26 +03:30
parent fa15b80c42
commit 227534a493
15 changed files with 895 additions and 2 deletions
+38 -2
View File
@@ -40,6 +40,17 @@ class AssetSummaryService
$mainWallet = $this->resolveMainWallet($userWallets);
$metalIds = $this->catalogMetalIds($catalog);
// موجودی کیف اصلی نباید به‌خاطر inactive بودن محصول نماینده از metal_totals حذف شود
if ($customerId > 0) {
$effectiveGold = $this->walletBalanceService->effectiveMainWalletGold($customerId, $ownerType);
if (abs($effectiveGold) >= 0.000001) {
$mainMetalId = $this->walletBalanceService->resolveMainWalletMetalId();
if ($mainMetalId > 0 && !in_array($mainMetalId, $metalIds, true)) {
$metalIds[] = $mainMetalId;
sort($metalIds);
}
}
}
$weightUnit = Controller::tradeWeightUnit();
$hasCountBased = $this->catalogHasCountBased($catalog);
$hasWeightBased = $this->catalogHasWeightBased($catalog);
@@ -478,7 +489,11 @@ class AssetSummaryService
return $group !== '' ? $group : 'آبشده';
}
/** اولین محصولِ لیست main_wallet_products که در کاتالوگ فعال است. */
/**
* اولین محصولِ لیست main_wallet_products.
* اگر در کاتالوگ فیلترشده (مثلاً فقط active) نبود، از DB بدون فیلتر active می‌خواند
* تا موجودی کیف اصلی برای اپ مشتری صفر نشود وقتی محصول نماینده غیرفعال است.
*/
private function resolveMainWalletRepresentative(Collection $catalogById, array $mainWalletProductIds): ?Product
{
foreach ($mainWalletProductIds as $productId) {
@@ -488,6 +503,23 @@ class AssetSummaryService
}
}
if ($mainWalletProductIds === []) {
return null;
}
$byId = Product::query()
->with('file')
->whereIn('id', $mainWalletProductIds)
->get()
->keyBy('id');
foreach ($mainWalletProductIds as $productId) {
$product = $byId->get((int) $productId);
if ($product) {
return $product;
}
}
return null;
}
@@ -668,7 +700,11 @@ class AssetSummaryService
if ($mainWalletProductIds !== []) {
// حالت صریح: کیف اصلی فقط یک‌بار، زیر فلزِ محصول نماینده
$meltedGrams = ($mainWalletMetalId !== null && (int) $metalId === $mainWalletMetalId)
// اگر نماینده پیدا نشد (محصول حذف‌شده)، به فلز resolveMainWalletMetalId برگرد
if ($mainWalletMetalId === null || $mainWalletMetalId <= 0) {
$mainWalletMetalId = $this->walletBalanceService->resolveMainWalletMetalId();
}
$meltedGrams = ((int) $metalId === (int) $mainWalletMetalId)
? $mainWalletGrams
: 0.0;
} else {