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, "用户不可答题"); } $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']; $qboinfo = $m_qbo->getinfobywhere($qbid, $answerid); if (empty($qboinfo)) { throw new \Exception("无答案内容"); } $label = $qboinfo['label']; $insertData = [ 'user_id' => $userid, 'seqb_id' => $qbid, 'answer' => $answerid, 'label' => $label, 'createtime' => date("Y-m-d H:i:s"), ]; $m_qar->addinfo($insertData); } if (in_array($type, [3])) { $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]); Db::commit(); } catch (\Exception $e) { Db::rollback(); $msg = $e->getMessage(); return backarr(0, $msg); } return backarr(1, "操作成功"); } }