Questionnaire.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Questionnaire extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'questionnaire';
  9. protected $validateName = 'Questionnaire';
  10. public function record_info($id){
  11. $info = Db::name('questionnaire_record')
  12. ->where('id',$id)
  13. ->find();
  14. if($info){
  15. $answers = Db::name('questionnaire_record_answer')
  16. ->where('questionnaire_record_id',$id)
  17. ->select();
  18. $qinfo = Db::name('questionnaire')
  19. ->where('id',$info['questionnaire_id'])
  20. ->find();
  21. $questions = json_decode($qinfo['questions'],true);
  22. foreach ($questions as $k=>$v){
  23. $answer = [];
  24. foreach ($answers as $key=>$val){
  25. if($val['question_id'] == $v['id']){
  26. $answer = $val;
  27. break;
  28. }
  29. }
  30. if($v['type'] == 'checkbox'){
  31. $questions[$k]['answer'] = empty($answer)||!$answer['answer']?[]:explode(',',$answer['answer']);
  32. }else{
  33. $questions[$k]['answer'] = empty($answer)||!$answer['answer']?'':$answer['answer'];
  34. }
  35. }
  36. $info['questions'] = $questions;
  37. $info['title'] = $qinfo['title'];
  38. $info['description'] = $qinfo['description'];
  39. $info['nickname'] ='游客';
  40. }
  41. return $info;
  42. }
  43. }