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

82 lines
2.2 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
if (Config::get('sendDiary_Telegram') == 'true') {
Telegram::Send(
str_replace(
array(
'%getTodayCheckinUser%',
'%lastday_total%'
),
array(
$sts->getTodayCheckinUser(),
Tools::flowAutoShow($lastday_total)
),
Config::get('sendDiary_Msg')
)
);
}
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();
}
}
}