0
0

AppMgr.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller;
  3. class AppMgr 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('sord','desc','trim'); //排序方式
  14. $order = $sortRow.' '.$sort;
  15. $map[] = ['del','=',0];
  16. $map= empty($map) ? true: $map;
  17. //数据查询
  18. $lists = db('app_mgr')->where($map)->limit($start,$length)->order($order)->select();
  19. //数据返回
  20. $totalCount = db('app_mgr')->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('AppMgr')->updates();
  37. if($res){
  38. $this->success('操作成功',url('index'));
  39. }else{
  40. $this->error(model('AppMgr')->getError());
  41. }
  42. }else{
  43. if($id){
  44. $info = db('AppMgr')->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('AppMgr')->where('id',$id)->setField('del',1);
  59. if($res){
  60. $this->success('删除成功');
  61. }else{
  62. $this->error('删除失败');
  63. }
  64. }
  65. /**
  66. * 改变字段值
  67. * @param int $fv
  68. * @param string $fn
  69. * @param int $fv
  70. */
  71. public function changeField($id=0,$fn='',$fv=0){
  72. if(!$fn||!$id){
  73. $this->error('参数错误');
  74. }
  75. $res = db('AppMgr')->where('id',$id)->setField($fn,$fv);
  76. if($res){
  77. $this->success('操作成功');
  78. }else{
  79. $this->error('操作失败');
  80. }
  81. }
  82. }