43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Console\Command;
|
|
|
|
class UserBirthdayNotify extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'user:birthday-notify';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '用户生日通知';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$now = now();
|
|
$users = User::whereDay('birthday', $now->day)->whereMonth('birthday', $now->month)->get();
|
|
$phone = $users->implode('phone', ',');
|
|
try {
|
|
$easySms = new EasySms(config('easysms'));
|
|
$result = $easySms->send($phone, [
|
|
'template' => 'SMS_463637721',
|
|
]);
|
|
logger('生日短信发送成功: ' . $phone, $result);
|
|
} catch (\Exception $e) {
|
|
logger()->error('生日短信发送失败', $e->getException('aliyun')->raw);
|
|
}
|
|
}
|
|
}
|