优惠券小程序

EmailQueue.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/3/22
  6. * Time: 15:47
  7. */
  8. namespace App\Support;
  9. use App\Models\Redis\RedisModel;
  10. class EmailQueue
  11. {
  12. const KEY = 'tbk_onlive_admin_email_queue_key';
  13. const DISABLE_EMAIL = [];
  14. public static function rPush($title, $content, $emails, $sender = '')
  15. {
  16. // 防止大量错误导致队列堆积
  17. if (RedisModel::lLen(self::KEY) > 1000) {
  18. return;
  19. }
  20. // 剔除已离职人员邮箱
  21. $sendEmails = [];
  22. if(is_array($emails)){
  23. foreach($emails as $email) {
  24. if(!in_array($email, self::DISABLE_EMAIL)) {
  25. $sendEmails[] = $email;
  26. }
  27. }
  28. }
  29. if(empty($sendEmails)) {
  30. return;
  31. }
  32. $emailData = json_encode([
  33. 'title' => $title,
  34. 'content' => $content,
  35. 'emails' => (array) $sendEmails,
  36. 'sender' => $sender
  37. ], JSON_UNESCAPED_UNICODE);
  38. RedisModel::rPush(self::KEY, $emailData);
  39. }
  40. }