diff --git a/app/api/controller/SendMsgCronJobController.php b/app/api/controller/SendMsgCronJobController.php index 95d9dfb..d45601e 100644 --- a/app/api/controller/SendMsgCronJobController.php +++ b/app/api/controller/SendMsgCronJobController.php @@ -71,7 +71,12 @@ class SendMsgCronJobController extends BaseController } - + /** + * @desc 老师布置作业通知 教师上传课程作业,后台翻译件上传之后发送 + * @param Request $request + * @return \support\Response + * @throws \GuzzleHttp\Exception\GuzzleException + */ public function uploadVersionSubjectHomeworkNotifyStudent(Request $request) { $res = (new SendMsgCronJobService())->uploadVersionSubjectHomeworkNotifyStudent(10); @@ -80,4 +85,42 @@ class SendMsgCronJobController extends BaseController } + /** + * @desc 后台翻译后台 通知外教老师 + * @param Request $request + * @return \support\Response + */ + public function studentUploadSubjectHomeworkNotifyTeacher(Request $request) + { + $res = (new SendMsgCronJobService())->studentUploadSubjectHomeworkNotifyTeacher(6); + + return $this->json($res); + } + + + /** + * @desc 学生上课时间确定成功提醒 + * @param Request $request + * @return \support\Response + */ + public function studentScheduleConfirmNotifyTeacher(Request $request) + { + $res = (new SendMsgCronJobService())->studentScheduleConfirmNotifyTeacher(84); + + return $this->json($res); + } + + + /** + * @desc + * @param Request $request + * @return \support\Response + */ + public function alertTeacherSubmitFreeTime(Request $request) + { + $res = (new SendMsgCronJobService())->studentScheduleConfirmNotifyTeacher(84); + + return $this->json($res); + } + } \ No newline at end of file diff --git a/app/common/model/StudentHomework.php b/app/common/model/StudentHomework.php index 6191dd4..03c1ef3 100644 --- a/app/common/model/StudentHomework.php +++ b/app/common/model/StudentHomework.php @@ -41,7 +41,8 @@ class StudentHomework extends BaseModel { return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind([ 'teacher_name', - 'teacher_account' => 'account' + 'teacher_account' => 'account', + 'teacher_openid'=> 'openid' ]); } diff --git a/app/common/model/StudentSchedule.php b/app/common/model/StudentSchedule.php index d66d861..8fb6474 100644 --- a/app/common/model/StudentSchedule.php +++ b/app/common/model/StudentSchedule.php @@ -26,7 +26,11 @@ class StudentSchedule extends BaseModel public function teacher() { - return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind(['teacher_account' => 'account', 'teacher_name']); + return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind([ + 'teacher_account' => 'account', + 'teacher_openid' => 'openid', + 'teacher_name' + ]); } public function subject() diff --git a/app/common/service/SendMsgCronJobService.php b/app/common/service/SendMsgCronJobService.php index 7c767e2..b073dd4 100644 --- a/app/common/service/SendMsgCronJobService.php +++ b/app/common/service/SendMsgCronJobService.php @@ -4,6 +4,8 @@ namespace app\common\service; use app\common\model\CronJob; use app\common\model\Student; +use app\common\model\StudentHomework; +use app\common\model\StudentSchedule; use app\common\model\SubjectHomework; use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; @@ -266,7 +268,7 @@ class SendMsgCronJobService /** - * @desc 老师上传作业后台管理员人员翻译过,重新上传通知学生 + * @desc 老师上传作业后台管理员人员翻译过,重新上传通知学生,课程作业通知 * @param $subject_homework_id * @return array|void * @throws \GuzzleHttp\Exception\GuzzleException @@ -280,22 +282,34 @@ class SendMsgCronJobService //查找相同老师、相同课程、相同学生的下一节课 $teacher_schedule_time = TeacherScheduleTime::where(['id' => $subject_homework->teacher_schedule_time_id])->with(['studentSchedule'])->findOrEmpty(); - print '
';
-            print_r($teacher_schedule_time->toArray());
-            die;
-
+            //查找下次课程开始时间
+            $next_teacher_schedule_time = TeacherScheduleTime::where([
+                'teacher_id' => $teacher_schedule_time->teacher_id,
+                'subject_id' => $teacher_schedule_time->subject_id,
+                'is_publish' => 1
+            ])
+                ->whereTime('start_time', '>', $teacher_schedule_time->start_time)
+                ->order('id asc')
+                ->limit(1)
+                ->findOrEmpty();
 
+            if (!$next_teacher_schedule_time->isEmpty()) {
+                $next_time = $next_teacher_schedule_time->start_time;
+            } else {
+                $next_time = '';//不能没有值
+            }
             if (!empty($subject_homework->homework_version_file_url)) {
+
                 $send_teacher_data = [
                     'touser' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',//@todo:发送人
-                    'template_id' => 'OKLtn1L12ZrKsJczk1IRn_8kcQ4aKBmMsYsnjgAkkfE',
+                    'template_id' => 'ng-vuuY_hHM3N2fR3VCGdjGldOrwmzVVQzebRgkW4uY',
                     'data' => [
                         'thing6' => [//课程名称
                             'value' => $subject_homework->english_name . '/' . date('m-d H:i', strtotime($subject_homework->start_time)),
                             'color' => '#000000'
                         ],
                         'thing2' => [//作业名称
-                            'value' => $subject_homework->teacher_name,
+                            'value' => $subject_homework->english_name . '/' . date('m-d H:i', strtotime($subject_homework->start_time)),
                             'color' => '#000000'
                         ],
                         'thing5' => [//批改老师
@@ -303,7 +317,7 @@ class SendMsgCronJobService
                             'color' => '#000000'
                         ],
                         'time3' => [//作业截止时间
-                            'value' => $subject_homework->teacher_name,
+                            'value' => $next_time,
                             'color' => '#000000'
                         ]
                     ],
@@ -315,6 +329,8 @@ class SendMsgCronJobService
 
 
                 $result = (new WechatSubscriptService())->sendMsg($send_teacher_data);
+                //@todo:写入日志中
+
             }
 
 
@@ -328,4 +344,124 @@ class SendMsgCronJobService
     }
 
 
+    /**
+     * @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' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',//@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);
+
+
+            return [
+                'code' => ResponseCode::SUCCESS,
+                'data' => [],
+                'msg' => 'success'
+            ];
+        } catch (Exception $e) {
+            return [
+                'code' => ResponseCode::FAIL,
+                'msg' => $e->getMessage()
+            ];
+        }
+    }
+
+
+
+    public function studentScheduleConfirmNotifyTeacher($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('未找到');
+            }
+
+
+            //@todo:日志
+
+            $send_teacher_data = [
+                'touser' => 'olfLh6o4CG9xb6_tA3y29shOj_Bo',//@todo:发送人
+                '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);
+
+            //@todo:添加日志
+
+            return [
+                'code' => ResponseCode::SUCCESS,
+                'data' => [],
+                'msg' => 'success'
+            ];
+        }catch (Exception $e){
+            return [
+                'code' => ResponseCode::FAIL,
+                'msg' => $e->getMessage()
+            ];
+        }
+    }
+
+
 }
\ No newline at end of file