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

合并分支 'heshupeng' 到 'master'

Heshupeng



查看合并请求 !302
@@ -72,6 +72,7 @@ class Study extends Backend @@ -72,6 +72,7 @@ class Study extends Backend
72 */ 72 */
73 public function pass_list($ids = null,$type = null) 73 public function pass_list($ids = null,$type = null)
74 { 74 {
  75 + @ini_set('memory_limit', '512M'); //过滤导出报错
75 $this->relationSearch = true; 76 $this->relationSearch = true;
76 //设置过滤方法 77 //设置过滤方法
77 $this->request->filter(['strip_tags']); 78 $this->request->filter(['strip_tags']);
@@ -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);
@@ -3517,7 +3517,10 @@ @@ -3517,7 +3517,10 @@
3517 "list": [{ //题目列表 3517 "list": [{ //题目列表
3518 "id": 1, //题目ID 3518 "id": 1, //题目ID
3519 "title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目 3519 "title": "测定混凝土立方体抗压强度时,标准试件的尺寸是( )㎜。", //题目
3520 - "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\"}]", //题目选项 3520 + "option": [{ //题目选项
  3521 + "key": "A", //选项
  3522 + "value": "1" //选项内容
  3523 + }],
3521 "type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题 3524 "type": "1", //题目类型:1=单选题,2=多选题,3=判断题,4=简答题
3522 }] 3525 }]
3523 } 3526 }
@@ -3593,7 +3596,7 @@ @@ -3593,7 +3596,7 @@
3593 <td>content</td> 3596 <td>content</td>
3594 <td>string</td> 3597 <td>string</td>
3595 <td></td> 3598 <td></td>
3596 - <td>{问题ID:回答内容}</td> 3599 + <td>[{id: 问题ID,value: 回答选项或内容}]</td>
3597 </tr> 3600 </tr>
3598 </tbody> 3601 </tbody>
3599 </table> 3602 </table>
@@ -3626,7 +3629,7 @@ @@ -3626,7 +3629,7 @@
3626 <form enctype="application/x-www-form-urlencoded" role="form" action="/mobile/questionnaire/submit" method="POST" name="form81" id="form81"> 3629 <form enctype="application/x-www-form-urlencoded" role="form" action="/mobile/questionnaire/submit" method="POST" name="form81" id="form81">
3627 <div class="form-group"> 3630 <div class="form-group">
3628 <label class="control-label" for="content">content</label> 3631 <label class="control-label" for="content">content</label>
3629 - <input type="string" class="form-control input-sm" id="content" required placeholder="{问题ID:回答内容}" name="content"> 3632 + <input type="string" class="form-control input-sm" id="content" required placeholder="[{id: 问题ID,value: 回答选项或内容}]" name="content">
3630 </div> 3633 </div>
3631 <div class="form-group"> 3634 <div class="form-group">
3632 <button type="submit" class="btn btn-success send" rel="81">提交</button> 3635 <button type="submit" class="btn btn-success send" rel="81">提交</button>
@@ -24366,7 +24369,7 @@ @@ -24366,7 +24369,7 @@
24366 24369
24367 <div class="row mt0 footer"> 24370 <div class="row mt0 footer">
24368 <div class="col-md-6" align="left"> 24371 <div class="col-md-6" align="left">
24369 - Generated on 2021-04-27 13:29:02 </div> 24372 + Generated on 2021-04-29 16:06:13 </div>
24370 <div class="col-md-6" align="right"> 24373 <div class="col-md-6" align="right">
24371 <a href="./" target="_blank">企智帮</a> 24374 <a href="./" target="_blank">企智帮</a>
24372 </div> 24375 </div>