wangjun 6 dní pred
rodič
commit
8c326b37c7

+ 20 - 0
application/index/controller/Worker.php

@@ -909,4 +909,24 @@ class Worker extends Controller {
         $res_r['data'] = $result['data'];
         return json_encode($res_r, 320);
     }
+    /**
+     * 设置答题人员
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2025-07-25
+     * isactive 是否有效 1有效 0无效
+     */
+    public function setquestionuser() {
+        $queryinfo = request()->param();
+        $l_f = new workermanger();
+        $result = $l_f->setquestionuser($queryinfo);
+        if (empty($result['status'])) {
+            $res_r['code'] = 0;
+        }
+        $res_r['msg'] = $result['msg'];
+        $res_r['data'] = $result['data'];
+        return json_encode($res_r, 320);
+    }
 }

+ 85 - 2
application/index/logic/workermanger.php

@@ -20,6 +20,7 @@ use app\index\model\userlocationhismodel;
 use app\index\model\prjlocationmodel;
 use app\index\model\noticemodel;
 use app\index\model\noticereadmodel;
+use app\index\model\questionusermodel;
 
 class workermanger {
     public function getallworkerlist($pagenum, $pagesize) {
@@ -252,9 +253,17 @@ class workermanger {
      * 根据用户姓名获取
      */
     public function getworkerinfobyname($arr) {
-        $wname = $arr['wname'];
+        // $wname = $arr['wname'];
+        $fields = ['qu_active', 'wname', 'qu_isanswer'];
+        $where = [];
+        foreach ($fields as $key => $value) {
+            if (isset($arr[$value])) {
+                $where[$value] = $arr[$value];
+            }
+        }
         $t_work = new gworkermodel();
-        $rlist = $t_work->selinfobyname($wname);
+        // $rlist = $t_work->selinfobyname($wname);
+        $rlist = $t_work->selinfobywhere($where);
         return $rlist;
     }
 
@@ -645,5 +654,79 @@ class workermanger {
         return $icount;
 
     }
+    /**
+     * 设置答题人员
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2025-07-25
+     * isactive 是否有效 1有效 0无效
+     */
+    public function setquestionuser($arr) {
+        $fillfields = ['ids'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "请求错误");
+            }
+        }
+        $ids = array_filter($arr['ids']);
 
+        $m_u = new gworkermodel();
+        $m_qu = new questionusermodel();
+
+        $isactive = 1;
+        if (isset($arr['isactive']) && empty($arr['isactive'])) {
+            $isactive = 0;
+        }
+        $errors = [];
+        $success_ids = [];
+        foreach ($ids as $key => $userid) {
+            $msg = "用户id[" . $userid . "]";
+            $uinfo = $m_u->getinfobyid($userid);
+            if (empty($uinfo)) {
+                $errors[] = $msg . "无信息";
+                unset($ids[$key]);
+                continue;
+            }
+            if (1 == $isactive) {
+                if (empty($uinfo['isactive'])) {
+                    $errors[] = $msg . "已无效";
+                    unset($ids[$key]);
+                    continue;
+                }
+                if ($m_qu->isactivebyuseid($userid)) {
+                    $errors[] = $msg . "已设置";
+                    unset($ids[$key]);
+                    continue;
+                }
+                $insertData = [
+                    'user_id' => $userid,
+                    'telno' => $uinfo['telno'],
+                    'is_active' => $isactive,
+                    'createtime' => date("Y-m-d H:i:s"),
+                ];
+                $quid = $m_qu->addinfo($insertData);
+            }
+            if (0 === $isactive) {
+                $quinfo = $m_qu->isactivebyuseid($userid);
+                if (empty($quinfo)) {
+                    unset($ids[$key]);
+                    continue;
+                }
+                $quid = $quinfo['id'];
+                $updateData = ['is_active' => 0];
+                $m_qu->updinfobyid($quid, $updateData);
+            }
+            $success_ids[] = ['userid' => $userid, 'quid' => $quid];
+        }
+        $data = [
+            'errors' => $errors,
+            'success_ids' => $success_ids,
+        ];
+        if (count($success_ids) <= 0) {
+            return backarr(0, "操作失败", $data);
+        }
+        return backarr(1, "操作成功", $data);
+    }
 }

