zarbox added 5

This commit is contained in:
2026-06-04 15:30:34 +03:30
parent 0574ade170
commit 9b0d360dcf
3 changed files with 47 additions and 7 deletions
@@ -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);
}
}