12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\common\model;
- use think\Db;
- class Questionnaire extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'questionnaire';
- protected $validateName = 'Questionnaire';
- public function record_info($id){
- $info = Db::name('questionnaire_record')
- ->where('id',$id)
- ->find();
- if($info){
- $answers = Db::name('questionnaire_record_answer')
- ->where('questionnaire_record_id',$id)
- ->select();
- $qinfo = Db::name('questionnaire')
- ->where('id',$info['questionnaire_id'])
- ->find();
- $questions = json_decode($qinfo['questions'],true);
- foreach ($questions as $k=>$v){
- $answer = [];
- foreach ($answers as $key=>$val){
- if($val['question_id'] == $v['id']){
- $answer = $val;
- break;
- }
- }
- if($v['type'] == 'checkbox'){
- $questions[$k]['answer'] = empty($answer)||!$answer['answer']?[]:explode(',',$answer['answer']);
- }else{
- $questions[$k]['answer'] = empty($answer)||!$answer['answer']?'':$answer['answer'];
- }
- }
- $info['questions'] = $questions;
- $info['title'] = $qinfo['title'];
- $info['description'] = $qinfo['description'];
- $info['nickname'] ='游客';
- }
- return $info;
- }
- }
|