fix buy and sell information 2
This commit is contained in:
@@ -305,20 +305,45 @@ class SingleOrderController extends Controller
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$abshode = $this->resolveAbshodeProductContext($data);
|
||||
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0);
|
||||
$buyTransaction = [
|
||||
"cash" => $data['payment_amount'],
|
||||
"gold" => $data['amount'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => $this->meltedOrProductBuyTitle($data),
|
||||
];
|
||||
if ($productId > 0) {
|
||||
$buyTransaction['product_id'] = $productId;
|
||||
$buyTransaction['note'] = 'product_id:' . $productId;
|
||||
$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 = [
|
||||
"cash" => $data['payment_amount'],
|
||||
"gold" => $data['amount'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => $this->meltedOrProductBuyTitle($data),
|
||||
];
|
||||
if ($productId > 0) {
|
||||
$buyTransaction['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);
|
||||
$response['1'] = 2;
|
||||
|
||||
@@ -503,28 +528,63 @@ class SingleOrderController extends Controller
|
||||
$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));
|
||||
}
|
||||
|
||||
$this->assertProviderOrderAccepted($data);
|
||||
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$abshode = $this->resolveAbshodeProductContext($data);
|
||||
$productId = (int) ($data['product_id'] ?? $abshode['id'] ?? 0);
|
||||
$sellTransaction = [
|
||||
"gold" => $goldDebit,
|
||||
"cash" => $data['total_price'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->meltedOrProductSellTitle($data),
|
||||
];
|
||||
if ($productId > 0) {
|
||||
$sellTransaction['product_id'] = $productId;
|
||||
$sellTransaction['note'] = 'product_id:' . $productId;
|
||||
|
||||
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 = [
|
||||
"gold" => $goldDebit,
|
||||
"cash" => $data['total_price'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->meltedOrProductSellTitle($data),
|
||||
];
|
||||
if ($productId > 0) {
|
||||
$sellTransaction['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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user