ScreenModule.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\admin\controller;
  3. class ScreenModule 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. $map[] = ['del','=',0];
  16. $map= empty($map) ? true: $map;
  17. //数据查询
  18. $lists = db('screen_module')->where($map)->limit($start,$length)->order('id desc')->select();
  19. //数据返回
  20. $totalCount = db('screen_module')->where($map)->count();
  21. $totalPage = ceil($totalCount/$length);
  22. $result['page'] = $page;
  23. $result['total'] = $totalPage;
  24. $result['records'] = $totalCount;
  25. $result['rows'] = $lists;
  26. return json($result);
  27. }else{
  28. return $this->fetch();
  29. }
  30. }
  31. /**
  32. * 新增/编辑
  33. */
  34. public function add($id=0){
  35. if(request()->isPost()){
  36. $res = model('ScreenModule')->updates();
  37. if($res){
  38. $this->success('操作成功',url('index'));
  39. }else{
  40. $this->error(model('ScreenModule')->getError());
  41. }
  42. }else{
  43. if($id){
  44. $info = db('screen_module')->where('id',$id)->find();
  45. $this->assign('info',$info);
  46. }
  47. return $this->fetch();
  48. }
  49. }
  50. /**
  51. * 删除记录
  52. * @param int $id
  53. */
  54. public function del($id=0){
  55. if(!$id){
  56. $this->error('参数错误');
  57. }
  58. $res = db('screen_module')->where('id',$id)->setField('del',1);
  59. if($res){
  60. $this->success('删除成功');
  61. }else{
  62. $this->error('删除失败');
  63. }
  64. }
  65. }