fix some bugs

This commit is contained in:
2026-07-18 15:04:08 +03:30
parent 4c7e4fdfde
commit eedde65be6
4 changed files with 94 additions and 29 deletions
+28
View File
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use App\Models\Price;
use App\Models\Product;
use Illuminate\Support\Collection;
use Rooyesh\Wallet\models\Wallet;
/**
* محاسبهٔ موجودی کیف — منبع واحد برای ادمین و APIها.
@@ -42,6 +43,33 @@ class WalletBalanceService
return (float) ($this->lineValue($line, 'gold') ?? 0);
}
/**
* موجودی مؤثر کیف اصلی برای نمایش آبشده =
* gold کیف اصلی + gold کیف‌های legacy محصولات main_wallet_products.
* owner_type در جمع نادیده گرفته می‌شود تا خریدهای قدیمی از دست نروند.
*/
public function effectiveMainWalletGold(int $ownerId): float
{
$mainGold = (float) Wallet::query()
->where('owner', $ownerId)
->whereNull('fund_id')
->whereNull('product_id')
->sum('gold');
$productIds = $this->mainWalletProductIds();
if ($productIds === []) {
return round($mainGold, 3);
}
$orphanedGold = (float) Wallet::query()
->where('owner', $ownerId)
->whereNull('fund_id')
->whereIn('product_id', $productIds)
->sum('gold');
return round($mainGold + $orphanedGold, 3);
}
/**
* جمع طلای قابل‌نمایش: کیف اصلی + کیف محصولات + قلک‌ها.
* کیف‌های legacy محصولات main_wallet_products شمرده نمی‌شوند.