Subject.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\yexam\service;
  3. use app\admin\model\yexam\Question;
  4. use app\admin\model\yexam\Unit;
  5. class Subject
  6. {
  7. public $model;
  8. public function __construct()
  9. {
  10. $this->model = new \app\admin\model\yexam\Subject();
  11. }
  12. /**
  13. * 获取科目列表
  14. * @param $page
  15. * @param $limit
  16. * @throws \think\Exception
  17. */
  18. public function getSubjectList($page,$limit){
  19. $count = $this->model->where(['status'=>1])->count();
  20. if($page){
  21. $data = $this->model->where(['status'=>1])->page($page,$limit)->order("weigh asc")->select();
  22. }else{
  23. $data = $this->model->where(['status'=>1])->order("weigh asc")->select();
  24. }
  25. return ['total'=>$count,'data'=>$data];
  26. }
  27. /**
  28. * 获取当前科目下的章节
  29. */
  30. public function getUnitList($subject_id,$pid,$page,$limit){
  31. $model = new Unit();
  32. $count = $model->where(['status'=>1,'subject_id'=>$subject_id,'pid'=>$pid])->count();
  33. if($page){
  34. $data = $model->field("id,unit_name as name,is_last")->where(['status'=>1,'subject_id'=>$subject_id,'pid'=>$pid])->page($page,$limit)->order("sort asc")->select();
  35. }else{
  36. $data = $model->field("id,unit_name as name,is_last")->where(['status'=>1,'subject_id'=>$subject_id,'pid'=>$pid])->order("sort asc")->select();
  37. }
  38. return ['total'=>$count,'data'=>$data];
  39. }
  40. /**
  41. * 获取指定科目下章节练习的题目总数
  42. */
  43. public function getSubjectQuestionNum($subject_id){
  44. $questionModel = new Question();
  45. return $questionModel->where(['subject_id'=>$subject_id,'unit_id'=>['neq',0]])->count();
  46. }
  47. /**
  48. * 获取指定科目下的章节练习的题目完成数量
  49. */
  50. public function getSubjectQuestionTestNum($subject_id,$user_id){
  51. $questionModel = new Question();
  52. return $questionModel
  53. ->alias("question")
  54. ->join("yexam_question_log log","question.id=log.question_id","inner")
  55. ->where(['question.subject_id'=>$subject_id,'question.unit_id'=>['neq',0],"log.user_id"=>$user_id])->count();
  56. }
  57. /**
  58. * 获取指定科目下的章节练习的题目正确数量
  59. */
  60. public function getSubjectQuestionRightNum($subject_id,$user_id){
  61. $questionModel = new Question();
  62. return $questionModel
  63. ->alias("question")
  64. ->join("yexam_question_log log","question.id=log.question_id","inner")
  65. ->where(['question.subject_id'=>$subject_id,'question.unit_id'=>['neq',0],"log.state"=>1,"log.user_id"=>$user_id])->count();
  66. }
  67. }