change copperConvertPage

This commit is contained in:
2026-11-01 12:42:14 +03:30
parent 9528056036
commit 3f59af5a6d
10 changed files with 495 additions and 3 deletions
@@ -122,7 +122,9 @@ class SingleOrderController extends Controller
// Check if the user wants to transact with a product or non-product (gold)
if (isset($data['product_id']) and $data['product'] = Product::find($data['product_id'])) {
$config->assertProductTradingOpen($data['product']);
if (empty($data['quote_unit_price'])) {
$config->assertProductTradingOpen($data['product']);
}
// Check if the user wants to buy
if ($data['direction'] == 1) {
@@ -353,6 +355,7 @@ class SingleOrderController extends Controller
$data['total_price'] = $data['amount'] * $data['price'];
$data['payment_amount'] = $data['total_price'] + $data['service_charge_price'];
$data['fee_asset'] = 'rial';
$this->applyConvertQuote($data);
$this->enforceProductOrderLimits($data, (float) $data['total_price']);
@@ -366,7 +369,7 @@ class SingleOrderController extends Controller
if ($wallet->cash < $data['payment_amount']) {
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
}
if (!$data['product']['open_buy']) {
if (empty($data['quote_unit_price']) && !$data['product']['open_buy']) {
throw new UnprocessableEntityHttpException('خرید این محصول در این لحظه مقدور نمیباشد');
}
$this->syncOrderProfitFields($data);
@@ -647,6 +650,7 @@ class SingleOrderController extends Controller
$data['total_price'] = $data['amount'] * $data['price'] - $data['service_charge_price'];
$data['payment_amount'] = $data['total_price'];
$data['fee_asset'] = 'rial';
$this->applyConvertQuote($data);
if ($data['total_price'] < 0) {
throw new UnprocessableEntityHttpException(
'مبلغ دریافتی فروش پس از کارمزد منفی شد. درصد کارمزد سفارش را بررسی کنید (باید اعشاری باشد؛ مثلاً ۰٫۰۱ برای ۱٪).'
@@ -659,7 +663,7 @@ class SingleOrderController extends Controller
if ($wallet_interface_product->wallet->gold < $data['number']) {
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
}
if (!$data['product']['open_sell']) {
if (empty($data['quote_unit_price']) && !$data['product']['open_sell']) {
throw new UnprocessableEntityHttpException('فروش این محصول در این لحظه مقدور نمیباشد');
}
$this->syncOrderProfitFields($data);
@@ -1403,6 +1407,32 @@ class SingleOrderController extends Controller
* اگر قیمت واحد سفارش حدود قیمت مثقال باشد، به قیمت هر گرم برگردان.
* جلوگیری از ۱۰ میلیون تومان → ۱۰۵ سوت وقتی مثقال در فیلد «هر گرم» نشسته.
*/
/** قیمت قفل‌شدهٔ تبدیل: تعداد × قیمت واحد، بدون کارمزد و بدون ضرب در وزن واحد. */
private function applyConvertQuote(array &$data): void
{
$quote = (float) ($data['quote_unit_price'] ?? 0);
if ($quote <= 0) {
return;
}
$number = (float) ($data['number'] ?? 0);
$data['amount'] = $number;
$data['price'] = $quote;
$data['price_original'] = $quote;
$data['difference'] = 0;
$data['fee'] = 0;
$data['total_fee'] = 0;
$data['service_charge'] = 0;
$data['service_charge_price'] = 0;
$data['service_charge_percentage'] = 0;
$data['total_amount'] = $number;
$data['total_price'] = $number * $quote;
$data['payment_amount'] = $data['total_price'];
$data['fee_asset'] = 'rial';
$data['fee_free'] = true;
$data['first_buy'] = false;
}
private function ensureOrderUnitPriceIsPerGram(array &$data): void
{
$live = $this->liveGramQuoteRial();