AppIcon.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class AppIcon extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'name' => input('name','','trim'),
  12. 'icon' => input('icon','','trim'),
  13. 'content' => input('content','','trim'),
  14. 'url' => input('url','','trim'),
  15. 'enable' => input('enable/d',0),
  16. 'mode' => input('mode/d',0),
  17. 'sort' => input('sort/d',0),
  18. 'cate_id' => input('cateId/d',0),
  19. ];
  20. $result = validate('AppIcon')->check($data,[],'');
  21. if(true !== $result){
  22. HelpHander::error(validate('AppIcon')->getError());
  23. }
  24. $id = $data['id'];
  25. unset($data['id']);
  26. if($id > 0){
  27. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  28. }else{
  29. $ret = $this->allowField(true)->save($data);
  30. }
  31. if(!$ret){
  32. HelpHander::error('操作失败');
  33. }
  34. return true;
  35. }
  36. public function info($id){
  37. $info = $this->where('id',$id)->where('del',0)->find();
  38. if(!$info){
  39. HelpHander::error('数据不存在');
  40. }
  41. return $info->toArray();
  42. }
  43. public function lists($page,$size){
  44. $lists = $this
  45. ->where('del',0)
  46. ->page($page,$size)
  47. ->order('id asc')
  48. ->select();
  49. $total = $this->where('del',0)->count();
  50. $data = [
  51. 'total' => $total,
  52. 'list' => $lists?$lists->toArray():[]
  53. ];
  54. return $data;
  55. }
  56. public function del($id){
  57. $ret = $this->where('id',$id)->setField('del',1);
  58. if(!$ret){
  59. HelpHander::error('删除失败');
  60. }
  61. return true;
  62. }
  63. public function changeStatus($id,$enable){
  64. $ret = $this->where('id',$id)->setField('enable',$enable);
  65. if(!$ret){
  66. HelpHander::error('操作失败');
  67. }
  68. return true;
  69. }
  70. // APP常用功能icon列表
  71. public function queryUserAllIcon($page,$size,$userId,$orgId){
  72. // 获取用户权限
  73. $roles = Db::name('user_roles')
  74. ->alias('ur')
  75. ->join('roles r','r.id = ur.roles_id')
  76. ->where('ur.user_id',$userId)
  77. ->where('r.org_id',$orgId)
  78. ->where('r.del',0)
  79. ->where('r.enable',1)
  80. ->column('r.appicons');
  81. if(!$roles){
  82. return [];
  83. }
  84. $rolesapps = [];
  85. foreach ($roles as $v){
  86. if($v){
  87. $rolesapps = array_merge($rolesapps,explode(',',$v));
  88. }
  89. }
  90. if(!$rolesapps){
  91. return [];
  92. }
  93. $rolesapps = array_unique($rolesapps);
  94. $appicons = model('UserAppIcon')->getUserIcons($userId,$orgId);
  95. $lists = $this
  96. ->where('del',0)
  97. ->where('enable',1)
  98. ->where('id','in',$rolesapps)
  99. ->page($page,$size)
  100. ->order('id asc')
  101. ->field('id,name,icon,url')
  102. ->select();
  103. $lists = $lists?$lists->toArray():[];
  104. foreach ($lists as $k=>$v){
  105. $lists[$k]['isMine'] = in_array($v['id'],$appicons)?0:1;
  106. }
  107. return $lists;
  108. }
  109. }