fix some bugs
This commit is contained in:
@@ -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 شمرده نمیشوند.
|
||||
|
||||
Reference in New Issue
Block a user