lqmac 7 months ago
parent a07704fd30
commit 949eddd5ca
  1. 90
      application/admin/controller/questions/TestPaper.php
  2. 24
      application/admin/model/questions/TestPaper.php
  3. 45
      application/admin/model/questions/TestPaperQuestions.php
  4. 160
      application/admin/model/questions/paper.php
  5. 865
      application/admin/view/questions/test_paper/add.php
  6. 6
      application/common.php
  7. 4
      application/wap/controller/Special.php
  8. 6
      application/wap/controller/Topic.php
  9. 8
      application/wap/model/topic/TestPaperQuestions.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);
@ -181,7 +182,8 @@ class TestPaper extends AuthController
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,28 +243,29 @@ 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)
// {
@ -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 {
//
// }
}
if ($question_type == 5) {
$where['type'] = 1;
$where['status'] = 1;
$list = \app\admin\model\questions\TestPaper::testPaperExercisesList($where);
} else {
$list = Questions::questionsList($where, $arrays);
}
$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 {

@ -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']);
@ -46,7 +48,7 @@ class TestPaper extends ModelBasic
} 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
@ -163,7 +179,7 @@ class TestPaper extends ModelBasic
return compact('data', 'count');
}
/**审核失败
/**审核失败
* @param $id
* @param $fail_msg
* @return bool

@ -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')

@ -0,0 +1,160 @@
{extend name="public/container"}
{block name="content"}
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-header">搜索条件</div>
<div class="layui-card-body">
<div class="layui-form layui-form-pane">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">试卷名称</label>
<div class="layui-input-inline">
<input type="text" name="title" id="demoReload" placeholder="请输入试卷名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="reload">搜索</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!--产品列表-->
<div class="layui-col-md12">
<div class="layui-card">
<div class="layui-card-header">试卷列表</div>
<div class="layui-card-body">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="window.location.reload()"><i class="layui-icon layui-icon-refresh"></i> 刷新</button>
</div>
<table class="layui-hide" id="List" lay-filter="List"></table>
<script type="text/html" id="image">
<img style="cursor: pointer;width: 80px;height: 40px;" lay-event='open_image' src="{{d.image}}">
</script>
</div>
</div>
</div>
</div>
</div>
<script src="{__ADMIN_PATH}js/layuiList.js"></script>
{/block}
{block name="script"}
<script>
var table_date=new Array();//用于保存当前页数据
var ids=new Array(); //用于保存选中的数据
var id={$id}
//实例化form
layList.form.render();
var table = layui.table;
table.render({
elem: '#List'
,url:"{:Url('questions.test_paper/getTestQuestionsList')}?question_type=5"+'&id='+id
,cols: [[
{type: 'checkbox'},
{field: 'id', title: '编号',align: 'center'},
{field: 'title', title: '试卷名称', align: 'center'},
{field: 'cate', title: '分类',align: 'center'},
]]
,id: 'testReload'
,page: {
theme: '#0092dc'
}
,limit:10
,done:function (res,curr,count) {
table_date=res.data;
for(var i=0;i< res.data.length;i++){
if(ids.length>0){
for (var j = 0; j < ids.length; j++) {
if(res.data[i].id == ids[j].id) {
res.data[i]["LAY_CHECKED"]='true';/*设置勾选*/
/*找到对应数据改变勾选样式*/
var index= res.data[i]['LAY_TABLE_INDEX'];
$('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
$('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
}
}
}
}
var checkStatus = table.checkStatus('List');/*获得选中的值 和判断是否是全选 isAll true全选 isAlL false 没有全选*/
if(checkStatus.isAll){
$('.layui-table-header th[data-field="0"] input[type="checkbox"]').prop('checked', true);
$('.layui-table-header th[data-field="0"] div[class="layui-unselect layui-form-checkbox"]').addClass('layui-form-checked');
}
removeArrayRepElement(ids);
$("#check_questions_tmp_"+question_type,window.parent.document).val(JSON.stringify(ids));
}
});
var $ = layui.$, active = {
reload: function(){
var demoReload = $('#demoReload');
//执行重载
table.reload('testReload', {
page: {
curr: 1 //重新从第 1 页开始
}
,where: {
title: demoReload.val(),
pid:$('#pids option:selected').val(),
}
}, 'data');
}
};
$('.layui-btn').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
//删除重复
function removeArrayRepElement(arr) {
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length; j++) {
if (arr[i].id == arr[j].id && i != j) {
arr.splice(j, 1);
}
}
}
return arr;
}
table.on('checkbox(List)', function (obj) {
if(obj.checked==true){
if(obj.type=='one'){
ids.push(obj.data);
}else{
for(var i=0;i<table_date.length;i++){
ids.push(table_date[i]);
}
}
ids=removeArrayRepElement(ids);
}else{
if(obj.type=='one'){
for(var i=0;i<ids.length;i++){
if(ids[i].id==obj.data.id){
ids.remove(i);
}
}
}else{
for(var i=0;i<ids.length;i++){
for(var j=0;j<table_date.length;j++){
if(ids[i].id==table_date[j].id){
ids.remove(i);
}
}
}
}
}
$("#check_questions_tmp_"+question_type,window.parent.document).val(JSON.stringify(ids));
});
Array.prototype.remove=function(dx){
if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++)
{
if(this[i]!=this[dx]){
this[n++]=this[i];
}
}
this.length-=1;
};
</script>
{/block}

