added percent in product price 4

This commit is contained in:
2026-07-05 13:04:00 +03:30
parent 3373bc82ca
commit 694fddc909
4 changed files with 45 additions and 25 deletions
@@ -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);