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
139 lines
5.2 KiB
PHP
Executable File
139 lines
5.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Models\Setting;
|
|
use App\Models\VisitorLog;
|
|
use App\Mail\PromotionMail;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MarketingController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('admin.marketing.index');
|
|
}
|
|
|
|
public function promoteProducts()
|
|
{
|
|
if (!module_enabled('products') || !class_exists(\App\Modules\Products\Models\Product::class)) {
|
|
return redirect()->route('admin.marketing.index')->with('error', 'O módulo de Produtos está desativado.');
|
|
}
|
|
|
|
$products = \App\Modules\Products\Models\Product::where('active', true)->with('category')->get();
|
|
return view('admin.marketing.promote_products', compact('products'));
|
|
}
|
|
|
|
public function promoteServices()
|
|
{
|
|
if (!module_enabled('services') || !class_exists(\App\Modules\Services\Models\Service::class)) {
|
|
return redirect()->route('admin.marketing.index')->with('error', 'O módulo de Serviços está desativado.');
|
|
}
|
|
|
|
$services = \App\Modules\Services\Models\Service::where('active', true)->get();
|
|
return view('admin.marketing.promote_services', compact('services'));
|
|
}
|
|
|
|
public function analytics()
|
|
{
|
|
// Grouping by Country
|
|
$countries = VisitorLog::select('country', DB::raw('count(*) as total'))
|
|
->groupBy('country')
|
|
->orderBy('total', 'desc')
|
|
->limit(10)
|
|
->get();
|
|
|
|
// Grouping by City
|
|
$cities = VisitorLog::select('city', 'region', DB::raw('count(*) as total'))
|
|
->groupBy('city', 'region')
|
|
->orderBy('total', 'desc')
|
|
->limit(10)
|
|
->get();
|
|
|
|
// Data for last 7 days access chart
|
|
$last7Days = collect(range(6, 0))->map(function ($days) {
|
|
$date = now()->subDays($days)->format('Y-m-d');
|
|
return [
|
|
'date' => now()->subDays($days)->format('d/m'),
|
|
'total' => VisitorLog::whereDate('created_at', $date)->count()
|
|
];
|
|
});
|
|
|
|
return view('admin.marketing.analytics', compact('countries', 'cities', 'last7Days'));
|
|
}
|
|
|
|
public function emailMarketing()
|
|
{
|
|
$products = collect();
|
|
$services = collect();
|
|
|
|
if (module_enabled('products') && class_exists(\App\Modules\Products\Models\Product::class)) {
|
|
$products = \App\Modules\Products\Models\Product::where('active', true)->get();
|
|
}
|
|
|
|
if (module_enabled('services') && class_exists(\App\Modules\Services\Models\Service::class)) {
|
|
$services = \App\Modules\Services\Models\Service::where('active', true)->get();
|
|
}
|
|
|
|
$userCount = User::where('user_type', 'User')->count();
|
|
|
|
return view('admin.marketing.email', compact('products', 'services', 'userCount'));
|
|
}
|
|
|
|
public function sendEmailMarketing(Request $request)
|
|
{
|
|
$request->validate([
|
|
'subject' => 'required|string|max:255',
|
|
'message' => 'required|string',
|
|
'button_text' => 'nullable|string|max:50',
|
|
'button_url' => 'nullable|string|max:500|regex:/^https?:\/\/.+\..+$/i',
|
|
], [
|
|
'button_url.regex' => 'O link do botão deve começar com http:// ou https:// e ter um formato válido.',
|
|
]);
|
|
|
|
$users = User::where('user_type', 'User')->get();
|
|
$company = (object)[
|
|
'name' => Setting::get('company_name', config('app.name')),
|
|
];
|
|
|
|
$productImage = null;
|
|
if ($request->product_id && module_enabled('products') && class_exists(\App\Modules\Products\Models\Product::class)) {
|
|
$product = \App\Modules\Products\Models\Product::find($request->product_id);
|
|
if ($product && $product->image) {
|
|
$productImage = asset('storage/' . $product->image);
|
|
}
|
|
} elseif ($request->service_id && module_enabled('services') && class_exists(\App\Modules\Services\Models\Service::class)) {
|
|
$service = \App\Modules\Services\Models\Service::find($request->service_id);
|
|
if ($service && $service->image) {
|
|
$productImage = asset('storage/' . $service->image);
|
|
}
|
|
}
|
|
|
|
foreach ($users as $user) {
|
|
// Check if user wants to receive emails (preference)
|
|
$prefs = $user->preferences ?? [];
|
|
if ($prefs['notifications_email'] ?? true) {
|
|
try {
|
|
Mail::to($user->email)->send(new PromotionMail(
|
|
$request->subject,
|
|
$request->message,
|
|
$request->button_text,
|
|
$request->button_url,
|
|
$productImage,
|
|
$company
|
|
));
|
|
} catch (\Exception $e) {
|
|
Log::error("Erro ao enviar e-mail de marketing para {$user->email}: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
return redirect()->route('admin.marketing.email')->with('success', 'E-mail de marketing enviado para ' . $users->count() . ' clientes!');
|
|
}
|
|
}
|