123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class UserAppIcon extends Model
- {
- public function queryAppIconList($userId,$orgId){
- // 获取用户权限
- $roles = Db::name('user_roles')
- ->alias('ur')
- ->join('roles r','r.id = ur.roles_id')
- ->where('ur.user_id',$userId)
- ->where('r.org_id',$orgId)
- ->where('r.del',0)
- ->where('r.enable',1)
- ->column('r.appicons');
- $rolesapps = [];
- if($roles){
- foreach ($roles as $v){
- if($v){
- $rolesapps = array_merge($rolesapps,explode(',',$v));
- }
- }
- }
- $rolesapps = array_unique($rolesapps);
- $appicons = $this->getUserIcons($userId,$orgId);
- $appiconsjj = array_intersect($rolesapps,$appicons);
- $lists = [];
- if($appiconsjj){
- $lists = Db::name('app_icon')
- ->where('id','in',$appiconsjj)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- }
- $banner = Db::name('banner')
- ->where('type',1)
- ->where('enable',1)
- ->where('del',0)
- ->order('sort asc,id asc')
- ->select();
- //$notice = model('Notice')->queryUserLastNotice($userId,$orgId);
- $notice = Db::name('leader_ship')
- ->where('del',0)
- ->where('enable',1)
- ->field('content')
- ->order('id desc')
- ->find();
- $iconList = Db::name('app_icon_cate')
- ->where('del',0)
- ->where('enable',1)
- ->field('id,name')
- ->select();
- $iconList[] = [
- 'id' => 0,
- 'name' => '综合总览'
- ];
- foreach ($iconList as $k=>$v){
- $appicon = [];
- if($rolesapps){
- $appicon = Db::name('app_icon')
- ->where('cate_id',$v['id'])
- ->where('id','in',$rolesapps)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- }
- $iconList[$k]['appIconList'] = $appicon?$appicon:[];
- }
- $data = [
- 'commonIcon' => $lists?$lists:[],
- 'bannerList' => $banner?$banner:[],
- 'iconList' => $iconList,
- 'latestNotice' => $notice
- ];
- return $data;
- }
- public function queryAppIconListNew($userId,$orgId){
- // 获取用户权限
- $roles = Db::name('user_roles')
- ->alias('ur')
- ->join('roles r','r.id = ur.roles_id')
- ->where('ur.user_id',$userId)
- ->where('r.org_id',$orgId)
- ->where('r.del',0)
- ->where('r.enable',1)
- ->column('r.appicons');
- $rolesapps = [];
- if($roles){
- foreach ($roles as $v){
- if($v){
- $rolesapps = array_merge($rolesapps,explode(',',$v));
- }
- }
- }
- // $rolesapps = array_unique($rolesapps);
- // $appicons = $this->getUserIcons($userId,$orgId);
- $appiconsjj = array_unique($rolesapps);
- $lists = [];
- if($appiconsjj){
- $lists = Db::name('app_icon')
- ->where('id','in',$appiconsjj)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- }
- $banner = Db::name('banner')
- ->where('type',1)
- ->where('enable',1)
- ->where('del',0)
- ->order('sort asc,id asc')
- ->select();
- // $notice = model('Notice')->queryUserLastNotice($userId,$orgId);
- $notice = Db::name('leader_ship')
- ->where('del',0)
- ->where('enable',1)
- ->field('content')
- ->order('id desc')
- ->find();
- $approval = model('Approval')->queryApprovalCateList($userId,$orgId);
- $lists = $lists?$lists:[];
- $modes = [12,13];
- $fcarr = $zharr = [];
- $token = input('token');
- // dump($lists);
- foreach ($lists as $k=>$v){
- if($v['url']){
- if(strstr($v['url'],'?') === false){
- $v['url'] = $v['url'].'?token='.$token.'&userId='.$userId;
- }else{
- $v['url'] = $v['url'].'&token='.$token.'&userId='.$userId;
- }
- }
- if(in_array($v['mode'],$modes)){
- $fcarr[] = $v;
- }else{
- $zharr[] = $v;
- }
- }
- // halt($zharr);
- $cateIcon = [
- // [
- // 'name' => '房产管理',
- // 'child' => $fcarr
- // ],
- [
- 'name' => '综合总览',
- 'child' => $zharr
- ],
- ];
- $data = [
- 'commonIcon' => $lists?$lists:[],
- 'bannerList' => $banner?$banner:[],
- 'approval' => $approval,
- 'latestNotice' => $notice,
- 'cateIcon' => $cateIcon
- ];
- return $data;
- }
- public function getUserIcons($userId,$orgId){
- $appicons = Db::name('user_app_icon')->where('user_id',$userId)->where('org_id',$orgId)->value('appicons');
- return $appicons?explode(',',$appicons):[];
- }
- public function updateAppIcon($iconId,$operation,$userId,$orgId){
- $info = Db::name('user_app_icon')
- ->where('user_id',$userId)
- ->where('org_id',$orgId)
- ->find();
- if($operation == 0){ // 添加
- if($info){
- $appicons = $info['appicons']?explode(',',$info['appicons']):[];
- if(in_array($iconId,$appicons)){
- HelpHander::error('已添加过,无需重新添加');
- }
- $appicons[] = $iconId;
- $ret = Db::name('user_app_icon')->where('id',$info['id'])->setField('appicons',implode(',',$appicons));
- }else{
- $ret = Db::name('user_app_icon')->insert(['user_id'=>$userId,'appicons'=>$iconId,'org_id'=>$orgId]);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- }else{ // 删除
- if($info){
- $appicons = $info['appicons']?explode(',',$info['appicons']):[];
- if(!$appicons){
- HelpHander::error('已删除');
- }
- $appicons = array_diff($appicons,[$iconId]);
- $ret = Db::name('user_app_icon')->where('id',$info['id'])->setField('appicons',implode(',',$appicons));
- if(!$ret){
- HelpHander::error('操作失败');
- }
- }else{
- HelpHander::error('已删除');
- }
- }
- return true;
- }
- }
|