+ 36 - 2
application/index/model/gworkermodel.php

@@ -38,8 +38,12 @@ class gworkermodel extends Model {
      * 获取一个企业的项目的所有工人
      */
     public function getallworkerbycid($start, $rlen, $cid) {
-        $strsql = "select a.*,c.pname,c.is_worker ";
-        $strsql = $strsql . "from t_workerinfo a left join t_p2wrelation b on a.id=b.wid and b.checkstatus=1 left join t_pinfo c on b.pid=c.id";
+        $strsql = "select a.*,c.pname,c.is_worker,IFNULL(tab.quactive,0) qu_active,IFNULL(tab.quisanswer,0) qu_isanswer";
+        // $strsql = $strsql . "from t_workerinfo a left join t_p2wrelation b on a.id=b.wid and b.checkstatus=1 left join t_pinfo c on b.pid=c.id";
+        $strsql = $strsql . " from t_workerinfo a
+            left join t_p2wrelation b on a.id=b.wid and b.checkstatus=1
+            left join t_pinfo c on b.pid=c.id
+            left join (select id,user_id,is_active as quactive,is_answer as quisanswer from t_question_user where is_active=1) as tab on tab.user_id=a.id";
         $strsql = $strsql . " where c.companyid=" . $cid;
         $strsql = $strsql . " order by a.dayprice,create_date desc";
         $strsql = $strsql . " limit " . $start . "," . $rlen;
@@ -198,6 +202,36 @@ class gworkermodel extends Model {
         return $rlist;
     }
 
+    public function selinfobywhere($where) {
+        $field = "w.*,IFNULL(tab.quactive,0) qu_active,IFNULL(tab.quisanswer,0) qu_isanswer";
+        $strsql = "select " . $field . " from t_workerinfo as w
+                   left join (select id,user_id,is_active as quactive,is_answer as quisanswer from t_question_user where is_active=1) as tab on tab.user_id=w.id";
+        $strsql = "select * from (" . $strsql . ") as tab1";
+        $usewhere = [];
+        if (isset($where['wname']) && !empty($where['wname'])) {
+            $name = $where['wname'];
+            $usewhere[] = "wname like '%" . $name . "%'";
+        }
+        if (isset($where['qu_active']) && !empty($where['qu_active'])) {
+            $qu_active = $where['qu_active'];
+            $usewhere[] = "qu_active='" . $qu_active . "'";
+        }
+        if (isset($where['qu_isanswer']) && !empty($where['qu_isanswer'])) {
+            $qu_isanswer = $where['qu_isanswer'];
+            $usewhere[] = "qu_isanswer='" . $qu_isanswer . "'";
+        }
+        if (!empty($where)) {
+            $where_str = implode(" and ", $usewhere);
+            $strsql .= " where " . $where_str;
+        }
+        $ordre = "id,cprojectid";
+        $strsql .= " order by " . $ordre;
+
+        $rlist = $this->query($strsql);
+        $rlist = collection($rlist)->toArray();
+        return $rlist;
+    }
+
     /*
      * 20210416
      * 获取生日是今天的员工

+ 31 - 0
application/index/model/questionusermodel.php

@@ -9,4 +9,35 @@ use think\Model;
  */
 class questionusermodel extends Model {
     protected $table = 't_question_user';
+    /**
+     * 校验是否已有有效数据
+     *
+     * @param  [type] $userid
+     * @return void
+     * @author wj
+     * @date 2025-07-25
+     */
+    public function isactivebyuseid($userid) {
+        $where_arr['user_id'] = $userid;
+        $where_arr['is_active'] = 1;
+        $rec = $this->where($where_arr)->find();
+        return $rec;
+    }
+
+    public function getinfobyid($id) {
+        $where_arr['id'] = $id;
+        $rec = $this->where($where_arr)->find();
+        return $rec;
+    }
+
+    public function addinfo($info) {
+        $id = $this->allowField(true)->isUpdate(false)->setAttr('id', null)->save($info);
+        return $id;
+    }
+
+    public function updinfobyid($id, $arr) {
+        $where_arr['id'] = $id;
+        $count = $this->where($where_arr)->update($arr);
+        return $count;
+    }
 }