master
cody 6 months ago
parent f38c64cc7d
commit cea3a14093

@ -0,0 +1,55 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use App\Notifications\AuditNotify;
use App\Notifications\BirthdayNotify;
use App\Repositories\MeetRepository;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Notification;
class CheckBirthday extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check_birthday';
/**
* The console command description.
*
* @var string
*/
protected $description = '检测今天哪些人生日';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = User::where('birthday', date('Y-m-d'))->get();
foreach ($users as $user) {
Notification::send($user, new BirthdayNotify(['user_id' => $user->id]));
}
return $this->info('更新完成');
}
}

@ -9,6 +9,7 @@ use App\Models\Config;
use App\Models\Course;
use App\Models\CourseSign;
use App\Models\Notifications;
use App\Models\User;
use EasyWeChat\Factory;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
@ -237,6 +238,12 @@ class SendNotification extends Command
$content = "{$smsSign}亲爱的同学最新课表已发布您可在STBC小程序“我的”-“我的课程”-“本班课表”中查看。";
$this->smsNotice($vo, $content);
break;
case "App\Notifications\BirthdayNotify":
// 排课通知
$user = User::find($data['user_id']);
$content = "{$smsSign}亲爱的同学:祝您生日快乐!";
$this->smsNotice($vo, $content);
break;
}
return $this->info('发送完成');
}

@ -18,9 +18,10 @@ class Kernel extends ConsoleKernel
$schedule->command("sms:notification")->everyMinute();
$schedule->command('update_sign_status')->everyMinute();
$schedule->command('update_letter')->everyMinute();
// $schedule->command('update_appointment')->everyMinute();
// $schedule->command('update_appointment')->everyMinute();
$schedule->command('update_appointment_total')->dailyAt('1:00');
// 生日检测
$schedule->command('check_birthday')->dailyAt('09:00');
}
/**

@ -246,7 +246,12 @@ class UserController extends CommonController
$enter_schoolmate = User::whereHas('courseSigns', function ($query) {
$query->where('fee_status', 1)->where('status', 1);
})->where('id', $this->getUserId())->count();
return $this->success(compact('user', 'door_appointments', 'course_signs', 'enter_schoolmate'));
// 是否生日
$is_birthday = 0;
if ($user->birthday == date('Y-m-d')) {
$is_birthday = 1;
}
return $this->success(compact('user', 'door_appointments', 'course_signs', 'enter_schoolmate', 'is_birthday'));
}
/**

@ -0,0 +1,48 @@
<?php
/**
* 缴费通知
*/
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class BirthdayNotify extends Notification
{
use Queueable;
public $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return $this->data;
}
}
Loading…
Cancel
Save