fix sql
This commit is contained in:
@@ -81,7 +81,7 @@ class SingleOrderController extends Controller
|
|||||||
$data['all_price'] = $latestPrice;
|
$data['all_price'] = $latestPrice;
|
||||||
$data['price'] = $basePrice;
|
$data['price'] = $basePrice;
|
||||||
$data['price_id'] = $latestPrice?->id;
|
$data['price_id'] = $latestPrice?->id;
|
||||||
$data['difference'] = $config->orderSpreadRial();
|
$data['difference'] = $config->orderPriceDiffRial();
|
||||||
$data['service_charge_percentage'] = $config->orderServiceChargePercentage();
|
$data['service_charge_percentage'] = $config->orderServiceChargePercentage();
|
||||||
|
|
||||||
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
||||||
@@ -122,7 +122,7 @@ class SingleOrderController extends Controller
|
|||||||
if ($data['direction'] == 1) {
|
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['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_buy']) * $data['number'];
|
||||||
$data['difference'] = $data['fee'] = $this->resolveCashSpread($config, $data['product'], 1);
|
$data['difference'] = $data['fee'] = $this->resolveCashPriceDiff($config, $data['product'], 1);
|
||||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||||
@@ -140,7 +140,7 @@ class SingleOrderController extends Controller
|
|||||||
} // Check if the user wants to sell
|
} // Check if the user wants to sell
|
||||||
else if ($data['direction'] == 2) {
|
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['service_charge_percentage'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell']) * $data['number'];
|
||||||
$data['difference'] = $data['fee'] = $this->resolveCashSpread($config, $data['product'], 2);
|
$data['difference'] = $data['fee'] = $this->resolveCashPriceDiff($config, $data['product'], 2);
|
||||||
$data['total_fee'] = $data['number'] * $data['fee'];
|
$data['total_fee'] = $data['number'] * $data['fee'];
|
||||||
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
$data['price_original'] = $data['product']['price'] + $data['product']['price_profit'];
|
||||||
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
$data['total_price_original'] = $data['product']['amount'] * ($data['price_original'] ?? 0);
|
||||||
@@ -166,10 +166,10 @@ class SingleOrderController extends Controller
|
|||||||
}
|
}
|
||||||
$config->assertProductTradingOpen($data['product']);
|
$config->assertProductTradingOpen($data['product']);
|
||||||
if ($data['direction'] == 1) {
|
if ($data['direction'] == 1) {
|
||||||
$data['difference'] = $this->resolveCashSpread($config, $data['product'], 1);
|
$data['difference'] = $this->resolveCashPriceDiff($config, $data['product'], 1);
|
||||||
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];
|
$data['service_charge_percentage'] = $data['product']['percent_fee_buy'];
|
||||||
} elseif ($data['direction'] == 2) {
|
} elseif ($data['direction'] == 2) {
|
||||||
$data['difference'] = $this->resolveCashSpread($config, $data['product'], 2);
|
$data['difference'] = $this->resolveCashPriceDiff($config, $data['product'], 2);
|
||||||
$data['service_charge_percentage'] = $data['product']['percent_fee_sell'];
|
$data['service_charge_percentage'] = $data['product']['percent_fee_sell'];
|
||||||
}
|
}
|
||||||
$data['total_fee'] = $data['amount'] * $data['difference'];
|
$data['total_fee'] = $data['amount'] * $data['difference'];
|
||||||
@@ -963,15 +963,15 @@ class SingleOrderController extends Controller
|
|||||||
* گلد علی / zaarbox / main_product: اختلاف سفارش = buy_fee/sell_fee نمایش (مثل /api/price/last).
|
* گلد علی / zaarbox / main_product: اختلاف سفارش = buy_fee/sell_fee نمایش (مثل /api/price/last).
|
||||||
* montzar و بقیه: همان cash_fee_buy/sell محصول (رفتار قبلی ابشدهخانگی).
|
* montzar و بقیه: همان cash_fee_buy/sell محصول (رفتار قبلی ابشدهخانگی).
|
||||||
*/
|
*/
|
||||||
private function resolveCashSpread(ConfigService $config, Product $product, int $direction): float
|
private function resolveCashPriceDiff(ConfigService $config, Product $product, int $direction): float
|
||||||
{
|
{
|
||||||
$provider = $config->priceProvider();
|
$provider = $config->priceProvider();
|
||||||
$alignWithDisplay = in_array($provider, ['zaarbox', 'main_product'], true);
|
$alignWithDisplay = in_array($provider, ['zaarbox', 'main_product'], true);
|
||||||
|
|
||||||
if ($alignWithDisplay) {
|
if ($alignWithDisplay) {
|
||||||
$display = $direction === 1
|
$display = $direction === 1
|
||||||
? $config->displayBuySpreadRial()
|
? $config->displayBuyPriceDiffRial()
|
||||||
: $config->displaySellSpreadRial();
|
: $config->displaySellPriceDiffRial();
|
||||||
|
|
||||||
if ($display > 0) {
|
if ($display > 0) {
|
||||||
return $display;
|
return $display;
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ class ReportController extends Controller
|
|||||||
protected function buildUpDownPrices(): array
|
protected function buildUpDownPrices(): array
|
||||||
{
|
{
|
||||||
$config = app(ConfigService::class);
|
$config = app(ConfigService::class);
|
||||||
$diffBuy = $config->displayBuySpreadRial();
|
$diffBuy = $config->displayBuyPriceDiffRial();
|
||||||
$diffSell = $config->displaySellSpreadRial();
|
$diffSell = $config->displaySellPriceDiffRial();
|
||||||
|
|
||||||
$extremes = $config->resolvedDailyBaseExtremes();
|
$extremes = $config->resolvedDailyBaseExtremes();
|
||||||
$up = $extremes['up'];
|
$up = $extremes['up'];
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class ConfigService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** اختلاف خرید نمایش (/api/price/last) — fee_single / buy_fee */
|
/** اختلاف خرید نمایش (/api/price/last) — fee_single / buy_fee */
|
||||||
public function displayBuySpreadRial(): float
|
public function displayBuyPriceDiffRial(): float
|
||||||
{
|
{
|
||||||
$feeSingle = (float) $this->get('fee_single', 0);
|
$feeSingle = (float) $this->get('fee_single', 0);
|
||||||
$buyFee = (float) $this->get('buy_fee', $feeSingle);
|
$buyFee = (float) $this->get('buy_fee', $feeSingle);
|
||||||
@@ -102,7 +102,7 @@ class ConfigService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** اختلاف فروش نمایش — fee_single / sell_fee */
|
/** اختلاف فروش نمایش — fee_single / sell_fee */
|
||||||
public function displaySellSpreadRial(): float
|
public function displaySellPriceDiffRial(): float
|
||||||
{
|
{
|
||||||
$feeSingle = (float) $this->get('fee_single', 0);
|
$feeSingle = (float) $this->get('fee_single', 0);
|
||||||
$sellFee = (float) $this->get('sell_fee', $feeSingle);
|
$sellFee = (float) $this->get('sell_fee', $feeSingle);
|
||||||
@@ -111,7 +111,7 @@ class ConfigService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** اختلاف ریالی سفارش — fee_single، بعد fee_cash (legacy)، بعد config/fee.php */
|
/** اختلاف ریالی سفارش — fee_single، بعد fee_cash (legacy)، بعد config/fee.php */
|
||||||
public function orderSpreadRial(): float
|
public function orderPriceDiffRial(): float
|
||||||
{
|
{
|
||||||
$feeSingle = $this->getString('fee_single', '');
|
$feeSingle = $this->getString('fee_single', '');
|
||||||
if ($feeSingle !== '') {
|
if ($feeSingle !== '') {
|
||||||
@@ -161,8 +161,8 @@ class ConfigService
|
|||||||
?string $priceSource = null,
|
?string $priceSource = null,
|
||||||
array $montzarFlags = []
|
array $montzarFlags = []
|
||||||
): array {
|
): array {
|
||||||
$diffBuy = (float) $this->displayBuySpreadRial();
|
$diffBuy = (float) $this->displayBuyPriceDiffRial();
|
||||||
$diffSell = (float) $this->displaySellSpreadRial();
|
$diffSell = (float) $this->displaySellPriceDiffRial();
|
||||||
$feeSingle = (float) $this->get('fee_single', 0);
|
$feeSingle = (float) $this->get('fee_single', 0);
|
||||||
|
|
||||||
$openBuy = true;
|
$openBuy = true;
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ class LivePriceCacheService
|
|||||||
|
|
||||||
$payload['up'] = $config->resolvedDailyBaseExtremes()['up'] > 0
|
$payload['up'] = $config->resolvedDailyBaseExtremes()['up'] > 0
|
||||||
? [
|
? [
|
||||||
'sell' => max(0, (int) ceil($config->resolvedDailyBaseExtremes()['down'] - $config->displaySellSpreadRial())),
|
'sell' => max(0, (int) ceil($config->resolvedDailyBaseExtremes()['down'] - $config->displaySellPriceDiffRial())),
|
||||||
'buy' => (int) ceil($config->resolvedDailyBaseExtremes()['up'] + $config->displayBuySpreadRial()),
|
'buy' => (int) ceil($config->resolvedDailyBaseExtremes()['up'] + $config->displayBuyPriceDiffRial()),
|
||||||
]
|
]
|
||||||
: ['sell' => $payload['sell'] ?? 0, 'buy' => $payload['buy'] ?? 0];
|
: ['sell' => $payload['sell'] ?? 0, 'buy' => $payload['buy'] ?? 0];
|
||||||
$payload['last_historical'] = $display->resolveHistoricalBasePrice();
|
$payload['last_historical'] = $display->resolveHistoricalBasePrice();
|
||||||
|
|||||||
@@ -465,8 +465,8 @@ class ProductDisplayPriceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$diffBuy = (int) $config->displayBuySpreadRial();
|
$diffBuy = (int) $config->displayBuyPriceDiffRial();
|
||||||
$diffSell = (int) $config->displaySellSpreadRial();
|
$diffSell = (int) $config->displaySellPriceDiffRial();
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
|
|||||||
@@ -898,7 +898,7 @@ UPDATE `settings` SET `description` = 'روشن: اگر API قیمت در دست
|
|||||||
UPDATE `settings` SET `description` = 'روشن: خارج از بازه «ساعت شروع» تا «ساعت پایان» معامله و نمایش قیمت بسته میشود. خاموش: محدودیت ساعتی سراسری اعمال نمیشود.' WHERE `key` = 'close_price';
|
UPDATE `settings` SET `description` = 'روشن: خارج از بازه «ساعت شروع» تا «ساعت پایان» معامله و نمایش قیمت بسته میشود. خاموش: محدودیت ساعتی سراسری اعمال نمیشود.' WHERE `key` = 'close_price';
|
||||||
UPDATE `settings` SET `description` = 'ساعت شروع فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۰۹:۰۰).' WHERE `key` = 'startDay';
|
UPDATE `settings` SET `description` = 'ساعت شروع فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۰۹:۰۰).' WHERE `key` = 'startDay';
|
||||||
UPDATE `settings` SET `description` = 'ساعت پایان فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۲۲:۰۰).' WHERE `key` = 'endDay';
|
UPDATE `settings` SET `description` = 'ساعت پایان فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۲۲:۰۰).' WHERE `key` = 'endDay';
|
||||||
UPDATE `settings` SET `description` = 'اختلاف پایه (ریال) بین قیمت خرید و فروش روی مظنه. معمولاً نصف فاصله اسپرد کل است.' WHERE `key` = 'fee_single';
|
UPDATE `settings` SET `description` = 'اختلاف پایه (ریال) بین قیمت خرید و فروش روی مظنه. معمولاً نصف مجموع اختلاف قیمت خرید و فروش است.' WHERE `key` = 'fee_single';
|
||||||
UPDATE `settings` SET `description` = 'مبلغ اضافه (ریال) روی قیمت پایه برای سمت خرید. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'buy_fee';
|
UPDATE `settings` SET `description` = 'مبلغ اضافه (ریال) روی قیمت پایه برای سمت خرید. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'buy_fee';
|
||||||
UPDATE `settings` SET `description` = 'مبلغ کسر (ریال) از قیمت پایه برای سمت فروش. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'sell_fee';
|
UPDATE `settings` SET `description` = 'مبلغ کسر (ریال) از قیمت پایه برای سمت فروش. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'sell_fee';
|
||||||
UPDATE `settings` SET `description` = 'درصد کارمزد هر سفارش از مبلغ معامله (اعشاری؛ مثلاً ۰٫۰۰۵ یعنی نیم در هزار).' WHERE `key` = 'fee_service_charge_percentage';
|
UPDATE `settings` SET `description` = 'درصد کارمزد هر سفارش از مبلغ معامله (اعشاری؛ مثلاً ۰٫۰۰۵ یعنی نیم در هزار).' WHERE `key` = 'fee_service_charge_percentage';
|
||||||
|
|||||||
@@ -926,7 +926,7 @@ UPDATE `settings` SET `description` = 'روشن: اگر API قیمت در دست
|
|||||||
UPDATE `settings` SET `description` = 'روشن: خارج از بازه «ساعت شروع» تا «ساعت پایان» معامله و نمایش قیمت بسته میشود. خاموش: محدودیت ساعتی سراسری اعمال نمیشود.' WHERE `key` = 'close_price';
|
UPDATE `settings` SET `description` = 'روشن: خارج از بازه «ساعت شروع» تا «ساعت پایان» معامله و نمایش قیمت بسته میشود. خاموش: محدودیت ساعتی سراسری اعمال نمیشود.' WHERE `key` = 'close_price';
|
||||||
UPDATE `settings` SET `description` = 'ساعت شروع فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۰۹:۰۰).' WHERE `key` = 'startDay';
|
UPDATE `settings` SET `description` = 'ساعت شروع فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۰۹:۰۰).' WHERE `key` = 'startDay';
|
||||||
UPDATE `settings` SET `description` = 'ساعت پایان فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۲۲:۰۰).' WHERE `key` = 'endDay';
|
UPDATE `settings` SET `description` = 'ساعت پایان فعالیت روزانه. فقط وقتی «بستن خودکار خارج از ساعت کاری» روشن باشد اعمال میشود (مثلاً ۲۲:۰۰).' WHERE `key` = 'endDay';
|
||||||
UPDATE `settings` SET `description` = 'اختلاف پایه (ریال) بین قیمت خرید و فروش روی مظنه. معمولاً نصف فاصله اسپرد کل است.' WHERE `key` = 'fee_single';
|
UPDATE `settings` SET `description` = 'اختلاف پایه (ریال) بین قیمت خرید و فروش روی مظنه. معمولاً نصف مجموع اختلاف قیمت خرید و فروش است.' WHERE `key` = 'fee_single';
|
||||||
UPDATE `settings` SET `description` = 'مبلغ اضافه (ریال) روی قیمت پایه برای سمت خرید. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'buy_fee';
|
UPDATE `settings` SET `description` = 'مبلغ اضافه (ریال) روی قیمت پایه برای سمت خرید. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'buy_fee';
|
||||||
UPDATE `settings` SET `description` = 'مبلغ کسر (ریال) از قیمت پایه برای سمت فروش. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'sell_fee';
|
UPDATE `settings` SET `description` = 'مبلغ کسر (ریال) از قیمت پایه برای سمت فروش. خالی = استفاده از «اختلاف پایه».' WHERE `key` = 'sell_fee';
|
||||||
UPDATE `settings` SET `description` = 'درصد کارمزد هر سفارش از مبلغ معامله (اعشاری؛ مثلاً ۰٫۰۰۵ یعنی نیم در هزار).' WHERE `key` = 'fee_service_charge_percentage';
|
UPDATE `settings` SET `description` = 'درصد کارمزد هر سفارش از مبلغ معامله (اعشاری؛ مثلاً ۰٫۰۰۵ یعنی نیم در هزار).' WHERE `key` = 'fee_service_charge_percentage';
|
||||||
|
|||||||
Reference in New Issue
Block a user