Files
boursecu_server/app/Models/PriceTrigger.php
T
mohmdsdgandCursor b0296c6e94 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>
2026-08-18 22:23:20 +03:30

55 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class PriceTrigger extends Model
{
use HasFactory, SoftDeletes;
private static ?bool $productIdColumnExists = null;
protected $fillable = [
'customer_id',
'product_id',
'target_price',
'price_condition',
'action',
'is_active',
'triggered_at',
];
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);
}
}