|
@@ -34,7 +34,10 @@ class Questionnaire extends Api |
|
@@ -34,7 +34,10 @@ class Questionnaire extends Api |
34
|
"list": [{ //题目列表
|
34
|
"list": [{ //题目列表
|
35
|
"id": 1, //题目ID
|
35
|
"id": 1, //题目ID
|
36
|
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
|
36
|
"title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
|
37
|
- "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\"}]", //题目选项
|
37
|
+ "option": [{ //题目选项
|
|
|
38
|
+ "key": "A", //选项
|
|
|
39
|
+ "value": "1" //选项内容
|
|
|
40
|
+ }],
|
38
|
"type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
|
41
|
"type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
|
39
|
}]
|
42
|
}]
|
40
|
}
|
43
|
}
|
|
@@ -43,6 +46,9 @@ class Questionnaire extends Api |
|
@@ -43,6 +46,9 @@ class Questionnaire extends Api |
43
|
public function questionList()
|
46
|
public function questionList()
|
44
|
{
|
47
|
{
|
45
|
$list = QuestionnaireQuestion::field('id,title,option,type')->select();
|
48
|
$list = QuestionnaireQuestion::field('id,title,option,type')->select();
|
|
|
49
|
+ foreach ($list as $v){
|
|
|
50
|
+ $v->option = json_decode($v['option'],true);
|
|
|
51
|
+ }
|
46
|
$this->success('成功',compact('list'));
|
52
|
$this->success('成功',compact('list'));
|
47
|
}
|
53
|
}
|
48
|
|
54
|
|
|
@@ -53,7 +59,7 @@ class Questionnaire extends Api |
|
@@ -53,7 +59,7 @@ class Questionnaire extends Api |
53
|
*
|
59
|
*
|
54
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
60
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
55
|
*
|
61
|
*
|
56
|
- * @ApiParams (name="content", type="string", required=true, description="{问题ID:回答内容}")
|
62
|
+ * @ApiParams (name="content", type="string", required=true, description="[{id: 问题ID,value: 回答选项或内容}]")
|
57
|
*
|
63
|
*
|
58
|
* @ApiReturn({
|
64
|
* @ApiReturn({
|
59
|
"code": 1,
|
65
|
"code": 1,
|
|
@@ -66,9 +72,15 @@ class Questionnaire extends Api |
|
@@ -66,9 +72,15 @@ class Questionnaire extends Api |
66
|
{
|
72
|
{
|
67
|
$content = $this->request->post('content');
|
73
|
$content = $this->request->post('content');
|
68
|
empty($content) && $this->error('缺少必要参数');
|
74
|
empty($content) && $this->error('缺少必要参数');
|
69
|
- $answer_list = array_filter(json_decode(htmlspecialchars_decode($content),true));
|
|
|
70
|
- $no_answer = QuestionnaireQuestion::where('id','not in', array_keys($answer_list))->find();
|
|
|
71
|
- !empty($no_answer) && $this->error('还有问题没有回答');
|
75
|
+ if(is_string($content)){
|
|
|
76
|
+ $content = htmlspecialchars_decode($content);
|
|
|
77
|
+ }
|
|
|
78
|
+ $answer_list = json_decode($content,true);
|
|
|
79
|
+ $no_answer = QuestionnaireQuestion::where('id','not in', array_column($answer_list,'id'))->field('id')->find();
|
|
|
80
|
+ !empty($no_answer) && $this->error('请回答第'.$no_answer['id'].'题');
|
|
|
81
|
+ foreach ($answer_list as $v){
|
|
|
82
|
+ empty($v['value']) && $this->error('请回答第'.$v['id'].'题');
|
|
|
83
|
+ }
|
72
|
Db::startTrans();
|
84
|
Db::startTrans();
|
73
|
try{
|
85
|
try{
|
74
|
$result_id = db('mobile_questionnaire_result')->insertGetId([
|
86
|
$result_id = db('mobile_questionnaire_result')->insertGetId([
|
|
@@ -77,12 +89,12 @@ class Questionnaire extends Api |
|
@@ -77,12 +89,12 @@ class Questionnaire extends Api |
77
|
'updatetime' => time()
|
89
|
'updatetime' => time()
|
78
|
]);
|
90
|
]);
|
79
|
$insertAll = [];
|
91
|
$insertAll = [];
|
80
|
- foreach($answer_list as $id => $answer){
|
92
|
+ foreach($answer_list as $val){
|
81
|
$insertAll[] = [
|
93
|
$insertAll[] = [
|
82
|
'user_id' => $this->auth->id,
|
94
|
'user_id' => $this->auth->id,
|
83
|
'result_id' => $result_id,
|
95
|
'result_id' => $result_id,
|
84
|
- 'question_id' => $id,
|
|
|
85
|
- 'content' => $answer,
|
96
|
+ 'question_id' => $val['id'],
|
|
|
97
|
+ 'content' => $val['value'],
|
86
|
];
|
98
|
];
|
87
|
}
|
99
|
}
|
88
|
(new QuestionnaireAnswer)->saveAll($insertAll);
|
100
|
(new QuestionnaireAnswer)->saveAll($insertAll);
|