WxNotice.php 3.2 KB

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