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('موجودی شما کمتر از میزان سفارش است'); throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
} }
$data['order'] = $order = Order::create($data); $data['order'] = $order = Order::create($data);
new TransactionInterface($wallet_interface, [ $buyTransaction = [
"cash" => $data['payment_amount'], "cash" => $data['payment_amount'],
"gold" => $data['amount'], "gold" => $data['amount'],
'expire_at' => now(), 'expire_at' => now(),
'active' => true, 'active' => true,
'order_id' => $order->id, 'order_id' => $order->id,
'start_at' => now(), 'start_at' => now(),
'title' => self::meltedGoldBuyTitle(), 'title' => $this->meltedOrProductBuyTitle($data),
], 1, true, false); ];
if (!empty($data['product_id'])) {
$buyTransaction['product_id'] = $data['product_id'];
}
new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false);
$response['1'] = 2; $response['1'] = 2;
//send to provider //send to provider
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']); $this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
@@ -368,14 +372,18 @@ class SingleOrderController extends Controller
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data)); throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
} }
$data['order'] = $order = Order::create($data); $data['order'] = $order = Order::create($data);
new TransactionInterface($wallet_interface, [ $sellTransaction = [
"gold" => $data['amount'], "gold" => $data['amount'],
"cash" => $data['total_price'], "cash" => $data['total_price'],
'expire_at' => now(), 'expire_at' => now(),
'active' => true, 'active' => true,
'order_id' => $order->id, 'order_id' => $order->id,
'title' => self::meltedGoldSellTitle(), 'title' => $this->meltedOrProductSellTitle($data),
], 2, false, true); ];
if (!empty($data['product_id'])) {
$sellTransaction['product_id'] = $data['product_id'];
}
new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true);
//send to Goldir //send to Goldir
$this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']); $this->sendProviderOrder($data, $wallet_interface, (int) $data['direction']);
@@ -749,18 +757,50 @@ class SingleOrderController extends Controller
return null; 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 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 private function transactionSubjectTitle(array $data): string
{ {
if ($this->isProductOrder($data)) { return $this->productTitleFromData($data) ?? self::meltedGoldLabel();
return $data['product']['title']; }
}
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 private function insufficientGoldBalanceMessage(array $data): string