questionlogic.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $answerid = $value['answer_id'];
  59. $qboinfo = $m_qbo->getinfobywhere($qbid, $answerid);
  60. if (empty($qboinfo)) {
  61. throw new \Exception("无答案内容");
  62. }
  63. $label = $qboinfo['label'];
  64. $insertData = [
  65. 'user_id' => $userid,
  66. 'seqb_id' => $qbid,
  67. 'answer' => $answerid,
  68. 'label' => $label,
  69. 'createtime' => date("Y-m-d H:i:s"),
  70. ];
  71. $m_qar->addinfo($insertData);
  72. }
  73. $quid = $quinfo['id'];
  74. $m_qu->updinfobyid($quid, ['is_active' => 0]);
  75. Db::commit();
  76. } catch (\Exception $e) {
  77. Db::rollback();
  78. $msg = $e->getMessage();
  79. return backarr(0, $msg);
  80. }
  81. return backarr(1, "操作成功");
  82. }
  83. }