diff --git a/app/Jobs/Host/CancelExpiredHostJob.php b/app/Jobs/Host/CancelExpiredHostJob.php new file mode 100644 index 0000000..4f6926a --- /dev/null +++ b/app/Jobs/Host/CancelExpiredHostJob.php @@ -0,0 +1,73 @@ +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(); + } + } + } +} diff --git a/app/Notifications/User/BalanceNotEnough.php b/app/Notifications/User/BalanceNotEnough.php new file mode 100644 index 0000000..90581ab --- /dev/null +++ b/app/Notifications/User/BalanceNotEnough.php @@ -0,0 +1,46 @@ +subject('账户余额不足') + ->greeting('您好,'.$user->name) + ->line('账户余额不足') + ->line('一个或多个主机已被暂停。') + ->action('查看主机', route('hosts.index')); + } + + /** + * Get the array representation of the notification. + */ + public function toArray(): array + { + return [ + 'title' => '账户余额不足', + 'message' => '被影响的主机已暂停。', + ]; + } +}