fix 上课前一天、10分钟通知教师、学生、家长
This commit is contained in:
parent
0e766c84f6
commit
15caabc73b
@ -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
|
||||
|
@ -116,6 +116,10 @@
|
||||
<span class="layui-badge layui-bg-orange">排课结果通知家长</span>
|
||||
{{# }else if(d.msg_type == 'class_begin_notify_teacher'){ }}
|
||||
<span class="layui-badge layui-bg-green">课程开始提醒教师</span>
|
||||
{{# }else if(d.msg_type == 'class_begin_notify_student'){ }}
|
||||
<span class="layui-badge layui-bg-green">课程开始提醒学生</span>
|
||||
{{# }else if(d.msg_type == 'class_begin_notify_parent'){ }}
|
||||
<span class="layui-badge layui-bg-green">课程开始提醒家长</span>
|
||||
{{# }else if(d.msg_type == 'subject_upload_notify_admin'){ }}
|
||||
<span class="layui-badge layui-bg-red">课程作业上传提醒管理员</span>
|
||||
{{# }else if(d.msg_type == 'subject_version_upload_notify_student'){ }}
|
||||
@ -192,7 +196,20 @@
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
</div>
|
||||
<!-- <span class="layui-badge layui-bg-green">课程开始提醒教师</span>-->
|
||||
{{# }else if(d.msg_type == 'class_begin_notify_student'){ }}
|
||||
<div>
|
||||
<span>教师:{{d.msg_info.teacher_name}}</span>
|
||||
<span>课程:{{d.msg_info.english_name}}</span>
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
</div>
|
||||
{{# }else if(d.msg_type == 'class_begin_notify_parent'){ }}
|
||||
<div>
|
||||
<span>教师:{{d.msg_info.teacher_name}}</span>
|
||||
<span>课程:{{d.msg_info.english_name}}</span>
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
<span>本地时间:{{d.msg_info.date}} {{d.msg_info.en_time}}</span>
|
||||
</div>
|
||||
{{# }else if(d.msg_type == 'subject_upload_notify_admin'){ }}
|
||||
<div>
|
||||
<span>教师:{{d.msg_info.teacher_name}}</span>
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user