feat(cms): implement complete SysSiteCMS content management system
Initial implementation of the HomeSysPanel CMS built with Laravel 13.0. Includes complete admin panel, content management, user authentication, modular architecture for products/services/chatbot, and marketing tools. Key features: - User authentication with email verification and password reset - Role-based access control (Admin/User with granular permissions) - Content management (pages, news, FAQ, downloads, galleries, banners) - Contact management system with subjects and responses - Marketing tools (email campaigns, visitor analytics, social sharing) - Modular architecture (Products, Services, Chatbot modules) - AI Chatbot integration with OpenRouter.ai and LlamaCpp support - Visitor tracking with geolocation - SEO optimization with meta tags and Open Graph - Responsive design with Bootstrap 5 - Dark mode support - Maintenance mode - Feature request system
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Chatbot\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ChatbotConversation extends Model
|
||||
{
|
||||
protected $table = 'chatbot_conversations';
|
||||
|
||||
protected $fillable = [
|
||||
'session_id',
|
||||
'visitor_name',
|
||||
'visitor_email',
|
||||
'visitor_phone',
|
||||
'visitor_city',
|
||||
'status',
|
||||
'rating',
|
||||
'rating_comment',
|
||||
'ended_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'rating' => 'integer',
|
||||
'ended_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the messages for this conversation.
|
||||
*/
|
||||
public function messages(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChatbotMessage::class, 'conversation_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a conversation by session ID.
|
||||
*/
|
||||
public static function getOrCreateBySession(string $sessionId): self
|
||||
{
|
||||
return self::firstOrCreate(
|
||||
['session_id' => $sessionId],
|
||||
['session_id' => $sessionId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the conversation is active.
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->status === 'active';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the conversation is ended.
|
||||
*/
|
||||
public function isEnded(): bool
|
||||
{
|
||||
return $this->status === 'ended';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the conversation context as an array of messages for the API.
|
||||
*/
|
||||
public function getContextForApi(int $maxMessages = 20): array
|
||||
{
|
||||
$messages = $this->messages()
|
||||
->orderBy('created_at', 'asc')
|
||||
->take($maxMessages)
|
||||
->get(['role', 'content']);
|
||||
|
||||
return $messages->map(fn($m) => [
|
||||
'role' => $m->role,
|
||||
'content' => $m->content,
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rating as star display text.
|
||||
*/
|
||||
public function getRatingStarsAttribute(): string
|
||||
{
|
||||
if (!$this->rating) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$stars = str_repeat('★', $this->rating) . str_repeat('☆', 5 - $this->rating);
|
||||
return $stars;
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Chatbot\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChatbotKnowledge extends Model
|
||||
{
|
||||
protected $table = 'chatbot_knowledge';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'content',
|
||||
'restrictions',
|
||||
'category',
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Available categories for knowledge base entries.
|
||||
*/
|
||||
public static function getCategories(): array
|
||||
{
|
||||
return [
|
||||
'company_info' => 'Informações da Empresa',
|
||||
'products' => 'Produtos',
|
||||
'services' => 'Serviços',
|
||||
'faq' => 'Perguntas Frequentes',
|
||||
'general' => 'Geral',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get only active entries.
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all knowledge as a formatted text for the system prompt.
|
||||
*/
|
||||
public static function getFormattedKnowledge(): string
|
||||
{
|
||||
$entries = self::active()->orderBy('category')->orderBy('title')->get();
|
||||
|
||||
if ($entries->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$grouped = $entries->groupBy('category');
|
||||
$categories = self::getCategories();
|
||||
$output = '';
|
||||
|
||||
foreach ($grouped as $category => $items) {
|
||||
$label = $categories[$category] ?? $category;
|
||||
$output .= "\n## {$label}\n";
|
||||
foreach ($items as $item) {
|
||||
$output .= "- **{$item->title}**: {$item->content}\n";
|
||||
if ($item->restrictions) {
|
||||
$output .= " - ⚠️ Restrição: {$item->restrictions}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Chatbot\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ChatbotMessage extends Model
|
||||
{
|
||||
protected $table = 'chatbot_messages';
|
||||
|
||||
protected $fillable = [
|
||||
'conversation_id',
|
||||
'role',
|
||||
'content',
|
||||
'tokens_used',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the conversation this message belongs to.
|
||||
*/
|
||||
public function conversation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChatbotConversation::class, 'conversation_id');
|
||||
}
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Chatbot\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChatbotRule extends Model
|
||||
{
|
||||
protected $table = 'chatbot_rules';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'content',
|
||||
'active',
|
||||
'order',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
'order' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope to get only active rules.
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active rules as a formatted text block for the system prompt.
|
||||
*
|
||||
* Returns an empty string when no active rule exists, so the prompt
|
||||
* stays clean and the AI behaves as before.
|
||||
*/
|
||||
public static function getFormattedRules(): string
|
||||
{
|
||||
$rules = self::active()->orderBy('order')->orderBy('id')->get();
|
||||
|
||||
if ($rules->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$output = '';
|
||||
foreach ($rules as $rule) {
|
||||
$output .= "- **{$rule->title}**: {$rule->content}\n";
|
||||
}
|
||||
|
||||
return trim($output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user