增加 两种通知
This commit is contained in:
parent
39b76d0fa7
commit
d1fad94644
73
app/Jobs/Host/CancelExpiredHostJob.php
Normal file
73
app/Jobs/Host/CancelExpiredHostJob.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Host;
|
||||
|
||||
use App\Models\Host;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CancelExpiredHostJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected ?Host $host;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Host $host = null)
|
||||
{
|
||||
$this->host = $host;
|
||||
|
||||
$this->onQueue('host-cost');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$now = now();
|
||||
|
||||
if (! $this->host) {
|
||||
$host = new Host();
|
||||
|
||||
// 查找试用到期的主机
|
||||
$host->where('day_at', $now->day)
|
||||
->where('hour_at', $now->hour)
|
||||
->where('trial_ends_at', '<', $now)
|
||||
->chunk(500, function ($hosts) {
|
||||
$hosts->each(function ($host) {
|
||||
/* @var Host $host */
|
||||
|
||||
if ($host->module->isUp()) {
|
||||
dispatch(new self($host));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 查找到期的主机
|
||||
$host->where('expired_at', '<', $now)
|
||||
->chunk(500, function ($hosts) {
|
||||
$hosts->each(function ($host) {
|
||||
/* @var Host $host */
|
||||
|
||||
if ($host->module->isUp()) {
|
||||
dispatch(new self($host));
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if ($this->host->isNextMonthCancel()) {
|
||||
$this->host->safeDelete();
|
||||
} else {
|
||||
$this->host->cost();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
46
app/Notifications/User/BalanceNotEnough.php
Normal file
46
app/Notifications/User/BalanceNotEnough.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\User;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\WebChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class BalanceNotEnough extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*/
|
||||
public function via(): array
|
||||
{
|
||||
return [WebChannel::class, 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(User $user): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('账户余额不足')
|
||||
->greeting('您好,'.$user->name)
|
||||
->line('账户余额不足')
|
||||
->line('一个或多个主机已被暂停。')
|
||||
->action('查看主机', route('hosts.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'title' => '账户余额不足',
|
||||
'message' => '被影响的主机已暂停。',
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user