SExam.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class SExam extends Model {
  7. function __construct(){
  8. parent::__construct();
  9. }
  10. public function getDetailByExamId($examId)
  11. {
  12. $result = array();
  13. if ($examId AND is_numeric($examId))
  14. {
  15. $result = $this->sConn->createCommand()
  16. ->from('exam')
  17. ->where("exam_id = '". $examId ."'")
  18. ->query()
  19. ->read();
  20. }
  21. return $result;
  22. }
  23. public function getDetailByExamId_SemesterId($examId, $semesterId)
  24. {
  25. $result = array();
  26. if ($examId AND is_numeric($examId) AND $semesterId AND is_numeric($semesterId))
  27. {
  28. $result = $this->sConn->createCommand()
  29. ->from('exam')
  30. ->where("exam_id = '". $examId ."' AND semester_id = '". $semesterId ."'")
  31. ->query()
  32. ->read();
  33. }
  34. return $result;
  35. }
  36. public function getDetailByExamId_SemesterId_TeacherId($examId, $semesterId, $teacherId)
  37. {
  38. $result = array();
  39. if ($examId AND is_numeric($examId) AND $semesterId AND is_numeric($semesterId) AND $teacherId AND is_numeric($teacherId))
  40. {
  41. $result = $this->sConn->createCommand()
  42. ->from('exam')
  43. ->where("exam_id = '". $examId ."' AND semester_id = '". $semesterId ."' AND teacher_id = '". $teacherId ."'")
  44. ->query()
  45. ->read();
  46. }
  47. return $result;
  48. }
  49. public function getMaxWeekNumByClassId_SemesterId($classId, $semesterId)
  50. {
  51. $result = 0;
  52. if ($classId AND is_numeric($classId) AND $semesterId AND is_numeric($semesterId))
  53. {
  54. $sql = "SELECT IFNULL(MAX(e.week_num), 0) AS MAX_VALUE "
  55. . "FROM exam e "
  56. . "WHERE e.semester_id = '". $semesterId ."' AND e.class_id = '". $classId ."'";
  57. $query = $this->sConn->createCommand($sql)->query()->read();
  58. $result = (int)$query['MAX_VALUE'];
  59. }
  60. return $result;
  61. }
  62. /*
  63. * 根据学期、科目读取考试
  64. * $is_all_quan 0-所有考试 1-全学科考试 2-非全学科考试
  65. */
  66. public function getExamBySubject_Semester($SubjectId,$SemesterId,$Grade,$Arts_science=0,$is_all_quan=0){
  67. if(!$SubjectId || !$SemesterId){
  68. return null;
  69. }
  70. $sql=" select exam_id,e.exam_group_id,`name`,e.create_time from exam e ";
  71. $sql.=" join exam_group g on e.exam_group_id=g.exam_group_id ";
  72. $sql.=" join class c on c.class_id=e.class_id ";
  73. $sql.=" where e.semester_id={$SemesterId} ";
  74. if(is_array($SubjectId)){
  75. $sql.="and e.subject_id in(".implode(',',$SubjectId).")";
  76. }else{
  77. $sql.="and e.subject_id={$SubjectId}";
  78. }
  79. if($Grade){
  80. $sql.=" and c.grade in(".implode(',',$Grade).") ";
  81. }
  82. if($Arts_science){
  83. $sql.=" and c.arts_science ={$Arts_science} ";
  84. }
  85. if($is_all_quan == 1){
  86. $sql.=" and g.qxk_paper_id is not null ";
  87. }else if($is_all_quan == 2){
  88. $sql.=" and g.qxk_paper_id is null ";
  89. }
  90. //$sql.=" and g.is_hide=0 and e.status=1 ";
  91. $sql.=" and e.status=1 and e.is_display=0";
  92. $sql.=" group by e.exam_group_id ";
  93. $sql.=" order by e.create_time desc ";
  94. $query = $this->sConn->createCommand($sql)->query()->readAll();
  95. return $query;
  96. }
  97. /*
  98. * 根据学期、科目读取考试
  99. * $is_all_quan 0-所有考试 1-全学科考试 2-非全学科考试
  100. */
  101. public function getExamBySubject_Semester_nogroup($SubjectId,$SemesterId,$Grade,$Arts_science=0,$is_all_quan=0){
  102. if(!$SubjectId || !$SemesterId){
  103. return null;
  104. }
  105. $sql=" select exam_id,e.exam_group_id,`name`,e.create_time from exam e ";
  106. $sql.=" join exam_group g on e.exam_group_id=g.exam_group_id ";
  107. $sql.=" join class c on c.class_id=e.class_id ";
  108. $sql.=" where e.semester_id={$SemesterId} ";
  109. if(is_array($SubjectId)){
  110. $sql.="and e.subject_id in(".implode(',',$SubjectId).")";
  111. }else{
  112. $sql.="and e.subject_id={$SubjectId}";
  113. }
  114. if($Grade){
  115. $sql.=" and c.grade in(".implode(',',$Grade).") ";
  116. }
  117. if($Arts_science){
  118. $sql.=" and c.arts_science ={$Arts_science} ";
  119. }
  120. if($is_all_quan == 1){
  121. $sql.=" and g.qxk_paper_id is not null ";
  122. }else if($is_all_quan == 2){
  123. $sql.=" and g.qxk_paper_id is null ";
  124. }
  125. $sql.=" and e.status=1 and e.is_display=0 ";
  126. $sql.=" order by e.create_time desc ";
  127. $query = $this->sConn->createCommand($sql)->query()->readAll();
  128. return $query;
  129. }
  130. /*读取阅卷完成考试数量*/
  131. public function CountByExamGroupId($ExamGroupIds){
  132. $sql="select exam_group_id from exam_group where exam_group_id in(".implode(',',$ExamGroupIds).") ";
  133. $sql.=" and upload_status=2 and status=2";
  134. return $this->sConn->createCommand($sql)->query()->count();
  135. }
  136. /*读取阅卷完成考试数量*/
  137. public function CountByExamClass($ExamGroupIds,$ClassIds){
  138. $sql="select exam_id from exam where exam_group_id in(".implode(',',$ExamGroupIds).") and class_id in(".implode(',',$ClassIds).") ";
  139. $sql.=" and status=1 ";
  140. return $this->sConn->createCommand($sql)->query()->count();
  141. }
  142. /*读取阅卷完成考试数量*/
  143. public function getByExamClass($ExamGroupId,$ClassId,$checkStatus=1){
  144. $sql="select exam_id from exam where exam_group_id ='".$ExamGroupId."' and class_id ='".$ClassId."' ";
  145. if($checkStatus){
  146. $sql.=" and status=1 ";
  147. }
  148. return $this->sConn->createCommand($sql)->query()->read();
  149. }
  150. public function getForExamGroupId_ClassId($ExamGroupId,$ClassId){
  151. $sql="select e.exam_id,c.class_name,e.status from exam e ";
  152. $sql.=" join class c on c.class_id=e.class_id ";
  153. $sql.=" where e.exam_group_id='".$ExamGroupId."' and e.class_id='".$ClassId."' ";
  154. return $this->sConn->createCommand($sql)->query()->read();
  155. }
  156. /*根据exam_group读取所有班级*/
  157. public function getClassByExamGroupId($ExamGroupId,$arts_science=0){
  158. if(!$ExamGroupId){
  159. return null;
  160. }
  161. if($arts_science){
  162. $sql="select e.exam_id,c.class_id from exam e ";
  163. $sql.=" join class c on c.class_id=e.class_id ";
  164. $sql.=" where e.exam_group_id='".$ExamGroupId."' and c.arts_science='".$arts_science."' ";
  165. $result= $this->sConn->createCommand($sql)->query()->readAll();
  166. }else{
  167. $result = $this->sConn->createCommand()
  168. ->from('exam')
  169. ->where("exam_group_id = '". $ExamGroupId ."' ")
  170. ->query()
  171. ->readAll();
  172. }
  173. return $result;
  174. }
  175. /*根据paper_id获取所有考试*/
  176. public function getExamByPaperIds($paperIds){
  177. if(!$paperIds || !is_array($paperIds)){
  178. return false;
  179. }
  180. $sql=" select e.exam_id from exam e ";
  181. $sql.=" join exam_group g on e.exam_group_id=g.exam_group_id ";
  182. $sql.=" join paper p on p.exam_id=e.exam_id ";
  183. $sql.=" where paper_id in(". implode(',',$paperIds) .") and g.status=1 ";
  184. $query = $this->sConn->createCommand($sql)->query()->readAll();
  185. return $query;
  186. }
  187. public function getExamsByIds($Exam_Ids){
  188. if(!$Exam_Ids || !is_array($Exam_Ids)){
  189. return false;
  190. }
  191. $sql=" select e.exam_id,e.name,e.create_time from exam e ";
  192. $sql.=" join exam_group g on e.exam_group_id=g.exam_group_id ";
  193. $sql.=" where exam_id in(". implode(',',$Exam_Ids) .") ";
  194. $query = $this->sConn->createCommand($sql)->query()->readAll();
  195. return $query;
  196. }
  197. public function getExamBySubjectTime($Subject_id,$SemesterId,$ExcludeExamGroupId,$StartTime,$grade=0){
  198. $Sql=" select e.exam_group_id,e.exam_id,e.tpl_data,e.name from exam e ";
  199. $Sql.=" join class c on c.class_id=e.class_id ";
  200. $Sql.=" where e.semester_id = '". $SemesterId ."' AND e.exam_group_id != '". $ExcludeExamGroupId ."' and e.subject_id='".$Subject_id."' and e.create_time>'".$StartTime."' and e.is_display=0 and e.status=1 ";
  201. if($grade){
  202. $Sql.=" and c.grade={$grade} ";
  203. }
  204. $Sql.=" group by exam_group_id order by create_time desc";
  205. $query = $this->sConn->createCommand($Sql)->query()->readAll();
  206. return $query;
  207. }
  208. public function getExamByPaperExcludeClass($Paper_id,$Class_Arr){
  209. if(!$Paper_id){
  210. return null;
  211. }
  212. $Sql=" Select e.exam_id,e.name,e.exam_group_id from exam e";
  213. $Sql.=" join paper p on p.exam_id=e.exam_id ";
  214. $Sql.=" where p.paper_id ='{$Paper_id}' and e.class_id not in (".implode(',',$Class_Arr).")";
  215. $query = $this->sConn->createCommand($Sql)->query()->read();
  216. return $query;
  217. }
  218. public function getExamByGroupId($Exam_Group_Id){
  219. if(!$Exam_Group_Id){
  220. return false;
  221. }
  222. $result = $this->sConn->createCommand()
  223. ->from('exam')
  224. ->where(" exam_group_id = '". $Exam_Group_Id ."' and is_display=0 ")
  225. ->query()
  226. ->readAll();
  227. return $result;
  228. }
  229. public function getExamSubjectId($exam_id){
  230. $result = 0;
  231. if(!$exam_id){
  232. return $result;
  233. }
  234. $rs = $this->sConn->createCommand()
  235. ->select('subject_id')
  236. ->from('exam')
  237. ->where(" exam_id = '". $exam_id ."'")
  238. ->query()
  239. ->read();
  240. if($rs){
  241. $result = (int)$rs['subject_id'];
  242. unset($rs);
  243. }
  244. return $result;
  245. }
  246. /*
  247. *根据考试组id,班级id统计考试学生
  248. */
  249. public function getStudentNumberByExamGroupId($EIds,$classIds){
  250. if(!$EIds || !$classIds){
  251. return null;
  252. }
  253. $sql = "select exam_id from exam where exam_group_id in(".implode(',',$EIds).") and class_id in(".implode(',',$classIds)."); ";
  254. $ExamIds = $this->sConn->createCommand($sql)->queryAll();
  255. $examIdArr=array();
  256. $paperIdArr=array();
  257. $result=0;
  258. if($ExamIds){
  259. foreach ($ExamIds as $val){
  260. $examIdArr[]=$val['exam_id'];
  261. }
  262. $sql_p = "select paper_id from paper where exam_id in(".implode(',',$examIdArr).");";
  263. $paperIds = $this->sConn->createCommand($sql_p)->queryAll();
  264. if($paperIds){
  265. foreach ($paperIds as $v){
  266. $paperIdArr[]=$v['paper_id'];
  267. }
  268. $sql_count="select DISTINCT(scoring) from `student_paper_relation` where paper_id in(".implode(',',$paperIdArr).") and is_complete=1 and is_del=0 and is_feedback=1 order by scoring desc ;";
  269. $allCoring=$this->sConn->createCommand($sql_p)->queryAll();
  270. if($allCoring){
  271. $result=count($allCoring);
  272. }
  273. }
  274. }
  275. return $result;
  276. }
  277. //读取7天内考试
  278. public function getExamIdByTime(){
  279. $result=array();
  280. $examIds=array();
  281. $subjectIdArr=array();
  282. $examGroupIdArr=array();
  283. $examNameArr=array();
  284. $time=time()-86400*7;
  285. $sql="select exam_id,subject_id,exam_group_id,`name`,complete_time from exam where complete_time>'{$time}' and status=1";
  286. $data = $this->sConn->createCommand($sql)->queryAll();
  287. if($data){
  288. foreach ($data as $datum){
  289. $examIds[]=$datum['exam_id'];
  290. $subjectIdArr[(string)$datum['exam_id']]=(int)$datum['subject_id'];
  291. $examGroupIdArr[(string)$datum['exam_id']]=$datum['exam_group_id'];
  292. $examNameArr[(string)$datum['exam_id']]=$datum['name'];
  293. $completeTimeArr[(string)$datum['exam_id']]=$datum['complete_time'];
  294. }
  295. $sql_wb="select spr.class_id,c.class_name,c.grade,spr.exam_id from student_paper_relation spr
  296. join class c on c.class_id=spr.class_id
  297. where `is_wrongbook_download`=1 and spr.exam_id in(".implode(',',$examIds).") GROUP BY class_id,exam_id";
  298. $wrongBook=$this->sConn->createCommand($sql_wb)->queryAll();
  299. if($wrongBook){
  300. foreach ($wrongBook as $val){
  301. $result[]=array(
  302. 'id'=>$examGroupIdArr[$val['exam_id']],
  303. 'subject'=>$subjectIdArr[$val['exam_id']],
  304. 'productType'=>7,
  305. 'classId'=>$val['class_id'],
  306. 'grade'=>$val['grade'],
  307. 'name'=>$examNameArr[$val['exam_id']],
  308. 'className'=>$val['class_name'],
  309. 'productName'=>'五级钻石纠错本 ',
  310. 'time'=>$completeTimeArr[$val['exam_id']]
  311. );
  312. }
  313. }
  314. $sql_isp="select spr.class_id,c.class_name,c.grade,spr.exam_id from student_paper_relation spr
  315. join class c on c.class_id=spr.class_id
  316. where `is_two_isp_download`=1 and spr.exam_id in(".implode(',',$examIds).") GROUP BY class_id,exam_id";
  317. $twoIsp=$this->sConn->createCommand($sql_isp)->queryAll();
  318. if($twoIsp){
  319. foreach ($twoIsp as $val){
  320. $result[]=array(
  321. 'id'=>$examGroupIdArr[$val['exam_id']],
  322. 'subject'=>$subjectIdArr[$val['exam_id']],
  323. 'productType'=>8,
  324. 'classId'=>$val['class_id'],
  325. 'grade'=>$val['grade'],
  326. 'name'=>$examNameArr[$val['exam_id']],
  327. 'className'=>$val['class_name'],
  328. 'productName'=>'二步皇冠个性化学习宝 ',
  329. 'time'=>$completeTimeArr[$val['exam_id']]
  330. );
  331. }
  332. }
  333. $sql_thIsp="select spr.class_id,c.class_name,c.grade,spr.exam_id from student_paper_relation spr
  334. join class c on c.class_id=spr.class_id
  335. where `is_three_isp_download`=1 and spr.exam_id in(".implode(',',$examIds).") GROUP BY class_id,exam_id";
  336. $threeIsp=$this->sConn->createCommand($sql_thIsp)->queryAll();
  337. if($threeIsp){
  338. foreach ($threeIsp as $val){
  339. $result[]=array(
  340. 'id'=>$examGroupIdArr[$val['exam_id']],
  341. 'subject'=>$subjectIdArr[$val['exam_id']],
  342. 'productType'=>9,
  343. 'classId'=>$val['class_id'],
  344. 'grade'=>$val['grade'],
  345. 'name'=>$examNameArr[$val['exam_id']],
  346. 'className'=>$val['class_name'],
  347. 'productName'=>'三步金冠个性化学习宝 ',
  348. 'time'=>$completeTimeArr[$val['exam_id']]
  349. );
  350. }
  351. }
  352. }
  353. return $result;
  354. }
  355. }