added percent in product price

This commit is contained in:
2026-07-04 18:00:57 +03:30
parent 4dea2fb212
commit 4ef0dfb2c0
7 changed files with 161 additions and 6 deletions
+34
View File
@@ -24,6 +24,7 @@ class Product extends Model
private static ?bool $tradeByQuantityColumnExists = null;
private static ?bool $inventoryColumnExists = null;
private static ?bool $overrideTradingHoursColumnExists = null;
private static ?bool $cashFeePercentModeColumnsExist = null;
protected static function booted(): void
{
@@ -56,6 +57,12 @@ class Product extends Model
if (!static::hasOverrideTradingHoursColumn()) {
unset($product->attributes['override_trading_hours']);
}
if (!static::hasCashFeePercentModeColumns()) {
unset(
$product->attributes['cash_fee_buy_is_percent'],
$product->attributes['cash_fee_sell_is_percent']
);
}
});
}
@@ -77,6 +84,27 @@ class Product extends Model
return static::$overrideTradingHoursColumnExists;
}
public static function hasCashFeePercentModeColumns(): bool
{
if (static::$cashFeePercentModeColumnsExist !== null) {
return static::$cashFeePercentModeColumnsExist;
}
try {
static::$cashFeePercentModeColumnsExist = Schema::hasColumn(
(new static)->getTable(),
'cash_fee_buy_is_percent'
) && Schema::hasColumn(
(new static)->getTable(),
'cash_fee_sell_is_percent'
);
} catch (\Throwable) {
static::$cashFeePercentModeColumnsExist = false;
}
return static::$cashFeePercentModeColumnsExist;
}
public static function hasPriceOffsetColumn(): bool
{
if (static::$priceOffsetColumnExists !== null) {
@@ -283,6 +311,8 @@ class Product extends Model
'percent_fee_sell', // Add percent_fee_sell to fillable
'cash_fee_buy', // Add cash_fee_buy to fillable
'cash_fee_sell', // Add cash_fee_sell to fillable
'cash_fee_buy_is_percent',
'cash_fee_sell_is_percent',
'percent_fee_buy', // Add percent_fee_buy to fillable
'order_limit_enabled',
'min_order_cash',
@@ -300,6 +330,8 @@ class Product extends Model
'show_in_assets' => false,
'trade_by_quantity' => false,
'use_last_price_if_zero' => false,
'cash_fee_buy_is_percent' => false,
'cash_fee_sell_is_percent' => false,
];
protected $casts = [
@@ -323,6 +355,8 @@ class Product extends Model
'max_order_cash' => 'int',
'cash_fee_buy' => 'int', // Cast to int or decimal if needed
'cash_fee_sell' => 'int', // Cast to int or decimal if needed
'cash_fee_buy_is_percent' => 'boolean',
'cash_fee_sell_is_percent' => 'boolean',
'price_offset_percent' => 'float',
'price_profit' => 'int',
];