From c9667cf136271e1bcc44436aa55fcda4d4802a19 Mon Sep 17 00:00:00 2001 From: Dai Date: Sun, 17 Nov 2024 21:23:46 +0800 Subject: [PATCH] =?UTF-8?q?fix=2010=E5=88=86=E9=92=9F=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=8F=91=E9=80=812=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/SendMsgCronJobService.php | 135 ++++++++++--------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/app/common/service/SendMsgCronJobService.php b/app/common/service/SendMsgCronJobService.php index c257069..8b544f0 100644 --- a/app/common/service/SendMsgCronJobService.php +++ b/app/common/service/SendMsgCronJobService.php @@ -11,6 +11,7 @@ use app\common\model\SubjectHomework; use app\common\model\Teacher; use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; +use support\Redis; use think\Exception; class SendMsgCronJobService @@ -366,7 +367,7 @@ class SendMsgCronJobService ]); // throw new Exception('未找到课程分配的学生'); } - + $student_info = []; foreach ($studentSchedule as $student) { @@ -582,8 +583,7 @@ class SendMsgCronJobService ->select(); foreach ($teacher_schedule_time as $item) { - - + $studentSchedule = $item->studentSchedule->toArray(); if (empty($studentSchedule)) { CronJob::create([ @@ -668,27 +668,32 @@ class SendMsgCronJobService "lang" => "zh_CN", ]; + $class_begin_notify_teacher_key = md5(serialize($send_teacher_data)); + if(!Redis::get($class_begin_notify_teacher_key)){ + Redis::setEx($class_begin_notify_teacher_key, 65, 1); + $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); - $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); + CronJob::create([ + 'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER, + 'teacher_id' => $item->teacher_id, + 'subject_id' => $item->subject_id, + 'student_id' => '', + 'teacher_schedule_time_id' => $item->id, + 'time' => $item->time, + 'en_time' => $item->en_time, + 'start_time' => $item->start_time, + 'end_time' => $item->end_time, + 'en_start_time' => $item->en_start_time, + 'en_end_time' => $item->en_end_time, + 'send_role' => 'teacher', + 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, + 'send_result_msg' => $result['msg'], + ]); + + } - CronJob::create([ - 'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER, - 'teacher_id' => $item->teacher_id, - 'subject_id' => $item->subject_id, - 'student_id' => '', - 'teacher_schedule_time_id' => $item->id, - 'time' => $item->time, - 'en_time' => $item->en_time, - 'start_time' => $item->start_time, - 'end_time' => $item->end_time, - 'en_start_time' => $item->en_start_time, - 'en_end_time' => $item->en_end_time, - 'send_role' => 'teacher', - 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, - 'send_result_msg' => $result['msg'], - ]); foreach ($student_info as $student) { @@ -720,27 +725,32 @@ class SendMsgCronJobService "lang" => "zh_CN", ]; + $class_begin_notify_student_key = md5(serialize($send_teacher_data)); + if(!Redis::get($class_begin_notify_student_key)){ + Redis::setEx($class_begin_notify_student_key, 65, 1); - $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); + $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); - CronJob::create([ - 'msg_type' => self::CLASS_BEGIN_NOTIFY_STUDENT, - 'teacher_id' => $item->teacher_id, - 'subject_id' => $item->subject_id, - 'student_id' => '', - 'teacher_schedule_time_id' => $item->id, - 'time' => $item->time, - 'en_time' => $item->en_time, - 'start_time' => $item->start_time, - 'end_time' => $item->end_time, - 'en_start_time' => $item->en_start_time, - 'en_end_time' => $item->en_end_time, - 'send_role' => 'student', - 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, - 'send_result_msg' => $result['msg'], - ]); + CronJob::create([ + 'msg_type' => self::CLASS_BEGIN_NOTIFY_STUDENT, + 'teacher_id' => $item->teacher_id, + 'subject_id' => $item->subject_id, + 'student_id' => '', + 'teacher_schedule_time_id' => $item->id, + 'time' => $item->time, + 'en_time' => $item->en_time, + 'start_time' => $item->start_time, + 'end_time' => $item->end_time, + 'en_start_time' => $item->en_start_time, + 'en_end_time' => $item->en_end_time, + 'send_role' => 'student', + 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, + 'send_result_msg' => $result['msg'], + ]); + + } //查找学生家长,同步发送消息给家长 @@ -773,27 +783,32 @@ class SendMsgCronJobService "lang" => "zh_CN", ]; + $class_begin_notify_parent_key = md5(serialize($send_teacher_data)); + + if (!Redis::get($class_begin_notify_parent_key)){ + Redis::setEx($class_begin_notify_parent_key, 65, 1); + $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); + CronJob::create([ + 'msg_type' => self::CLASS_BEGIN_NOTIFY_PARENT, + 'teacher_id' => $item->teacher_id, + 'subject_id' => $item->subject_id, + 'student_id' => '', + 'teacher_schedule_time_id' => $item->id, + 'time' => $item->time, + 'en_time' => $item->en_time, + 'start_time' => $item->start_time, + 'end_time' => $item->end_time, + 'en_start_time' => $item->en_start_time, + 'en_end_time' => $item->en_end_time, + 'send_role' => 'parent', + 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, + 'send_result_msg' => $result['msg'], + ]); + } - $result = (new WechatSubscriptService())->sendMsg($send_teacher_data); - CronJob::create([ - 'msg_type' => self::CLASS_BEGIN_NOTIFY_PARENT, - 'teacher_id' => $item->teacher_id, - 'subject_id' => $item->subject_id, - 'student_id' => '', - 'teacher_schedule_time_id' => $item->id, - 'time' => $item->time, - 'en_time' => $item->en_time, - 'start_time' => $item->start_time, - 'end_time' => $item->end_time, - 'en_start_time' => $item->en_start_time, - 'en_end_time' => $item->en_end_time, - 'send_role' => 'parent', - 'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), - 'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0, - 'send_result_msg' => $result['msg'], - ]); } }