You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Malio/app/Command/DailyMail.php

72 lines
2.0 KiB
PHTML

9 years ago
<?php
namespace App\Command;
use App\Models\User;
use App\Models\Ann;
use App\Services\Config;
use App\Services\Mail;
use App\Utils\Telegram;
use App\Utils\Tools;
use App\Services\Analytics;
use Exception;
9 years ago
class DailyMail
{
public static function sendDailyMail()
{
$users = User::all();
$logs = Ann::orderBy('id', 'desc')->get();
$text1 = '';
8 years ago
9 years ago
foreach ($logs as $log) {
if (strpos($log->content, 'Links') === false) {
$text1 = $text1 . $log->content . '<br><br>';
9 years ago
}
}
8 years ago
9 years ago
$lastday_total = 0;
8 years ago
9 years ago
foreach ($users as $user) {
8 years ago
$lastday = (($user->u + $user->d) - $user->last_day_t) / 1024 / 1024;
$lastday_total += (($user->u + $user->d) - $user->last_day_t);
if ($user->sendDailyMail == 1) {
echo 'Send daily mail to user: ' . $user->id;
$subject = Config::get('appName') . '-每日流量报告以及公告';
9 years ago
$to = $user->email;
$text = '下面是系统中目前的公告:<br><br>' . $text1 . '<br><br>晚安!';
8 years ago
9 years ago
try {
Mail::send($to, $subject, 'news/daily-traffic-report.tpl', [
'user' => $user, 'text' => $text, 'lastday' => $lastday
9 years ago
], [
]);
} catch (Exception $e) {
9 years ago
echo $e->getMessage();
}
$text = '';
9 years ago
}
}
8 years ago
9 years ago
$sts = new Analytics();
8 years ago
Telegram::Send('各位老爷少奶奶,我来为大家报告一下系统今天的运行状况哈~' .
8 years ago
PHP_EOL .
'今日签到人数:' . $sts->getTodayCheckinUser() . PHP_EOL .
'今日使用总流量:' . Tools::flowAutoShow($lastday_total) . PHP_EOL .
'晚安~');
9 years ago
}
public static function reall()
{
$users = User::all();
foreach ($users as $user) {
8 years ago
$user->last_day_t = ($user->u + $user->d);
9 years ago
$user->save();
}
}
}