公众号消息
This commit is contained in:
parent
0a75a36f35
commit
639f2aa380
@ -5,6 +5,8 @@ namespace app\api\controller;
|
||||
use app\BaseController;
|
||||
use app\common\model\TeacherScheduleTime;
|
||||
use app\common\service\SendMsgCronJobService;
|
||||
use app\constant\ResponseCode;
|
||||
use app\utils\WechatUtil;
|
||||
use support\Request;
|
||||
use think\Exception;
|
||||
|
||||
@ -13,6 +15,19 @@ class SendMsgCronJobController extends BaseController
|
||||
|
||||
protected $noNeedLogin = ['*'];
|
||||
|
||||
|
||||
public function getToken()
|
||||
{
|
||||
$token = WechatUtil::getAccessToken();
|
||||
|
||||
return $this->json([
|
||||
'code' => ResponseCode::SUCCESS,
|
||||
'data' => $token,
|
||||
'msg' => 'success'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @desc 排课发布成功之后,发送通知
|
||||
* @param $teacher_schedule_time
|
||||
@ -39,7 +54,9 @@ class SendMsgCronJobController extends BaseController
|
||||
*/
|
||||
public function classBeginMsgToTeacher()
|
||||
{
|
||||
$res = (new SendMsgCronJobService())->classBeginMsgToTeacher();
|
||||
|
||||
return $this->json($res);
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,6 +13,13 @@ 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_teacher';
|
||||
|
||||
|
||||
/**
|
||||
* 排课成功通知
|
||||
* @param $teacher_schedule_time_id
|
||||
* @return void
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function teacherScheduleTimePublishMsg($teacher_schedule_time_id)
|
||||
{
|
||||
try {
|
||||
@ -144,4 +151,73 @@ class SendMsgCronJobService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上课时间 提前一天通知老师
|
||||
* @return void
|
||||
*/
|
||||
public function classBeginMsgToTeacher()
|
||||
{
|
||||
try {
|
||||
$teacher_schedule_time = TeacherScheduleTime::where(['is_publish'=>1])
|
||||
->whereTime('start_time', '>=', date('Y-m-d 00:00:00', strtotime('+21 day')))
|
||||
->whereTime('start_time', '<=', date('Y-m-d 23:59:59', strtotime('+21 day')))
|
||||
->with(['teacherAttr', 'subject', 'studentSchedule'])
|
||||
->select();
|
||||
|
||||
foreach ($teacher_schedule_time as $item) {
|
||||
|
||||
$studentSchedule = $item->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'));
|
||||
$send_teacher_data = [
|
||||
'touser' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',//@todo:发送人
|
||||
'template_id' => 'gTtXWz35mjbtbOZdq6uNBIqy2_W-gu7F4H6s5N-vNAI',
|
||||
'data' => [
|
||||
'thing8' => [//课程名称
|
||||
'value' => $item->english_name,
|
||||
'color' => '#000000'
|
||||
],
|
||||
'thing1' => [//上课时间
|
||||
'time5' => $item->end_time,
|
||||
'color' => '#000000'
|
||||
],
|
||||
'thing5' => [//任课教师
|
||||
'value' => $item->teacherAttr->teacher_name,
|
||||
'color' => '#000000'
|
||||
],
|
||||
'thing4' => [//学员姓名
|
||||
'value' => $student_name,
|
||||
'color' => '#000000'
|
||||
]
|
||||
],
|
||||
'miniprogram' => [
|
||||
|
||||
],
|
||||
"lang" => "zh_CN",
|
||||
];
|
||||
$result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
|
||||
}
|
||||
|
||||
}catch (Exception $e) {
|
||||
return [
|
||||
'code' => ResponseCode::FAIL,
|
||||
'msg' => $e->getMessage()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user