wallet handling

This commit is contained in:
2026-06-15 11:25:10 +03:30
parent e9ddcacdb6
commit 81dfdbdb96
5 changed files with 30 additions and 22 deletions
@@ -111,8 +111,9 @@ class SingleOrderController extends Controller
$data['price_original'] = $data['price'];
$data['payment_remind'] = 0;
$data['fee'] = $data['difference'];
$wallet_interface = new WalletInterface($data['customer_id'], 2);
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$ownerType = (int) ($customer?->type ?? 2);
$wallet_interface = new WalletInterface($data['customer_id'], $ownerType);
$wallet = $wallet_interface->wallet;
if (!$wallet) {
throw new UnprocessableEntityHttpException('کیف پول یافت نشد.');
}
@@ -668,8 +669,9 @@ class SingleOrderController extends Controller
$data['payment_sts'] = 4;
$data['price_original'] = $data['price'];
$add_sell_price = config('add_sell_price.single');
$wallet_interface = new WalletInterface($data['customer_id'], 2);
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$customer = Customer::findOrFail($data['customer_id']);
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
$data['total_price_original'] = $data['amount'] * $data['price_original'];
$data['payment_remind'] = 0;
$data['fee'] = $add_sell_price;
@@ -732,16 +734,16 @@ class SingleOrderController extends Controller
$this->Send($admin->mobile, $message);
});
$Walet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$companyName = $this->Config('name_fa');
$mainWallet = Wallet::where('owner', $data['customer_id'])
->where('owner_type', $customer->type)
->main()
->first();
$companyurl = $this->Config('app_url');
$weight = $data['amount'];
$totalAmount = $data['total_price'];
$pricePerGram = $totalAmount / $weight;
$goldBalance = $Walet->gold;
$remainingBalance = $Walet->cash;
$pricePerGram = $weight > 0 ? $totalAmount / $weight : 0;
$goldBalance = $mainWallet->gold ?? 0;
$remainingBalance = $mainWallet->cash ?? 0;
$message = "$companyName\n";
$message .= "خرید آبشده\n";