Some checks failed
ci/woodpecker/push/ci Pipeline failed
- Add AgentStatus model for tracking user availability (online/away/busy/offline) - Add ChatQuickReply model for pre-written chat responses - Add agent status toggle to seller account dropdown menu - Add quick replies management page under CRM settings - Create migration for chat_quick_replies, chat_attachments, agent_statuses tables - Add API endpoint for updating agent status
91 lines
2.1 KiB
PHP
91 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class AgentStatus extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'business_id',
|
|
'status',
|
|
'status_message',
|
|
'last_seen_at',
|
|
'status_changed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'last_seen_at' => 'datetime',
|
|
'status_changed_at' => 'datetime',
|
|
];
|
|
|
|
public const STATUS_ONLINE = 'online';
|
|
public const STATUS_AWAY = 'away';
|
|
public const STATUS_BUSY = 'busy';
|
|
public const STATUS_OFFLINE = 'offline';
|
|
|
|
public static function statuses(): array
|
|
{
|
|
return [
|
|
self::STATUS_ONLINE => 'Online',
|
|
self::STATUS_AWAY => 'Away',
|
|
self::STATUS_BUSY => 'Busy',
|
|
self::STATUS_OFFLINE => 'Offline',
|
|
];
|
|
}
|
|
|
|
public static function statusColors(): array
|
|
{
|
|
return [
|
|
self::STATUS_ONLINE => 'success',
|
|
self::STATUS_AWAY => 'warning',
|
|
self::STATUS_BUSY => 'error',
|
|
self::STATUS_OFFLINE => 'ghost',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function business(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Business::class);
|
|
}
|
|
|
|
public static function getOrCreate(int $userId, int $businessId): self
|
|
{
|
|
return self::firstOrCreate(
|
|
['user_id' => $userId, 'business_id' => $businessId],
|
|
['status' => self::STATUS_OFFLINE, 'status_changed_at' => now()]
|
|
);
|
|
}
|
|
|
|
public function setStatus(string $status, ?string $message = null): self
|
|
{
|
|
$this->update([
|
|
'status' => $status,
|
|
'status_message' => $message,
|
|
'status_changed_at' => now(),
|
|
]);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isOnline(): bool
|
|
{
|
|
return $this->status === self::STATUS_ONLINE;
|
|
}
|
|
|
|
public function getStatusColor(): string
|
|
{
|
|
return self::statusColors()[$this->status] ?? 'ghost';
|
|
}
|
|
}
|