NoticeCommon.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\controller;
  3. class NoticeCommon extends Auth
  4. {
  5. public function index(){
  6. if(request()->isAjax()){
  7. //分页参数
  8. $length = input('rows',10,'intval'); //每页条数
  9. $page = input('page',1,'intval'); //第几页
  10. $start = ($page - 1) * $length; //分页开始位置
  11. //排序
  12. $sortRow = input('sidx','id','trim'); //排序列
  13. $sort = input('sort','desc','trim'); //排序方式
  14. $order = $sortRow.' '.$sort;
  15. $title = input('title','','trim');
  16. if($title){
  17. $map[] = ['title','like','%'.$title.'%'];
  18. }
  19. $cateId = input('cateId','');
  20. if($cateId){
  21. $map[] = ['cate_id','=',$cateId];
  22. }
  23. $map[] = ['del','=',0];
  24. $map[] = ['org_id','=',$this->orgId];
  25. $map= empty($map) ? true: $map;
  26. //数据查询
  27. $lists = db('notice_common')->where($map)->limit($start,$length)->order('id desc')->select();
  28. foreach ($lists as $k=>$v){
  29. $lists[$k]['notice_cate'] = db('notice_cate')->where('id',$v['cate_id'])->where('del',0)->value('name');
  30. $lists[$k]['create_user'] = db('user')->where('id',$v['create_user_id'])->value('real_name');
  31. }
  32. //数据返回
  33. $totalCount = db('notice_common')->where($map)->count();
  34. $totalPage = ceil($totalCount/$length);
  35. $result['page'] = $page;
  36. $result['total'] = $totalPage;
  37. $result['records'] = $totalCount;
  38. $result['rows'] = $lists;
  39. return json($result);
  40. }else{
  41. $cate = model('NoticeCate')->lists();
  42. $this->assign('cate',$cate);
  43. return $this->fetch();
  44. }
  45. }
  46. /**
  47. * 新增/编辑
  48. */
  49. public function add($id=0){
  50. if(request()->isPost()){
  51. $res = model('NoticeCommon')->updates();
  52. if($res){
  53. $this->success('操作成功',url('index'));
  54. }else{
  55. $this->error(model('NoticeCommon')->getError());
  56. }
  57. }else{
  58. $title = '添加';
  59. if($id){
  60. $title = '编辑';
  61. $info = db('notice_common')->where('id',$id)->find();
  62. $this->assign('info',$info);
  63. }
  64. $userAll = model('User')->gerUserAll(cur_org_id());
  65. $cate = model('NoticeCate')->lists();
  66. $rolesAll = model('Roles')->getRolesAll(cur_org_id());
  67. $this->assign('userAll',$userAll);
  68. $this->assign('rolesAll',$rolesAll);
  69. $this->assign('cate',$cate);
  70. $this->assign('title',$title);
  71. return $this->fetch();
  72. }
  73. }
  74. /**
  75. * 删除记录
  76. * @param int $id
  77. */
  78. public function del($id=0){
  79. if(!$id){
  80. $this->error('参数错误');
  81. }
  82. $res = model('NoticeCommon')->del($id);
  83. if($res){
  84. $this->success('删除成功');
  85. }else{
  86. $this->error('删除失败');
  87. }
  88. }
  89. public function details($id) {
  90. $info = db('notice_common')->where('id',$id)->find();
  91. $info['cate_name'] = db('notice_cate')->where('id',$info['cate_id'])->value('name');
  92. $info['create_user'] = db('user')->where('id',$info['create_user_id'])->value('real_name');
  93. $this->assign('info',$info);
  94. return $this->fetch();
  95. }
  96. }