课程通知
This commit is contained in:
parent
24e7eeab4d
commit
1393de1ddb
115
plugin/admin/app/controller/sendMsgNotifyController.php
Normal file
115
plugin/admin/app/controller/sendMsgNotifyController.php
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\admin\app\controller;
|
||||||
|
|
||||||
|
use app\common\model\CronJob;
|
||||||
|
use app\common\model\Student;
|
||||||
|
use app\common\model\TeacherScheduleTime;
|
||||||
|
use app\common\service\SendMsgCronJobService;
|
||||||
|
use app\common\service\WechatSubscriptService;
|
||||||
|
use app\constant\ResponseCode;
|
||||||
|
use support\Request;
|
||||||
|
use think\Exception;
|
||||||
|
|
||||||
|
class sendMsgNotifyController extends Crud
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排课成功通知
|
||||||
|
* @param $teacher_schedule_time_id
|
||||||
|
* @return void
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
|
*/
|
||||||
|
public function teacherScheduleTimePublishMsgToStudent(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$teacher_schedule_time_id = $request->post('id');
|
||||||
|
$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 $student) {
|
||||||
|
|
||||||
|
|
||||||
|
$send_teacher_data = [
|
||||||
|
'touser' => $student['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_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'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => ResponseCode::WEB_API_SUCCESS,
|
||||||
|
'msg' => $result['msg']
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return json([
|
||||||
|
'code' => ResponseCode::WEB_API_FAIL,
|
||||||
|
'msg' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user