course/app/common/service/SendMsgCronJobService.php

1517 lines
71 KiB
PHP
Raw Normal View History

2024-08-04 22:28:52 +08:00
<?php
namespace app\common\service;
2024-08-04 23:31:50 +08:00
use app\common\model\CronJob;
use app\common\model\Student;
2024-08-19 22:48:14 +08:00
use app\common\model\StudentHomework;
use app\common\model\StudentParent;
2024-08-19 22:48:14 +08:00
use app\common\model\StudentSchedule;
2024-08-05 22:34:26 +08:00
use app\common\model\SubjectHomework;
2024-08-30 23:23:41 +08:00
use app\common\model\Teacher;
2024-08-04 22:28:52 +08:00
use app\common\model\TeacherScheduleTime;
2024-08-04 23:31:50 +08:00
use app\constant\ResponseCode;
2024-08-04 22:28:52 +08:00
use think\Exception;
class SendMsgCronJobService
{
const TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER = 'teacher_schedule_time_publish_to_teacher';
2024-08-29 23:22:32 +08:00
const TEACHER_SCHEDULE_TIME_PUBLISH_STUDENT = 'teacher_schedule_time_publish_to_student';
2024-08-04 22:28:52 +08:00
const TEACHER_SCHEDULE_TIME_PUBLISH_PARENTS = 'teacher_schedule_time_publish_to_parent';
// const TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER = 'teacher_schedule_time_publish_to_teacher';
2024-08-05 21:59:13 +08:00
2024-08-26 22:19:21 +08:00
/**
* 通知类型
*/
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';
2024-08-26 22:19:21 +08:00
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';
const SUBJECT_REPORT_UPLOAD_NOTIFY_STUDENT = 'subject_report_upload_notify_student';
const SUBJECT_REPORT_UPLOAD_NOTIFY_PARENT = 'subject_report_upload_notify_parent';
2024-08-26 22:19:21 +08:00
const STUDENT_UPLOAD_HOMEWORK_NOTIFY_TEACHER = 'student_upload_homework_notify_teacher';
const ADMIN_NOTIFY_STUDENT_SCHEDULE_TIME = 'admin_notify_student_schedule_time';
const ADMIN_NOTIFY_TEACHER_SUBMIT_FREE_TIME = 'admin_notify_teacher_submit_free_time';
const MSG_TYPE = [
'schedule_time_publish_to_teacher' => '课程时间发布通知教师',//后台分配好课程时间之后发布时发送
'schedule_time_publish_to_student' => '课程安排学生发布通知学生',//课程时间选好学生发布之后发送
'class_begin_notify_teacher' => '课程开始前一天通知教师',//课程开始前一天通知教师
'subject_upload_notify_admin' => '教师上传课程作业通知管理员',//教师上传课程作业之后通知管理员
'subject_version_upload_notify_student' => '课程作业翻译后通知学生',//课程作业管理员翻译发布之后通知学生
'student_upload_homework_notify_teacher' => '学生上传课程作业通知教师',//学生上传课程作业之后通知教师
'admin_notify_student_schedule_time' => '管理员通知学生上课时间',//管理员通知学生上课时间确定提醒
'admin_notify_teacher_submit_free_time' => '管理员通知教师上传空闲时间',//管理员通知教师上传空闲时间
];
2024-08-05 21:59:13 +08:00
/**
* 排课成功通知
* @param $teacher_schedule_time_id
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
2024-08-29 23:22:32 +08:00
public function teacherScheduleTimePublishMsgToTeacher($teacher_schedule_time_id)
2024-08-04 22:28:52 +08:00
{
try {
2024-08-04 23:31:50 +08:00
$teacher_schedule_time = TeacherScheduleTime::where(['id' => $teacher_schedule_time_id])->with(['teacherAttr', 'subject', 'studentSchedule'])
->findOrEmpty();
2024-08-04 22:28:52 +08:00
2024-08-04 23:31:50 +08:00
if ($teacher_schedule_time->isEmpty()) {
throw new Exception('教师排课不存在');
}
$studentSchedule = $teacher_schedule_time->studentSchedule->toArray();
if (empty($studentSchedule)) {
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']]);
}
2024-08-04 22:28:52 +08:00
2024-08-04 23:31:50 +08:00
//给教师发送消息
$msgInfo = $teacher_schedule_time->toArray();
2024-08-06 17:15:31 +08:00
$student_name = implode(',', array_column($student_info, 'student_name'));
2024-08-04 23:31:50 +08:00
$send_teacher_data = [
2024-10-09 10:21:46 +08:00
'touser' => $teacher_schedule_time->teacherAttr->openid,
2024-08-04 23:31:50 +08:00
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
2024-08-04 22:28:52 +08:00
'data' => [
'time2' => [//上课时间
2024-08-04 23:31:50 +08:00
'value' => $teacher_schedule_time->en_start_time,
2024-08-04 22:28:52 +08:00
'color' => '#000000'
],
'thing1' => [//课程名称
2024-08-04 23:31:50 +08:00
'value' => $teacher_schedule_time->english_name,
2024-08-04 22:28:52 +08:00
'color' => '#000000'
],
'thing5' => [//上课老师
2024-08-04 23:31:50 +08:00
'value' => $teacher_schedule_time->teacherAttr->teacher_name,
2024-08-04 22:28:52 +08:00
'color' => '#000000'
],
'thing4' => [//学员姓名
2024-08-04 23:31:50 +08:00
'value' => $student_name,
2024-08-04 22:28:52 +08:00
'color' => '#000000'
]
],
'miniprogram' => [
2024-08-04 23:31:50 +08:00
2024-08-04 22:28:52 +08:00
],
"lang" => "zh_CN",
];
2024-08-04 23:31:50 +08:00
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
CronJob::create([
'msg_type' => self::TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER,
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
2024-08-06 17:15:31 +08:00
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'teacher',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-08-04 23:31:50 +08:00
'msg_info' => json_encode($msgInfo, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-08-06 17:15:31 +08:00
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
2024-08-04 23:31:50 +08:00
2024-08-29 23:22:32 +08:00
} catch (Exception $e) {
}
}
/**
* 排课成功通知
* @param $teacher_schedule_time_id
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function teacherScheduleTimePublishMsgToStudent($teacher_schedule_time_id)
{
try {
$teacher_schedule_time = TeacherScheduleTime::where(['id' => $teacher_schedule_time_id])->with(['teacherAttr', 'subject', 'studentSchedule'])
->findOrEmpty();
if ($teacher_schedule_time->isEmpty()) {
throw new Exception('教师排课不存在');
}
$studentSchedule = $teacher_schedule_time->studentSchedule->toArray();
if (empty($studentSchedule)) {
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']]);
}
$student_name = implode(',', array_column($student_info, 'student_name'));
2024-09-22 20:55:12 +08:00
foreach ($student_info as $item) {
2024-08-04 23:31:50 +08:00
$send_teacher_data = [
2024-09-22 20:55:12 +08:00
'touser' => $item['openid'],
2024-08-04 23:31:50 +08:00
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
'data' => [
'time2' => [//上课时间
'value' => $teacher_schedule_time->start_time,
'color' => '#000000'
],
'thing1' => [//课程名称
'value' => $teacher_schedule_time->subject_name,
'color' => '#000000'
],
'thing5' => [//上课老师
'value' => $teacher_schedule_time->teacherAttr->teacher_name,
'color' => '#000000'
],
'thing4' => [//学员姓名
'value' => $student_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
CronJob::create([
2024-08-29 23:22:32 +08:00
'msg_type' => self::TEACHER_SCHEDULE_TIME_PUBLISH_STUDENT,
2024-08-04 23:31:50 +08:00
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
2024-08-06 17:15:31 +08:00
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'student',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-08-29 23:22:32 +08:00
'msg_info' => json_encode($teacher_schedule_time->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-08-06 17:15:31 +08:00
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
2024-08-04 23:31:50 +08:00
]);
//查找学生家长,同步发送消息给家长
$parents = StudentParent::where(['id' => $student['parent_id']])->findOrEmpty();
if (!$parents->isEmpty()) {
$send_teacher_data = [
'touser' => $parents['openid'],
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
'data' => [
'time2' => [//上课时间
'value' => $teacher_schedule_time->start_time,
'color' => '#000000'
],
'thing1' => [//课程名称
'value' => $teacher_schedule_time->subject_name,
'color' => '#000000'
],
'thing5' => [//上课老师
'value' => $teacher_schedule_time->teacherAttr->teacher_name,
'color' => '#000000'
],
'thing4' => [//学员姓名
'value' => $student_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
CronJob::create([
'msg_type' => SendMsgCronJobService::TEACHER_SCHEDULE_TIME_PUBLISH_PARENTS,
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'parent',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher_schedule_time->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
}
2024-10-08 21:52:40 +08:00
if (isset($teacher_schedule_time['teacherAttr']) && !empty($teacher_schedule_time['teacherAttr']['openid']) && 0) {
//发送给教师
$send_teacher_data = [
'touser' => $teacher_schedule_time['teacherAttr']['openid'],
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
'data' => [
'time2' => [//上课时间
'value' => $teacher_schedule_time->start_time,
'color' => '#000000'
],
'thing1' => [//课程名称
'value' => $teacher_schedule_time->subject_name,
'color' => '#000000'
],
'thing5' => [//上课老师
'value' => $teacher_schedule_time->teacherAttr->teacher_name,
'color' => '#000000'
],
'thing4' => [//学员姓名
'value' => $student_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
CronJob::create([
'msg_type' => SendMsgCronJobService::TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER,
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'student',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher_schedule_time->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
}
2024-08-04 23:31:50 +08:00
}
2024-08-04 22:28:52 +08:00
2024-08-04 23:31:50 +08:00
} catch (Exception $e) {
2024-08-04 22:28:52 +08:00
}
}
2024-08-05 21:59:13 +08:00
/**
* 上课时间 提前一天通知老师
* @return void
*/
public function classBeginMsgToTeacherBeforeDay()
2024-08-05 21:59:13 +08:00
{
try {
2024-08-06 17:15:31 +08:00
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
2024-08-29 23:22:32 +08:00
->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+1 day')))
->whereTime('start_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day')))
2024-08-05 21:59:13 +08:00
->with(['teacherAttr', 'subject', 'studentSchedule'])
->select();
foreach ($teacher_schedule_time as $item) {
$studentSchedule = $item->studentSchedule->toArray();
if (empty($studentSchedule)) {
2024-08-29 23:22:32 +08:00
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' => '未找到课程分配的学生',
]);
2024-08-05 21:59:13 +08:00
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']]);
2024-08-05 21:59:13 +08:00
}
2024-08-06 17:15:31 +08:00
$student_name = implode(',', array_column($student_info, 'student_name'));
2024-08-29 23:22:32 +08:00
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('未找到课程分配的学生');
}
2024-08-05 21:59:13 +08:00
$send_teacher_data = [
2024-09-13 22:11:40 +08:00
'touser' => $item['teacherArr']['openid'],
2024-08-05 22:34:26 +08:00
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
2024-08-05 21:59:13 +08:00
'data' => [
'thing8' => [//课程名称
'value' => $item->english_name,
'color' => '#000000'
],
2024-08-05 22:34:26 +08:00
'time5' => [//上课时间
'value' => $item->end_time,
2024-08-05 21:59:13 +08:00
'color' => '#000000'
],
2024-08-05 22:34:26 +08:00
'thing4' => [//任课教师
2024-08-05 21:59:13 +08:00
'value' => $item->teacherAttr->teacher_name,
'color' => '#000000'
],
2024-08-05 22:34:26 +08:00
'thing7' => [//学员姓名
2024-08-05 21:59:13 +08:00
'value' => $student_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
2024-08-05 22:34:26 +08:00
2024-08-29 23:22:32 +08:00
2024-08-05 22:34:26 +08:00
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
2024-08-29 23:22:32 +08:00
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',
2024-08-29 23:22:32 +08:00
'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'],
]);
}
}
2024-08-05 22:34:26 +08:00
}
2024-08-06 17:15:31 +08:00
} catch (Exception $e) {
2024-08-29 23:22:32 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
/**
* 上课时间 提前一天通知老师
* @return void
*/
public function classBeginMsgToMsgBeforeTenMinute()
{
try {
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
2024-10-07 23:44:36 +08:00
->whereTime('start_time', '>=', date('Y-m-d H:i:s', strtotime('+10 minute')))
->whereTime('start_time', '<=', date('Y-m-d H:i:s', strtotime('+11 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('未找到课程分配的学生');
}
2024-10-07 23:35:02 +08:00
var_dump($item->toArray());
$send_teacher_data = [
2024-10-07 23:35:02 +08:00
'touser' => $item['teacherAttr']['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 = [
2024-10-07 23:35:02 +08:00
'touser' => $student['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()
];
}
}
2024-08-29 23:22:32 +08:00
/**
* 上课时间 提前一天通知老师
* @return void
*/
public function classBeginSingleMsgToTeacher($teacher_schedule_time_id)
{
try {
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1, 'id' => $teacher_schedule_time_id])
->with(['teacherAttr', 'subject', 'studentSchedule'])
->findOrEmpty();
$studentSchedule = $teacher_schedule_time->studentSchedule->toArray();
if (empty($studentSchedule)) {
CronJob::create([
'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER,
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'student',
'send_data' => json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher_schedule_time->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']]);
}
$student_name = implode(',', array_column($student_info, 'student_name'));
if (empty($student_name)) {
CronJob::create([
'msg_type' => self::CLASS_BEGIN_NOTIFY_TEACHER,
'teacher_id' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'student',
'send_data' => json_encode([], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher_schedule_time->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => 0,
'send_result_msg' => '未找到课程分配的学生',
]);
throw new Exception('未找到课程分配的学生');
}
$send_teacher_data = [
2024-09-13 22:11:40 +08:00
'touser' => $teacher_schedule_time['teacherArr']['openid'],
2024-08-29 23:22:32 +08:00
'template_id' => 'yYw0jnlhjnq4AJ_CAlAghgGyV0bvbVHG-eV8TNC3REI',
'data' => [
'thing8' => [//课程名称
'value' => $teacher_schedule_time->english_name,
'color' => '#000000'
],
'time5' => [//上课时间
'value' => $teacher_schedule_time->end_time,
'color' => '#000000'
],
'thing4' => [//任课教师
'value' => $teacher_schedule_time->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' => $teacher_schedule_time->teacher_id,
'subject_id' => $teacher_schedule_time->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $teacher_schedule_time->id,
'time' => $teacher_schedule_time->time,
'en_time' => $teacher_schedule_time->en_time,
'start_time' => $teacher_schedule_time->start_time,
'end_time' => $teacher_schedule_time->end_time,
'en_start_time' => $teacher_schedule_time->en_start_time,
'en_end_time' => $teacher_schedule_time->en_end_time,
'send_role' => 'student',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher_schedule_time->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
} catch (Exception $e) {
2024-08-05 22:34:26 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
/**
* @desc 管理员人员作业审阅结果通知
* @param $subject_homework_id
* @return array|void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function teacherPublishSubjectHomework($subject_homework_id)
{
try {
$subject_homework = SubjectHomework::where(['id' => $subject_homework_id])->with(['teacher', 'subject'])->findOrEmpty();
$send_teacher_data = [
'touser' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',//@todo发送人
'template_id' => 'OKLtn1L12ZrKsJczk1IRn_8kcQ4aKBmMsYsnjgAkkfE',
'data' => [
'thing1' => [//作业名称
2024-08-29 23:22:32 +08:00
'value' => substr($subject_homework->english_name . '/' . date('m-d H:i', strtotime($subject_homework->start_time)), 0, 18) . '..',
2024-08-05 22:34:26 +08:00
'color' => '#000000'
],
'thing2' => [//教师姓名
'value' => $subject_homework->teacher_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
2024-08-29 23:22:32 +08:00
CronJob::create([
'msg_type' => self::SUBJECT_UPLOAD_NOTIFY_ADMIN,
'teacher_id' => $subject_homework->teacher_id,
'subject_id' => $subject_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
'time' => $subject_homework->time,
'en_time' => $subject_homework->en_time,
'start_time' => $subject_homework->start_time,
'end_time' => $subject_homework->end_time,
'en_start_time' => $subject_homework->en_start_time,
'en_end_time' => $subject_homework->en_end_time,
'send_role' => 'admin',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($subject_homework->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
2024-08-05 22:34:26 +08:00
2024-08-06 17:15:31 +08:00
} catch (Exception $e) {
2024-08-05 22:34:26 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
2024-09-22 21:46:18 +08:00
];
}
}
/**
* @desc 课程报告发布之后通知学生家长
* @param $subject_homework_id
* @return array|void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function uploadSubjectReportVersionNotifyStudentParents($subject_homework_id)
{
try {
$subject_homework = SubjectHomework::where(['id' => $subject_homework_id])->with(['teacher', 'subject'])->findOrEmpty();
2024-09-22 21:46:18 +08:00
//查找该课程作业的课程的学生
$student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id])->with(['student', 'subject', 'teacher'])->findOrEmpty();
2024-09-22 21:46:18 +08:00
//
// $student_homework = StudentHomework::where(['id' => $student_homework_id])->with(['teacher', 'subject'])->findOrEmpty();
//查找相同老师、相同课程、相同学生的下一节课
$next_student_schedule_time = StudentSchedule::where([
'student_id' => $student_schedule->student_id,
'teacher_id' => $student_schedule->teacher_id,
'subject_id' => $student_schedule->subject_id
])->whereTime('start_time', '>', $student_schedule->start_time)
->order('id asc')
->limit(1)
->findOrEmpty();
if (!$next_student_schedule_time->isEmpty()) {
$next_time = $next_student_schedule_time->start_time;
} else {
// $next_time = date('Y-m-d H:i:s', strtotime('+7 day',$next_student_schedule_time->start_time ));//不能没有值
$next_time = '作业提交时间为下次上课前';//不能没有值
}
if (!empty($subject_homework->subject_file_url)) {
$send_teacher_data = [
'touser' => $student_schedule->student_openid,
'template_id' => 'bhnq2bLVoTx1-6dKL065JPXWTm6AVGsUmvuW8kEA1VU',
2024-09-22 21:46:18 +08:00
'data' => [
'thing6' => [//课程名称
2024-09-22 21:46:18 +08:00
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
'color' => '#000000'
],
2024-10-08 22:39:32 +08:00
'thing2' => [//上传者
'value' => $student_schedule->teacher_name,
2024-09-22 21:46:18 +08:00
'color' => '#000000'
],
// 'thing5' => [//批改老师
// 'value' => $student_schedule->teacher_name,
// 'color' => '#000000'
// ],
'time4' => [//上传时间
'value' => $subject_homework->created_at,
2024-09-22 21:46:18 +08:00
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
//@todo:写入日志中
CronJob::create([
'msg_type' => self::SUBJECT_REPORT_UPLOAD_NOTIFY_STUDENT,
2024-09-22 21:46:18 +08:00
'teacher_id' => $subject_homework->teacher_id,
'subject_id' => $subject_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
'time' => $subject_homework->time,
'en_time' => $subject_homework->en_time,
'start_time' => $subject_homework->start_time,
'end_time' => $subject_homework->end_time,
'en_start_time' => $subject_homework->en_start_time,
'en_end_time' => $subject_homework->en_end_time,
'send_role' => 'student',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode(['student' => $student_schedule, 'subject_homework' => $subject_homework->toArray()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-09-22 21:46:18 +08:00
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
//查找学生的家长
$student = Student::where(['id' => $student_schedule->student_id])->findOrEmpty();
$parent = StudentParent::where(['id' => $student->parent_id])->findOrEmpty();
if (!$parent->isEmpty()) {
$send_teacher_data = [
'touser' => $parent->openid,
'template_id' => 'bhnq2bLVoTx1-6dKL065JPXWTm6AVGsUmvuW8kEA1VU',
'data' => [
'thing6' => [//课程名称
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing2' => [//作业名称
2024-10-08 22:43:21 +08:00
'value' => $student_schedule->teacher_name,
'color' => '#000000'
],
// 'thing5' => [//批改老师
// 'value' => $student_schedule->teacher_name,
// 'color' => '#000000'
// ],
'time4' => [//上传时间
'value' => $subject_homework->created_at,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
//@todo:写入日志中
CronJob::create([
'msg_type' => self::SUBJECT_REPORT_UPLOAD_NOTIFY_PARENT,
'teacher_id' => $subject_homework->teacher_id,
'subject_id' => $subject_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
'time' => $subject_homework->time,
'en_time' => $subject_homework->en_time,
'start_time' => $subject_homework->start_time,
'end_time' => $subject_homework->end_time,
'en_start_time' => $subject_homework->en_start_time,
'en_end_time' => $subject_homework->en_end_time,
'send_role' => 'parent',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode(['parent' => $parent->toArray(), 'subject_homework' => $subject_homework->toArray()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
}
2024-09-22 21:46:18 +08:00
}
} catch (Exception $e) {
2024-09-22 21:46:18 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
2024-08-05 22:34:26 +08:00
];
}
}
2024-08-06 17:15:31 +08:00
/**
2024-08-19 22:48:14 +08:00
* @desc 老师上传作业后台管理员人员翻译过,重新上传通知学生,课程作业通知
2024-08-06 17:15:31 +08:00
* @param $subject_homework_id
* @return array|void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
2024-09-22 21:34:58 +08:00
public function uploadVersionSubjectHomeworkNotifyStudent($subject_homework_id)
2024-08-05 22:34:26 +08:00
{
try {
$subject_homework = SubjectHomework::where(['id' => $subject_homework_id])->with(['teacher', 'subject'])->findOrEmpty();
2024-09-22 21:34:58 +08:00
//查找该课程作业的课程的学生
$student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id])->with(['student', 'subject', 'teacher'])->findOrEmpty();
2024-09-22 21:34:58 +08:00
//
// $student_homework = StudentHomework::where(['id' => $student_homework_id])->with(['teacher', 'subject'])->findOrEmpty();
2024-08-06 17:15:31 +08:00
//查找相同老师、相同课程、相同学生的下一节课
2024-08-29 23:22:32 +08:00
$next_student_schedule_time = StudentSchedule::where([
2024-09-22 21:34:58 +08:00
'student_id' => $student_schedule->student_id,
'teacher_id' => $student_schedule->teacher_id,
'subject_id' => $student_schedule->subject_id
])->whereTime('start_time', '>', $student_schedule->start_time)
2024-08-19 22:48:14 +08:00
->order('id asc')
->limit(1)
->findOrEmpty();
2024-08-06 17:15:31 +08:00
2024-08-29 23:22:32 +08:00
if (!$next_student_schedule_time->isEmpty()) {
$next_time = '请在' . date('m-d H:i', strtotime($next_student_schedule_time->start_time)) . '前上传';
2024-08-19 22:48:14 +08:00
} else {
2024-09-22 21:34:58 +08:00
// $next_time = date('Y-m-d H:i:s', strtotime('+7 day',$next_student_schedule_time->start_time ));//不能没有值
$next_time = '作业提交时间为下次上课前';//不能没有值
2024-08-19 22:48:14 +08:00
}
2024-09-22 21:34:58 +08:00
if (!empty($subject_homework->homework_file_url)) {
2024-08-19 22:48:14 +08:00
2024-08-05 22:34:26 +08:00
$send_teacher_data = [
2024-09-22 21:34:58 +08:00
'touser' => $student_schedule->student_openid,
'template_id' => 'ng-vuuY_hHM3N2fR3VCGdhtg5zfYRmgdiYuffPEgXDs',
2024-08-05 22:34:26 +08:00
'data' => [
'thing6' => [//课程名称
2024-09-22 21:34:58 +08:00
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
2024-08-05 22:34:26 +08:00
'color' => '#000000'
],
'thing2' => [//作业名称
2024-09-22 21:34:58 +08:00
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
2024-08-05 22:34:26 +08:00
'color' => '#000000'
],
'thing9' => [//学生姓名
2024-10-08 22:39:32 +08:00
'value' => $student_schedule->student_name,
'color' => '#000000'
],
'thing5' => [//批改老师
2024-09-22 21:34:58 +08:00
'value' => $student_schedule->teacher_name,
2024-08-05 22:34:26 +08:00
'color' => '#000000'
],
'thing7' => [//班级名称
2024-08-19 22:48:14 +08:00
'value' => $next_time,
2024-08-05 22:34:26 +08:00
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
2024-08-05 21:59:13 +08:00
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
2024-08-19 22:48:14 +08:00
//@todo:写入日志中
2024-08-29 23:22:32 +08:00
CronJob::create([
'msg_type' => self::SUBJECT_VERSION_UPLOAD_NOTIFY_STUDENT,
'teacher_id' => $subject_homework->teacher_id,
'subject_id' => $subject_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
'time' => $subject_homework->time,
'en_time' => $subject_homework->en_time,
'start_time' => $subject_homework->start_time,
'end_time' => $subject_homework->end_time,
'en_start_time' => $subject_homework->en_start_time,
'en_end_time' => $subject_homework->en_end_time,
'send_role' => 'student',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode(['student_schedule'=>$student_schedule->toArray(),'subject_homework'=>$subject_homework->toArray()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
2024-08-29 23:22:32 +08:00
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
//发送给家长
$student = Student::where(['id' => $student_schedule->student_id])->findOrEmpty();
$parent = StudentParent::where(['id' => $student->parent_id])->findOrEmpty();
if (!$parent->isEmpty()) {
$send_teacher_data = [
'touser' => $parent->openid,
'template_id' => 'ng-vuuY_hHM3N2fR3VCGdhtg5zfYRmgdiYuffPEgXDs',
'data' => [
'thing6' => [//课程名称
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing2' => [//作业名称
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing9' => [//学生姓名
'value' => substr($student_schedule->english_name . '/' . date('m-d H:i', strtotime($student_schedule->start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing5' => [//批改老师
'value' => $student_schedule->teacher_name,
'color' => '#000000'
],
'thing7' => [//班级名称
'value' => $next_time,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
2024-08-05 21:59:13 +08:00
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
//@todo:写入日志中
CronJob::create([
'msg_type' => self::SUBJECT_VERSION_UPLOAD_NOTIFY_PARENT,
'teacher_id' => $subject_homework->teacher_id,
'subject_id' => $subject_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id,
'time' => $subject_homework->time,
'en_time' => $subject_homework->en_time,
'start_time' => $subject_homework->start_time,
'end_time' => $subject_homework->end_time,
'en_start_time' => $subject_homework->en_start_time,
'en_end_time' => $subject_homework->en_end_time,
'send_role' => 'parent',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode(['parent' => $parent->toArray(), 'subject_homework' => $subject_homework->toArray()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
}
}
2024-08-05 22:34:26 +08:00
2024-08-06 17:15:31 +08:00
} catch (Exception $e) {
2024-08-05 21:59:13 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
2024-08-05 22:34:26 +08:00
2024-08-05 21:59:13 +08:00
}
2024-08-19 22:48:14 +08:00
/**
* @desc 学生完成上传作业,通知老师
* @param $request
* @return array
*/
public function studentUploadSubjectHomeworkNotifyTeacher($student_homework_id)
{
try {
$student_homework = StudentHomework::where(['id' => $student_homework_id])->with(['teacher', 'subject', 'student'])->findOrEmpty();
//获取教师openid
$send_teacher_data = [
'touser' => $student_homework->teacher_openid,//@todo发送人
2024-08-19 22:48:14 +08:00
'template_id' => 'IYIMurENbyxkQ_axIsrkjOnfoURe4jOVpHU6zcGyksU',
'data' => [
'thing1' => [//课程名称
'value' => substr($student_homework->english_name . '/' . date('m-d H:i', strtotime($student_homework->en_start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing2' => [//作业名称
'value' => substr($student_homework->english_name . '/' . date('m-d H:i', strtotime($student_homework->en_start_time)), 0, 18) . '..',
'color' => '#000000'
],
'thing3' => [//批改老师
'value' => $student_homework->teacher_name,
'color' => '#000000'
],
'thing5' => [//学生
'value' => $student_homework->student_name,
'color' => '#000000'
],
'time4' => [//提交时间
'value' => $student_homework->created_at,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
2024-08-29 23:22:32 +08:00
CronJob::create([
'msg_type' => self::STUDENT_UPLOAD_HOMEWORK_NOTIFY_TEACHER,
'teacher_id' => $student_homework->teacher_id,
'subject_id' => $student_homework->subject_id,
'student_id' => '',
'teacher_schedule_time_id' => $student_homework->teacher_schedule_time_id,
'time' => $student_homework->time,
'en_time' => $student_homework->en_time,
'start_time' => $student_homework->start_time,
'end_time' => $student_homework->end_time,
'en_start_time' => $student_homework->en_start_time,
'en_end_time' => $student_homework->en_end_time,
'send_role' => 'teacher',
2024-08-29 23:22:32 +08:00
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($student_homework->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
2024-08-19 22:48:14 +08:00
return [
'code' => ResponseCode::SUCCESS,
'data' => [],
'msg' => 'success'
];
} catch (Exception $e) {
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
2024-08-30 23:23:41 +08:00
/**
* @desc 课程确定之后提醒学生上课
* @param $student_schedule_id
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function manualNotifyStudentScheduleAfterConfirm($student_schedule_id)
2024-08-19 22:48:14 +08:00
{
try {
2024-08-26 22:19:21 +08:00
$student_schedule = StudentSchedule::where(['id' => $student_schedule_id, 'is_publish' => 1])->with(['teacher', 'student', 'subject'])->findOrEmpty();
2024-08-19 22:48:14 +08:00
2024-08-26 22:19:21 +08:00
if ($student_schedule->isEmpty()) {
2024-08-19 22:48:14 +08:00
throw new Exception('未找到');
}
$send_teacher_data = [
2024-09-13 22:11:40 +08:00
'touser' => $student_schedule->student_openid,
2024-08-19 22:48:14 +08:00
'template_id' => '9zKhl4mYHNcz2jW8MGEtfZXU2M3slaIers9-NCpY4Xc',
'data' => [
'time3' => [//上课时间
'value' => $student_schedule->en_start_time,
'color' => '#000000'
],
'thing2' => [//课程名称
'value' => $student_schedule->english_name,
'color' => '#000000'
],
'thing4' => [//上课老师
'value' => $student_schedule->teacher_name,
'color' => '#000000'
],
'thing1' => [//学生名称
'value' => $student_schedule->student_name,
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
return [
'code' => ResponseCode::SUCCESS,
'data' => [],
'msg' => 'success'
];
2024-08-26 22:19:21 +08:00
} catch (Exception $e) {
2024-08-19 22:48:14 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
2024-08-30 23:23:41 +08:00
/**
* @desc 提醒教师上传空闲时间
* @param $teacher
* @return array|void
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function alertTeacherSubmitFreeTime($teacher_id)
{
try {
$teacher = Teacher::where(['id' => $teacher_id])->findOrEmpty();
if ($teacher->isEmpty()) {
2024-08-30 23:23:41 +08:00
throw new Exception('未找到教师信息');
}
$send_teacher_data = [
2024-09-13 22:11:40 +08:00
'touser' => $teacher->openid,//@todo发送人
2024-09-26 11:15:44 +08:00
'template_id' => 'lNWBJMGhR5suLinI_E7d6KXGiwGuKkyJCzT1ThokS1k',
2024-08-30 23:23:41 +08:00
'data' => [
2024-09-26 11:15:44 +08:00
'thing1' => [//教师姓名
2024-08-30 23:23:41 +08:00
'value' => $teacher->teacher_name,
'color' => '#000000'
],
2024-09-26 11:15:44 +08:00
'thing3' => [//课次
2024-09-26 11:17:34 +08:00
'value' => 'Submit free time',
2024-08-30 23:23:41 +08:00
'color' => '#000000'
]
],
'miniprogram' => [
],
"lang" => "zh_CN",
];
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
CronJob::create([
'msg_type' => self::ADMIN_NOTIFY_TEACHER_SUBMIT_FREE_TIME,
'teacher_id' => $teacher->id,
'send_role' => 'teacher',
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'msg_info' => json_encode($teacher->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
'send_result_msg' => $result['msg'],
]);
return $result;
} catch (Exception $e) {
2024-08-30 23:23:41 +08:00
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
2024-09-26 10:41:55 +08:00
}