PhProtocol.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\controller;
  3. class PhProtocol 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[] = ['org_id','=',$this->orgId];
  16. $map= empty($map) ? true: $map;
  17. //数据查询
  18. $lists = db('ph_protocol')->limit($start,$length)->where($map)->order($order)->select();
  19. //数据返回
  20. $totalCount = db('ph_protocol')->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('PhProtocol')->updates();
  37. if($res){
  38. $this->success('操作成功',url('index'));
  39. }else{
  40. $this->error(model('PhProtocol')->getError());
  41. }
  42. }else{
  43. $title = '新增';
  44. if($id){
  45. $title = '编辑';
  46. $info = db('ph_protocol')->where('id',$id)->find();
  47. $this->assign('info',$info);
  48. }
  49. $this->assign('title',$title);
  50. return $this->fetch();
  51. }
  52. }
  53. }