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'){ }} +