fix some bugs from fee

This commit is contained in:
2026-07-28 10:33:11 +03:30
parent 7c68115b39
commit 745f7fcfd6
8 changed files with 51 additions and 80 deletions
@@ -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);