💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 修改课表 ## 需求说明 在指定的日期,替换科目ID。 #### 实现: *1、修改的情况* **班级课表:** 根据日期(当前日期大于修改日期时就启用修改后的课表)、周、节、科目,去判断是否有修改。如果有修改,则覆盖掉旧的课表。 **教师课表:** 根据老师执教的班级、日期、科目获取是否有修改课表的记录。如果有修改,才修改教师课表。 所教班级、周、节、科目,去判断是否有修改。 *2、新增的情况* **班级课表:** 根据班级、日期(修改前,不需要修改)判断是否有新增课表的记录。如果有,添加到课表中。 **教师课表:** .... ## 会有影响的接口 **课表管理:** - ~~获取作息时间 tms/timetable/getRestTimetable~~ - ~~批量设置作息时间 tms/timetable/settingRestTime~~ - ~~选择年级ID获取班级列表 tms/timetable/getClassesList~~ - 获取班级课表 tms/timetable/getClassTimetable - ~~设置班级课程表 tms/timetable/setClassesTimetable~~ - 获取教师课表列表 tms/timetable/getTeacherTimetableList **教师首页课表:** - 获取教师课表 xingke/timetable/getTeacherTimetable - ~~获取教师所教的班级 xingke/timetable/getClassListByTeacherID~~ - ~~教师调课 xingke/timetable/saveAdjustClass~~ - ~~获取每节课开始和结束时间 xingke/timetable/getTimetableSetting~~ - ~~获取课程表资源: xingke/timetable/getResources~~ **学生首页课表:** - 获取班级课程表 xingke/timetable/getClassTimeTable ## 修改课表记录表字段 - fdTermID - fdClassID - fdDate - fdWeekID - fdClassIndex - fdSubjectID - fdSourceSubjectID - fdUserID - fdCreate ``` CREATE TABLE `tbTimetableChange` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fdTermID` int(11) DEFAULT NULL COMMENT '学期ID', `fdClassID` int(11) DEFAULT NULL COMMENT '班级ID', `fdDate` date DEFAULT NULL COMMENT '指定变更日期', `fdWeekID` tinyint(4) DEFAULT NULL COMMENT '星期 1-7', `fdClassIndex` tinyint(4) DEFAULT NULL COMMENT '当前课节次', `fdSubjectID` tinyint(4) DEFAULT NULL COMMENT '当前课科目ID', `fdSourceSubjectID` tinyint(4) DEFAULT NULL COMMENT '原课被修改为科目ID', `fdUserID` int(11) DEFAULT NULL COMMENT '操作者用户ID', `fdCreate` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `classid` (`fdClassID`) ) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8 COMMENT='修改课表记录'; ``` ### 获取课表接口 Request URL: http://ketang.test/index.php?r=tms/timetable/getClassTimetable&classID=20331&gradeID=7 - Request Method: GET - r: tms/timetable/getClassTimetable - classID: 20331 - gradeID: 7 ```json { "data": { "timetable": [{ "weekID": "1", "class": [{ "classIndex": "1", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "2", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "3", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "4", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "5", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "6", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "8", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "9", "subjectID": "3", "subject": "英语", "teacher": [{ "name": "香钦源", "id": "1251338" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "10", "subjectID": "7", "subject": "音乐", "teacher": [] }], "date": "2019-5-27", "week": "周一" }, { "weekID": "2", "class": [{ "classIndex": "1", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "2", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "3", "subjectID": "5", "subject": "科学", "teacher": [] }, { "classIndex": "4", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "5", "subjectID": "6", "subject": "体育与健康", "teacher": [] }, { "classIndex": "6", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "8", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "9", "subjectID": "7", "subject": "音乐", "teacher": [] }, { "classIndex": "10", "subjectID": "7", "subject": "音乐", "teacher": [] }], "date": "2019-5-28", "week": "周二" }, { "weekID": "3", "class": [{ "classIndex": "3", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "4", "subjectID": "8", "subject": "美术", "teacher": [{ "name": "帅嘉亮", "id": "1459420" }] }, { "classIndex": "5", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "8", "subjectID": "10", "subject": "其他", "teacher": [] }, { "classIndex": "9", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "10", "subjectID": "11", "subject": "物理", "teacher": [] }], "date": "2019-5-29", "week": "周三" }, { "weekID": "4", "class": [{ "classIndex": "3", "subjectID": "11", "subject": "物理", "teacher": [] }, { "classIndex": "4", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "5", "subjectID": "12", "subject": "化学", "teacher": [] }, { "classIndex": "8", "subjectID": "7", "subject": "音乐", "teacher": [] }, { "classIndex": "9", "subjectID": "8", "subject": "美术", "teacher": [{ "name": "帅嘉亮", "id": "1459420" }] }, { "classIndex": "10", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }], "date": "2019-5-30", "week": "周四" }, { "weekID": "5", "class": [{ "classIndex": "3", "subjectID": "16", "subject": "信息技术", "teacher": [] }, { "classIndex": "4", "subjectID": "15", "subject": "历史", "teacher": [] }, { "classIndex": "5", "subjectID": "14", "subject": "地理", "teacher": [] }, { "classIndex": "8", "subjectID": "4", "subject": "政治(道德与法治)", "teacher": [] }, { "classIndex": "9", "subjectID": "3", "subject": "英语", "teacher": [{ "name": "香钦源", "id": "1251338" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "10", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }], "date": "2019-5-31", "week": "周五" }, { "weekID": "6", "class": [{ "classIndex": "5", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "6", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "8", "subjectID": "3", "subject": "英语", "teacher": [{ "name": "香钦源", "id": "1251338" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "9", "subjectID": "2", "subject": "数学", "teacher": [{ "name": "吴金容", "id": "1424397" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }] }, { "classIndex": "10", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }], "date": "2019-6-01", "week": "周六" }, { "weekID": "7", "class": [{ "classIndex": "8", "subjectID": "7", "subject": "音乐", "teacher": [] }, { "classIndex": "9", "subjectID": "1", "subject": "语文", "teacher": [{ "name": "贺洵", "id": "2895089" }, { "name": "香钦源", "id": "1251338" }, { "name": "莫小一", "id": "677552" }, { "name": "董老师", "id": "618430" }] }, { "classIndex": "10", "subjectID": "5", "subject": "科学", "teacher": [] }], "date": "2019-6-02", "week": "周日" }], "classNum": { "morningClassNum": "0", "forenoonClassNum": "4", "afternoonClassNum": "3", "nightClassNum": "0" }, "isHeader": false }, "status": 0, "msg": "success", "ssk": null, "systime": 1559119015000 } ``` ## 代码 *D:\wamp\www\ketang.test\weike\protected\modules\tms\controllers\TimetableController.php* ``` private function _checkChangeTimetable($timetables, $termID, $week, $subjectIDs = []) { $classID = 0; foreach ($timetables as $k => $v) { $classID = $v->fdClassID; $dateFullName = $week[$v->fdWeekID - 1]['date']; $weekID = $v->fdWeekID; $classIndex = $v->fdClassIndex; $subjectID = $v->fdSubjectID; // 按日期查询是否有修改课表(换课) add by wangbo 2019-6-18 /*$change = TimetableService::factory()->getChangeTimetable($termID, $classID, $dateFullName, $weekID, $classIndex, $subjectID); if ($change) { $timetables[$k]->fdSubjectID = $change->fdSourceSubjectID; }*/ // p($timetables); die; } // 获取本周的起始时间,查询本周是否有新增的课程 /*$beginDate = $week[0]['date']; $endDate = $week[count($week) - 1]['date'];*/ $today = date("Y-m-d"); $criteria = new CDbCriteria(); $criteria->compare("fdTermID", $termID); $criteria->compare("fdClassID", $classID); $criteria->compare("fdSubjectID", 0); if ($subjectIDs) { // 教师课表,需要按教师所教科目查询 $criteria->addInCondition("fdSourceSubjectID", $subjectIDs); } $criteria->addCondition("fdBeginDate <= '{$today}'"); $criteria->addCondition("fdEndDate >= '{$today}'"); $res = teaTimetableChange::model()->findAll($criteria); // var_dump($res); die; // var_dump( $timetables); die; /* SELECT * FROM `wkteach`.`tbTimetableChange` `t` WHERE ((((fdTermID=:ycp164) AND (fdClassID=:ycp165)) AND (fdSubjectID=:ycp166)) AND (fdBeginDate <= '2019-06-03')) AND (fdEndDate >= '2019-06-03') */ // var_dump($res); die; if ($res && $timetables) { foreach ($res as $v) { $temp = clone $timetables[0]; $temp->fdClassIndex = $v->fdClassIndex; $temp->fdWeekID = $v->fdWeekID; $temp->fdSubjectID = $v->fdSourceSubjectID; $timetables = array_merge($timetables, [$temp]); } } // var_dump($timetables); die; return $timetables; } ```