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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user