123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace app\index\logic;
- use app\index\model\daycheckinfo;
- use app\index\model\gworkermodel;
- use app\index\model\pinfomodel;
- use app\index\model\prjlocationmodel;
- use app\index\model\pwrelationmodel;
- use app\index\model\ginfomodel;
- use app\index\model\wheadmodel;
- use app\index\model\contactmodel;
- use app\index\model\gcmodel;
- use app\index\model\questionanswerrecordmodel;
- use app\index\model\questionbankmodel;
- use app\index\model\questionbankoptionsmodel;
- use app\index\model\questionusermodel;
- use app\index\model\transfermodel;
- use think\Db;
- /**
- * 答题
- *
- * @author wj
- * @date 2025-07-25
- */
- class questionlogic {
- public function getquestionlist($arr) {
- $m_qb = new questionbankmodel();
- $m_qbo = new questionbankoptionsmodel();
- $m_qu = new questionusermodel();
- $userid = $arr['user_id'];
- $quinfo = $m_qu->isactivebyuseid($userid);
- if (empty($quinfo)) {
- return backarr(0, "用户不可答题");
- }
- $qb_list = $m_qb->getlistall();
- foreach ($qb_list as $key => $value) {
- $qbid = $value['id'];
- $options = $m_qbo->getoptionsbyseqbid($qbid);
- $value['options'] = $options;
- $qb_list[$key] = $value;
- }
- return backarr(1, "操作成功", $qb_list);
- }
- public function saveanswer($arr) {
- $m_qb = new questionbankmodel();
- $m_qbo = new questionbankoptionsmodel();
- $m_qar = new questionanswerrecordmodel();
- $m_qu = new questionusermodel();
- $userid = $arr['user_id'];
- $quinfo = $m_qu->isactivebyuseid($userid);
- if (empty($quinfo)) {
- return backarr(0, "用户不可答题");
- }
- $answertime = $quinfo['id'];
- $answers = $arr['answers'];
- Db::startTrans();
- try {
- foreach ($answers as $key => $value) {
- $qbid = $value['qb_id'];
- $qbinfo = $m_qb->getinfobyid($qbid);
- if (empty($qbinfo)) {
- throw new \Exception("无问题信息");
- }
- $type = $qbinfo['type'];
- if (in_array($type, [1, 2])) {
- $answerid = $value['answer_id'];
- $answerid_arr = array_filter(explode(",", $answerid));
- $label_arr = [];
- foreach ($answerid_arr as $key => $aid) {
- $qboinfo = $m_qbo->getinfobywhere($qbid, $aid);
- if (empty($qboinfo)) {
- continue;
- }
- $label_arr[] = $qboinfo['label'];
- }
- $label = implode(" ", $label_arr);
- $insertData = [
- 'user_id' => $userid,
- 'seqb_id' => $qbid,
- 'answer' => $answerid,
- 'label' => $label,
- 'createtime' => date("Y-m-d H:i:s"),
- 'answer_time' => $answertime,
- ];
- $m_qar->addinfo($insertData);
- }
- if (in_array($type, [3])) {
- $answer_str = !isset($value['answer_str']) || empty($value['answer_str']) ? "" : $value['answer_str'];
- $insertData = [
- 'user_id' => $userid,
- 'seqb_id' => $qbid,
- 'answer' => $answer_str,
- 'createtime' => date("Y-m-d H:i:s"),
- ];
- $m_qar->addinfo($insertData);
- }
- }
- $quid = $quinfo['id'];
- $m_qu->updinfobyid($quid, ['is_active' => 0, 'is_answer' => 1, 'answer_time' => date("Y-m-d H:i:s")]);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $msg = $e->getMessage();
- return backarr(0, $msg);
- }
- return backarr(1, "操作成功");
- }
- }
|