fix some bugs 3
This commit is contained in:
@@ -46,26 +46,33 @@ class WalletBalanceService
|
||||
/**
|
||||
* موجودی مؤثر کیف اصلی برای نمایش آبشده =
|
||||
* gold کیف اصلی + gold کیفهای legacy محصولات main_wallet_products.
|
||||
* owner_type در جمع نادیده گرفته میشود تا خریدهای قدیمی از دست نروند.
|
||||
*
|
||||
* @param int|null $ownerType اگر داده شود فقط همان owner_type جمع میشود (همتراز wallet/me).
|
||||
*/
|
||||
public function effectiveMainWalletGold(int $ownerId): float
|
||||
public function effectiveMainWalletGold(int $ownerId, ?int $ownerType = null): float
|
||||
{
|
||||
$mainGold = (float) Wallet::query()
|
||||
$mainQuery = Wallet::query()
|
||||
->where('owner', $ownerId)
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->sum('gold');
|
||||
->whereNull('product_id');
|
||||
if ($ownerType !== null) {
|
||||
$mainQuery->where('owner_type', $ownerType);
|
||||
}
|
||||
$mainGold = (float) $mainQuery->sum('gold');
|
||||
|
||||
$productIds = $this->mainWalletProductIds();
|
||||
if ($productIds === []) {
|
||||
return round($mainGold, 3);
|
||||
}
|
||||
|
||||
$orphanedGold = (float) Wallet::query()
|
||||
$orphanedQuery = Wallet::query()
|
||||
->where('owner', $ownerId)
|
||||
->whereNull('fund_id')
|
||||
->whereIn('product_id', $productIds)
|
||||
->sum('gold');
|
||||
->whereIn('product_id', $productIds);
|
||||
if ($ownerType !== null) {
|
||||
$orphanedQuery->where('owner_type', $ownerType);
|
||||
}
|
||||
$orphanedGold = (float) $orphanedQuery->sum('gold');
|
||||
|
||||
return round($mainGold + $orphanedGold, 3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user