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);
|
$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);
|
||||||
$buyTransaction = [
|
$usesProductWallet = $productId > 0 && !$config->isMainWalletProduct($productId);
|
||||||
"cash" => $data['payment_amount'],
|
|
||||||
"gold" => $data['amount'],
|
if ($usesProductWallet) {
|
||||||
'expire_at' => now(),
|
new TransactionInterface($wallet_interface, [
|
||||||
'active' => true,
|
"cash" => $data['payment_amount'],
|
||||||
'order_id' => $order->id,
|
"product_id" => $productId,
|
||||||
'start_at' => now(),
|
'expire_at' => now(),
|
||||||
'title' => $this->meltedOrProductBuyTitle($data),
|
'active' => true,
|
||||||
];
|
'order_id' => $order->id,
|
||||||
if ($productId > 0) {
|
'start_at' => now(),
|
||||||
$buyTransaction['product_id'] = $productId;
|
'title' => 'برداشت وجه نقد',
|
||||||
$buyTransaction['note'] = 'product_id:' . $productId;
|
], 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);
|
$this->finalizeProviderOrder($data);
|
||||||
$response['1'] = 2;
|
$response['1'] = 2;
|
||||||
|
|
||||||
@@ -503,28 +528,63 @@ 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) {
|
||||||
$sellTransaction = [
|
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||||
"gold" => $goldDebit,
|
new TransactionInterface($wallet_interface_product, [
|
||||||
"cash" => $data['total_price'],
|
"gold" => $goldDebit,
|
||||||
'expire_at' => now(),
|
"product_id" => $productId,
|
||||||
'active' => true,
|
'expire_at' => now(),
|
||||||
'order_id' => $order->id,
|
'active' => true,
|
||||||
'title' => $this->meltedOrProductSellTitle($data),
|
'order_id' => $order->id,
|
||||||
];
|
'start_at' => now(),
|
||||||
if ($productId > 0) {
|
'title' => $this->meltedOrProductSellTitle($data),
|
||||||
$sellTransaction['product_id'] = $productId;
|
], 1, false, false);
|
||||||
$sellTransaction['note'] = 'product_id:' . $productId;
|
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);
|
$this->finalizeProviderOrder($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user