fixed show true when price is 0
This commit is contained in:
@@ -32,6 +32,10 @@ class SingleOrderController extends Controller
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['payment_product_id'] = $this->resolveGoldPaymentProductId($data);
|
||||
if (preg_match('/^gold:\d+$/', (string) ($data['method'] ?? ''))) {
|
||||
$data['method'] = 'gold';
|
||||
}
|
||||
$data['is_katod'] = ($data['method'] ?? null) === 'katod';
|
||||
if ($data['is_katod']) {
|
||||
$data['method'] = 'gold';
|
||||
@@ -332,22 +336,69 @@ class SingleOrderController extends Controller
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['wallet'] = $wallet;
|
||||
if ($wallet->gold < $data['total_amount']) {
|
||||
|
||||
$paymentProductId = (int) ($data['payment_product_id'] ?? 0);
|
||||
$paymentWalletInterface = $wallet_interface;
|
||||
$paymentProduct = null;
|
||||
$paymentWallet = $wallet;
|
||||
|
||||
if ($paymentProductId > 0) {
|
||||
$paymentProduct = Product::find($paymentProductId);
|
||||
if (
|
||||
!$paymentProduct
|
||||
|| (int) ($paymentProduct->metal_id ?? 0) !== (int) ($data['product']['metal_id'] ?? 0)
|
||||
) {
|
||||
throw new UnprocessableEntityHttpException('روش پرداخت نامعتبر است.');
|
||||
}
|
||||
|
||||
$paymentWalletInterface = $this->productWalletInterface($paymentProductId);
|
||||
$paymentWallet = $paymentWalletInterface->wallet;
|
||||
if (!$paymentWallet) {
|
||||
throw new UnprocessableEntityHttpException('کیف پول یافت نشد.');
|
||||
}
|
||||
}
|
||||
|
||||
if ((float) $paymentWallet->gold < $data['total_amount']) {
|
||||
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
|
||||
}
|
||||
if (!$data['product']['open_buy']) {
|
||||
throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$data['transaction'][] = new TransactionInterface($wallet_interface, $_inp = [
|
||||
|
||||
$paymentSellTitle = $paymentProduct
|
||||
? self::productSellTitle($paymentProduct->title ?? '')
|
||||
: self::mainMetalSellTitle();
|
||||
|
||||
$paymentTransaction = [
|
||||
"number" => $data['number'],
|
||||
"gold" => $data['total_amount'],
|
||||
"product_id" => $data["product_id"],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => self::mainMetalSellTitle(),
|
||||
], 12, false, true);
|
||||
'title' => $paymentSellTitle,
|
||||
];
|
||||
|
||||
if ($paymentProductId > 0) {
|
||||
$paymentTransaction['product_id'] = $paymentProductId;
|
||||
$this->normalizeProductWalletGold($paymentWalletInterface);
|
||||
$data['transaction'][] = new TransactionInterface(
|
||||
$paymentWalletInterface,
|
||||
$paymentTransaction,
|
||||
1,
|
||||
false,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
$data['transaction'][] = new TransactionInterface(
|
||||
$paymentWalletInterface,
|
||||
$paymentTransaction,
|
||||
12,
|
||||
false,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
@@ -794,6 +845,20 @@ class SingleOrderController extends Controller
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveGoldPaymentProductId(array $data): ?int
|
||||
{
|
||||
if (!empty($data['payment_product_id'])) {
|
||||
return (int) $data['payment_product_id'];
|
||||
}
|
||||
|
||||
$method = (string) ($data['method'] ?? '');
|
||||
if (preg_match('/^gold:(\d+)$/', $method, $matches)) {
|
||||
return (int) $matches[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveAbshodeProductContext(array $data): array
|
||||
{
|
||||
$productId = (int) ($data['product_id'] ?? $data['abshode_id'] ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user