123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class AppIcon extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'name' => input('name','','trim'),
- 'icon' => input('icon','','trim'),
- 'content' => input('content','','trim'),
- 'url' => input('url','','trim'),
- 'enable' => input('enable/d',0),
- 'mode' => input('mode/d',0),
- 'sort' => input('sort/d',0),
- 'cate_id' => input('cateId/d',0),
- ];
- $result = validate('AppIcon')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('AppIcon')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size){
- $lists = $this
- ->where('del',0)
- ->page($page,$size)
- ->order('id asc')
- ->select();
- $total = $this->where('del',0)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function changeStatus($id,$enable){
- $ret = $this->where('id',$id)->setField('enable',$enable);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- // APP常用功能icon列表
- public function queryUserAllIcon($page,$size,$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');
- if(!$roles){
- return [];
- }
- $rolesapps = [];
- foreach ($roles as $v){
- if($v){
- $rolesapps = array_merge($rolesapps,explode(',',$v));
- }
- }
- if(!$rolesapps){
- return [];
- }
- $rolesapps = array_unique($rolesapps);
- $appicons = model('UserAppIcon')->getUserIcons($userId,$orgId);
- $lists = $this
- ->where('del',0)
- ->where('enable',1)
- ->where('id','in',$rolesapps)
- ->page($page,$size)
- ->order('id asc')
- ->field('id,name,icon,url')
- ->select();
- $lists = $lists?$lists->toArray():[];
- foreach ($lists as $k=>$v){
- $lists[$k]['isMine'] = in_array($v['id'],$appicons)?0:1;
- }
- return $lists;
- }
- }
|