This commit is contained in:
2026-07-06 17:06:03 +03:30
parent 0f775d20e8
commit c155d49070
4 changed files with 108 additions and 19 deletions
+52
View File
@@ -260,6 +260,7 @@ class AssetSummaryService
'unit_weight' => $this->productUnitWeightLabel($catalogProduct),
'show_in_assets' => $this->shouldShowInAssets($catalogProduct),
'is_melted' => true,
'is_main_wallet' => true,
'file' => $this->filePayload($catalogProduct),
];
}
@@ -267,6 +268,57 @@ class AssetSummaryService
return $cards;
}
/**
* کارت موجودی یک محصول از assets-summary — منبع واحد با صفحهٔ اصلی و کیف پول.
*/
public function productInventoryCard(int $customerId, int $ownerType, int $productId): ?array
{
$summary = $this->buildForCustomer($customerId, $ownerType);
foreach ($summary['inventory_cards'] as $card) {
if ((int) ($card['product_id'] ?? 0) === $productId) {
return $card;
}
}
return null;
}
/** موجودی نمایشی محصول — همسان با inventory_cards */
public function productDisplayQuantity(int $customerId, int $ownerType, int $productId): float
{
$card = $this->productInventoryCard($customerId, $ownerType, $productId);
if ($card !== null) {
return (float) ($card['quantity'] ?? 0);
}
$wallet = Wallet::query()
->where('owner', $customerId)
->where('owner_type', $ownerType)
->where('product_id', $productId)
->whereNull('fund_id')
->first();
return (float) ($wallet->gold ?? 0);
}
/**
* کیف مؤثر برای برداشت/تحویل فیزیکی — null یعنی کیف اصلی.
*/
public function effectiveProductWalletIdForCustomer(int $customerId, int $ownerType, int $productId): ?int
{
if ($this->configService->isMainWalletProduct($productId)) {
return null;
}
$card = $this->productInventoryCard($customerId, $ownerType, $productId);
if ($card !== null && !empty($card['is_main_wallet'])) {
return null;
}
return $productId;
}
private function resolveMainWallet(Collection $userWallets): ?Wallet
{
return $userWallets->first(