Add formula-based product pricing (P/W/MG) for Parsian-style unit prices.

Port FormulaPriceService from colleague app so admins can compute a single unit price from reference mid, weight, and wage instead of offset coefficients.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-10 16:47:29 +03:30
co-authored by Cursor
parent 71a48c9c08
commit f421fcb83f
9 changed files with 515 additions and 9 deletions
+28
View File
@@ -28,6 +28,7 @@ class Product extends Model
private static ?bool $cashFeePercentModeColumnsExist = null;
private static ?bool $physicalDeliveryColumnsExist = null;
private static ?bool $descriptionColumnExists = null;
private static ?bool $priceFormulaColumnsExist = null;
protected static function booted(): void
{
@@ -78,9 +79,32 @@ class Product extends Model
$product->attributes['min_physical_delivery_quantity']
);
}
if (!static::hasPriceFormulaColumns()) {
unset(
$product->attributes['price_formula_enabled'],
$product->attributes['price_formula']
);
}
});
}
public static function hasPriceFormulaColumns(): bool
{
if (static::$priceFormulaColumnsExist !== null) {
return static::$priceFormulaColumnsExist;
}
try {
$table = (new static)->getTable();
static::$priceFormulaColumnsExist = Schema::hasColumn($table, 'price_formula_enabled')
&& Schema::hasColumn($table, 'price_formula');
} catch (\Throwable) {
static::$priceFormulaColumnsExist = false;
}
return static::$priceFormulaColumnsExist;
}
public static function hasPhysicalDeliveryColumns(): bool
{
if (static::$physicalDeliveryColumnsExist !== null) {
@@ -418,6 +442,8 @@ class Product extends Model
'description',
'direct_price',
'app_price', // روشن: قیمت واحد از قیمت زندهٔ اپ هر گرم × وزن محاسبه می‌شود
'price_formula_enabled',
'price_formula',
];
protected $attributes = [
@@ -427,6 +453,7 @@ class Product extends Model
'cash_fee_buy_is_percent' => false,
'cash_fee_sell_is_percent' => false,
'app_price' => false,
'price_formula_enabled' => false,
];
protected $casts = [
@@ -457,6 +484,7 @@ class Product extends Model
'price_offset_percent' => 'float',
'price_profit' => 'int',
'app_price' => 'boolean',
'price_formula_enabled' => 'boolean',
];
static $METAL_ID = [