1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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, "用户不可答题");
- }
- $answers = $arr['answers'];
- Db::startTrans();
- try {
- foreach ($answers as $key => $value) {
- $qbid = $value['qb_id'];
- $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);
- }
- $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, "操作成功");
- }
- }
|