2026-08-23 14:16:00 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class Automation extends Model
|
|
|
|
|
{
|
|
|
|
|
use SoftDeletes;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'code',
|
|
|
|
|
'is_active',
|
|
|
|
|
'starts_at',
|
|
|
|
|
'ends_at',
|
|
|
|
|
'sms_send_hour',
|
2026-08-24 22:13:06 +03:30
|
|
|
'sms_send_minute',
|
2026-08-23 14:16:00 +03:30
|
|
|
'in_app_send_hour',
|
2026-08-24 22:13:06 +03:30
|
|
|
'in_app_send_minute',
|
2026-08-23 14:16:00 +03:30
|
|
|
'trigger_type',
|
|
|
|
|
'trigger_config',
|
|
|
|
|
'last_anchor_price',
|
|
|
|
|
'conditions',
|
|
|
|
|
'channels',
|
|
|
|
|
'title',
|
|
|
|
|
'body',
|
|
|
|
|
'cooldown_hours',
|
|
|
|
|
'max_sends',
|
|
|
|
|
'logic_fingerprint',
|
|
|
|
|
'sent_count',
|
|
|
|
|
'failed_count',
|
|
|
|
|
'last_sms_run_at',
|
|
|
|
|
'last_in_app_run_at',
|
|
|
|
|
'created_by',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_active' => 'boolean',
|
|
|
|
|
'starts_at' => 'datetime',
|
|
|
|
|
'ends_at' => 'datetime',
|
|
|
|
|
'trigger_config' => 'array',
|
|
|
|
|
'conditions' => 'array',
|
|
|
|
|
'channels' => 'array',
|
|
|
|
|
'last_anchor_price' => 'float',
|
|
|
|
|
'sms_send_hour' => 'integer',
|
2026-08-24 22:13:06 +03:30
|
|
|
'sms_send_minute' => 'integer',
|
2026-08-23 14:16:00 +03:30
|
|
|
'in_app_send_hour' => 'integer',
|
2026-08-24 22:13:06 +03:30
|
|
|
'in_app_send_minute' => 'integer',
|
2026-08-23 14:16:00 +03:30
|
|
|
'cooldown_hours' => 'integer',
|
|
|
|
|
'max_sends' => 'integer',
|
|
|
|
|
'sent_count' => 'integer',
|
|
|
|
|
'failed_count' => 'integer',
|
|
|
|
|
'last_sms_run_at' => 'datetime',
|
|
|
|
|
'last_in_app_run_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function sends(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AutomationSend::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delayedJobs(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AutomationDelayedJob::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function usesChannel(string $channel): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($channel, $this->channels ?? [], true);
|
|
|
|
|
}
|
|
|
|
|
}
|