questionlogic.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $answers = $arr['answers'];
  54. Db::startTrans();
  55. try {
  56. foreach ($answers as $key => $value) {
  57. $qbid = $value['qb_id'];
  58. $qbinfo = $m_qb->getinfobyid($qbid);
  59. if (empty($qbinfo)) {
  60. throw new \Exception("无问题信息");
  61. }
  62. $type = $qbinfo['type'];
  63. if (in_array($type, [1, 2])) {
  64. $answerid = $value['answer_id'];
  65. $qboinfo = $m_qbo->getinfobywhere($qbid, $answerid);
  66. if (empty($qboinfo)) {
  67. throw new \Exception("无答案内容");
  68. }
  69. $label = $qboinfo['label'];
  70. $insertData = [
  71. 'user_id' => $userid,
  72. 'seqb_id' => $qbid,
  73. 'answer' => $answerid,
  74. 'label' => $label,
  75. 'createtime' => date("Y-m-d H:i:s"),
  76. ];
  77. $m_qar->addinfo($insertData);
  78. }
  79. if (in_array($type, [3])) {
  80. $answer_str = $value['answer_str'];
  81. $insertData = [
  82. 'user_id' => $userid,
  83. 'seqb_id' => $qbid,
  84. 'answer' => $answer_str,
  85. 'createtime' => date("Y-m-d H:i:s"),
  86. ];
  87. $m_qar->addinfo($insertData);
  88. }
  89. }
  90. $quid = $quinfo['id'];
  91. $m_qu->updinfobyid($quid, ['is_active' => 0]);
  92. Db::commit();
  93. } catch (\Exception $e) {
  94. Db::rollback();
  95. $msg = $e->getMessage();
  96. return backarr(0, $msg);
  97. }
  98. return backarr(1, "操作成功");
  99. }
  100. }