ServiceTime.php 3.7 KB

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