QueueApi.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhoujun
  5. * Date: 2018/9/1
  6. * Time: 12:11
  7. */
  8. namespace addons\faqueue\library;
  9. use addons\faqueue\model\FaqueueLog;
  10. use think\Db;
  11. use think\Queue;
  12. class QueueApi
  13. {
  14. public static function sendEmail($subject, $to, $message)
  15. {
  16. $data = [
  17. 'subject' => $subject,
  18. 'to' => $to,
  19. 'message' => $message,
  20. ];
  21. return self::push('addons\faqueue\library\jobs\EmailJob', $data);
  22. }
  23. public static function smsSend($mobile, $code = null, $event = 'default')
  24. {
  25. $data = [
  26. 'method' => 'send',
  27. 'mobile' => $mobile,
  28. 'code' => $code,
  29. 'event' => $event,
  30. ];
  31. return self::push('addons\faqueue\library\jobs\SmsJob', $data);
  32. }
  33. public static function smsNotice($mobile, $msg = '', $template = null)
  34. {
  35. $data = [
  36. 'method' => 'notice',
  37. 'mobile' => $mobile,
  38. 'msg' => $msg,
  39. 'template' => $template,
  40. ];
  41. return self::push('addons\faqueue\library\jobs\SmsJob', $data);
  42. }
  43. //发生im消息推送-自定义消息飘屏
  44. public static function sendGroupMessage($type, $sender, $receiver, $partyInfo, $giftUserParty)
  45. {
  46. if (!$type) {
  47. return false;
  48. }
  49. $messageData = [
  50. 'type' => $type,
  51. 'content' => [
  52. 'party_info' => [
  53. 'party_id' => $partyInfo['id'],
  54. 'room_type' => $partyInfo['room_type'],
  55. 'party_name' => $partyInfo['party_name']
  56. ],
  57. 'notice_info' => [
  58. 'sender' => $sender,
  59. 'receiver' => $receiver,
  60. 'gift_num' => $giftUserParty['number'],
  61. 'gift_name' => $giftUserParty['gift_name'],
  62. 'gift_image' => $giftUserParty['gift_gif_image'],
  63. 'gift_rgb_color' => "#fde4ac"
  64. ]
  65. ]
  66. ];
  67. return self::later(1, 'addons\faqueue\library\jobs\SendImMsessageJob', $messageData);
  68. }
  69. //定时检测贵族保级
  70. public static function timeRelegation($id, $endTime=0,$noble=0)
  71. {
  72. if (empty($id)) {
  73. return false;
  74. }
  75. $messageData = [
  76. 'user_id'=>$id,
  77. 'end_time'=>$endTime,
  78. 'noble'=>$noble
  79. ];
  80. return self::later($endTime-time(),'addons\faqueue\library\jobs\CheckRelegation', $messageData);
  81. // return self::later(30,'addons\faqueue\library\jobs\CheckRelegation', $messageData);
  82. }
  83. public static function push($job, $data = '', $queue = null)
  84. {
  85. return Queue::push($job, $data, $queue);
  86. }
  87. public static function later($delay, $job, $data = '', $queue = null)
  88. {
  89. return Queue::later($delay, $job, $data, $queue);
  90. }
  91. }