classify admin

This commit is contained in:
Husanjonazamov
2026-02-24 12:52:01 +05:00
commit e0f1989655
769 changed files with 1263008 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands;
use Devaslanphp\AutoTranslate\Commands\AutoTranslate;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Stichoza\GoogleTranslate\GoogleTranslate;
class CustomAutoTranslate extends AutoTranslate
{
protected $signature = 'custom:auto-translate';
protected $description = 'This command will search everywhere in your code for translations and generate JSON files for you.';
public function handle()
{
$locales = config('auto-translate.locales');
$files = ['en.json', 'en_web.json', 'en_app.json']; // Add your JSON files here
foreach ($locales as $locale) {
foreach ($files as $file) {
try {
Artisan::call('translatable:export ' . $locale);
// Adjust the file path to handle different file names
$filePath = lang_path(str_replace('en', $locale, $file));
if (File::exists($filePath)) {
$this->info('Translating ' . $locale . ' for ' . $file . ', please wait...');
$results = [];
$localeFile = File::get($filePath);
$localeFileContent = array_keys(json_decode($localeFile, true));
$translator = new GoogleTranslate($locale);
$translator->setSource(config('app.fallback_locale'));
foreach ($localeFileContent as $key) {
$results[$key] = $translator->translate($key);
}
File::put($filePath, json_encode($results, JSON_UNESCAPED_UNICODE));
}
} catch (\Exception $e) {
$this->error('Error: ' . $e->getMessage());
}
}
}
return 0;
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Stichoza\GoogleTranslate\GoogleTranslate;
class CustomTranslateMissing extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'custom:translate-missing {type} {locale}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Translate missing keys in a specific JSON file based on the provided type and locale.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$type = $this->argument('type');
$locale = $this->argument('locale');
$base = config('auto-translate.base_locale', 'en');
$fileName = match ($type) {
'web' => 'en_web.json',
'panel' => 'en.json',
'app' => 'en_app.json',
default => $this->error('Invalid type specified.') && exit(Command::FAILURE),
};
$baseFilePath = lang_path($fileName);
$localeFilePath = match ($type) {
'web' => lang_path($locale . '_web.json'),
'panel' => lang_path($locale . '.json'),
'app' => lang_path($locale . '_app.json'),
default => $this->error('Invalid type specified.') && exit(Command::FAILURE),
};
if (!File::exists($baseFilePath)) {
$this->error("Base file '{$baseFilePath}' not found.");
return Command::FAILURE;
}
$baseTranslations = json_decode(File::get($baseFilePath), true);
$localeTranslations = File::exists($localeFilePath) ? json_decode(File::get($localeFilePath), true) : [];
$translator = new GoogleTranslate();
$translator->setSource($base);
$translator->setTarget($locale);
$newLocaleTranslations = [];
foreach ($baseTranslations as $key => $baseTranslation) {
try {
$translatedText = $translator->translate($baseTranslation);
$newLocaleTranslations[$key] = $translatedText;
} catch (\Exception $e) {
$this->error('Error: ' . $e->getMessage());
$newLocaleTranslations[$key] = $baseTranslation;
}
}
File::put($localeFilePath, json_encode($newLocaleTranslations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
$this->info("Translation for type '{$type}' and locale '{$locale}' completed successfully.");
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\ExpiringItemService;
class NotifyExpiringItems extends Command
{
protected $signature = 'notify:expiring-items';
protected $description = 'Send notifications for items expiring in 2 days.';
protected $expiringItemService;
/**
* Inject the ExpiringItemService
*/
public function __construct(ExpiringItemService $expiringItemService)
{
parent::__construct();
$this->expiringItemService = $expiringItemService;
}
/**
* Execute the console command.
*/
public function handle()
{
$this->expiringItemService->notifyExpiringItems();
$this->info('Expiring Advertisement notifications sent successfully.');
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\ExpiringItemService;
class NotifyExpiringPackages extends Command
{
protected $signature = 'notify:expiring-packages';
protected $description = 'Send notifications for expiring packages.';
public function __construct()
{
parent::__construct();
}
public function handle(ExpiringItemService $expiringItemService)
{
$expiringItemService->notifyExpiringPackages();
$this->info('Expiring packages notifications sent successfully.');
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ProcessQueue extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'queue:process
{--tries=3 : Number of times to attempt a job}
{--timeout=300 : The number of seconds a child process can run}
{--max-jobs=50 : Number of jobs to process before stopping}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Process queue jobs with stop-when-empty';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
// IMPORTANT:
// Do not rely on the `jobs` table count here.
// The default queue connection may be `redis`/`sqs`/etc, where there is no `jobs` table.
// `queue:work --stop-when-empty` will exit automatically if there are no jobs.
$connection = config('queue.default');
$this->info("Processing queue connection [{$connection}]...");
$this->call('queue:work', [
'connection' => $connection,
'--stop-when-empty' => true,
'--tries' => $this->option('tries'),
'--timeout' => $this->option('timeout'),
'--max-jobs' => $this->option('max-jobs'),
]);
return Command::SUCCESS;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\UserFcmToken;
use App\Services\NotificationService;
class SendFcmBatch extends Command
{
protected $signature = 'send:fcm-batch {data}';
protected $description = 'Send FCM notifications in batch from background';
public function handle()
{
$data = json_decode($this->argument('data'), true);
$title = $data['title'] ?? '';
$message = $data['message'] ?? '';
$type = $data['type'] ?? 'notification';
$customBodyFields = $data['customBodyFields'] ?? [];
$sendToAll = $data['sendToAll'] ?? false;
$userIds = $data['userIds'] ?? [];
$this->info("🔔 Sending FCM notifications...");
// ✅ If sendToAll = true
if ($sendToAll) {
// Fetch tokens with user preference
$tokens = UserFcmToken::with('user')
->whereHas('user', fn($q) => $q->where('notification', 1))
->get(['fcm_token', 'platform_type']);
// Split tokens by platform
$androidIosTokens = $tokens->whereIn('platform_type', ['Android', 'iOS'])->pluck('fcm_token')->toArray();
$otherTokens = $tokens->whereNotIn('platform_type', ['Android', 'iOS'])->pluck('fcm_token')->toArray();
// ✅ Send Android/iOS via Topic
if (!empty($androidIosTokens)) {
NotificationService::sendFcmNotification(
[], $title, $message, $type, $customBodyFields, true
);
$this->info("📱 Topic-based notification sent to Android/iOS users.");
}
// ✅ Send Others via Chunk (if any)
if (!empty($otherTokens)) {
collect($otherTokens)->chunk(500)->each(function ($chunk) use ($title, $message, $type, $customBodyFields) {
NotificationService::sendFcmNotification(
$chunk->toArray(), $title, $message, $type, $customBodyFields, false
);
});
$this->info("💻 Chunk-based notification sent to other platform users.");
}
} else {
// ✅ Send to specific selected users
UserFcmToken::with('user')
->whereIn('user_id', $userIds)
->whereHas('user', fn($q) => $q->where('notification', 1))
->chunk(500, function ($tokens) use ($title, $message, $type, $customBodyFields) {
$fcmTokens = $tokens->pluck('fcm_token')->toArray();
NotificationService::sendFcmNotification(
$fcmTokens, $title, $message, $type, $customBodyFields, false
);
});
$this->info("👥 Notifications sent to selected users.");
}
$this->info("✅ FCM notifications process completed successfully!");
}
}

45
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
\App\Console\Commands\CustomAutoTranslate::class,
\App\Console\Commands\CustomTranslateMissing::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('notify:expiring-items')->daily();
$schedule->command('notify:expiring-packages')->daily();
// Process queue jobs every minute
// Using custom command that wraps queue:work for better reliability
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}