多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 同步课程统计功能 # ## 1. 学习统计:获取学生的同步课程 ## http://t.wmxuetang.com/index.php?r=croom/manage/getTeachCourse&userID=474598 返回格式JSON: ``` { "data": [ { "id": "20", "version": "人教版", "subjectID": 2, "subjectName": "数学", "textBookID": 42038, "textBookName": "八年级上册", "expire": 1556586494000, "expireStatus": 0, "cover": "http://file.cnweike.cn/content/tmp/0/0/226/57954/53518.jpg" }, { "id": "21", "version": "人教版", "subjectID": 2, "subjectName": "数学", "textBookID": 53743, "textBookName": "八年级下册", "expire": 1536225016000, "expireStatus": 1, "cover": "http://file.cnweike.cn/content/tmp/0/0/1/260/83582.jpg" }, { "id": "412", "version": "人教版", "subjectID": 2, "subjectName": "数学", "textBookID": 54534, "textBookName": "九年级上册", "expire": 1537862783000, "expireStatus": 1, "cover": "http://file.cnweike.cn/content/tmp/0/0/1/260/83583.jpg" }, { "id": "943", "version": "新课标人教A版", "subjectID": 2, "subjectName": "数学", "textBookID": 4839, "textBookName": "必修三", "expire": 0, "expireStatus": 2, "cover": "http://file.cnweike.cn/content/tmp/0/0/226/57877/53441.jpg" }, { "id": "3633", "version": "新课标人教A版", "subjectID": 2, "subjectName": "数学", "textBookID": 4677, "textBookName": "必修一", "expire": 0, "expireStatus": 2, "cover": "http://file.cnweike.cn/content/tmp/0/0/226/57875/53439.jpg" } ], "status": 0, "msg": "success", "ssk": null } ``` *D:\wamp\www\xue.test\xuetang\protected\modules\croom\controllers\ManageController.php* ``` /** * 学习统计:获取学生的同步课程 * @example http://t.wmxuetang.com/index.php?r=croom/manage/getTeachCourse&userID=474598 * @url croom/manage/getTeachCourse * @param * userID */ public function actionGetTeachCourse(){ $args['userID'] = RequestUtils::getNormalRequest('userID');; $args['status'] = WK::CNT_ENABLE; $args['order'] = 't.id ASC'; $args['with'] = array('tag','tag.version'); $teachCourses = TeachCourseService::factory()->getTeachCourses($args); $list = array(); if($teachCourses){ foreach ($teachCourses as $teachCourse){ $cover = RelevanceService::factory()->getTextbookCover($teachCourse->fdTagID); $versionObject = wkeVersion::model()->findByPk($teachCourse->tag->version->fdValue); $item = array(); $item['id'] = $teachCourse->id; $item['version'] = $versionObject->fdName; $item['subjectID'] = (int)$teachCourse->fdSubjectID; $item['subjectName'] = Yii::app()->params['SUBJECT_ARR'][$teachCourse->fdSubjectID]; $item['textBookID'] = (int)$teachCourse->fdTagID; $item['textBookName'] = $teachCourse->tag->fdName; $item['expire'] = strtotime($teachCourse->fdExpire)*1000; $item['expireStatus'] = $teachCourse->fdExpire ? (time() > strtotime($teachCourse->fdExpire) ? 1 : 0) : 2; //0未到期 1已到期 2未购买 $item['cover'] = $cover; $list[] = $item; } } ResponseUtils::json(array('data'=>$list),0,"success"); } ``` ## 2. 同步课程练习数据统计 ``` /** * 学习统计:同步课程练习数据统计 * @author wangbo 2019-1-23 * @url croom/manage/myTeachCourseRecordStatistics * @example http://t.wmxuetang.com/index.php?r=croom/manage/myTeachCourseRecordStatistics&userID=474598&textBookID=42038&begin=1547596800000 * @param * userID * textBookID * begin * end */ public function actionMyTeachCourseRecordStatistics() { $userID = RequestUtils::getNormalRequest('userID', 0); $textbookID = RequestUtils::getNormalRequest('textBookID', 0); $end = RequestUtils::getNormalRequest('end', (time() + 3600 * 24) * 1000); $begin = RequestUtils::getNormalRequest('begin', (time() - 3600 * 24 * 30) * 1000); //默认是30天 // todo:校验数据 if (!$textbookID) { ResponseUtils::json(null, 1, '缺少必填参数textBookID'); } $data = TeachCourseService::factory()->getTeachCourseByUserID($textbookID, $userID, $begin, $end); if ($data) { ResponseUtils::json(['data' => array_values($data)]); } ResponseUtils::json(['data' => []]); } ``` *D:\wamp\www\xue.test\xuetang\protected\service\TeachCourseService.php* ``` /** * 同步课程,学生学习统计查询 * @param $textbookID * @param int $userID * @return array * @author wangbo 2019-1-23 */ public function getTeachCourseByUserID($textbookID, $userID, $begin, $end) { if(!$textbookID) return array(); $knowLedges = $this->getBookTree($textbookID); $teachCourse = TeachCourse::model()->findByAttributes(['fdUserID' => $userID, 'fdTagID' => $textbookID]); if (!$teachCourse) { return array(); } $teachCourseID = $teachCourse->id; // 获取章、节、知识点目录结构 $courseChapter = array(); if($knowLedges){ foreach ($knowLedges as $knowledge){ //章 $knowFirst['id'] = $knowledge['id']; $knowFirst['name'] = $knowledge['name']; $knowFirst['level'] = $knowledge['level']; $book = Tag::model()->findByPk($knowledge['id']); $tags = CategoryService::factory()->getChildren('Tag', $knowledge['id'], null, $book->fdLeft, $book->fdRight, true, 0); $temp = array(); foreach ($tags as $tag) { //节 $child = array(); $child['id'] = $tag->id; $child['name'] = $tag->fdName; $child['level'] = $tag->fdLevel; if ($knowledge['id'] == $tag->fdParentID) { $temp[$tag->id] = $child; } else { $temp[$tag->fdParentID] ? $temp[$tag->fdParentID]['childNode'][$tag->id] = $child : null; //过滤已屏蔽章的小节 } // 知识点 if($tag->fdLevel == 3){ $point = V2RelevanceService::factory()->getTagRelevancy($tag->id,null,null,array('tag'),'t.fdOrder ASC,t.id ASC'); if($point){ foreach ($point as $v){ $know = []; $know['id'] = $v->fdTagID; $know['name'] = $v->tag->fdName; $know['level'] = $v->tag->fdLevel; // 练习次数 $total = $this->getUserTeachCourseRecordTotal($teachCourseID, $v->fdTagID, $begin, $end); if ($total['count']) { $know['totalExamCount'] = $total['count']; $know['scoreRates'] = round($total['scoreRates']); $temp[$tag->id]['childNode'][$v->fdTagID] = $know; } } } } } $temp = $this->_arrConvert($temp); if ($temp) { $knowFirst['childNode'] = array_values($temp); $courseChapter[$knowledge['id']] = $knowFirst; } } } $courseChapter = $this->_arrConvert($courseChapter); foreach ($courseChapter as $k => $v) { if ($v['childNode']) { foreach ($v['childNode'] as $i => $j) { if ($v['childNode'][$i]['childNode']) { $courseChapter[$k]['childNode'][$i]['childNode'] = array_values($v['childNode'][$i]['childNode']); } } } } return $courseChapter; } ```