| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\App;
 
- use think\Db;
 
- class ArticleWorker extends Auth
 
- {
 
-     public function __construct(App $app = null) {
 
-         parent::__construct($app);
 
-     }
 
-     public function index(){
 
-         if(request()->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;
 
-     }
 
- }
 
 
  |