|
@@ -0,0 +1,161 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Jobs\Manager\Process;
|
|
|
|
|
+
|
|
|
|
|
+use Illuminate\Bus\Queueable;
|
|
|
|
|
+use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
|
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
|
+use Illuminate\Queue\SerializesModels;
|
|
|
|
|
+use App\Facades\Servers\Logs\Log;
|
|
|
|
|
+use App\Models\Manager\Process\SubNoticeLog as SubNoticeLogModel;
|
|
|
|
|
+use App\Models\Manager\Process\StatisticsNotices as StatisticsNoticesModel;
|
|
|
|
|
+use App\Servers\Email\VerifyCode as EmailVerifyCode;
|
|
|
|
|
+use App\Servers\Sms\VerifyCode as SmsVerifyCode;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 发送订阅通知
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2026-04-11
|
|
|
|
|
+ */
|
|
|
|
|
+class SendNoticeJobs implements ShouldQueue
|
|
|
|
|
+{
|
|
|
|
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
+ protected $message_data;
|
|
|
|
|
+ protected $user_data;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Create a new job instance.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function __construct(array $message_data)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->message_data = $message_data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Execute the job.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function handle()
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $company_id = $this->message_data['company_id'];
|
|
|
|
|
+ $SubNoticeLogModel = new SubNoticeLogModel();
|
|
|
|
|
+
|
|
|
|
|
+ //查询需要发送的通知,push_time等于当前时间,或者大于当前时间5分钟的通知
|
|
|
|
|
+ $now_time = time();
|
|
|
|
|
+ $sub_notice_list = $SubNoticeLogModel->where(['company_id' => $company_id])->whereOr([['push_time', '=', $now_time], ['push_time', '>', $now_time - 300]])->get()->toarray();
|
|
|
|
|
+ if (empty($sub_notice_list)) return true;
|
|
|
|
|
+ //执行发送站内信
|
|
|
|
|
+ $this->send_internal_msg($sub_notice_list);
|
|
|
|
|
+ //执行发送邮件内容
|
|
|
|
|
+ $this->send_email_content($sub_notice_list);
|
|
|
|
|
+ //执行发送短信记录
|
|
|
|
|
+ // $this->send_sms_record($sub_notice_list);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::info('job_error', '发送订阅通知队列失败', ['data' => $this->message_data, 'error' => $e->getMessage()]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送站内信通知
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2026-04-11
|
|
|
|
|
+ * @param $data
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ public function send_internal_msg($sub_notice_list)
|
|
|
|
|
+ {
|
|
|
|
|
+ $StatisticsNoticesModel = new StatisticsNoticesModel();
|
|
|
|
|
+ $SubNoticeLogModel = new SubNoticeLogModel();
|
|
|
|
|
+ $notices_data = [];
|
|
|
|
|
+ foreach ($sub_notice_list as $key => $value) {
|
|
|
|
|
+ if ($value['internal_notice_status'] == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $notices_data[] = [
|
|
|
|
|
+ 'company_id' => $value['company_id'],
|
|
|
|
|
+ 'employee_id' => $value['custom_uid'],
|
|
|
|
|
+ 'title' => $value['internal_notice_content'],
|
|
|
|
|
+ 'ext_data' => $value['ext_data'],
|
|
|
|
|
+ 'insert_time' => time()
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ //发送站内信通知
|
|
|
|
|
+ $StatisticsNoticesModel->insert($notices_data);
|
|
|
|
|
+ //更新发送状态
|
|
|
|
|
+ $SubNoticeLogModel->whereIn('id', array_column($sub_notice_list, 'id'))->update(['internal_notice_status' => 0]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 执行发送邮件内容
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2026-04-11
|
|
|
|
|
+ * @param $data
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ public function send_email_content($sub_notice_list)
|
|
|
|
|
+ {
|
|
|
|
|
+ $EmailVerifyCode = new EmailVerifyCode();
|
|
|
|
|
+ $SubNoticeLogModel = new SubNoticeLogModel();
|
|
|
|
|
+ foreach ($sub_notice_list as $key => $value) {
|
|
|
|
|
+ if ($value['email_status'] == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $email_to = $value['email'];
|
|
|
|
|
+ $email_content = json_decode($value['email_content'], true);
|
|
|
|
|
+ $email_title = $email_content['email_title'];
|
|
|
|
|
+ $email_content = $email_content['email_content'];
|
|
|
|
|
+ $res_msg = $EmailVerifyCode->sendSmtpEmail($email_to, $email_title, $email_content);
|
|
|
|
|
+ Log::info('job_send_email', '订阅邮件通知推送队列记录', ['email' => $email_to, 'email_content' => $email_content, 'msg' => $res_msg]);
|
|
|
|
|
+ //更新发送状态
|
|
|
|
|
+ $SubNoticeLogModel->where(['id' => $value['id']])->update(['email_status' => 0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 执行发送短信记录
|
|
|
|
|
+ * @author 唐远望
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @date 2026-04-11
|
|
|
|
|
+ * @param $data
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ */
|
|
|
|
|
+ public function send_sms_record($sub_notice_list)
|
|
|
|
|
+ {
|
|
|
|
|
+ $SmsVerifyCode = new SmsVerifyCode();
|
|
|
|
|
+ $SubNoticeLogModel = new SubNoticeLogModel();
|
|
|
|
|
+ foreach ($sub_notice_list as $key => $value) {
|
|
|
|
|
+ if ($value['status'] == 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $mobile = $value['mobile'];
|
|
|
|
|
+ $sms_content = json_decode($value['sms_content'], true);
|
|
|
|
|
+ $totle_number = $sms_content['totle_number'];
|
|
|
|
|
+ $number1 = $sms_content['number1'];
|
|
|
|
|
+ $number2 = $sms_content['number2'];
|
|
|
|
|
+ $number3 = $sms_content['number3'];
|
|
|
|
|
+ $sms_tpl_id = $sms_content['sms_tpl_id'];
|
|
|
|
|
+ $res_msg = $SmsVerifyCode->sendContent($mobile, ['totle_number' => $totle_number, 'number1' => $number1, 'number2' => $number2, 'number3' => $number3], $sms_tpl_id);
|
|
|
|
|
+ Log::info('job_send_sms', '订阅短信通知推送队列记录', ['email' => $mobile, 'sms_tpl_id' => $sms_tpl_id, 'msg' => $res_msg]);
|
|
|
|
|
+ //更新发送状态
|
|
|
|
|
+ $SubNoticeLogModel->where(['id' => $value['id']])->update(['status' => 0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public function failed(\Throwable $exception)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log::info('job_error', '发送订阅通知队列完全失败', ['data' => $this->message_data, 'error' => $exception]);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|