Warming.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Heanup\Library;
  3. use Heanup\App\Api\Config\GlobalConfig;
  4. class Warming
  5. {
  6. public static function semdMail($type, $domain, $total, $log_file = null)
  7. {
  8. $day = date("Ymd");
  9. $count = Redis::instance()->incr("alert_" . $type . $day . "_count");
  10. if ($count >= $total) {
  11. $key = "alert_" . $type . "_" . $day;
  12. if (Redis::instance()->get($key)) {
  13. return true;
  14. } else {
  15. Redis::instance()->set($key, 1, 86400);
  16. $receipt = GlobalConfig::getData('recieve');
  17. $subject = GlobalConfig::getData('subject');
  18. $subject = sprintf($subject, $domain);
  19. $body = GlobalConfig::getData('body');
  20. if ($log_file) {
  21. $attachment = ['path' => $log_file, 'name'=>sprintf('log[%s].txt',date("Y-m-d"))];
  22. } else {
  23. $attachment = [];
  24. }
  25. Email::instance()->sendMail($receipt, $subject, $body, $attachment);
  26. }
  27. }
  28. }
  29. }