fix some bugs 3
This commit is contained in:
@@ -38,7 +38,10 @@ class OrderController extends Controller
|
|||||||
|
|
||||||
$lastPrice = (float) (Price::latest('created_at')->value('price') ?? 0);
|
$lastPrice = (float) (Price::latest('created_at')->value('price') ?? 0);
|
||||||
|
|
||||||
$goldAmount = app(WalletBalanceService::class)->effectiveMainWalletGold((int) $customerId);
|
$goldAmount = app(WalletBalanceService::class)->effectiveMainWalletGold(
|
||||||
|
(int) $customerId,
|
||||||
|
(int) ($customer->type ?? 2)
|
||||||
|
);
|
||||||
|
|
||||||
$orders = Order::query()
|
$orders = Order::query()
|
||||||
->where('customer_id', $customerId)
|
->where('customer_id', $customerId)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class ProductController extends SuperController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($representativeId !== null) {
|
if ($representativeId !== null) {
|
||||||
$mainWalletGold = $balanceService->effectiveMainWalletGold((int) $user->id);
|
$mainWalletGold = $balanceService->effectiveMainWalletGold((int) $user->id, (int) $user->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
$products = $products->filter(function ($product) use ($mainWalletProductIds, $representativeId) {
|
$products = $products->filter(function ($product) use ($mainWalletProductIds, $representativeId) {
|
||||||
|
|||||||
@@ -271,17 +271,15 @@ class PargarInboundController extends Controller
|
|||||||
$goldInv = isset($data['GoldInv']) ? (float) str_replace('/', '.', (string) $data['GoldInv']) : 0;
|
$goldInv = isset($data['GoldInv']) ? (float) str_replace('/', '.', (string) $data['GoldInv']) : 0;
|
||||||
$rialInv = isset($data['RialInv']) ? (float) str_replace('/', '.', (string) $data['RialInv']) : 0;
|
$rialInv = isset($data['RialInv']) ? (float) str_replace('/', '.', (string) $data['RialInv']) : 0;
|
||||||
|
|
||||||
$wallet = $customer->wallet->where('fund_id', null)->first();
|
// خواندن و نوشتن روی همان کیف اصلی مشتری — نه first() تصادفی
|
||||||
if ($wallet) {
|
$ownerType = (int) ($customer->type ?? 2);
|
||||||
$goldDiff = $goldInv - (float) $wallet->gold;
|
$walletInterface = new WalletInterface($customer->id, $ownerType);
|
||||||
$rialDiff = $rialInv - (float) $wallet->cash;
|
$wallet = $walletInterface->wallet;
|
||||||
} else {
|
|
||||||
$goldDiff = $goldInv;
|
$goldDiff = $goldInv - (float) ($wallet->gold ?? 0);
|
||||||
$rialDiff = $rialInv;
|
$rialDiff = $rialInv - (float) ($wallet->cash ?? 0);
|
||||||
}
|
|
||||||
|
|
||||||
if (abs($goldDiff) >= 0.01 || abs($rialDiff) >= 1) {
|
if (abs($goldDiff) >= 0.01 || abs($rialDiff) >= 1) {
|
||||||
$walletInterface = new WalletInterface($customer->id, 2);
|
|
||||||
new TransactionInterface($walletInterface, [
|
new TransactionInterface($walletInterface, [
|
||||||
'cash' => $rialDiff,
|
'cash' => $rialDiff,
|
||||||
'gold' => $goldDiff,
|
'gold' => $goldDiff,
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ class AssetSummaryService
|
|||||||
$metalsWithProductWallet,
|
$metalsWithProductWallet,
|
||||||
$mainWalletProductIds,
|
$mainWalletProductIds,
|
||||||
$userWallets,
|
$userWallets,
|
||||||
$customerId
|
$customerId,
|
||||||
|
$ownerType
|
||||||
),
|
),
|
||||||
$this->buildInventoryCards($userWallets, $catalogById, $mainWalletProductIds, $mainWallet),
|
$this->buildInventoryCards($userWallets, $catalogById, $mainWalletProductIds, $mainWallet),
|
||||||
);
|
);
|
||||||
@@ -71,7 +72,8 @@ class AssetSummaryService
|
|||||||
$catalogById,
|
$catalogById,
|
||||||
$metalsWithProductWallet,
|
$metalsWithProductWallet,
|
||||||
$mainWalletProductIds,
|
$mainWalletProductIds,
|
||||||
$customerId
|
$customerId,
|
||||||
|
$ownerType
|
||||||
);
|
);
|
||||||
$cashWallet = $this->walletBalanceService->mainWalletCash($userWallets);
|
$cashWallet = $this->walletBalanceService->mainWalletCash($userWallets);
|
||||||
$assetsRialValue = $this->sumAssetsRialValue(
|
$assetsRialValue = $this->sumAssetsRialValue(
|
||||||
@@ -218,12 +220,13 @@ class AssetSummaryService
|
|||||||
array $metalsWithProductWallet = [],
|
array $metalsWithProductWallet = [],
|
||||||
array $mainWalletProductIds = [],
|
array $mainWalletProductIds = [],
|
||||||
Collection $userWallets,
|
Collection $userWallets,
|
||||||
int $customerId = 0
|
int $customerId = 0,
|
||||||
|
int $ownerType = 0
|
||||||
): array {
|
): array {
|
||||||
$cards = [];
|
$cards = [];
|
||||||
$mainWalletGrams = Controller::weightToGrams(
|
$mainWalletGrams = Controller::weightToGrams(
|
||||||
$customerId > 0
|
$customerId > 0
|
||||||
? $this->walletBalanceService->effectiveMainWalletGold($customerId)
|
? $this->walletBalanceService->effectiveMainWalletGold($customerId, $ownerType)
|
||||||
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds)
|
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds)
|
||||||
);
|
);
|
||||||
$assignedMetalIds = [];
|
$assignedMetalIds = [];
|
||||||
@@ -237,9 +240,10 @@ class AssetSummaryService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$mainWalletWeight = $customerId > 0
|
$mainWalletWeight = $customerId > 0
|
||||||
? $this->walletBalanceService->effectiveMainWalletGold($customerId)
|
? $this->walletBalanceService->effectiveMainWalletGold($customerId, $ownerType)
|
||||||
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds);
|
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds);
|
||||||
if ($mainWalletWeight <= 0) {
|
// صفر کامل را نشان نده؛ منفی را نشان بده تا اختلاف موجودی دیده شود
|
||||||
|
if (abs($mainWalletWeight) < 0.000001) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +326,7 @@ class AssetSummaryService
|
|||||||
public function productDisplayQuantity(int $customerId, int $ownerType, int $productId): float
|
public function productDisplayQuantity(int $customerId, int $ownerType, int $productId): float
|
||||||
{
|
{
|
||||||
if ($this->configService->isMainWalletProduct($productId)) {
|
if ($this->configService->isMainWalletProduct($productId)) {
|
||||||
return $this->walletBalanceService->effectiveMainWalletGold($customerId);
|
return $this->walletBalanceService->effectiveMainWalletGold($customerId, $ownerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
$card = $this->productInventoryCard($customerId, $ownerType, $productId);
|
$card = $this->productInventoryCard($customerId, $ownerType, $productId);
|
||||||
@@ -609,7 +613,8 @@ class AssetSummaryService
|
|||||||
Collection $catalogById,
|
Collection $catalogById,
|
||||||
array $metalsWithProductWallet = [],
|
array $metalsWithProductWallet = [],
|
||||||
array $mainWalletProductIds = [],
|
array $mainWalletProductIds = [],
|
||||||
int $customerId = 0
|
int $customerId = 0,
|
||||||
|
int $ownerType = 0
|
||||||
): array {
|
): array {
|
||||||
if ($metalIds === []) {
|
if ($metalIds === []) {
|
||||||
return [];
|
return [];
|
||||||
@@ -617,7 +622,7 @@ class AssetSummaryService
|
|||||||
|
|
||||||
$mainWalletGrams = Controller::weightToGrams(
|
$mainWalletGrams = Controller::weightToGrams(
|
||||||
$customerId > 0
|
$customerId > 0
|
||||||
? $this->walletBalanceService->effectiveMainWalletGold($customerId)
|
? $this->walletBalanceService->effectiveMainWalletGold($customerId, $ownerType)
|
||||||
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds)
|
: $this->effectiveMainWalletGold($userWallets, $mainWallet, $mainWalletProductIds)
|
||||||
);
|
);
|
||||||
$totals = [];
|
$totals = [];
|
||||||
|
|||||||
@@ -46,26 +46,33 @@ class WalletBalanceService
|
|||||||
/**
|
/**
|
||||||
* موجودی مؤثر کیف اصلی برای نمایش آبشده =
|
* موجودی مؤثر کیف اصلی برای نمایش آبشده =
|
||||||
* gold کیف اصلی + gold کیفهای legacy محصولات main_wallet_products.
|
* 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)
|
->where('owner', $ownerId)
|
||||||
->whereNull('fund_id')
|
->whereNull('fund_id')
|
||||||
->whereNull('product_id')
|
->whereNull('product_id');
|
||||||
->sum('gold');
|
if ($ownerType !== null) {
|
||||||
|
$mainQuery->where('owner_type', $ownerType);
|
||||||
|
}
|
||||||
|
$mainGold = (float) $mainQuery->sum('gold');
|
||||||
|
|
||||||
$productIds = $this->mainWalletProductIds();
|
$productIds = $this->mainWalletProductIds();
|
||||||
if ($productIds === []) {
|
if ($productIds === []) {
|
||||||
return round($mainGold, 3);
|
return round($mainGold, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orphanedGold = (float) Wallet::query()
|
$orphanedQuery = Wallet::query()
|
||||||
->where('owner', $ownerId)
|
->where('owner', $ownerId)
|
||||||
->whereNull('fund_id')
|
->whereNull('fund_id')
|
||||||
->whereIn('product_id', $productIds)
|
->whereIn('product_id', $productIds);
|
||||||
->sum('gold');
|
if ($ownerType !== null) {
|
||||||
|
$orphanedQuery->where('owner_type', $ownerType);
|
||||||
|
}
|
||||||
|
$orphanedGold = (float) $orphanedQuery->sum('gold');
|
||||||
|
|
||||||
return round($mainGold + $orphanedGold, 3);
|
return round($mainGold + $orphanedGold, 3);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user