作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

APP改版

... ... @@ -57,7 +57,10 @@ class Almighty extends Model
return isset($list[$value]) ? $list[$value] : '';
}
public function category()
{
return $this->belongsTo('app\admin\model\mobile\QuestionCategory', 'target_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
... ... @@ -31,12 +31,36 @@ class Almighty extends Api
}
/**
* @ApiTitle (分类)
* @ApiSummary (分类)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599814710",
"data": {
"list": [{ // 分类列表
"id": 2, //分类ID
"name": "分类名称", //分类名称
}]
}
})
*/
public function index()
{
$list = \app\mobile\model\QuestionCategory::order('createtime desc')->field('id,name')->select();
$this->success('成功',compact('list'));
}
/**
* @ApiTitle (全能题库-题目列表)
* @ApiSummary (全能题库-题目列表)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="category_id", type="inter", required=true, description="分类ID")
* @ApiParams (name="answer_type", type="string", required=true, description="作答类型:0=全部,1=已答题,2=未答题,3=错题")
* @ApiParams (name="question_type", type="string", required=true, description="试题题型:0=全部,1=单选题,2=多选题,3=判断题,4=简答题")
*
... ... @@ -61,6 +85,7 @@ class Almighty extends Api
public function questionList()
{
$user_id = $this->auth->id ? $this->auth->id : 0;
$category_id = $this->request->param('category_id');
$answer_type = $this->request->param('answer_type');
$question_type = $this->request->param('question_type');
$where['q.target_type'] = '1';
... ... @@ -83,6 +108,10 @@ class Almighty extends Api
if(!empty($question_type)){
$where['q.type'] = $question_type;
}
// 分类
if(!empty($category_id)){
$where['q.target_id'] = $category_id;
}
$list = Question::alias('q')
->join('mobile_question_note qn','q.id = qn.question_id and qn.user_id='.$user_id,'left')
->join('mobile_question_collect qc','q.id = qc.question_id and qc.user_id='.$user_id,'left')
... ... @@ -188,7 +217,11 @@ class Almighty extends Api
$is_wrong = '0';
if($question['type'] != '4'){
if($question['answer'] == $answer){
$score = $question['score'];
if($question['target_type'] == '2'){
$score = Simulation::where('id',$question['target_id'])->value('question_score');
}else{
$score = $question['score'];
}
}else{
$is_wrong = '1';
}
... ...
... ... @@ -378,4 +378,23 @@ class Index extends Api
{
$this->success('成功', ['is_on' => 0]);
}
/**
* @ApiTitle (问卷开关)
* @ApiSummary (问卷开关)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599017563",
"data": {
"is_on": 0 //问卷开关:0=关闭,1=开启
}
})
*/
public function questionnaireSwitch()
{
$this->success('成功', ['is_on' => Db::name('mobile_config')->where('id',1)->value('questionnaire_switch')]);
}
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\controller;
use app\common\controller\Api;
use app\mobile\model\QuestionnaireQuestion;
use app\mobile\model\QuestionnaireAnswer;
use think\Db;
use think\Exception;
use think\exception\PDOException;
/**
* 问卷接口
* @ApiWeigh (98)
*/
class Questionnaire extends Api
{
protected $noNeedLogin = ['questionList'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (问卷-题目列表)
* @ApiSummary (问卷-题目列表)
* @ApiMethod (POST)
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599032660",
"data": {
"list": [{ //题目列表
"id": 1, //题目ID
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
"option": "[{\"name\":\"A\",\"gender\":\"100\\u00d7100\\u00d7100\"},{\"name\":\"B\",\"gender\":\"150\\u00d7150\\u00d7150\"},{\"name\":\"C\",\"gender\":\"200\\u00d7200\\u00d7200\"},{\"name\":\"D\",\"gender\":\"70.7\\u00d770.7\\u00d770.7\"}]", //题目选项
"type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
}]
}
})
*/
public function questionList()
{
$list = QuestionnaireQuestion::field('id,title,option,type')->select();
$this->success('成功',compact('list'));
}
/**
* @ApiTitle (问卷-提交)
* @ApiSummary (问卷-提交)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="content", type="string", required=true, description="{问题ID:回答内容}")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599032660",
"data": null
})
*/
public function submit()
{
$content = $this->request->post('content');
empty($content) && $this->error('缺少必要参数');
$answer_list = array_filter(json_decode(htmlspecialchars_decode($content),true));
$no_answer = QuestionnaireQuestion::where('id','not in', array_keys($answer_list))->find();
!empty($no_answer) && $this->error('还有问题没有回答');
Db::startTrans();
try{
$result_id = db('mobile_questionnaire_result')->insertGetId([
'user_id' => $this->auth->id,
'createtime' => time(),
'updatetime' => time()
]);
$insertAll = [];
foreach($answer_list as $id => $answer){
$insertAll[] = [
'user_id' => $this->auth->id,
'result_id' => $result_id,
'question_id' => $id,
'content' => $answer,
];
}
(new QuestionnaireAnswer)->saveAll($insertAll);
Db::commit();
}catch (PDOException $e){
Db::rollback();
$this->error($e->getMessage());
}catch (Exception $e){
Db::rollback();
$this->error($e->getMessage());
}
$this->success('提交成功');
}
}
\ No newline at end of file
... ...
... ... @@ -154,13 +154,16 @@ class Simulation extends Api
q.type,
q.answer,
if(qc.id > 0,1,0) is_collect
')->order(['type'=>'asc'])
')->orderRaw('rand()')->limit($info['question_num'])
->order(['type'=>'asc'])
->select();
$total = count($list);
// 删除原来的做题记录
QuestionAnswer::where('question_id','in',array_column($list, 'id'))
->where('user_id',$user_id)
->delete();
// 把题目ID存到缓存
cache('simulation_'.$user_id, array_column($list, 'id'));
$this->success('成功',compact('time','total','list'));
}
... ... @@ -196,10 +199,14 @@ class Simulation extends Api
empty($simulation_id) && $this->error('缺少必要参数');
$info = $this->model->get($simulation_id);
empty($info) && $this->error('试卷信息不存在');
$where = [
'q.target_id' => $simulation_id,
'q.target_type' => '2',
'q.id' => cache('simulation_'.$user_id) ? ['in',cache('simulation_'.$user_id)] : 0
];
$list = Question::alias('q')
->join('mobile_question_answer qa','q.id = qa.question_id and user_id='.$user_id,'left')
->where('q.target_id',$simulation_id)
->where('q.target_type','2')
->where($where)
->field('
q.id,
q.title,
... ...
... ... @@ -305,6 +305,7 @@ class User extends Api
}
$this->auth->setAllowFields(['id', 'mobile', 'group_id']);
$data = ['userinfo' => $this->auth->getUserInfo()];
$data['questionnaire_switch'] = Db::name('mobile_config')->where('id',1)->value('questionnaire_switch');
$this->success('登录成功', $data);
}
... ...
<?php
namespace app\mobile\model;
use think\Model;
class QuestionCategory extends Model
{
// 表名
protected $name = 'mobile_question_category';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class QuestionnaireAnswer extends Model
{
// 表名
protected $name = 'mobile_questionnaire_answer';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
<?php
namespace app\mobile\model;
use think\Model;
class QuestionnaireQuestion extends Model
{
// 表名
protected $name = 'mobile_questionnaire_question';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
}
\ No newline at end of file
... ...
... ... @@ -60,6 +60,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'category.name', title: __('Category.name'), searchList: Config.caegoryList, formatter: Table.api.formatter.normal},
{field: 'title', title: __('title'), operate:'LIKE'},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}, formatter: Table.api.formatter.normal},
{field: 'answer', title: __('Answer')},
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/question_category/index' + location.search,
add_url: 'mobile/question_category/add',
edit_url: 'mobile/question_category/edit',
del_url: 'mobile/question_category/del',
multi_url: 'mobile/question_category/multi',
table: 'mobile_question_category',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
$('#c-type').on('change',function (obj) {
var select_type = $(this).val();
switch(select_type){
case "1":
$('.fieldlist2').addClass('hidden');
$('.fieldlist0').removeClass('hidden');
$('.fieldlist1').addClass('hidden');
$('.option').removeClass('hidden');
break;
case "2":
$('.fieldlist2').addClass('hidden');
$('.fieldlist0').addClass('hidden');
$('.fieldlist1').removeClass('hidden');
$('.option').removeClass('hidden');
break;
case "3":
$('.fieldlist2').removeClass('hidden');
$('.fieldlist0').addClass('hidden');
$('.fieldlist1').addClass('hidden');
$('.option').removeClass('hidden');
break;
case "4":
$('.option').addClass('hidden');
break;
}
});
$("input[name='[key]']").on('change',function (obj) {
$(this).next().next(':radio').value($(this).val());
});
//监听文本框改变事件
$(document).on('change keyup changed', "input[name$='[key]']", function () {
$(this).parent().parent().find(':radio').val($(this).val());
});
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/questionnaire/questionnaire_question/index' + location.search,
add_url: 'mobile/questionnaire/questionnaire_question/add',
edit_url: 'mobile/questionnaire/questionnaire_question/edit',
del_url: 'mobile/questionnaire/questionnaire_question/del',
multi_url: 'mobile/questionnaire/questionnaire_question/multi',
table: 'mobile_questionnaire_question',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
sortOrder: 'asc',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'title', title: __('title'), operate:'LIKE'},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3'),"4":__('Type 4')}, formatter: Table.api.formatter.normal},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
setTimeout(function () {
$("#c-type").trigger("change");
}, 100);
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'mobile/questionnaire/questionnaire_result/index' + location.search,
add_url: 'mobile/questionnaire/questionnaire_result/add',
edit_url: 'mobile/questionnaire/questionnaire_result/edit',
del_url: 'mobile/questionnaire/questionnaire_result/del',
multi_url: 'mobile/questionnaire/questionnaire_result/multi',
table: 'mobile_questionnaire_result',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user_id', title: __('User_id')},
{field: 'user.username', title: __('User.username')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'info',
text: __('查看详情'),
title: __('查看详情'),
classname: 'btn btn-xs btn-info btn-dialog',
icon: 'fa fa-book',
url: 'mobile/questionnaire/questionnaire_result/info?result_id={id}'
}
],
formatter: Table.api.formatter.operate
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -32,6 +32,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'do_num_virtual', title: __('Do_num_virtual')},
{field: 'do_num_real', title: __('Do_num_real')},
{field: 'satisfaction', title: __('Satisfaction')},
{field: 'question_num', title: __('Question_num')},
{field: 'question_score', title: __('Question_score')},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
{
... ...
此 diff 太大无法显示。