added percent in product price 4
This commit is contained in:
@@ -201,7 +201,10 @@ class CartController extends Controller
|
||||
->load('items');
|
||||
}
|
||||
|
||||
$wallet = Wallet::where('owner',auth('customer')->id())->whereNull('fund_id')->whereNull('product_id')
|
||||
$wallet = Wallet::where('owner', auth('customer')->id())
|
||||
->where('owner_type', auth('customer')->user()->type)
|
||||
->whereNull('fund_id')
|
||||
->whereNull('product_id')
|
||||
->first();
|
||||
|
||||
if (!$wallet) {
|
||||
|
||||
@@ -19,6 +19,7 @@ use App\Models\Setting;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\ReferralGiftService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
|
||||
@@ -56,14 +57,20 @@ class CustomerController extends Controller
|
||||
$mainWalletProductIds = app(\App\Services\ConfigService::class)->mainWalletProductIds();
|
||||
|
||||
$treasureGrams = 0;
|
||||
$wallet->wp = Wallet::with('product')->where('owner', $user->id)->get();
|
||||
$wallet->wp = Wallet::with('product')
|
||||
->where('owner', $user->id)
|
||||
->where('owner_type', $user->type)
|
||||
->get();
|
||||
foreach ($wallet->wp as $row) {
|
||||
if ($row->product_id != null && !in_array((int) $row->product_id, $mainWalletProductIds, true)) {
|
||||
$treasureGrams += self::productLineWeightToGrams($row->product, $row->gold);
|
||||
}
|
||||
}
|
||||
|
||||
$goldAbGrams = self::weightToGrams((float) Wallet::where('owner', $user->id)->where('product_id', null)->sum('gold'));
|
||||
$goldAbGrams = self::weightToGrams((float) Wallet::where('owner', $user->id)
|
||||
->where('owner_type', $user->type)
|
||||
->where('product_id', null)
|
||||
->sum('gold'));
|
||||
$userGoldGrams = self::weightToGrams((float) $user->gold);
|
||||
|
||||
$wallet->treasure = round(self::gramsToTradeUnit($treasureGrams), 3);
|
||||
@@ -76,7 +83,10 @@ class CustomerController extends Controller
|
||||
}
|
||||
$wallet->gold_ab = round(self::gramsToTradeUnit($goldAbGrams), 2);
|
||||
|
||||
$user->wallets = Wallet::with(['product'])->where('owner', $user->id)->get() ?? new Wallet();
|
||||
$user->wallets = Wallet::with(['product'])
|
||||
->where('owner', $user->id)
|
||||
->where('owner_type', $user->type)
|
||||
->get() ?? new Wallet();
|
||||
|
||||
$count_gold = 0;
|
||||
$count_silver = 0;
|
||||
@@ -112,7 +122,7 @@ class CustomerController extends Controller
|
||||
$count_cash_from_copper += ($walletSingle->product->price * self::productPriceMultiplier($walletSingle->product)) * $walletSingle->gold;
|
||||
$count_product += $walletSingle->gold;
|
||||
}
|
||||
} else {
|
||||
} elseif ($walletSingle->fund_id === null) {
|
||||
$count_gold += self::weightToGrams((float) $walletSingle->gold);
|
||||
$count_cash_pure += $walletSingle->cash;
|
||||
$wallet->count_cash_wallet = $walletSingle->cash;
|
||||
@@ -133,19 +143,21 @@ class CustomerController extends Controller
|
||||
|
||||
$count_cash_total = $count_cash_from_gold + $count_cash_from_silver + $count_cash_from_copper + $count_cash_pure;
|
||||
|
||||
$wallet->count_cash_wallets = $count_cash_total - $wallet->count_cash_wallet;
|
||||
$mainWalletCash = app(WalletBalanceService::class)->mainWalletCash($user->wallets);
|
||||
$wallet->count_cash_wallet = $mainWalletCash;
|
||||
$wallet->count_cash_wallets = $count_cash_total - $mainWalletCash;
|
||||
$wallet->count_gold = round(self::gramsToTradeUnit($count_gold), 3);
|
||||
$wallet->count_gold_wallets = round($wallet->count_gold - $wallet->count_gold_wallet, 3);
|
||||
$wallet->count_silver = round(self::gramsToTradeUnit($count_silver), 3);
|
||||
$wallet->count_copper = round(self::gramsToTradeUnit($count_copper), 3);
|
||||
$wallet->count_cash = $count_cash_pure;
|
||||
$wallet->count_product = $count_product;
|
||||
$wallet->cash_from_gold = $count_cash_from_gold;
|
||||
$wallet->cash_from_silver = $count_cash_from_silver;
|
||||
$wallet->cash_from_copper = $count_cash_from_copper;
|
||||
$wallet->count_cash_total = $count_cash_total;
|
||||
// cash در پاسخ = موجودی ریالی کیف اصلی (نه کیف legacy محصولات main_wallet_products)
|
||||
$wallet->cash = $count_cash_pure;
|
||||
$wallet->cash = $mainWalletCash;
|
||||
$wallet->count_cash = $mainWalletCash;
|
||||
|
||||
// جمع واقعی طلا از کیفها — همتراز wallet/me و کارت محصول (بدون دوبارهشماری customers.gold)
|
||||
$wallet->gold_sum = round((float) $wallet->count_gold, 2);
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Models\Price;
|
||||
use App\Models\Setting;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Services\AssetSummaryService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use App\Services\ZaarboxPriceService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
@@ -38,25 +39,28 @@ class WalletController extends Controller
|
||||
return response()->json($records);
|
||||
}
|
||||
|
||||
public function walletMe()
|
||||
public function walletMe(WalletBalanceService $balanceService)
|
||||
{
|
||||
$customerId = auth('customer')->id();
|
||||
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
|
||||
$customer = auth('customer')->user();
|
||||
$customerId = (int) $customer->id;
|
||||
$ownerType = (int) $customer->type;
|
||||
|
||||
$wallets = Wallet::query()
|
||||
->where('owner', $customerId)
|
||||
->whereNull('product_id')
|
||||
->whereNull('fund_id')
|
||||
->first();
|
||||
->where('owner_type', $ownerType)
|
||||
->get();
|
||||
|
||||
if (!$wallet) {
|
||||
$wallet = Wallet::select(['owner', 'id', 'gold', 'cash'])
|
||||
->where('owner', $customerId)
|
||||
->whereNull('fund_id')
|
||||
->first() ?? new Wallet();
|
||||
}
|
||||
$mainWallet = $wallets->first(
|
||||
fn (Wallet $row) => $row->fund_id === null && $row->product_id === null
|
||||
);
|
||||
|
||||
$wallet['gold_sum'] = round(Wallet::where('owner', $customerId)->where('product_id', null)->sum('gold'), 2);
|
||||
|
||||
return response()->json($wallet);
|
||||
return response()->json([
|
||||
'owner' => $customerId,
|
||||
'id' => $mainWallet?->id,
|
||||
'gold' => $balanceService->mainWalletGold($wallets),
|
||||
'cash' => $balanceService->mainWalletCash($wallets),
|
||||
'gold_sum' => round($balanceService->totalGoldWeight($wallets), 2),
|
||||
]);
|
||||
}
|
||||
|
||||
public function assetsSummary(AssetSummaryService $assetSummaryService)
|
||||
|
||||
@@ -19,7 +19,8 @@ class AssetSummaryService
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly ConfigService $configService
|
||||
private readonly ConfigService $configService,
|
||||
private readonly WalletBalanceService $walletBalanceService
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ class AssetSummaryService
|
||||
$this->buildInventoryCards($userWallets, $catalogById, $mainWalletProductIds, $mainWallet),
|
||||
);
|
||||
$metalTotals = $this->buildMetalTotals($userWallets, $mainWallet, $metalIds, $weightUnit, $catalogById, $metalsWithProductWallet, $mainWalletProductIds);
|
||||
$cashWallet = (float) ($mainWallet?->cash ?? 0);
|
||||
$cashWallet = $this->walletBalanceService->mainWalletCash($userWallets);
|
||||
$assetsRialValue = $this->sumAssetsRialValue(
|
||||
$metalTotals,
|
||||
$userWallets,
|
||||
|
||||
Reference in New Issue
Block a user