diff --git a/application/admin/controller/questions/TestPaper.php b/application/admin/controller/questions/TestPaper.php old mode 100755 new mode 100644 index 267ed1d2..bcd00ed8 --- a/application/admin/controller/questions/TestPaper.php +++ b/application/admin/controller/questions/TestPaper.php @@ -34,6 +34,7 @@ use app\admin\model\merchant\Merchant; use app\admin\model\system\WebRecommend; use app\admin\model\system\WebRecommendRelation; use app\admin\model\user\User; + /** * 试卷 * Class TestPaper @@ -71,7 +72,7 @@ class TestPaper extends AuthController return Json::successlayui(TestPaperModel::testPaperExercisesList($where)); } -/**资料审核 + /**资料审核 * @return mixed */ public function examine($type = 1) @@ -110,7 +111,7 @@ class TestPaper extends AuthController * @return mixed|void * @throws \think\exception\DbException */ - public function examineDetails($id,$type) + public function examineDetails($id, $type) { if (!$id) return Json::fail('参数错误'); $details = TestPaperModel::get($id); @@ -180,8 +181,9 @@ class TestPaper extends AuthController TestPaperModel::rollbackTrans(); return Json::fail('操作失败!'); } - } - /** + } + + /** * 用户答题记录 */ public function answerNotes($type = 1, $test_id = 0, $uid = 0) @@ -211,13 +213,14 @@ class TestPaper extends AuthController /** * 用户答题 */ - public function answers($record_id = 0, $test_id = 0, $type = 1, $uid =0) + public function answers($record_id = 0, $test_id = 0, $type = 1, $uid = 0) { - $dat=TestPaperModel::where('id',$test_id)->field('single_sort,many_sort,judge_sort')->find(); + $dat = TestPaperModel::where('id', $test_id)->field('single_sort,many_sort,judge_sort')->find(); $this->assign(['record_id' => $record_id, 'test_id' => $test_id, 'type' => $type, 'uid' => $uid, 'single_sort' => $dat['single_sort'], 'many_sort' => $dat['many_sort'], 'judge_sort' => $dat['judge_sort']]); // $this->assign(['record_id' => $record_id, 'test_id' => $test_id, 'type' => $type]); return $this->fetch(); } + /**答题信息 * @param $uid * @return void @@ -227,10 +230,11 @@ class TestPaper extends AuthController */ public function getUserInformation($uid) { - if(!$uid) return Json::fail('参数错误'); - $data=User::where(['uid'=>$uid])->field('nickname,name,uid,avatar')->find(); + if (!$uid) return Json::fail('参数错误'); + $data = User::where(['uid' => $uid])->field('nickname,name,uid,avatar')->find(); return Json::successful($data); } + /**成绩 * @param int $record_id * @param int $test_id @@ -239,32 +243,33 @@ class TestPaper extends AuthController * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function getUserAchievement($record_id=0,$test_id=0,$uid=0) - { - if(!$record_id || !$test_id || !$uid) return Json::fail('参数错误'); - $dat=TestPaperModel::where('id',$test_id)->field('title,item_number,total_score')->find(); - $record=ExaminationRecord::where(['id'=>$record_id,'test_id'=>$test_id,'uid'=>$uid,'type'=>2])->find(); - $data['title']=$dat['title']; - $data['item_number']=$dat['item_number']; - $data['total_score']=$dat['total_score']; - $data['yes_questions']=$record['yes_questions']; - $data['score']=$record['score']; - $data['start_time']=date('Y-m-d H:i',$record['start_time']); + public function getUserAchievement($record_id = 0, $test_id = 0, $uid = 0) + { + if (!$record_id || !$test_id || !$uid) return Json::fail('参数错误'); + $dat = TestPaperModel::where('id', $test_id)->field('title,item_number,total_score')->find(); + $record = ExaminationRecord::where(['id' => $record_id, 'test_id' => $test_id, 'uid' => $uid, 'type' => 2])->find(); + $data['title'] = $dat['title']; + $data['item_number'] = $dat['item_number']; + $data['total_score'] = $dat['total_score']; + $data['yes_questions'] = $record['yes_questions']; + $data['score'] = $record['score']; + $data['start_time'] = date('Y-m-d H:i', $record['start_time']); return Json::successful($data); } + /**试卷中的试题答题情况 * @param int $id * @param int $type */ - public function getTestPaperAnswers($test_id=0,$record_id=0,$question_type=1) + public function getTestPaperAnswers($test_id = 0, $record_id = 0, $question_type = 1) { - - if(!$test_id || !$record_id) return Json::fail('参数错误'); - return Json::successful(TestPaperQuestions::getExaminationRecordAnswers($test_id,$record_id,$question_type)); + + if (!$test_id || !$record_id) return Json::fail('参数错误'); + return Json::successful(TestPaperQuestions::getExaminationRecordAnswers($test_id, $record_id, $question_type)); } // public function getTestPaperAnswers($test_id, $record_id) // { - + // $where = parent::getMore([ // ['page', 1], // ['limit', 20], @@ -303,6 +308,13 @@ class TestPaper extends AuthController return $this->fetch('questions'); } + + public function paper($id = 1) + { + $this->assign(['id' => $id, 'question_type' => 5, 'cateList' => QuestionsCategpry::taskCategoryAll(2)]); + return $this->fetch('paper'); + } + /** * 获取题库列表 */ @@ -312,14 +324,28 @@ class TestPaper extends AuthController ['page', 1], ['limit', 20], ['pid', 0], - ['title', ''] + ['title', ''], + ['type', 1], + ]); $where['type'] = $question_type; $arrays = []; if ($id) { $arrays = TestPaperQuestions::where(['test_id' => $id])->column('questions_id'); +// if ($question_type == 5) { +//// $where['ids'] = TestPaperQuestions::where(['test_id' => $id,])->where('pid', '>',0)->column('test_id'); +// } else { +// +// } } - $list = Questions::questionsList($where, $arrays); + if ($question_type == 5) { + $where['type'] = 1; + $where['status'] = 1; + $list = \app\admin\model\questions\TestPaper::testPaperExercisesList($where); + } else { + $list = Questions::questionsList($where, $arrays); + } + return Json::successlayui($list); } @@ -368,11 +394,13 @@ class TestPaper extends AuthController $many_tmp_list = TestPaperQuestions::gettestPaperQuestions($id, 2); $judge_tmp_list = TestPaperQuestions::gettestPaperQuestions($id, 3); $answer_tmp_list = TestPaperQuestions::gettestPaperQuestions($id, 4); + $paper_tmp_list = TestPaperQuestions::gettestPaperQuestions($id, 5)->toArray(); if ($type == 2) $grade = TestPaperScoreGrade::testPaperScoreGradeList($id); } else { $single_tmp_list = []; $many_tmp_list = []; $judge_tmp_list = []; + $paper_tmp_list = []; $answer_tmp_list = []; } $this->assign([ @@ -383,6 +411,7 @@ class TestPaper extends AuthController 'single_tmp_list' => json_encode($single_tmp_list), 'many_tmp_list' => json_encode($many_tmp_list), 'judge_tmp_list' => json_encode($judge_tmp_list), + 'paper_tmp_list' => json_encode($paper_tmp_list), 'answer_tmp_list' => json_encode($answer_tmp_list) ]); return $this->fetch(); @@ -439,12 +468,15 @@ class TestPaper extends AuthController ['judgeIds', ''], ['answerIds', ''], ['grade', ''], - ['sort', 0] + ['sort', 0], + ['paperIds', ""] ]); if ($data['tid'] <= 0) return Json::fail('请选择试题分类'); if (!$data['title']) return Json::fail('请输入试卷标题'); if ($type == 2 && !$data['image']) return Json::fail('请添加试卷封面图'); - if ($data['single_number'] < 0 || $data['many_number'] < 0 || $data['judge_number'] < 0) return Json::fail('各类型题目数量不能小于0'); + if($data['paperIds'] == '') { + if ($data['single_number'] < 0 || $data['many_number'] < 0 || $data['judge_number'] < 0) return Json::fail('各类型题目数量不能小于0'); + } $data['item_number'] = bcadd($data['single_number'], bcadd($data['many_number'], $data['judge_number'] + $data['answer_number'], 0), 0); $total_single_score = bcmul($data['single_number'], $data['single_score'], 0); $total_many_score = bcmul($data['many_number'], $data['many_score'], 0); @@ -466,6 +498,7 @@ class TestPaper extends AuthController $manyIds = json_decode($data['manyIds']); $judgeIds = json_decode($data['judgeIds']); $answerIds = json_decode($data['answerIds']); + $paperIds = json_decode($data['paperIds'], true); $grade = json_decode($data['grade'], true); TestPaperModel::beginTrans(); if ($id) { @@ -480,11 +513,13 @@ class TestPaper extends AuthController $res3 = TestPaperQuestions::addTestPaperQuestions($id, $type, (int)$data['many_number'], $manyIds ?? [], $data['many_score']); $res4 = TestPaperQuestions::addTestPaperQuestions($id, $type, (int)$data['judge_number'], $judgeIds ?? [], $data['judge_score']); $res4 = TestPaperQuestions::addTestPaperQuestions($id, $type, (int)$data['answer_number'], $answerIds ?? [], $data['answer_score']); + $res6 = TestPaperQuestions::addTestPaper($id, $paperIds); } else { $res2 = TestPaperQuestions::addRandomGroupQuestions($id, $type, 1, $data['cate_id'], (int)$data['single_number'], $data['single_score']); $res3 = TestPaperQuestions::addRandomGroupQuestions($id, $type, 2, $data['cate_id'], (int)$data['many_number'], $data['many_score']); $res4 = TestPaperQuestions::addRandomGroupQuestions($id, $type, 3, $data['cate_id'], (int)$data['judge_number'], $data['judge_score']); $res4 = TestPaperQuestions::addRandomGroupQuestions($id, $type, 4, $data['cate_id'], (int)$data['answer_number'], $data['answer_score']); + $res6 = true; } $res5 = $this->inspectTestQuestions($id); } else { @@ -493,6 +528,7 @@ class TestPaper extends AuthController if (TestPaperModel::be(['title' => $data['title'], 'is_del' => 0])) { return Json::fail('标题已存在!'); } + $res = TestPaperModel::insertGetId($data); $res1 = true; if ($type == 2) { @@ -503,15 +539,17 @@ class TestPaper extends AuthController $res3 = TestPaperQuestions::addTestPaperQuestions($res, $type, (int)$data['many_number'], $manyIds, $data['many_score']); $res4 = TestPaperQuestions::addTestPaperQuestions($res, $type, (int)$data['judge_number'], $judgeIds, $data['judge_score']); $res4 = TestPaperQuestions::addTestPaperQuestions($res, $type, (int)$data['answer_number'], $answerIds, $data['answer_score']); + $res6 = TestPaperQuestions::addTestPaper($res, $paperIds); } else { $res2 = TestPaperQuestions::addRandomGroupQuestions($res, $type, 1, $data['cate_id'], (int)$data['single_number'], $data['single_score']); $res3 = TestPaperQuestions::addRandomGroupQuestions($res, $type, 2, $data['cate_id'], (int)$data['many_number'], $data['many_score']); $res4 = TestPaperQuestions::addRandomGroupQuestions($res, $type, 3, $data['cate_id'], (int)$data['judge_number'], $data['judge_score']); $res4 = TestPaperQuestions::addRandomGroupQuestions($res, $type, 4, $data['cate_id'], (int)$data['answer_number'], $data['answer_score']); + $res6 = true; } $res5 = $this->inspectTestQuestions($res); } - if ($res && $res1 && $res2 && $res3 && $res4 && $res5) { + if ($res && $res1 && $res2 && $res3 && $res4 && $res5 && $res6) { TestPaperModel::commitTrans(); return Json::successful('添加/编辑成功'); } else { diff --git a/application/admin/model/questions/TestPaper.php b/application/admin/model/questions/TestPaper.php old mode 100755 new mode 100644 index d0c360e8..950ceb25 --- a/application/admin/model/questions/TestPaper.php +++ b/application/admin/model/questions/TestPaper.php @@ -22,6 +22,7 @@ use service\WechatTemplateService; use app\wap\model\routine\RoutineTemplate; use app\admin\model\wechat\WechatUser; use app\admin\model\system\WebRecommendRelation; + /** * 试卷列表 Model * Class TestPaper @@ -34,9 +35,10 @@ class TestPaper extends ModelBasic public static function setWhere($where) { $model = self::order('sort desc,add_time desc')->where(['is_del' => 0]); - if (isset($where['pid']) && $where['pid']) $model = $model->where('tid', $where['pid']); + if (isset($where['pid']) && $where['pid'] > 0) $model = $model->where('tid', $where['pid']); if (isset($where['type']) && $where['type']) $model = $model->where('type', $where['type']); if (isset($where['is_show']) && $where['is_show'] != '') $model = $model->where('is_show', $where['is_show']); + if (isset($where['ids']) && count($where['ids']) > 0) $model = $model->whereIn('id', $where['ids']); if ($where['title'] != '') $model = $model->where('title', 'like', "%$where[title]%"); if (isset($where['mer_id']) && $where['mer_id'] != '') { $model = $model->where('mer_id', $where['mer_id']); @@ -45,8 +47,8 @@ class TestPaper extends ModelBasic $model = $model->where('status', $where['status']); } else { $model = $model->where('status', 'in', [-1, 0]); - } - return $model; + } + return $model; } /**试卷列表 @@ -55,6 +57,8 @@ class TestPaper extends ModelBasic public static function testPaperExercisesList($where) { $data = self::setWhere($where)->page($where['page'], $where['limit'])->select(); + + foreach ($data as $key => &$value) { $value['cate'] = TestPaperCategoryModel::where('id', $value['tid'])->value('title'); $value['recommend'] = RecommendRelation::where('a.link_id', $value['id'])->where('a.type', 'in', '11,12')->alias('a') @@ -67,11 +71,22 @@ class TestPaper extends ModelBasic } else { $value['mer_name'] = '总平台'; } + $ids = TestPaperQuestions::where(['test_id' => $value['id']])->column('pid'); + if (count($ids) > 0) { + $papers = TestPaper::whereIn('id', $ids)->select(); + $value['item_number'] = $value['item_number'] + array_sum($papers->column('item_number')); + $value['single_number'] = $value['single_number'] + array_sum($papers->column('single_number')); + $value['many_number'] = $value['many_number'] + array_sum($papers->column('many_number')); + $value['judge_number'] = $value['judge_number'] + array_sum($papers->column('judge_number')); + $value['answer_number'] = $value['answer_number'] + array_sum($papers->column('answer_number')); + $value['answer'] = $value['answer'] + array_sum($papers->column('answer')); + } } $count = self::setWhere($where)->count(); return compact('data', 'count'); } -/**发送试卷列表 + + /**发送试卷列表 * @param $where */ public static function sendTestPaperExercisesList($where) @@ -110,6 +125,7 @@ class TestPaper extends ModelBasic $count = self::setWhere($where)->count(); return compact('data', 'count'); } + /**试卷列表 * @param $type * @return false|\PDOStatement|string|\think\Collection @@ -136,7 +152,7 @@ class TestPaper extends ModelBasic } else { $item['mer_name'] = '总平台'; } - } + } $count = self::setWhere($where)->where('id', 'not in', $source)->count(); return compact('data', 'count'); } @@ -163,7 +179,7 @@ class TestPaper extends ModelBasic return compact('data', 'count'); } - /**审核失败 + /**审核失败 * @param $id * @param $fail_msg * @return bool diff --git a/application/admin/model/questions/TestPaperQuestions.php b/application/admin/model/questions/TestPaperQuestions.php old mode 100755 new mode 100644 index 4ed41fb8..9f0762c7 --- a/application/admin/model/questions/TestPaperQuestions.php +++ b/application/admin/model/questions/TestPaperQuestions.php @@ -11,6 +11,8 @@ namespace app\admin\model\questions; +use think\Collection; +use think\helper\Arr; use traits\ModelTrait; use basic\ModelBasic; use service\UtilService as Util; @@ -49,6 +51,22 @@ class TestPaperQuestions extends ModelBasic return true; } + public static function addTestPaper($id, $data) + { + foreach ($data as $v) { + $item = []; + $item['type'] = 2; + $item['question_type'] = 5; + $item['test_id'] = $id; + $item['questions_id'] = 0; + $item['pid'] = $v['id']; + if (self::be($item)) continue; + self::set($item); + } + + return true; + } + /**试题列表 * @param $id */ @@ -75,12 +93,12 @@ class TestPaperQuestions extends ModelBasic return compact('data', 'count'); } - public static function setRecordWhere($test_id,$record_id,$question_type) + public static function setRecordWhere($test_id, $record_id, $question_type) { - $model =self::alias('tq')->where('tq.test_id',$test_id)->where('q.question_type',$question_type) - ->join('ExaminationTestRecord e','e.questions_id=tq.questions_id and e.e_id='.$record_id,'LEFT') - ->join('Questions q','q.id=tq.questions_id') - ->join('TestPaper t','t.id=tq.test_id') + $model = self::alias('tq')->where('tq.test_id', $test_id)->where('q.question_type', $question_type) + ->join('ExaminationTestRecord e', 'e.questions_id=tq.questions_id and e.e_id=' . $record_id, 'LEFT') + ->join('Questions q', 'q.id=tq.questions_id') + ->join('TestPaper t', 't.id=tq.test_id') ->field('t.single_number,t.single_score,t.many_number,t.many_score,t.judge_number,t.judge_score,t.answer_number,t.answer_score,q.stem,q.image,q.is_img,q.option,q.answer,q.difficulty,q.question_type,e.user_answer,e.is_correct,e.score'); return $model; } @@ -88,12 +106,12 @@ class TestPaperQuestions extends ModelBasic /**用户答题结果 * @param $where */ - public static function getExaminationRecordAnswers($test_id,$record_id,$question_type) + public static function getExaminationRecordAnswers($test_id, $record_id, $question_type) { - $model=self::setRecordWhere($test_id,$record_id,$question_type); + $model = self::setRecordWhere($test_id, $record_id, $question_type); $data = ($data = $model->select()) && count($data) ? $data->toArray() : []; - foreach ($data as $key=>&$item){ - if($item['is_correct']!=2) $item['score']=0; + foreach ($data as $key => &$item) { + if ($item['is_correct'] != 2) $item['score'] = 0; } return $data; } @@ -148,6 +166,15 @@ class TestPaperQuestions extends ModelBasic public static function gettestPaperQuestions($id, $question_type) { if (!$id) return []; + + if ($question_type == 5) { + $ids = self::where(['test_id' => $id, 'question_type' => $question_type])->column('pid'); + return TestPaper::alias('t1') + ->join('TestPaperCategory t2', 't1.tid=t2.id') + ->whereIn('t1.id', $ids) + ->field("t1.id,t1.title,t2.title as cate") + ->select(); + } return self::alias('t')->where(['t.test_id' => $id, 't.question_type' => $question_type, 'q.is_del' => 0])->order('sort desc,id desc') ->join('Questions q', 't.questions_id=q.id') ->field('t.sort,t.test_id,q.id,q.question_type,q.pid,q.stem,q.is_del,q.is_img') diff --git a/application/admin/model/questions/paper.php b/application/admin/model/questions/paper.php new file mode 100644 index 00000000..cc237254 --- /dev/null +++ b/application/admin/model/questions/paper.php @@ -0,0 +1,160 @@ +{extend name="public/container"} +{block name="content"} +
+
选择图片