parent
8f12308f83
commit
59acfcd1af
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\EmailRecord;
|
||||
use App\Models\EmailRecordUser;
|
||||
use App\Models\User;
|
||||
use App\Repositories\MeetRepository;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
class SendEmail extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'send_email';
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$emailRecords = EmailRecord::whereHas('emailRecordUsers', function ($query) {
|
||||
$query->where('status', 0);
|
||||
})->where(function ($query) {
|
||||
$query->whereNull('time')->orWhere('time', '<', date('Y-m-d H:i:s'));
|
||||
})->get();
|
||||
foreach ($emailRecords as $records) {
|
||||
// 获取模版配置
|
||||
$emailTemplate = $records->emailTemplate;
|
||||
// 获取未发送人员
|
||||
$emailRecordUsers = $records->emailRecordUsers->where('status', 0);
|
||||
foreach ($emailRecordUsers as $recordUser) {
|
||||
// 替换后的标题
|
||||
$title = EmailRecordUser::template($records->subject, $recordUser);
|
||||
// 替换后的内容
|
||||
$template = EmailRecordUser::template($emailTemplate->content, $recordUser);
|
||||
// 发送邮件
|
||||
EmailRecordUser::email($title, $template, $recordUser);
|
||||
$recordUser->status = 1;
|
||||
$recordUser->save();
|
||||
}
|
||||
}
|
||||
return $this->info('更新完成');
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
{!! $template !!}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue