ScreenTemplate.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\admin\controller;
  3. class ScreenTemplate 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_template')->where($map)->limit($start,$length)->order('id desc')->select();
  19. //数据返回
  20. $totalCount = db('screen_template')->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('ScreenTemplate')->updates();
  37. if($res){
  38. $this->success('操作成功',url('index'));
  39. }else{
  40. $this->error(model('ScreenTemplate')->getError());
  41. }
  42. }else{
  43. $meta_title = '新增模板';
  44. if($id){
  45. $info = db('screen_template')->where('id',$id)->find();
  46. $meta_title = '编辑模板';
  47. $this->assign('info',$info);
  48. }
  49. $moduleList = db('screen_module')->where('del',0)->select();
  50. $this->assign('moduleList',$moduleList);
  51. $this->assign('meta_title',$meta_title);
  52. return $this->fetch();
  53. }
  54. }
  55. /**
  56. * 删除记录
  57. * @param int $id
  58. */
  59. public function del($id=0){
  60. if(!$id){
  61. $this->error('参数错误');
  62. }
  63. $res = db('screen_template')->where('id',$id)->setField('del',1);
  64. if($res){
  65. $this->success('删除成功');
  66. }else{
  67. $this->error('删除失败');
  68. }
  69. }
  70. }