|
@@ -0,0 +1,72 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+/**
|
|
|
+ * 社区服务
|
|
|
+ */
|
|
|
+class Service extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //服务类型列表
|
|
|
+ public function paper_list(){
|
|
|
+ $list = Db::name('service_paper')->where(['status'=>1])->whereNull('deletetime')->order('weigh desc')->select();
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //题目列表
|
|
|
+ public function question_list(){
|
|
|
+ $paper_id = input('paper_id');
|
|
|
+ $list = Db::name('service_question')->where('paper_id',$paper_id)->where(['status'=>1])->whereNull('deletetime')->order('weigh desc, id desc')->select();
|
|
|
+ foreach($list as $k=>$v){
|
|
|
+ $options = json_decode($v['options_json'],true);
|
|
|
+
|
|
|
+ foreach ($options as $key=>$value){
|
|
|
+ $op = [
|
|
|
+ 'key' => $key,
|
|
|
+ 'value' => $value
|
|
|
+ ];
|
|
|
+ $list[$k]['options'][] = $op;
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($list[$k]['options_json']);
|
|
|
+ }
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //提交
|
|
|
+ public function submit(){
|
|
|
+
|
|
|
+ $paper_id = input('paper_id');
|
|
|
+ $answer_json = input('answer','','trim');
|
|
|
+
|
|
|
+ $list = Db::name('service_question')->where('paper_id',$paper_id)->where(['status'=>1])->whereNull('deletetime')->order('weigh desc, id desc')->select();
|
|
|
+ $question_ids = array_column($list, 'id');
|
|
|
+
|
|
|
+ $answer = json_decode($answer_json,true);
|
|
|
+ if(count($list) != count($answer)){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+ if(array_column($answer,'id') != $question_ids){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'paper_id' => $paper_id,
|
|
|
+ 'question_ids' => implode(',',$question_ids),
|
|
|
+ 'user_answers' => $answer_json,
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $grade_id = Db::name('service_grade')->insert($data);
|
|
|
+ $this->success('提交成功',$grade_id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|