wangjun 6 giorni fa
parent
commit
b36ac31cf6

+ 46 - 0
application/index/controller/Question.php

@@ -0,0 +1,46 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2020/1/27
+ * Time: 15:38
+ */
+
+namespace app\index\controller;
+use app\index\logic\prjmanger;
+use app\index\logic\headmanger;
+use app\index\logic\workermanger;
+use app\index\logic\contactlogic;
+use app\index\logic\questionlogic;
+use think\Controller;
+
+class Question extends Controller {
+    public function getquestionlist() {
+        $queryinfo = request()->param();
+        $l_q = new questionlogic();
+        $result = $l_q->getquestionlist($queryinfo);
+        if (empty($result['status'])) {
+            $res_r['code'] = 0;
+        } else {
+            $res_r['code'] = 200;
+        }
+        $res_r['msg'] = $result['msg'];
+        $res_r['data'] = $result['data'];
+        return json_encode($res_r, 320);
+    }
+
+    public function saveanswer() {
+        $queryinfo = request()->param();
+        $l_q = new questionlogic();
+        $result = $l_q->saveanswer($queryinfo);
+        if (empty($result['status'])) {
+            $res_r['code'] = 0;
+        } else {
+            $res_r['code'] = 200;
+        }
+        $res_r['msg'] = $result['msg'];
+        $res_r['data'] = $result['data'];
+        return json_encode($res_r, 320);
+    }
+
+}

+ 89 - 0
application/index/logic/questionlogic.php

@@ -0,0 +1,89 @@
+<?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, "操作成功");
+    }
+}

+ 4 - 0
application/index/model/questionanswerrecordmodel.php

@@ -9,4 +9,8 @@ use think\Model;
  */
 class questionanswerrecordmodel extends Model {
     protected $table = 't_question_answer_record';
+    public function addinfo($info) {
+        $id = $this->allowField(true)->isUpdate(false)->setAttr('id', null)->save($info);
+        return $id;
+    }
 }

+ 5 - 0
application/index/model/questionbankmodel.php

@@ -9,4 +9,9 @@ use think\Model;
  */
 class questionbankmodel extends Model {
     protected $table = 't_question_bank';
+
+    public function getlistall() {
+        $list = $this->where([])->order("sort asc")->select();
+        return $list;
+    }
 }

+ 17 - 0
application/index/model/questionbankoptionsmodel.php

@@ -9,4 +9,21 @@ use think\Model;
  */
 class questionbankoptionsmodel extends Model {
     protected $table = 't_question_bank_options';
+
+    public function getoptionsbyseqbid($qbid) {
+        $list = $this->where(['seqb_id' => $qbid])->order("id asc")->select();
+        return $list;
+    }
+    public function getinfobyid($id) {
+        $where_arr['id'] = $id;
+        $rec = $this->where($where_arr)->find();
+        return $rec;
+    }
+
+    public function getinfobywhere($qbid, $id) {
+        $where_arr['id'] = $id;
+        $where_arr['seqb_id'] = $qbid;
+        $rec = $this->where($where_arr)->find();
+        return $rec;
+    }
 }