fix some bugs from fee
This commit is contained in:
@@ -8,7 +8,6 @@ use App\Http\Controllers\Single\SingleOrderController;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\Price;
|
||||
use App\Models\Setting;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
@@ -55,8 +54,8 @@ class OrderController extends Controller
|
||||
return (int) $order->direction === 1 ? $profitPerMoment : -$profitPerMoment;
|
||||
});
|
||||
|
||||
$feeSingle = (float) (Setting::where('key', 'fee_single')->value('value') ?? config('fee.single', 0));
|
||||
$currentPriceWithFee = $lastPrice + $feeSingle;
|
||||
$buyFee = app(\App\Services\ConfigService::class)->displayBuyPriceDiffRial();
|
||||
$currentPriceWithFee = $lastPrice + $buyFee;
|
||||
$averagePriceWithFee = $averagePrice + $averageFee;
|
||||
|
||||
return response()->json([
|
||||
|
||||
@@ -78,7 +78,7 @@ class SingleOrderController extends Controller
|
||||
$data['all_price'] = $latestPrice;
|
||||
$data['price'] = $basePrice;
|
||||
$data['price_id'] = $latestPrice?->id;
|
||||
$data['difference'] = $config->orderPriceDiffRial();
|
||||
$data['difference'] = $config->orderPriceDiffRial(isset($data['direction']) ? (int) $data['direction'] : null);
|
||||
$data['service_charge_percentage'] = $config->orderServiceChargePercentage();
|
||||
|
||||
$fee_free = Setting::where('key', 'fee_free')->where('is_active', true)->value('value');
|
||||
@@ -1265,8 +1265,8 @@ class SingleOrderController extends Controller
|
||||
|
||||
/**
|
||||
* اختلاف قیمت سفارش:
|
||||
* - محصول با «قیمت اپ»: اختلاف پایه تنظیمات (sell_fee/buy_fee/fee_single) + تب اختلاف محصول
|
||||
* - بدون قیمت اپ: فقط تب اختلاف محصول (cash_fee) — بدون ۱M تنظیمات اپ
|
||||
* - محصول با «قیمت اپ»: buy_fee / sell_fee + تب اختلاف محصول
|
||||
* - بدون قیمت اپ: فقط تب اختلاف محصول (cash_fee)
|
||||
*
|
||||
* @return array{
|
||||
* amount: float,
|
||||
@@ -1302,21 +1302,14 @@ class SingleOrderController extends Controller
|
||||
$keys = [];
|
||||
|
||||
if ($usesAppPrice) {
|
||||
$feeSingle = (float) $config->get('fee_single', 0);
|
||||
if ($isBuy) {
|
||||
$buyFee = (float) $config->get('buy_fee', $feeSingle);
|
||||
$settingsAmt = $buyFee > 0 ? $buyFee : $feeSingle;
|
||||
$settingsKey = $buyFee > 0 ? 'buy_fee' : 'fee_single';
|
||||
$settingsTitle = $buyFee > 0
|
||||
? 'اختلاف پایه اپ · اضافه قیمت خرید (buy_fee)'
|
||||
: 'اختلاف پایه اپ · اختلاف پایه (fee_single)';
|
||||
$settingsAmt = $config->displayBuyPriceDiffRial();
|
||||
$settingsKey = 'buy_fee';
|
||||
$settingsTitle = 'اختلاف پایه اپ · اضافه قیمت خرید (buy_fee)';
|
||||
} else {
|
||||
$sellFee = (float) $config->get('sell_fee', $feeSingle);
|
||||
$settingsAmt = $sellFee > 0 ? $sellFee : $feeSingle;
|
||||
$settingsKey = $sellFee > 0 ? 'sell_fee' : 'fee_single';
|
||||
$settingsTitle = $sellFee > 0
|
||||
? 'اختلاف پایه اپ · کسر قیمت فروش (sell_fee)'
|
||||
: 'اختلاف پایه اپ · اختلاف پایه (fee_single)';
|
||||
$settingsAmt = $config->displaySellPriceDiffRial();
|
||||
$settingsKey = 'sell_fee';
|
||||
$settingsTitle = 'اختلاف پایه اپ · کسر قیمت فروش (sell_fee)';
|
||||
}
|
||||
|
||||
if ($settingsAmt > 0) {
|
||||
|
||||
@@ -51,7 +51,7 @@ class ReportController extends Controller
|
||||
|
||||
public function updatePrise()
|
||||
{
|
||||
$difference = (float) (Setting::where('key', 'fee_single')->value('value') ?? config('fee.single', 0));
|
||||
$config = app(ConfigService::class);
|
||||
$lastPrice = Price::latest()->first();
|
||||
|
||||
if (!$lastPrice) {
|
||||
@@ -60,9 +60,12 @@ class ReportController extends Controller
|
||||
|
||||
$PriceTriggers = PriceTrigger::where("is_active", true)->get();
|
||||
foreach ($PriceTriggers as $PriceTrigger) {
|
||||
$diff = $PriceTrigger->dirction == 1
|
||||
? $config->displaySellPriceDiffRial()
|
||||
: ($PriceTrigger->dirction == 2 ? $config->displayBuyPriceDiffRial() : 0.0);
|
||||
$priseGold = $PriceTrigger->dirction == 1
|
||||
? $lastPrice->price - $difference
|
||||
: ($PriceTrigger->dirction == 2 ? $lastPrice->price + $difference : $lastPrice->price);
|
||||
? $lastPrice->price - $diff
|
||||
: ($PriceTrigger->dirction == 2 ? $lastPrice->price + $diff : $lastPrice->price);
|
||||
|
||||
if (eval('return $priseGold ' . $PriceTrigger->price_condition . ' $PriceTrigger->target_price;')) {
|
||||
$customer = Customer::find($PriceTrigger->customer_id);
|
||||
|
||||
@@ -24,7 +24,7 @@ class Order extends Model
|
||||
'fee',//سود هر گرم
|
||||
'total_fee',//سود کل
|
||||
'fee_source',//settings|product|app+product|none
|
||||
'fee_source_key',//sell_fee|buy_fee|fee_single|cash_fee_sell|...
|
||||
'fee_source_key',//sell_fee|buy_fee|cash_fee_sell|...
|
||||
'fee_source_label',
|
||||
'fee_breakdown',//فاکتور اقلام سود (JSON)
|
||||
'service_charge_percentage',//درصد کارمزد
|
||||
|
||||
@@ -773,8 +773,8 @@ class BalanceReportService
|
||||
}
|
||||
if ($source === 'settings') {
|
||||
return $direction === 2
|
||||
? 'تنظیمات سراسری (sell_fee / fee_single)'
|
||||
: 'تنظیمات سراسری (buy_fee / fee_single)';
|
||||
? 'تنظیمات سراسری (sell_fee)'
|
||||
: 'تنظیمات سراسری (buy_fee)';
|
||||
}
|
||||
|
||||
return $direction === 2
|
||||
|
||||
@@ -101,38 +101,35 @@ class ConfigService
|
||||
return $fromDb !== '' ? $fromDb : (string) env('NODE_SHARED_SECRET', '');
|
||||
}
|
||||
|
||||
/** اختلاف خرید نمایش (/api/price/last) — fee_single / buy_fee */
|
||||
/** اختلاف خرید نمایش (/api/price/last) — فقط buy_fee (صفر یعنی بدون اختلاف) */
|
||||
public function displayBuyPriceDiffRial(): float
|
||||
{
|
||||
$feeSingle = (float) $this->get('fee_single', 0);
|
||||
$buyFee = (float) $this->get('buy_fee', $feeSingle);
|
||||
$raw = $this->getString('buy_fee', '');
|
||||
|
||||
return $buyFee > 0 ? $buyFee : $feeSingle;
|
||||
return $raw === '' ? 0.0 : (float) $raw;
|
||||
}
|
||||
|
||||
/** اختلاف فروش نمایش — fee_single / sell_fee */
|
||||
/** اختلاف فروش نمایش — فقط sell_fee (صفر یعنی بدون اختلاف) */
|
||||
public function displaySellPriceDiffRial(): float
|
||||
{
|
||||
$feeSingle = (float) $this->get('fee_single', 0);
|
||||
$sellFee = (float) $this->get('sell_fee', $feeSingle);
|
||||
$raw = $this->getString('sell_fee', '');
|
||||
|
||||
return $sellFee > 0 ? $sellFee : $feeSingle;
|
||||
return $raw === '' ? 0.0 : (float) $raw;
|
||||
}
|
||||
|
||||
/** اختلاف ریالی سفارش — fee_single، بعد fee_cash (legacy)، بعد config/fee.php */
|
||||
public function orderPriceDiffRial(): float
|
||||
/**
|
||||
* اختلاف ریالی سفارش — فقط buy_fee / sell_fee بر اساس جهت.
|
||||
* fee_single دیگر منبع نیست.
|
||||
*
|
||||
* @param int|null $direction 1=خرید، 2=فروش، null=خرید (برای سازگاری)
|
||||
*/
|
||||
public function orderPriceDiffRial(?int $direction = null): float
|
||||
{
|
||||
$feeSingle = $this->getString('fee_single', '');
|
||||
if ($feeSingle !== '') {
|
||||
return (float) $feeSingle;
|
||||
if ($direction === 2) {
|
||||
return $this->displaySellPriceDiffRial();
|
||||
}
|
||||
|
||||
$legacyCash = $this->getString('fee_cash', '');
|
||||
if ($legacyCash !== '') {
|
||||
return (float) $legacyCash;
|
||||
}
|
||||
|
||||
return (float) config('fee.single', 0);
|
||||
return $this->displayBuyPriceDiffRial();
|
||||
}
|
||||
|
||||
/** درصد کارمزد سفارش — fee_service_charge_percentage، service_charge_percentage، config/fee.php */
|
||||
@@ -172,7 +169,6 @@ class ConfigService
|
||||
): array {
|
||||
$diffBuy = (float) $this->displayBuyPriceDiffRial();
|
||||
$diffSell = (float) $this->displaySellPriceDiffRial();
|
||||
$feeSingle = (float) $this->get('fee_single', 0);
|
||||
|
||||
$openBuy = true;
|
||||
$openSell = true;
|
||||
@@ -191,16 +187,9 @@ class ConfigService
|
||||
return compact('sell', 'buy', 'priceLast');
|
||||
}
|
||||
|
||||
$sell = $openSell ? (int) ceil($priceValue - $feeSingle) : 0;
|
||||
$buy = $openBuy ? (int) ceil($priceValue + $feeSingle) : 0;
|
||||
$priceLast = (int) ceil($priceValue + $feeSingle);
|
||||
|
||||
$provider = $this->priceProvider();
|
||||
if (in_array($provider, ['main_product', 'zaarbox'], true)) {
|
||||
$sell = $openSell ? (int) ceil($priceValue - $diffSell) : 0;
|
||||
$buy = $openBuy ? (int) ceil($priceValue + $diffBuy) : 0;
|
||||
$priceLast = (int) ceil($priceValue + $diffBuy);
|
||||
}
|
||||
$sell = $openSell ? (int) ceil($priceValue - $diffSell) : 0;
|
||||
$buy = $openBuy ? (int) ceil($priceValue + $diffBuy) : 0;
|
||||
$priceLast = (int) ceil($priceValue + $diffBuy);
|
||||
|
||||
return compact('sell', 'buy', 'priceLast');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user