AttendanceAddr.php 3.4 KB

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