questionlogic.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\index\logic;
  3. use app\index\model\daycheckinfo;
  4. use app\index\model\gworkermodel;
  5. use app\index\model\pinfomodel;
  6. use app\index\model\prjlocationmodel;
  7. use app\index\model\pwrelationmodel;
  8. use app\index\model\ginfomodel;
  9. use app\index\model\wheadmodel;
  10. use app\index\model\contactmodel;
  11. use app\index\model\gcmodel;
  12. use app\index\model\questionanswerrecordmodel;
  13. use app\index\model\questionbankmodel;
  14. use app\index\model\questionbankoptionsmodel;
  15. use app\index\model\questionusermodel;
  16. use app\index\model\transfermodel;
  17. use think\Db;
  18. /**
  19. * 答题
  20. *
  21. * @author wj
  22. * @date 2025-07-25
  23. */
  24. class questionlogic {
  25. public function getquestionlist($arr) {
  26. $m_qb = new questionbankmodel();
  27. $m_qbo = new questionbankoptionsmodel();
  28. $m_qu = new questionusermodel();
  29. $userid = $arr['user_id'];
  30. $quinfo = $m_qu->isactivebyuseid($userid);
  31. if (empty($quinfo)) {
  32. return backarr(0, "用户不可答题");
  33. }
  34. $qb_list = $m_qb->getlistall();
  35. foreach ($qb_list as $key => $value) {
  36. $qbid = $value['id'];
  37. $options = $m_qbo->getoptionsbyseqbid($qbid);
  38. $value['options'] = $options;
  39. $qb_list[$key] = $value;
  40. }
  41. return backarr(1, "操作成功", $qb_list);
  42. }
  43. public function saveanswer($arr) {
  44. $m_qb = new questionbankmodel();
  45. $m_qbo = new questionbankoptionsmodel();
  46. $m_qar = new questionanswerrecordmodel();
  47. $m_qu = new questionusermodel();
  48. $userid = $arr['user_id'];
  49. $quinfo = $m_qu->isactivebyuseid($userid);
  50. if (empty($quinfo)) {
  51. return backarr(0, "用户不可答题");
  52. }
  53. $answertime = $quinfo['id'];
  54. $answers = $arr['answers'];
  55. Db::startTrans();
  56. try {
  57. foreach ($answers as $key => $value) {
  58. $qbid = $value['qb_id'];
  59. $qbinfo = $m_qb->getinfobyid($qbid);
  60. if (empty($qbinfo)) {
  61. throw new \Exception("无问题信息");
  62. }
  63. $type = $qbinfo['type'];
  64. if (in_array($type, [1, 2])) {
  65. $answerid = $value['answer_id'];
  66. $answerid_arr = array_filter(explode(",", $answerid));
  67. $label_arr = [];
  68. foreach ($answerid_arr as $key => $aid) {
  69. $qboinfo = $m_qbo->getinfobywhere($qbid, $aid);
  70. if (empty($qboinfo)) {
  71. continue;
  72. }
  73. $label_arr[] = $qboinfo['label'];
  74. }
  75. $label = implode(" ", $label_arr);
  76. $insertData = [
  77. 'user_id' => $userid,
  78. 'seqb_id' => $qbid,
  79. 'answer' => $answerid,
  80. 'label' => $label,
  81. 'createtime' => date("Y-m-d H:i:s"),
  82. 'answer_time' => $answertime,
  83. ];
  84. $m_qar->addinfo($insertData);
  85. }
  86. if (in_array($type, [3])) {
  87. $answer_str = !isset($value['answer_str']) || empty($value['answer_str']) ? "" : $value['answer_str'];
  88. $insertData = [
  89. 'user_id' => $userid,
  90. 'seqb_id' => $qbid,
  91. 'answer' => $answer_str,
  92. 'createtime' => date("Y-m-d H:i:s"),
  93. ];
  94. $m_qar->addinfo($insertData);
  95. }
  96. }
  97. $quid = $quinfo['id'];
  98. $m_qu->updinfobyid($quid, ['is_active' => 0, 'is_answer' => 1, 'answer_time' => date("Y-m-d H:i:s")]);
  99. Db::commit();
  100. } catch (\Exception $e) {
  101. Db::rollback();
  102. $msg = $e->getMessage();
  103. return backarr(0, $msg);
  104. }
  105. return backarr(1, "操作成功");
  106. }
  107. }