fix zarin duplicate hesab and convert mesghal unit price to gram before cash/weight.
Reuse an existing Zarin hesab instead of a second addhesab, and stop rial-locked orders from treating mesghal as per-gram. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -193,6 +193,34 @@ class ConfigService
|
||||
return $raw === '' ? 0.0 : (float) $raw;
|
||||
}
|
||||
|
||||
public const DEFAULT_CHANGE_MESGHAL = 4.3318;
|
||||
|
||||
/** وزن هر مثقال به گرم — برای تشخیص قیمت مثقال بهجای قیمت گرم */
|
||||
public function changeMesghalFactor(): float
|
||||
{
|
||||
$value = (float) $this->get('change_mesghal', self::DEFAULT_CHANGE_MESGHAL);
|
||||
|
||||
return $value > 0 ? $value : self::DEFAULT_CHANGE_MESGHAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* اگر قیمت واحد حدود قیمت مثقال باشد (گرم زنده × ضریب)، به قیمت هر گرم برگردان.
|
||||
*/
|
||||
public function gramUnitPriceIfMesghalQuoted(float $unitPrice, float $liveGramPrice): float
|
||||
{
|
||||
$factor = $this->changeMesghalFactor();
|
||||
if ($unitPrice <= 0 || $liveGramPrice <= 0 || $factor <= 1) {
|
||||
return $unitPrice;
|
||||
}
|
||||
|
||||
$ratio = $unitPrice / $liveGramPrice;
|
||||
if ($ratio >= $factor * 0.92 && $ratio <= $factor * 1.08) {
|
||||
return $unitPrice / $factor;
|
||||
}
|
||||
|
||||
return $unitPrice;
|
||||
}
|
||||
|
||||
/** اختلاف فروش نمایش — فقط sell_fee (صفر یعنی بدون اختلاف) */
|
||||
public function displaySellPriceDiffRial(): float
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user