isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 $map1 = []; $map = []; $b = input('begin','','trim'); $e = input('end','','trim'); $title = input('title','','trim');//护工 if($title) { $map1[] = ['title', 'like', '%' . $title . '%']; } if($b && $e){ if($b <= $e){ $b = date('Ymd',strtotime($b)); $e = date('Ymd',strtotime($e)); $map[] = ['create_yyyymmdd','>=',$b]; $map[] = ['create_yyyymmdd','<=',$e]; } } if($b && $e==''){ $b = date('Ymd',strtotime($b)); $map[] = ['create_yyyymmdd','>=',$b]; } if($b=='' && $e){ $e = date('Ymd',strtotime($e)); $map[] = ['create_yyyymmdd','<=',$e]; } $cateId = input('roles_id','','trim'); if($cateId){ $map1['roles_id'] = $cateId; } //数据返回 $res = $this->show_all_page_search_worker($this->orgId,$map,$map1,$start,$length); $totalPage = $res['total']; $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $res['count']; $result['rows'] = $res['data']; return json($result); }else{ $this->assign('m_name','员工学习数据'); $cate = Db::name('roles') ->where('enable',1) ->where('del',0) ->where('del',0) ->where('org_id',$this->orgId) ->where('parent_id','>',0) ->select(); $this->assign('cate',$cate); return $this->fetch(); } } // 获取员工学习数据 public function show_all_page_search_worker($org, $map,$map1,$start,$length) { $pageSize = $length; $total = 0; $roles_ids = array(); if(isset($map1['roles_id'])){ $roles_ids[] = $map1['roles_id']; }else{ $roles_ids = $this->get_worker_roles([],$org); } if($roles_ids){ $query = Db::name('user') ->alias('a') ->where('b.roles_id','in',$roles_ids); }else{ $query = Db::name('user') ->alias('a') ->where('b.roles_id','=',-1); } $query->where('c.org_id',$org); $query->where('a.del',0); $query->join('user_roles b','user.id = b.user_id'); $query->join('user_org c','user.id = c.user_id'); $db = clone $query; $count = $query->count(); $db1 = $db; $total = ceil($count / $pageSize); //查看当前的 $pageNumber = empty($pageNumber) ? 0 : $pageNumber; //防止访问超过实际页数 $pageNumber = max(0, min($pageNumber, $total - 1)); $offset = $pageNumber * $pageSize; $db1->limit($start, $length); $db1->field('a.id as user_id,a.real_name,b.roles_id'); $list = $db1->select(); foreach ($list as $k=>$v){ $list[$k]['roles_name'] = Db::name('roles') ->where('id',$v['roles_id']) ->value('name'); $res = Db::name('record') ->where($map) ->where('user_id',$v['user_id']) ->field('SUM(view) as views,SUM(time) as times') ->group('user_id') ->find(); $list[$k]['views'] = 0; $list[$k]['times'] = 0; if($res){ $list[$k]['views'] = $res['views']; $list[$k]['times'] = $res['times']; } } $ret = array('data' => $list, 'total' => $total, 'count' => $count); return $ret; } public function get_worker_roles($roles,$org){ $roles_ids = array(); if (!$roles) { $roles_ids = Db::name('roles') ->where('enable',1) ->where('del',0) ->where('del',0) ->where('org_id',$org) ->where('parent_id','>',0) ->column('id'); }else{ $roles_ids = $roles; } return $roles_ids; } public function workLog($id){ if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 $res = $this->show_all_page_search_worker_record($this->orgId,$id,$start,$length); $totalPage = $res['total']; $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $res['count']; $result['rows'] = $res['data']; return json($result); }else{ $user = Db::name('user') ->where('id',$id) ->value('real_name'); $this->assign('m_name','['.$user.']学习记录'); $this->assign('id',$id); return $this->fetch(); } } // 员工学习数据 -- 查看 public function show_all_page_search_worker_record($org,$uid,$start,$length){ $pageSize = $length; $total = 0; $query = Db::name('record') ->alias('a') ->join('article b','b.id = a.article_id') ->where('a.user_id',$uid) ->where('a.org_id',$org) ->group('a.article_id'); $db = clone $query; $count = $query->count(); $this->db = $db; $total = ceil($count / $pageSize); //查看当前的 $pageNumber = empty($pageNumber) ? 0 : $pageNumber; //防止访问超过实际页数 $pageNumber = max(0, min($pageNumber, $total - 1)); $offset = $pageNumber * $pageSize; $this->db->field('b.title,b.limit,a.user_id,a.article_id,a.id'); $this->db->limit($start, $length); $this->db->order('a.id', 'DESC'); $list = $this->db->select(); foreach ($list as $k=>$v){ $res = Db::name('record') ->where('user_id',$v['user_id']) ->where('article_id',$v['article_id']) ->field('SUM(time) as times')->find(); $list[$k]['times'] = 0; if($res){ $list[$k]['times'] = $res['times']; } if($list[$k]['times'] >= $list[$k]['limit']){ $list[$k]['status'] = '达标'; }else{ $list[$k]['status'] = '未达标'; } } $ret = array('data' => $list, 'total' => $total, 'count' => $count); return $ret; } }