fix borcecu edits 3
This commit is contained in:
@@ -120,7 +120,10 @@ class SingleOrderController extends Controller
|
||||
|
||||
$config->assertMainGoldZeroBeforeOtherProductBuy($wallet, $data['product']);
|
||||
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']) * $data['number'];
|
||||
// کارمزد فقط از fee_service_charge_percentage (بالا ست شده) — percent_fee_* مربوط به کارمزد نیست
|
||||
if (!empty($data['fee_free'])) {
|
||||
$data['service_charge_percentage'] = 0;
|
||||
}
|
||||
$data['price_original'] = $this->resolveProductUnitBasePrice($data['product']);
|
||||
$this->applyCashPriceDiff($config, $data['product'], 1, $data, (float) $data['price_original']);
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
@@ -138,7 +141,9 @@ class SingleOrderController extends Controller
|
||||
}
|
||||
} // Check if the user wants to sell
|
||||
else if ($data['direction'] == 2) {
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']) * $data['number'];
|
||||
if (!empty($data['fee_free'])) {
|
||||
$data['service_charge_percentage'] = 0;
|
||||
}
|
||||
$data['price_original'] = $this->resolveProductUnitBasePrice($data['product']);
|
||||
$this->applyCashPriceDiff($config, $data['product'], 2, $data, (float) $data['price_original']);
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
@@ -168,10 +173,15 @@ class SingleOrderController extends Controller
|
||||
$config->assertProductTradingOpen($data['product']);
|
||||
if ($data['direction'] == 1) {
|
||||
$this->applyCashPriceDiff($config, $data['product'], 1, $data, (float) ($data['price_original'] ?? 0));
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];
|
||||
// کارمزد همان fee_service_charge_percentage — override با percent_fee_* ممنوع
|
||||
if (!empty($data['fee_free'])) {
|
||||
$data['service_charge_percentage'] = 0;
|
||||
}
|
||||
} elseif ($data['direction'] == 2) {
|
||||
$this->applyCashPriceDiff($config, $data['product'], 2, $data, (float) ($data['price_original'] ?? 0));
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_sell'];
|
||||
if (!empty($data['fee_free'])) {
|
||||
$data['service_charge_percentage'] = 0;
|
||||
}
|
||||
}
|
||||
// fee اولیه از orderPriceDiffRial ممکن است با اختلاف واقعی محصول فرق کند
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
@@ -377,20 +387,25 @@ class SingleOrderController extends Controller
|
||||
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['price'] += $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount'] + ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
// محصول تعدادی: کارمزد فقط از ریال (fee_service_charge_percentage)
|
||||
$feeRate = isset($data['fee_free']) && $data['fee_free'] === true
|
||||
? 0.0
|
||||
: (float) ($data['service_charge_percentage'] ?? 0);
|
||||
$data['service_charge'] = $this->normalizeGoldAmount($feeRate * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_amount'] = $data['amount'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'] + $data['service_charge_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
|
||||
if (!empty($data['first_buy']) && ($minFirstBuy = Setting::where('is_active', 1)->where('key', 'min_first_buy')->value('value'))) {
|
||||
if ($data['total_price'] < (int) $minFirstBuy) {
|
||||
if ($data['payment_amount'] < (int) $minFirstBuy) {
|
||||
throw new UnprocessableEntityHttpException('حداقل سفارش اول ' . number_format((int) $minFirstBuy) . ' ریال میباشد.');
|
||||
}
|
||||
}
|
||||
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['wallet'] = $wallet;
|
||||
if ($wallet->cash < $data['payment_amount']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
@@ -402,7 +417,7 @@ class SingleOrderController extends Controller
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$data['transaction'][] = new TransactionInterface($wallet_interface, $_inp = [
|
||||
"number" => $data['number'],
|
||||
"cash" => $data['total_price'],
|
||||
"cash" => $data['payment_amount'],
|
||||
"product_id" => $data["product_id"],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
@@ -430,13 +445,18 @@ class SingleOrderController extends Controller
|
||||
|
||||
$data['price'] += $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount'] + ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy'] * $data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
// محصول تعدادی: کارمزد از ریال (fee_service_charge_percentage)
|
||||
$feeRate = isset($data['fee_free']) && $data['fee_free'] === true
|
||||
? 0.0
|
||||
: (float) ($data['service_charge_percentage'] ?? 0);
|
||||
$data['service_charge'] = $this->normalizeGoldAmount($feeRate * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_amount'] = $data['amount'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$data['total_fee'] = 0;
|
||||
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
|
||||
$data['wallet'] = $wallet;
|
||||
|
||||
$paymentProductId = (int) ($data['payment_product_id'] ?? 0);
|
||||
@@ -463,6 +483,9 @@ class SingleOrderController extends Controller
|
||||
if ((float) $paymentWallet->gold < $data['total_amount']) {
|
||||
throw new UnprocessableEntityHttpException($this->insufficientGoldBalanceMessage($data));
|
||||
}
|
||||
if ($data['service_charge_price'] > 0 && $wallet->cash < $data['service_charge_price']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی ریالی شما برای کارمزد کافی نیست');
|
||||
}
|
||||
if (!$data['product']['open_buy']) {
|
||||
throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
@@ -502,6 +525,17 @@ class SingleOrderController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
if ($data['service_charge_price'] > 0) {
|
||||
$data['transaction'][] = new TransactionInterface($wallet_interface, [
|
||||
"cash" => $data['service_charge_price'],
|
||||
"product_id" => $data["product_id"],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => 'کارمزد معامله',
|
||||
], 12, false, false);
|
||||
}
|
||||
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
@@ -623,13 +657,18 @@ class SingleOrderController extends Controller
|
||||
$data['price'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['price'] -= $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
// محصول تعدادی: کارمزد فقط از ریال
|
||||
$feeRate = isset($data['fee_free']) && $data['fee_free'] === true
|
||||
? 0.0
|
||||
: (float) ($data['service_charge_percentage'] ?? 0);
|
||||
$data['service_charge'] = $this->normalizeGoldAmount($feeRate * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_amount'] = $data['amount'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$grossTotal = (float) ($data['amount'] * $data['price']);
|
||||
$this->enforceProductOrderLimits($data, $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
|
||||
if ($wallet_interface_product->wallet->gold < $data['number']) {
|
||||
@@ -666,18 +705,26 @@ class SingleOrderController extends Controller
|
||||
{
|
||||
$data['price'] -= $data['difference'];
|
||||
$data['amount'] = $data['number'] * $data['product']['amount'];
|
||||
$data['total_amount'] = $data['amount'] - ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_price'] = $data['total_amount'] * $data['price'];
|
||||
// محصول تعدادی: کارمزد فقط از ریال
|
||||
$feeRate = isset($data['fee_free']) && $data['fee_free'] === true
|
||||
? 0.0
|
||||
: (float) ($data['service_charge_percentage'] ?? 0);
|
||||
$data['service_charge'] = $this->normalizeGoldAmount($feeRate * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$data['total_amount'] = $data['amount'];
|
||||
$data['total_price'] = $data['amount'] * $data['price'];
|
||||
$data['payment_amount'] = $data['total_price'];
|
||||
$data['fee_asset'] = 'rial';
|
||||
$data['total_fee'] = 0;
|
||||
$grossTotal = (float) ($data['amount'] * $data['price']);
|
||||
$this->enforceProductOrderLimits($data, $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
if ($wallet_interface_product->wallet->gold < $data['number']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
if ($data['service_charge_price'] > 0 && $wallet->cash < $data['service_charge_price']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی ریالی شما برای کارمزد کافی نیست');
|
||||
}
|
||||
if (!$data['product']['open_sell']) {
|
||||
throw new UnprocessableEntityHttpException('فروش این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
@@ -692,6 +739,16 @@ class SingleOrderController extends Controller
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->meltedOrProductSellTitle($data),
|
||||
], 12, true, false);
|
||||
if ($data['service_charge_price'] > 0) {
|
||||
$data['transaction'][] = new TransactionInterface($wallet_interface, [
|
||||
"cash" => $data['service_charge_price'],
|
||||
"product_id" => $data["product_id"],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => 'کارمزد معامله',
|
||||
], 12, false, false);
|
||||
}
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
"gold" => $data['number'],
|
||||
|
||||
Reference in New Issue
Block a user