From 15caabc73baed1185892f84b544cf4d83de4ca62 Mon Sep 17 00:00:00 2001 From: Dai Date: Sun, 29 Sep 2024 17:21:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=8A=E8=AF=BE=E5=89=8D=E4=B8=80?= =?UTF-8?q?=E5=A4=A9=E3=80=8110=E5=88=86=E9=92=9F=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=95=99=E5=B8=88=E3=80=81=E5=AD=A6=E7=94=9F=E3=80=81=E5=AE=B6?= =?UTF-8?q?=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/SendMsgCronJobService.php | 360 ++++++++++++++++++- plugin/admin/app/view/cron-job/index.html | 19 +- process/Task.php | 10 +- 3 files changed, 383 insertions(+), 6 deletions(-) diff --git a/app/common/service/SendMsgCronJobService.php b/app/common/service/SendMsgCronJobService.php index 796db68..236cfc9 100644 --- a/app/common/service/SendMsgCronJobService.php +++ b/app/common/service/SendMsgCronJobService.php @@ -28,6 +28,8 @@ class SendMsgCronJobService const SCHEDULE_TIME_PUBLISH_TO_TEACHER = 'schedule_time_publish_to_teacher'; const SCHEDULE_TIME_PUBLISH_TO_STUDENT = 'schedule_time_publish_to_student'; const CLASS_BEGIN_NOTIFY_TEACHER = 'class_begin_notify_teacher'; + const CLASS_BEGIN_NOTIFY_STUDENT = 'class_begin_notify_student'; + const CLASS_BEGIN_NOTIFY_PARENT = 'class_begin_notify_parent'; const SUBJECT_UPLOAD_NOTIFY_ADMIN = 'subject_upload_notify_admin'; const SUBJECT_VERSION_UPLOAD_NOTIFY_STUDENT = 'subject_version_upload_notify_student'; const SUBJECT_VERSION_UPLOAD_NOTIFY_PARENT = 'subject_version_upload_notify_parent'; @@ -330,7 +332,7 @@ class SendMsgCronJobService * 上课时间 提前一天通知老师 * @return void */ - public function classBeginMsgToTeacher() + public function classBeginMsgToTeacherBeforeDay() { try { $teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1]) @@ -370,7 +372,7 @@ class SendMsgCronJobService } $student = Student::where(['id' => $student['student_id']])->findOrEmpty(); - array_push($student_info, ['id' => $student['id'], 'student_name' => $student['student_name'], 'openid' => $student['openid']]); + array_push($student_info, ['id' => $student['id'], 'student_name' => $student['student_name'], 'openid' => $student['openid'], 'parent_id' => $student['parent_id']]); } $student_name = implode(',', array_column($student_info, 'student_name')); @@ -438,12 +440,119 @@ class SendMsgCronJobService 'end_time' => $item->end_time, 'en_start_time' => $item->en_start_time, 'en_end_time' => $item->en_end_time, - 'send_role' => 'student', + '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){ + //通知学生 + $send_teacher_data = [ + 'touser' => $student['openid']->openid, + 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', + 'data' => [ + 'thing8' => [//课程名称 + 'value' => $item->english_name, + 'color' => '#000000' + ], + 'time5' => [//上课时间 + 'value' => $item->end_time, + 'color' => '#000000' + ], + 'thing4' => [//任课教师 + 'value' => $item->teacherAttr->teacher_name, + 'color' => '#000000' + ], + 'thing7' => [//学员姓名 + 'value' => $student_name, + 'color' => '#000000' + ] + ], + 'miniprogram' => [ + + ], + "lang" => "zh_CN", + ]; + + + $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'], + ]); + + + //查找学生家长,同步发送消息给家长 + $parents = StudentParent::where(['id' => $student['parent_id']])->findOrEmpty(); + if(!$parents->isEmpty()){ + $send_teacher_data = [ + 'touser' => $parents->openid, + 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', + 'data' => [ + 'thing8' => [//课程名称 + 'value' => $item->english_name, + 'color' => '#000000' + ], + 'time5' => [//上课时间 + 'value' => $item->end_time, + 'color' => '#000000' + ], + 'thing4' => [//任课教师 + 'value' => $item->teacherAttr->teacher_name, + 'color' => '#000000' + ], + 'thing7' => [//学员姓名 + 'value' => $student_name, + 'color' => '#000000' + ] + ], + 'miniprogram' => [ + + ], + "lang" => "zh_CN", + ]; + + + $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'], + ]); + } + } } } catch (Exception $e) { @@ -455,6 +564,251 @@ class SendMsgCronJobService } } + + + /** + * 上课时间 提前一天通知老师 + * @return void + */ + public function classBeginMsgToMsgBeforeTenMinute() + { + try { + $teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1]) + ->whereTime('start_time', '<=', date('Y-m-d H:i:s', strtotime('+10 minute'))) + ->with(['teacherAttr', 'subject', 'studentSchedule']) + ->select(); + + foreach ($teacher_schedule_time as $item) { + + if(strtotime($item['start_time']) - time() > 60){ + continue; + } + + $studentSchedule = $item->studentSchedule->toArray(); + if (empty($studentSchedule)) { + 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' => 'student', + 'send_data' => json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'send_result' => 0, + 'send_result_msg' => '未找到课程分配的学生', + ]); + throw new Exception('未找到课程分配的学生'); + } + + $student_info = []; + foreach ($studentSchedule as $student) { + if (!$student['is_publish']) { +// throw new Exception($student['student_name'] . '的排课未发布'); + } + + $student = Student::where(['id' => $student['student_id']])->findOrEmpty(); + array_push($student_info, ['id' => $student['id'], 'student_name' => $student['student_name'], 'openid' => $student['openid'], 'parent_id' => $student['parent_id']]); + } + $student_name = implode(',', array_column($student_info, 'student_name')); + + if (empty($student_name)) { + 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' => 'student', + 'send_data' => json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'msg_info' => json_encode($item->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + 'send_result' => 0, + 'send_result_msg' => '未找到课程分配的学生', + ]); + throw new Exception('未找到课程分配的学生'); + } + + $send_teacher_data = [ + 'touser' => $item['teacherArr']['openid'], + 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', + 'data' => [ + 'thing8' => [//课程名称 + 'value' => $item->english_name, + 'color' => '#000000' + ], + 'time5' => [//上课时间 + 'value' => $item->end_time, + 'color' => '#000000' + ], + 'thing4' => [//任课教师 + 'value' => $item->teacherAttr->teacher_name, + 'color' => '#000000' + ], + 'thing7' => [//学员姓名 + 'value' => $student_name, + 'color' => '#000000' + ] + ], + 'miniprogram' => [ + + ], + "lang" => "zh_CN", + ]; + + + $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'], + ]); + + + foreach ($student_info as $student){ + //通知学生 + $send_teacher_data = [ + 'touser' => $student['openid']->openid, + 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', + 'data' => [ + 'thing8' => [//课程名称 + 'value' => $item->english_name, + 'color' => '#000000' + ], + 'time5' => [//上课时间 + 'value' => $item->end_time, + 'color' => '#000000' + ], + 'thing4' => [//任课教师 + 'value' => $item->teacherAttr->teacher_name, + 'color' => '#000000' + ], + 'thing7' => [//学员姓名 + 'value' => $student_name, + 'color' => '#000000' + ] + ], + 'miniprogram' => [ + + ], + "lang" => "zh_CN", + ]; + + + $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'], + ]); + + + //查找学生家长,同步发送消息给家长 + $parents = StudentParent::where(['id' => $student['parent_id']])->findOrEmpty(); + if(!$parents->isEmpty()){ + $send_teacher_data = [ + 'touser' => $parents->openid, + 'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI', + 'data' => [ + 'thing8' => [//课程名称 + 'value' => $item->english_name, + 'color' => '#000000' + ], + 'time5' => [//上课时间 + 'value' => $item->end_time, + 'color' => '#000000' + ], + 'thing4' => [//任课教师 + 'value' => $item->teacherAttr->teacher_name, + 'color' => '#000000' + ], + 'thing7' => [//学员姓名 + 'value' => $student_name, + 'color' => '#000000' + ] + ], + 'miniprogram' => [ + + ], + "lang" => "zh_CN", + ]; + + + $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'], + ]); + } + } + + } + + } catch (Exception $e) { + + return [ + 'code' => ResponseCode::FAIL, + 'msg' => $e->getMessage() + ]; + } + } + + + /** * 上课时间 提前一天通知老师 * @return void diff --git a/plugin/admin/app/view/cron-job/index.html b/plugin/admin/app/view/cron-job/index.html index 1367317..de20654 100644 --- a/plugin/admin/app/view/cron-job/index.html +++ b/plugin/admin/app/view/cron-job/index.html @@ -116,6 +116,10 @@ 排课结果通知家长 {{# }else if(d.msg_type == 'class_begin_notify_teacher'){ }} 课程开始提醒教师 + {{# }else if(d.msg_type == 'class_begin_notify_student'){ }} + 课程开始提醒学生 + {{# }else if(d.msg_type == 'class_begin_notify_parent'){ }} + 课程开始提醒家长 {{# }else if(d.msg_type == 'subject_upload_notify_admin'){ }} 课程作业上传提醒管理员 {{# }else if(d.msg_type == 'subject_version_upload_notify_student'){ }} @@ -192,7 +196,20 @@ 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} - + {{# }else if(d.msg_type == 'class_begin_notify_student'){ }} +
+ 教师:{{d.msg_info.teacher_name}} + 课程:{{d.msg_info.english_name}} + 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} + 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} +
+ {{# }else if(d.msg_type == 'class_begin_notify_parent'){ }} +
+ 教师:{{d.msg_info.teacher_name}} + 课程:{{d.msg_info.english_name}} + 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} + 本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}} +
{{# }else if(d.msg_type == 'subject_upload_notify_admin'){ }}
教师:{{d.msg_info.teacher_name}} diff --git a/process/Task.php b/process/Task.php index e3f3de3..a8b42d2 100644 --- a/process/Task.php +++ b/process/Task.php @@ -12,9 +12,15 @@ class Task // 每天的7点50执行,注意这里省略了秒位 new Crontab('50 7 * * *', function(){ - //上课前一天提醒教师 + //上课前一天提醒教师、学生、家长 (new SendMsgCronJobService())->classBeginMsgToTeacher(); }); + // 每分钟执行一次 + new Crontab('0 */1 * * * *', function(){ + //上课前10分钟提醒教师、学生、家长 + (new SendMsgCronJobService())->classBeginMsgToMsgBeforeTenMinute(); + }); + } -} \ No newline at end of file +}