fix buy and sell information 2

This commit is contained in:
2026-07-09 17:47:27 +03:30
parent c43855d844
commit c0c84a9b39
@@ -305,6 +305,30 @@ class SingleOrderController extends Controller
$data['order'] = $order = Order::create($data); $data['order'] = $order = Order::create($data);
$abshode = $this->resolveAbshodeProductContext($data); $abshode = $this->resolveAbshodeProductContext($data);
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0); $productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0);
$usesProductWallet = $productId > 0 && !$config->isMainWalletProduct($productId);
if ($usesProductWallet) {
new TransactionInterface($wallet_interface, [
"cash" => $data['payment_amount'],
"product_id" => $productId,
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
'title' => 'برداشت وجه نقد',
], 12, false, false);
$wallet_interface_product = $this->productWalletInterface($productId);
$this->normalizeProductWalletGold($wallet_interface_product);
new TransactionInterface($wallet_interface_product, [
"gold" => $data['amount'],
"product_id" => $productId,
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
'title' => $this->meltedOrProductBuyTitle($data),
], 1, true, false);
} else {
$buyTransaction = [ $buyTransaction = [
"cash" => $data['payment_amount'], "cash" => $data['payment_amount'],
"gold" => $data['amount'], "gold" => $data['amount'],
@@ -319,6 +343,7 @@ class SingleOrderController extends Controller
$buyTransaction['note'] = 'product_id:' . $productId; $buyTransaction['note'] = 'product_id:' . $productId;
} }
new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false); new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false);
}
$this->finalizeProviderOrder($data); $this->finalizeProviderOrder($data);
$response['1'] = 2; $response['1'] = 2;
@@ -503,15 +528,49 @@ class SingleOrderController extends Controller
$data['total_price'] = $targetCash; $data['total_price'] = $targetCash;
} }
if ($wallet->gold < $goldDebit) { $abshode = $this->resolveAbshodeProductContext($data);
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0);
$usesProductWallet = $productId > 0 && !$config->isMainWalletProduct($productId);
$goldWallet = $wallet;
$wallet_interface_product = null;
if ($usesProductWallet) {
$wallet_interface_product = $this->productWalletInterface($productId);
$goldWallet = $wallet_interface_product->wallet;
if (!$goldWallet) {
throw new UnprocessableEntityHttpException('کیف پول محصول یافت نشد.');
}
}
if ($goldWallet->gold < $goldDebit) {
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data)); throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
} }
$this->assertProviderOrderAccepted($data); $this->assertProviderOrderAccepted($data);
$data['order'] = $order = Order::create($data); $data['order'] = $order = Order::create($data);
$abshode = $this->resolveAbshodeProductContext($data);
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0); if ($usesProductWallet) {
$this->normalizeProductWalletGold($wallet_interface_product);
new TransactionInterface($wallet_interface_product, [
"gold" => $goldDebit,
"product_id" => $productId,
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
'title' => $this->meltedOrProductSellTitle($data),
], 1, false, false);
new TransactionInterface($wallet_interface, [
"cash" => $data['total_price'],
"product_id" => $productId,
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
'title' => 'واریز وجه نقد',
], 12, false, true);
} else {
$sellTransaction = [ $sellTransaction = [
"gold" => $goldDebit, "gold" => $goldDebit,
"cash" => $data['total_price'], "cash" => $data['total_price'],
@@ -525,6 +584,7 @@ class SingleOrderController extends Controller
$sellTransaction['note'] = 'product_id:' . $productId; $sellTransaction['note'] = 'product_id:' . $productId;
} }
new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true); new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true);
}
$this->finalizeProviderOrder($data); $this->finalizeProviderOrder($data);
} }