first commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\SendSMSJob;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class NotifySubEnd extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:notify-sub-end';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
User::with([
|
||||
'products' => fn ($q) => $q->whereNotIn('gateway', [Transaction::GATEWAYS['cafe'], Transaction::GATEWAYS['myket']])->whereDate('expire_at', now()->subDay()),
|
||||
'products.packageName',
|
||||
])->whereHas('products', fn ($q) => $q->whereDate('expire_at', now()->subDay()))->chunkById(300, function ($users) {
|
||||
foreach ($users as $user) {
|
||||
$link = config('redirects.' . str_replace('.', '*', $user->products[0]->packageName->name));
|
||||
dump($user->mobile);
|
||||
SendSMSJob::dispatch([
|
||||
'mobile' => $user->mobile,
|
||||
'message' => "کاربرعزیز
|
||||
اشتراک برنامه {$user->products[0]->packageName->title} برای شما به پایان رسید
|
||||
برای تمدید کلیک کنید
|
||||
$link"
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Reminder;
|
||||
use App\Jobs\SendPushJob;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SendDueReminders extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'reminders:send-due';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
protected $description = 'Send push notifications for due reminders';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$now = now();
|
||||
$yesterday = now()->subDay();
|
||||
|
||||
$reminders = Reminder::with(['user', 'packageName'])->where(function ($query) use ($now) {
|
||||
$query->where('repeatable', false)
|
||||
->where('time', '<=', $now)
|
||||
->whereNull('last_repeat');
|
||||
})
|
||||
->orWhere(function ($query) use ($now, $yesterday) {
|
||||
$query->where('repeatable', true)
|
||||
->where('time', '<=', $now)
|
||||
->where(function ($sub) use ($now, $yesterday) {
|
||||
$sub->whereNull('last_repeat')
|
||||
->orWhere('last_repeat', '<=', $yesterday);
|
||||
});
|
||||
})
|
||||
->get();
|
||||
|
||||
if ($reminders->isEmpty()) {
|
||||
$this->info('No reminders due at this time.');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
foreach ($reminders as $reminder) {
|
||||
$user = $reminder->user;
|
||||
$packageName = $reminder->packageName;
|
||||
|
||||
if ($reminder->last_repeat?->addDays($reminder->repeat_days)->isFuture()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SendPushJob::dispatch(
|
||||
user: $user,
|
||||
title: $reminder->title,
|
||||
packageName: $packageName,
|
||||
description: $reminder->description ?? '',
|
||||
data: $reminder->data ?? []
|
||||
);
|
||||
|
||||
$reminder->last_repeat = $now;
|
||||
$reminder->save();
|
||||
|
||||
$this->info("Queued push notification for reminder {$reminder->id}.");
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user