File diff suppressed because it is too large Load Diff

@ -249,14 +249,14 @@ function getversion()
* @param int $pid
* @return array
*/
function subTree(array $data, int $pid = 0) {
function subTree(array $data, int $pid = 0, $field = 'pid') {
// 返回的结果
$arr = [];
foreach ($data as $val) {
// 给定的PID是当前记录的上级ID
if ($pid == $val['pid']) {
if ($pid == $val[$field]) {
// 递归
$val['children'] = subTree($data,$val['id']);
$val['children'] = subTree($data,$val['id'], $field);
$arr[] = $val;
}
}

@ -66,6 +66,7 @@ use app\wap\model\topic\Relation;
use app\wap\model\user\UserRecharge;
use think\Log;
use service\AliVodServices;
use service\UtilService as Util;
/**专题
@ -131,7 +132,8 @@ class Special extends AuthController
*/
public function getSpecialSubject()
{
$category = SpecialSubject::with('children')->where(['is_show' => 1, 'is_del' => 0])->order('sort desc,id desc')->where('grade_id', 0)->select();
$category = SpecialSubject::where(['is_show' => 1, 'is_del' => 0])->order('sort desc,id desc')->select();
$category = subTree($category->toArray(), 0, 'grade_id');
$recommend = SpecialSubject::where(['is_show' => 1, 'is_del' => 0, 'is_recommend' => 1])->where('grade_id', 'neq', 0)->order('sort desc,id desc')->select();
return JsonService::successful([

@ -555,6 +555,12 @@ class Topic extends AuthController
} else if ($type == 2) {
$value['is_pay'] = (!$this->uid || $this->uid == 0) ? false : TestPaperObtain::PayTestPaper($value['id'], $this->uid, 2);
}
$ids = \app\admin\model\questions\TestPaperQuestions::where(['test_id' => $value['id']])->column('pid');
if (count($ids) > 0) {
$papers = \app\admin\model\questions\TestPaper::whereIn('id', $ids)->select();
$value['item_number'] = $value['item_number'] + array_sum($papers->column('item_number'));
}
$value['answer'] = $value['answer'] + $value['fake_sales'];
}
}

@ -36,14 +36,16 @@ class TestPaperQuestions extends ModelBasic
*/
public static function getQuestionslist($test_id, $type, $question_type = 0)
{
(array)$test_ids = self::where(['test_id' => $test_id, 'type' => $type,])->where('pid', '>', 0)->column('pid');
$model = self::alias('p')->join('Questions q', 'p.questions_id=q.id')
->where(['p.type' => $type, 'p.test_id' => $test_id, 'q.is_del' => 0]);
->where(['p.type' => $type, 'q.is_del' => 0])
->whereIn('test_id', array_merge($test_ids,[$test_id]));
if ($question_type) {
$model = $model->where('p.question_type', $question_type);
}
$list = $model->field('p.*,q.option,q.stem,q.image,q.answer,q.difficulty,q.analysis,q.relation,q.is_img,q.is_del')
->order('p.sort desc')->select();
$list = count($list) > 0 ? $list->toArray() : [];
return $list;
return count($list) > 0 ? $list->toArray() : [];
}
}

Loading…
Cancel
Save