fix amount 7
This commit is contained in:
@@ -241,6 +241,7 @@ class SingleOrderController extends Controller
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$abshode = $this->resolveAbshodeProductContext($data);
|
||||
$buyTransaction = [
|
||||
"cash" => $data['payment_amount'],
|
||||
"gold" => $data['amount'],
|
||||
@@ -248,10 +249,13 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => $this->meltedOrProductBuyTitle($data),
|
||||
'title' => $abshode['title'] !== ''
|
||||
? self::productBuyTitle($abshode['title'])
|
||||
: self::meltedGoldBuyTitle(),
|
||||
];
|
||||
if (!empty($data['product_id'])) {
|
||||
$buyTransaction['product_id'] = $data['product_id'];
|
||||
if ($abshode['id'] > 0) {
|
||||
$buyTransaction['product_id'] = $abshode['id'];
|
||||
$buyTransaction['note'] = 'product_id:' . $abshode['id'];
|
||||
}
|
||||
new TransactionInterface($wallet_interface, $buyTransaction, 1, true, false);
|
||||
$response['1'] = 2;
|
||||
@@ -372,16 +376,20 @@ class SingleOrderController extends Controller
|
||||
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
|
||||
}
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$abshode = $this->resolveAbshodeProductContext($data);
|
||||
$sellTransaction = [
|
||||
"gold" => $data['amount'],
|
||||
"cash" => $data['total_price'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->meltedOrProductSellTitle($data),
|
||||
'title' => $abshode['title'] !== ''
|
||||
? self::productSellTitle($abshode['title'])
|
||||
: self::meltedGoldSellTitle(),
|
||||
];
|
||||
if (!empty($data['product_id'])) {
|
||||
$sellTransaction['product_id'] = $data['product_id'];
|
||||
if ($abshode['id'] > 0) {
|
||||
$sellTransaction['product_id'] = $abshode['id'];
|
||||
$sellTransaction['note'] = 'product_id:' . $abshode['id'];
|
||||
}
|
||||
new TransactionInterface($wallet_interface, $sellTransaction, 2, false, true);
|
||||
|
||||
@@ -757,6 +765,34 @@ class SingleOrderController extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveAbshodeProductContext(array $data): array
|
||||
{
|
||||
$productId = (int) ($data['product_id'] ?? $data['abshode_id'] ?? 0);
|
||||
$product = null;
|
||||
|
||||
if (!empty($data['product'])) {
|
||||
$candidate = $data['product'];
|
||||
if ($candidate instanceof Product) {
|
||||
$product = $candidate;
|
||||
} elseif (is_array($candidate) && !empty($candidate['id'])) {
|
||||
$product = Product::find($candidate['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$product && $productId > 0) {
|
||||
$product = Product::find($productId);
|
||||
}
|
||||
|
||||
if (!$product) {
|
||||
return ['id' => 0, 'title' => ''];
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int) $product->id,
|
||||
'title' => trim((string) $product->title),
|
||||
];
|
||||
}
|
||||
|
||||
private function productTitleFromData(array $data): ?string
|
||||
{
|
||||
$product = $data['product'] ?? null;
|
||||
|
||||
Reference in New Issue
Block a user