NoticeCommon.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class NoticeCommon 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. $title = input('title','','trim');
  17. if($title){
  18. $map[] = ['title','like','%'.$title.'%'];
  19. }
  20. $cateId = input('cateId','');
  21. if($cateId){
  22. $map[] = ['cate_id','=',$cateId];
  23. }
  24. $map[] = ['del','=',0];
  25. $map[] = ['org_id','=',$this->orgId];
  26. $map= empty($map) ? true: $map;
  27. //数据查询
  28. $lists = db('notice_common')->where($map)->limit($start,$length)->order('id desc')->select();
  29. foreach ($lists as $k=>$v){
  30. $lists[$k]['notice_cate'] = db('notice_cate')->where('id',$v['cate_id'])->where('del',0)->value('name');
  31. $lists[$k]['create_user'] = db('user')->where('id',$v['create_user_id'])->value('real_name');
  32. }
  33. //数据返回
  34. $totalCount = db('notice_common')->where($map)->count();
  35. $totalPage = ceil($totalCount/$length);
  36. $result['page'] = $page;
  37. $result['total'] = $totalPage;
  38. $result['records'] = $totalCount;
  39. $result['rows'] = $lists;
  40. return json($result);
  41. }else{
  42. $cate = model('NoticeCate')->lists();
  43. $this->assign('cate',$cate);
  44. return $this->fetch();
  45. }
  46. }
  47. /**
  48. * 新增/编辑
  49. */
  50. public function add($id=0){
  51. if(request()->isPost()){
  52. $res = model('NoticeCommon')->updates();
  53. if($res){
  54. $this->success('操作成功',url('index'));
  55. }else{
  56. $this->error(model('NoticeCommon')->getError());
  57. }
  58. }else{
  59. $title = '添加';
  60. if($id){
  61. $title = '编辑';
  62. $info = db('notice_common')->where('id',$id)->find();
  63. $this->assign('info',$info);
  64. }
  65. $userAll = Db::name('user')
  66. ->alias('u')
  67. ->field('u.id,u.real_name as title')
  68. ->join('user_org uo','u.id=uo.user_id')
  69. ->where('uo.org_id',$this->orgId)
  70. ->where('enable',1)
  71. ->where('type',0)
  72. ->where('del',0)
  73. ->select();
  74. $cate = model('NoticeCate')->lists();
  75. $rolesAll = model('Roles')->getRolesAll(cur_org_id());
  76. $this->assign('userAll',$userAll);
  77. $this->assign('rolesAll',$rolesAll);
  78. $this->assign('cate',$cate);
  79. $this->assign('title',$title);
  80. return $this->fetch();
  81. }
  82. }
  83. /**
  84. * 删除记录
  85. * @param int $id
  86. */
  87. public function del($id=0){
  88. if(!$id){
  89. $this->error('参数错误');
  90. }
  91. $res = model('NoticeCommon')->del($id);
  92. if($res){
  93. $this->success('删除成功');
  94. }else{
  95. $this->error('删除失败');
  96. }
  97. }
  98. public function details($id) {
  99. $info = db('notice_common')->where('id',$id)->find();
  100. $info['cate_name'] = db('notice_cate')->where('id',$info['cate_id'])->value('name');
  101. $info['create_user'] = db('user')->where('id',$info['create_user_id'])->value('real_name');
  102. $this->assign('info',$info);
  103. return $this->fetch();
  104. }
  105. //通知详情
  106. public function noticeDetail($id=0){
  107. $info = db('notice')->where('id',$id)->find();
  108. $this->assign('info',$info);
  109. return $this->fetch();
  110. }
  111. }