0
0

Service.php 2.5 KB

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