Screen.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Screen extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','id','trim'); //排序列
  14. $sort = input('sort','desc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $map[] = ['del','=',0];
  17. $map[] = ['org_id','=',$this->orgId];
  18. $map= empty($map) ? true: $map;
  19. //数据查询
  20. $lists = db('screen')->where($map)->limit($start,$length)->order('id desc')->select();
  21. foreach ($lists as $k=>$v){
  22. $lists[$k]['temp_title'] = \db('screen_template')->where('id',$v['tid'])->value('title');
  23. $lists[$k]['surl'] = config('app.screen_url').'/home?token='.think_encrypt($v['id'].'|'.$this->orgId);
  24. }
  25. //数据返回
  26. $totalCount = db('screen')->where($map)->count();
  27. $totalPage = ceil($totalCount/$length);
  28. $result['page'] = $page;
  29. $result['total'] = $totalPage;
  30. $result['records'] = $totalCount;
  31. $result['rows'] = $lists;
  32. return json($result);
  33. }else{
  34. $map1[] = ['del','=',0];
  35. $map1[] = ['org_id','=',$this->orgId];
  36. $map2[] = ['del','=',0];
  37. $map2[] = ['org_id','=',0];
  38. //数据查询
  39. $lists = db('screen')->whereOr([$map1,$map2])->order('id desc')->select();
  40. $nlist = [];
  41. foreach ($lists as $k=>$v){
  42. if($v['type'] == 2){
  43. $lists[$k]['surl'] = $v['url'];
  44. }else if($v['type'] == 1){
  45. if($v['org_id'] == 0){
  46. $lists[$k]['surl'] = config('app.screen_url').'/home?token='.think_encrypt($v['id'].'|'.$this->orgId);
  47. }else{
  48. $lists[$k]['surl'] = config('app.screen_url').'/home?token='.think_encrypt($v['id'].'|'.$v['org_id']);
  49. }
  50. }else if($v['type'] == 3){ // 3D大屏
  51. $lists[$k]['surl'] = $v['url'].'?token='.think_encrypt($v['id'].'|'.$v['org_id']);
  52. }
  53. if(!$v['auth'] || ($v['auth'] && model('Roles')->checkUserAuths($this->userId,$v['auth']))){
  54. $nlist[] = $lists[$k];
  55. }
  56. }
  57. $this->assign('lists',$nlist);
  58. return $this->fetch();
  59. }
  60. }
  61. /**
  62. * 新增/编辑
  63. */
  64. public function add($id=0){
  65. if(request()->isPost()){
  66. $res = model('Screen')->updates();
  67. if($res){
  68. $this->success('操作成功',url('index'));
  69. }else{
  70. $this->error(model('Screen')->getError());
  71. }
  72. }else{
  73. $meta_title = '新增大屏';
  74. $nums = 0;
  75. if($id){
  76. $info = db('screen')->where('id',$id)->find();
  77. if($info){
  78. $nums = \db('screen_template')->where('id',$info['tid'])->value('nums');
  79. $info['content2'] = $info['content']?json_decode($info['content'],true):[];
  80. }
  81. $meta_title = '编辑大屏';
  82. $this->assign('info',$info);
  83. }
  84. $this->assign('nums',$nums);
  85. $tempList = db('screen_template')->where('del',0)->select();
  86. $this->assign('tempList',$tempList);
  87. $moduleList = db('screen_module')->where('del',0)->select();
  88. $this->assign('moduleList',$moduleList);
  89. $this->assign('meta_title',$meta_title);
  90. return $this->fetch();
  91. }
  92. }
  93. /**
  94. * 删除记录
  95. * @param int $id
  96. */
  97. public function del($id=0){
  98. if(!$id){
  99. $this->error('参数错误');
  100. }
  101. $res = db('screen')->where('id',$id)->setField('del',1);
  102. if($res){
  103. $this->success('删除成功');
  104. }else{
  105. $this->error('删除失败');
  106. }
  107. }
  108. }