1452 lines
67 KiB
PHP
1452 lines
67 KiB
PHP
<?php
|
||
|
||
namespace app\common\service;
|
||
|
||
use app\common\model\CronJob;
|
||
use app\common\model\Student;
|
||
use app\common\model\StudentHomework;
|
||
use app\common\model\StudentParent;
|
||
use app\common\model\StudentSchedule;
|
||
use app\common\model\SubjectHomework;
|
||
use app\common\model\Teacher;
|
||
use app\common\model\TeacherScheduleTime;
|
||
use app\constant\ResponseCode;
|
||
use think\Exception;
|
||
|
||
class SendMsgCronJobService
|
||
{
|
||
const TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER = 'teacher_schedule_time_publish_to_teacher';
|
||
const TEACHER_SCHEDULE_TIME_PUBLISH_STUDENT = 'teacher_schedule_time_publish_to_student';
|
||
|
||
const TEACHER_SCHEDULE_TIME_PUBLISH_PARENTS = 'teacher_schedule_time_publish_to_parent';
|
||
// const TEACHER_SCHEDULE_TIME_PUBLISH_TEACHER = 'teacher_schedule_time_publish_to_teacher';
|
||
|
||
|
||
/**
|
||
* 通知类型
|
||
*/
|
||
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';
|
||
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' => '管理员通知教师上传空闲时间',//管理员通知教师上传空闲时间
|
||
];
|
||
|
||
/**
|
||
* 排课成功通知
|
||
* @param $teacher_schedule_time_id
|
||
* @return void
|
||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||
*/
|
||
public function teacherScheduleTimePublishMsgToTeacher($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']]);
|
||
}
|
||
|
||
//给教师发送消息
|
||
$msgInfo = $teacher_schedule_time->toArray();
|
||
$student_name = implode(',', array_column($student_info, 'student_name'));
|
||
$send_teacher_data = [
|
||
'touser' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',
|
||
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
|
||
'data' => [
|
||
'time2' => [//上课时间
|
||
'value' => $teacher_schedule_time->en_start_time,
|
||
'color' => '#000000'
|
||
],
|
||
'thing1' => [//课程名称
|
||
'value' => $teacher_schedule_time->english_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' => self::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' => 'teacher',
|
||
'send_data' => json_encode($send_teacher_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||
'msg_info' => json_encode($msgInfo, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||
'send_result' => $result['code'] == ResponseCode::SUCCESS ? 1 : 0,
|
||
'send_result_msg' => $result['msg'],
|
||
]);
|
||
|
||
} 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'));
|
||
|
||
foreach ($student_info as $item) {
|
||
|
||
$send_teacher_data = [
|
||
'touser' => $item['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' => self::TEACHER_SCHEDULE_TIME_PUBLISH_STUDENT,
|
||
'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'],
|
||
]);
|
||
|
||
|
||
//查找学生家长,同步发送消息给家长
|
||
$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'],
|
||
]);
|
||
}
|
||
|
||
if (isset($teacher_schedule_time['teacherAttr']) && !empty($teacher_schedule_time['teacherAttr']['openid'])) {
|
||
//发送给教师
|
||
$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'],
|
||
]);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
} catch (Exception $e) {
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 上课时间 提前一天通知老师
|
||
* @return void
|
||
*/
|
||
public function classBeginMsgToTeacherBeforeDay()
|
||
{
|
||
try {
|
||
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish' => 1])
|
||
->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')))
|
||
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
||
->select();
|
||
|
||
foreach ($teacher_schedule_time as $item) {
|
||
$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
|
||
*/
|
||
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
|
||
*/
|
||
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 = [
|
||
'touser' => $teacher_schedule_time['teacherArr']['openid'],
|
||
'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) {
|
||
|
||
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' => [//作业名称
|
||
'value' => substr($subject_homework->english_name . '/' . date('m-d H:i', strtotime($subject_homework->start_time)), 0, 18) . '..',
|
||
'color' => '#000000'
|
||
],
|
||
'thing2' => [//教师姓名
|
||
'value' => $subject_homework->teacher_name,
|
||
'color' => '#000000'
|
||
]
|
||
],
|
||
'miniprogram' => [
|
||
|
||
],
|
||
"lang" => "zh_CN",
|
||
];
|
||
|
||
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
|
||
|
||
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'],
|
||
]);
|
||
|
||
} catch (Exception $e) {
|
||
return [
|
||
'code' => ResponseCode::FAIL,
|
||
'msg' => $e->getMessage()
|
||
];
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @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();
|
||
//查找该课程作业的课程的学生
|
||
$student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id])->with(['student', 'subject', 'teacher'])->findOrEmpty();
|
||
//
|
||
// $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',
|
||
'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'
|
||
],
|
||
// '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_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' => $student_schedule, 'subject_homework' => $subject_homework->toArray()], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||
'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' => [//作业名称
|
||
'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'
|
||
// ],
|
||
'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_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'],
|
||
]);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
} catch (Exception $e) {
|
||
return [
|
||
'code' => ResponseCode::FAIL,
|
||
'msg' => $e->getMessage()
|
||
];
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @desc 老师上传作业后台管理员人员翻译过,重新上传通知学生,课程作业通知
|
||
* @param $subject_homework_id
|
||
* @return array|void
|
||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||
*/
|
||
public function uploadVersionSubjectHomeworkNotifyStudent($subject_homework_id)
|
||
{
|
||
try {
|
||
$subject_homework = SubjectHomework::where(['id' => $subject_homework_id])->findOrEmpty();
|
||
//查找该课程作业的课程的学生
|
||
$student_schedule = StudentSchedule::where(['teacher_schedule_time_id' => $subject_homework->teacher_schedule_time_id])->with(['student', 'subject', 'teacher'])->findOrEmpty();
|
||
|
||
print '<pre>';
|
||
print_r($student_schedule->toArray());
|
||
die;
|
||
|
||
//
|
||
// $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' => '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'
|
||
],
|
||
'thing3' => [//批改老师
|
||
'value' => $student_schedule->teacher_name,
|
||
'color' => '#000000'
|
||
],
|
||
'time8' => [//机构名称
|
||
'value' => $next_time,
|
||
'color' => '#000000'
|
||
]
|
||
],
|
||
'miniprogram' => [
|
||
|
||
],
|
||
"lang" => "zh_CN",
|
||
];
|
||
|
||
|
||
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
|
||
//@todo:写入日志中
|
||
|
||
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($subject_homework->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()
|
||
];
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @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:发送人
|
||
'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);
|
||
|
||
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',
|
||
'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'],
|
||
]);
|
||
|
||
return [
|
||
'code' => ResponseCode::SUCCESS,
|
||
'data' => [],
|
||
'msg' => 'success'
|
||
];
|
||
} catch (Exception $e) {
|
||
return [
|
||
'code' => ResponseCode::FAIL,
|
||
'msg' => $e->getMessage()
|
||
];
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @desc 课程确定之后提醒学生上课
|
||
* @param $student_schedule_id
|
||
* @return array
|
||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||
*/
|
||
public function manualNotifyStudentScheduleAfterConfirm($student_schedule_id)
|
||
{
|
||
try {
|
||
$student_schedule = StudentSchedule::where(['id' => $student_schedule_id, 'is_publish' => 1])->with(['teacher', 'student', 'subject'])->findOrEmpty();
|
||
|
||
if ($student_schedule->isEmpty()) {
|
||
throw new Exception('未找到');
|
||
}
|
||
|
||
|
||
$send_teacher_data = [
|
||
'touser' => $student_schedule->student_openid,
|
||
'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'
|
||
];
|
||
} catch (Exception $e) {
|
||
return [
|
||
'code' => ResponseCode::FAIL,
|
||
'msg' => $e->getMessage()
|
||
];
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @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()) {
|
||
throw new Exception('未找到教师信息');
|
||
}
|
||
$send_teacher_data = [
|
||
'touser' => $teacher->openid,//@todo:发送人
|
||
'template_id' => 'lNWBJMGhR5suLinI_E7d6KXGiwGuKkyJCzT1ThokS1k',
|
||
'data' => [
|
||
'thing1' => [//教师姓名
|
||
'value' => $teacher->teacher_name,
|
||
'color' => '#000000'
|
||
],
|
||
'thing3' => [//课次
|
||
'value' => 'Submit free time',
|
||
'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) {
|
||
return [
|
||
'code' => ResponseCode::FAIL,
|
||
'msg' => $e->getMessage()
|
||
];
|
||
}
|
||
}
|
||
|
||
}
|