fix some bugs
This commit is contained in:
@@ -27,17 +27,17 @@ class WalletBalanceService
|
||||
}
|
||||
|
||||
/** @param Collection|array<int, mixed>|null $wallets */
|
||||
public function mainWalletCash(Collection|array|null $wallets): float
|
||||
public function mainWalletCash(Collection|array|null $wallets, ?int $ownerType = null): float
|
||||
{
|
||||
$line = $this->mainWalletLine($wallets);
|
||||
$line = $this->mainWalletLine($wallets, $ownerType);
|
||||
|
||||
return (float) ($this->lineValue($line, 'cash') ?? 0);
|
||||
}
|
||||
|
||||
/** @param Collection|array<int, mixed>|null $wallets */
|
||||
public function mainWalletGold(Collection|array|null $wallets): float
|
||||
public function mainWalletGold(Collection|array|null $wallets, ?int $ownerType = null): float
|
||||
{
|
||||
$line = $this->mainWalletLine($wallets);
|
||||
$line = $this->mainWalletLine($wallets, $ownerType);
|
||||
|
||||
return (float) ($this->lineValue($line, 'gold') ?? 0);
|
||||
}
|
||||
@@ -389,12 +389,21 @@ class WalletBalanceService
|
||||
}
|
||||
|
||||
/** @param Collection|array<int, mixed>|null $wallets */
|
||||
private function mainWalletLine(Collection|array|null $wallets): mixed
|
||||
private function mainWalletLine(Collection|array|null $wallets, ?int $ownerType = null): mixed
|
||||
{
|
||||
foreach ($this->walletLines($wallets) as $line) {
|
||||
if ($this->lineValue($line, 'fund_id') === null && $this->lineValue($line, 'product_id') === null) {
|
||||
return $line;
|
||||
if ($this->lineValue($line, 'fund_id') !== null || $this->lineValue($line, 'product_id') !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($ownerType !== null) {
|
||||
$lineOwnerType = $this->lineValue($line, 'owner_type');
|
||||
if ($lineOwnerType !== null && (int) $lineOwnerType !== $ownerType) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user