feat(server): evaluate price alerts per product and fix gold discharge rounding

Alerts now bind to a product_id and share one evaluator; displayed gold within a rounding step discharges the full wallet.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 22:23:20 +03:30
co-authored by Cursor
parent 341b2da2c9
commit b0296c6e94
10 changed files with 454 additions and 55 deletions
+27
View File
@@ -9,8 +9,11 @@ class PriceTrigger extends Model
{
use HasFactory, SoftDeletes;
private static ?bool $productIdColumnExists = null;
protected $fillable = [
'customer_id',
'product_id',
'target_price',
'price_condition',
'action',
@@ -20,8 +23,32 @@ class PriceTrigger extends Model
protected $casts = [
"is_active" => "boolean",
];
public static function hasProductIdColumn(): bool
{
if (static::$productIdColumnExists !== null) {
return static::$productIdColumnExists;
}
try {
static::$productIdColumnExists = \Illuminate\Support\Facades\Schema::hasColumn(
(new static)->getTable(),
'product_id'
);
} catch (\Throwable) {
static::$productIdColumnExists = false;
}
return static::$productIdColumnExists;
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
}