fix wallet

This commit is contained in:
2026-06-10 13:11:51 +03:30
parent fe4d85325e
commit 539e38d034
14 changed files with 957 additions and 293 deletions
+29
View File
@@ -19,6 +19,7 @@ class Product extends Model
private static ?bool $priceColumnExists = null;
private static ?bool $orderLimitColumnsExist = null;
private static ?bool $showInAssetsColumnExists = null;
private static ?bool $useLastPriceIfZeroColumnExists = null;
protected static function booted(): void
{
@@ -36,6 +37,9 @@ class Product extends Model
if (!static::hasShowInAssetsColumn()) {
unset($product->attributes['show_in_assets']);
}
if (!static::hasUseLastPriceIfZeroColumn()) {
unset($product->attributes['use_last_price_if_zero']);
}
});
}
@@ -109,6 +113,24 @@ class Product extends Model
return static::$showInAssetsColumnExists;
}
public static function hasUseLastPriceIfZeroColumn(): bool
{
if (static::$useLastPriceIfZeroColumnExists !== null) {
return static::$useLastPriceIfZeroColumnExists;
}
try {
static::$useLastPriceIfZeroColumnExists = Schema::hasColumn(
(new static)->getTable(),
'use_last_price_if_zero'
);
} catch (\Throwable) {
static::$useLastPriceIfZeroColumnExists = false;
}
return static::$useLastPriceIfZeroColumnExists;
}
public function orderLimitsEnabled(): bool
{
if (!static::hasOrderLimitColumns() || !($this->order_limit_enabled ?? false)) {
@@ -160,6 +182,7 @@ class Product extends Model
'for_barayand', // Whether it is for Barayand (boolean).
'show', // Whether to show the record (boolean).
'show_in_assets', // Show balance on customer assets page cards
'use_last_price_if_zero', // Keep last DB price when automatic provider returns zero
'open_sell', // Whether selling is open (boolean).
'auto_open_at', // Whether selling is open (boolean).
'auto_close_at', // Whether selling is open (boolean).
@@ -180,11 +203,17 @@ class Product extends Model
'bubble',
];
protected $attributes = [
'show_in_assets' => false,
'use_last_price_if_zero' => false,
];
protected $casts = [
'can_canceled' => 'boolean', // Cast to boolean.
'active' => 'boolean', // Cast to boolean.
'show' => 'boolean', // Cast to boolean.
'show_in_assets' => 'boolean',
'use_last_price_if_zero' => 'boolean',
'for_barayand' => 'boolean', // Cast to boolean.
'open_sell' => 'boolean', // Cast to boolean.
'auto_sell' => 'boolean', // Cast to boolean (you mentioned this in your casts but it's missing in `$fillable`).