zarbox added 5
This commit is contained in:
@@ -113,7 +113,7 @@ class SingleOrderController extends Controller
|
||||
if ($data['direction'] == 1) {
|
||||
|
||||
$data['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']) * $data['number'];
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_buy'];
|
||||
$data['difference'] = $data['fee'] = $this->resolveCashSpread($config, $data['product'], 1);
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||
@@ -131,7 +131,7 @@ 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'];
|
||||
$data['difference'] = $data['fee'] = $data['product']['cash_fee_sell'];
|
||||
$data['difference'] = $data['fee'] = $this->resolveCashSpread($config, $data['product'], 2);
|
||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||
@@ -156,10 +156,10 @@ class SingleOrderController extends Controller
|
||||
throw new UnprocessableEntityHttpException('محصول آبشده یافت نشد.');
|
||||
}
|
||||
if ($data['direction'] == 1) {
|
||||
$data['difference'] = $data['product']['cash_fee_buy'];
|
||||
$data['difference'] = $this->resolveCashSpread($config, $data['product'], 1);
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];
|
||||
} elseif ($data['direction'] == 2) {
|
||||
$data['difference'] = $data['product']['cash_fee_sell'];
|
||||
$data['difference'] = $this->resolveCashSpread($config, $data['product'], 2);
|
||||
$data['service_charge_percentage'] = $data['product']['percent_fee_sell'];
|
||||
}
|
||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||
@@ -702,4 +702,26 @@ class SingleOrderController extends Controller
|
||||
{
|
||||
return 'موجودی ' . self::metalTypeLabel() . ' شما کمتر از میزان سفارش است';
|
||||
}
|
||||
|
||||
/**
|
||||
* گلد علی / zaarbox / main_product: اختلاف سفارش = buy_fee/sell_fee نمایش (مثل /api/price/last).
|
||||
* montzar و بقیه: همان cash_fee_buy/sell محصول (رفتار قبلی ابشدهخانگی).
|
||||
*/
|
||||
private function resolveCashSpread(ConfigService $config, Product $product, int $direction): float
|
||||
{
|
||||
$provider = $config->priceProvider();
|
||||
$alignWithDisplay = in_array($provider, ['zaarbox', 'main_product'], true);
|
||||
|
||||
if ($alignWithDisplay) {
|
||||
$display = $direction === 1
|
||||
? $config->displayBuySpreadRial()
|
||||
: $config->displaySellSpreadRial();
|
||||
|
||||
if ($display > 0) {
|
||||
return $display;
|
||||
}
|
||||
}
|
||||
|
||||
return (float) ($direction === 1 ? $product->cash_fee_buy : $product->cash_fee_sell);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,9 +519,9 @@ class ReportController extends Controller
|
||||
$storedPrice = $lastPrice ?? Price::latest()->first();
|
||||
if ($storedPrice && (float) $storedPrice->price > 0) {
|
||||
$base = (float) $storedPrice->price;
|
||||
$sell = $open_sell ? (int) ceil($base - $difference) : 0;
|
||||
$buy = $open_buy ? (int) ceil($base + $difference) : 0;
|
||||
$priceLast = (int) ceil($base + $difference);
|
||||
$sell = $open_sell ? (int) ceil($base - $diff_sell) : 0;
|
||||
$buy = $open_buy ? (int) ceil($base + $diff_buy) : 0;
|
||||
$priceLast = (int) ceil($base + $diff_buy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,24 @@ class ConfigService
|
||||
return (int) ($value === false || $value === null || $value === '' ? $default : $value);
|
||||
}
|
||||
|
||||
/** اختلاف خرید نمایش (/api/price/last) — fee_single / buy_fee */
|
||||
public function displayBuySpreadRial(): float
|
||||
{
|
||||
$feeSingle = (float) $this->get('fee_single', 0);
|
||||
$buyFee = (float) $this->get('buy_fee', $feeSingle);
|
||||
|
||||
return $buyFee > 0 ? $buyFee : $feeSingle;
|
||||
}
|
||||
|
||||
/** اختلاف فروش نمایش — fee_single / sell_fee */
|
||||
public function displaySellSpreadRial(): float
|
||||
{
|
||||
$feeSingle = (float) $this->get('fee_single', 0);
|
||||
$sellFee = (float) $this->get('sell_fee', $feeSingle);
|
||||
|
||||
return $sellFee > 0 ? $sellFee : $feeSingle;
|
||||
}
|
||||
|
||||
/**
|
||||
* تنها منبع فعال قیمت — فقط یکی از: montzar | etehadie | taban_gohar | main_product
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user