123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use think\Db;
- class User extends Index
- {
- // 项目大屏--员工数据分析
- public function userCate(){
- $lists = model('WorkTypeMode')->getWorkerUserStatistics($this->orgId);
- $data = [];
- foreach ($lists as $v){
- $data[] = [
- 'name' => $v['name'],
- 'value' => $v['count']
- ];
- }
- HelpHander::success($data);
- }
- // 项目大屏--员工好评度排名
- public function userPraise(){
- $allUids = model('WorkTypeMode')->getWorkerUserIds($this->orgId);
- $users = [];
- if($allUids){
- $users = Db::name('user')
- ->where('id','in',$allUids)
- ->order('score desc,id asc')
- ->field('id,real_name')
- ->limit(10)
- ->select();
- $users = $users?$users:[];
- }
- $data = [];
- $host = config("app.app_host");
- foreach ($users as $k=>$v){
- if($k == 0){
- $top = '<img src="'.$host.'/img/org-top1.png" width="35" style="margin-top:5px">';
- }else if($k == 1){
- $top = '<img src="'.$host.'/img/org-top2.png" width="35" style="margin-top:5px">';
- }else if($k == 2){
- $top = '<img src="'.$host.'/img/org-top3.png" width="35" style="margin-top:5px">';
- }else{
- $top = 'TOP'.($k+1);
- }
- $data[] = [$top,$v['real_name']];
- }
- HelpHander::success($data);
- }
- // 项目大屏--员工实时在岗情况
- public function userPosition(){
- $lists = Db::name('todo')
- ->where('todo_mode',3)
- ->where('org_id',$this->orgId)
- ->where('create_yyyymmdd',date('Ymd'))
- ->field('count(*) as count,to_user_id')
- ->group('to_user_id')
- ->distinct(true)
- ->order('count desc,to_user_id asc')
- ->select();
- $data = [];
- foreach ($lists as $k=>$v){
- $addr = Db::name('convey_plan_record')
- ->alias('cpr')
- ->join('address a','a.id = cpr.addr_id')
- ->where('user_id',$v['to_user_id'])
- ->value('title');
- $username = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $data[] = [$username?$username:'',$v['count'],$addr?$addr:''];
- }
- HelpHander::success($data);
- }
- public function userDep(){
- $depList = Db::name('dep')->where('enable',1)->where('org_id',$this->orgId)->where('del',0)->limit(6)->order('id desc')->select();
- $data = [];
- foreach ($depList as $v){
- $data[] = [
- 'name' => $v['title'],
- 'value' => Db::name('user_dep')
- ->alias('ud')
- ->join('user u','u.id=ud.user_id')
- ->where('ud.dep_id',$v['id'])
- ->where('u.del',0)
- ->count(),
- ];
- }
- HelpHander::success($data);
- }
- //新项目大屏---在岗人员情况
- public function onGuardUserData(){
- $type = input('type','');
- $pid = 0;
- if($type == 1){
- $pid = 7;
- }elseif ($type == 2){
- $pid = 8;
- }elseif ($type == 3){
- $pid = 6;
- }elseif ($type == 4){
- $pid = 5;
- }elseif ($type == 5){
- $pid = 9;
- }elseif ($type == 6){
- $pid = 11;
- }
- $rolesId = Db::name('roles')
- ->where('parent_id',$pid)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $userCount = Db::name('user')
- ->alias('u')
- ->field('u.id,u.real_name,ur.roles_id')
- ->join('user_roles ur','ur.user_id=u.id')
- ->where('u.del',0)
- ->where('u.enable',1)
- ->whereIn('ur.roles_id',$rolesId)
- ->count();
- $rolesUser = Db::name('user')
- ->alias('u')
- ->field('u.id,u.real_name,ur.roles_id')
- ->join('user_roles ur','ur.user_id=u.id')
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->whereIn('ur.roles_id',$rolesId)
- ->select();
- foreach ($rolesUser as $k=>$v){
- $roles = Db::name('roles')->where('id',$v['roles_id'])->find();
- $rolesUser[$k]['roles_name'] = Db::name('roles')->where('id',$roles['parent_id'])->value('name');
- $rolesUser[$k]['dep_name'] = Db::name('user_dep')
- ->alias('ud')
- ->join('dep d','d.id=ud.dep_id')
- ->where('ud.user_id',$v['id'])
- ->where('d.org_id',$this->orgId)
- ->value('d.title');
- }
- $list = [];
- foreach ($rolesUser as $k=>$v){
- $list[$k][] = $v['roles_name'];
- $list[$k][] = $v['dep_name'];
- $list[$k][] = $v['real_name'];
- }
- $data = [
- 'userCount'=>$userCount,
- 'rolesCount'=>count($rolesUser),
- 'list'=>$list
- ];
- HelpHander::success($data);
- }
- //人员在岗数据总览
- public function orgUserCount(){
- $userCount = Db::name('user')
- ->alias('u')
- ->join('user_org uo','u.id=uo.user_id')
- ->where('uo.org_id',$this->orgId)
- ->where('u.type',0)
- ->where('enable',1)
- ->where('del',0)
- ->count();
- $userPostCount = Db::name('user')
- ->alias('u')
- ->join('user_org uo','u.id=uo.user_id')
- ->where('uo.org_id',$this->orgId)
- ->where('u.work',1)
- ->where('u.type',0)
- ->where('del',0)
- ->where('enable',1)
- ->count();
- $data = [
- ['name'=>'总人数','value'=>$userCount],
- ['name'=>'在岗人员','value'=>$userPostCount]
- ];
- HelpHander::success($data);
- }
- public function rolesUserData(){
- $data = [
- ['pid'=>8,'name'=>'保洁','value'=>0],
- ['pid'=>7,'name'=>'维修','value'=>0],
- ['pid'=>5,'name'=>'保安','value'=>0],
- ['pid'=>6,'name'=>'运送','value'=>0],
- ['pid'=>11,'name'=>'陪护','value'=>0],
- ];
- foreach ($data as $k=>$v){
- $data[$k]['pid'] = Db::name('roles')
- ->where('parent_id',$v['pid'])
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- }
- foreach ($data as $k=>$v){
- $data[$k]['value'] = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$v['pid'])
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- unset($data[$k]['pid']);
- }
- HelpHander::success($data);
- }
- public function bjUserCountData(){
- //保洁
- $bjRolesId = Db::name('roles')
- ->where('parent_id',8)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $bjCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$bjRolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- $bjWorkCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$bjRolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->count();
- $bl = $bl2 = 0;
- if($bjCount > 0){
- $bl = round($bjWorkCount/$bjCount*100,1);
- $bl2 = 100 - $bl;
- }
- $data = [
- 'count'=>['bjCount'=>$bjCount,'bjWorkCount'=>$bjWorkCount],
- 'count2'=>[['value'=>$bl],['value'=>$bl2]],
- 'bl'=>$bl
- ];
- HelpHander::success($data);
- }
- public function wxUserCountData(){
- //维修
- $rolesId = Db::name('roles')
- ->where('parent_id',7)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- $workCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->count();
- $bl = $bl2 = 0;
- if($count > 0){
- $bl = round($workCount/$count*100,1);
- $bl2 = 100 - $bl;
- }
- $data = [
- 'count'=>['count'=>$count,'workCount'=>$workCount],
- 'count2'=>[['value'=>$bl],['value'=>$bl2]],
- 'bl'=>$bl
- ];
- HelpHander::success($data);
- }
- public function baUserCountData(){
- //保安
- $rolesId = Db::name('roles')
- ->where('parent_id',5)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- $workCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->count();
- $bl = $bl2 = 0;
- if($count > 0){
- $bl = round($workCount/$count*100,1);
- $bl2 = 100 - $bl;
- }
- $data = [
- 'count'=>['count'=>$count,'workCount'=>$workCount],
- 'count2'=>[['value'=>$bl],['value'=>$bl2]],
- 'bl'=>$bl
- ];
- HelpHander::success($data);
- }
- public function phUserCountData(){
- //陪护
- $rolesId = Db::name('roles')
- ->where('parent_id',11)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- $workCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->count();
- $bl = $bl2 = 0;
- if($count > 0){
- $bl = round($workCount/$count*100,1);
- $bl2 = 100 - $bl;
- }
- $workUserIds = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->column('u.id');
- $isWorkCount = Db::name('ph_todo')->whereIn('user_id',$workUserIds)->where('org_id',$this->orgId)->where('status',1)->group('user_id')->count();
- $noWorkCount = $workCount - $isWorkCount;
- if($noWorkCount < 1 ){
- $noWorkCount = 0;
- }
- $data = [
- 'count'=>['count'=>$count,'workCount'=>$workCount,'noWorkCount'=>$noWorkCount],
- 'count2'=>[['value'=>$bl],['value'=>$bl2]],
- 'bl'=>$bl
- ];
- HelpHander::success($data);
- }
- public function ysUserCountData(){
- //运送
- $rolesId = Db::name('roles')
- ->where('parent_id',6)
- ->where('del',0)
- ->where('type',1)
- ->where('enable',1)
- ->where('org_id',$this->orgId)
- ->column('id');
- $count = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->count();
- $workCount = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->count();
- $bl = $bl2 = 0;
- if($count > 0){
- $bl = round($workCount/$count*100,1);
- $bl2 = 100 - $bl;
- }
- $workUserIds = Db::name('user')
- ->alias('u')
- ->join('user_roles ur','ur.user_id=u.id')
- ->whereIn('ur.roles_id',$rolesId)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->where('u.work',1)
- ->column('u.id');
- $isWorkCount = Db::name('todo')->whereIn('to_user_id',$workUserIds)->where('org_id',$this->orgId)->where('todo_mode',2)->where('work_type_mode',3)->group('to_user_id')->where('del',0)->count();
- $noWorkCount = $workCount - $isWorkCount;
- if($noWorkCount < 1 ){
- $noWorkCount = 0;
- }
- $data = [
- 'count'=>['count'=>$count,'workCount'=>$workCount,'noWorkCount'=>$noWorkCount],
- 'count2'=>[['value'=>$bl],['value'=>$bl2]],
- 'bl'=>$bl
- ];
- HelpHander::success($data);
- }
- public function userCount(){
- $userCount = Db::name('user')
- ->alias('u')
- ->join('user_org uo','uo.user_id=u.id')
- ->join('org o','o.id=uo.org_id')
- ->where('u.del',0)
- ->where('u.type','in',[0,2])
- ->where('o.enable',1)
- ->where('o.del',0)
- ->where('o.id',$this->orgId)
- ->count();
- HelpHander::success($userCount);
- }
- // 项目大屏--满意度排名
- public function userCommentScoreList(){
- $user = Db::name('comment')
- ->field('user_id')
- ->where('org_id',$this->orgId)
- ->group('user_id')
- ->select();
- foreach ($user as $k=>$v){
- $user[$k]['score'] = Db::name('comment')
- ->where('org_id',$this->orgId)
- ->where('user_id',$v['user_id'])
- ->sum('score');
- $user[$k]['name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
- $user[$k]['dep'] = Db::name('user_dep')
- ->alias('ud')
- ->join('dep d','d.id=ud.dep_id')
- ->where('ud.user_id',$v['user_id'])
- ->value('title');
- $rolesId = Db::name('user_roles')
- ->alias('ur')
- ->join('roles r','r.id=ur.roles_id')
- ->where('ur.user_id',$v['user_id'])
- ->value('r.parent_id');
- $user[$k]['roles'] = $rolesId ? Db::name('roles')->where('id',$rolesId)->value('name'):'';
- $user[$k]['task'] = Db::name('comment')
- ->where('org_id',$this->orgId)
- ->where('user_id',$v['user_id'])
- ->count();
- }
- $list = list_sort_by($user,'score','desc');
- $data = [];
- $host = config("app.app_host");
- foreach ($list as $k=>$v){
- if(isset($k) && $k==0){
- $top = '<img src="'.$host.'/img/org-top1.png" width="30" style="margin-top:5px" >';
- }elseif (isset($k) && $k==1){
- $top = '<img src="'.$host.'/img/org-top2.png" width="30" style="margin-top:5px" >';
- }elseif (isset($k) && $k==2){
- $top = '<img src="'.$host.'/img/org-top3.png" width="30" style="margin-top:5px">';
- }else{
- $top = 'TOP'.($k+1);
- }
- $data[] = [$top,$v['name'],$v['dep'],$v['roles'],$v['task'],$v['score']];
- }
- HelpHander::success($data);
- }
- }
|