fix amount 6

This commit is contained in:
2026-06-09 13:28:02 +03:30
parent e83afb89d5
commit cd182d2f87
@@ -241,15 +241,19 @@ class SingleOrderController extends Controller
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
}
$data['order'] = $order = Order::create($data);
new TransactionInterface($wallet_interface, [
$buyTransaction = [
"cash" => $data['payment_amount'],
"gold" => $data['amount'],
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'start_at' => now(),
'title' => self::meltedGoldBuyTitle(),
], 1, true, false);
'title' => $this->meltedOrProductBuyTitle($data),
];
if (!empty($data['product_id'])) {
$buyTransaction['product_id'] = $data['product_id'];
}
new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false);
$response['1'] = 2;
//send to provider
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
@@ -368,14 +372,18 @@ class SingleOrderController extends Controller
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
}
$data['order'] = $order = Order::create($data);
new TransactionInterface($wallet_interface, [
$sellTransaction = [
"gold" => $data['amount'],
"cash" => $data['total_price'],
'expire_at' => now(),
'active' => true,
'order_id' => $order->id,
'title' => self::meltedGoldSellTitle(),
], 2, false, true);
'title' => $this->meltedOrProductSellTitle($data),
];
if (!empty($data['product_id'])) {
$sellTransaction['product_id'] = $data['product_id'];
}
new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true);
//send to Goldir
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
@@ -749,18 +757,50 @@ class SingleOrderController extends Controller
return null;
}
private function productTitleFromData(array $data): ?string
{
$product = $data['product'] ?? null;
if (!$product) {
return null;
}
if (is_array($product)) {
$title = $product['title'] ?? null;
} else {
$title = $product->title ?? null;
}
$title = trim((string) $title);
return $title !== '' ? $title : null;
}
private function isProductOrder(array $data): bool
{
return !empty($data['product_id']) && !empty($data['product']['title']);
return !empty($data['product_id']) && $this->productTitleFromData($data) !== null;
}
private function transactionSubjectTitle(array $data): string
{
if ($this->isProductOrder($data)) {
return $data['product']['title'];
}
return $this->productTitleFromData($data) ?? self::meltedGoldLabel();
}
return self::meltedGoldLabel();
private function meltedOrProductBuyTitle(array $data): string
{
$productTitle = $this->productTitleFromData($data);
return $productTitle !== null
? self::productBuyTitle($productTitle)
: self::meltedGoldBuyTitle();
}
private function meltedOrProductSellTitle(array $data): string
{
$productTitle = $this->productTitleFromData($data);
return $productTitle !== null
? self::productSellTitle($productTitle)
: self::meltedGoldSellTitle();
}
private function insufficientGoldBalanceMessage(array $data): string