0
0

AttendanceClass.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\admin\controller;
  3. class AttendanceClass 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_class')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
  24. foreach ($lists as $k=>$v){
  25. $content = json_decode($v['content'],true);
  26. $dates = $content['dates'];
  27. $times = [];
  28. foreach ($dates as $kk=>$vv){
  29. $st = '';
  30. if($vv['snext'] == 1){
  31. $st .= '次日'.$vv['stime'];
  32. }else{
  33. $st .= $vv['stime'];
  34. }
  35. $st .= '-';
  36. if($vv['enext'] == 1){
  37. $st .= '次日'.$vv['etime'];
  38. }else{
  39. $st .= $vv['etime'];
  40. }
  41. $times[] = $st;
  42. }
  43. $lists[$k]['timeAll'] = implode(',',$times);
  44. }
  45. //数据返回
  46. $totalCount = db('attendance_class')->where($map)->count();
  47. $totalPage = ceil($totalCount/$length);
  48. $result['page'] = $page;
  49. $result['total'] = $totalPage;
  50. $result['records'] = $totalCount;
  51. $result['rows'] = $lists;
  52. return json($result);
  53. }else{
  54. return $this->fetch();
  55. }
  56. }
  57. /**
  58. * 新增/编辑
  59. */
  60. public function add($id=0){
  61. if(request()->isPost()){
  62. $res = model('AttendanceClass')->updates();
  63. if($res){
  64. $this->success('操作成功',url('index'));
  65. }else{
  66. $this->error(model('AttendanceClass')->getError());
  67. }
  68. }else{
  69. $title = '新增';
  70. if($id){
  71. $title = '编辑';
  72. $info = db('attendance_class')->where('id',$id)->find();
  73. $content = json_decode($info['content'],true);
  74. $info['type'] = $content['type'];
  75. $dates = $content['dates'];
  76. // $timeOne = $timeTwo = $timeThree = '';
  77. // $timeOne = $dates[0]['stime'].','.$dates[0]['etime'];
  78. // if(!empty($dates[1])){
  79. // $timeTwo = $dates[1]['stime'].','.$dates[1]['etime'];
  80. // }
  81. // if(!empty($dates[2])){
  82. // $timeThree = $dates[2]['stime'].','.$dates[2]['etime'];
  83. // }
  84. //
  85. // $info['time1'] = $timeOne;
  86. // $info['time2'] = $timeTwo;
  87. // $info['time3'] = $timeThree;
  88. $info['start1'] = $dates[0]['stime'];
  89. $info['end1'] = $dates[0]['etime'];
  90. if(!empty($dates[1])){
  91. $info['start2'] = $dates[1]['stime'];
  92. $info['end2'] = $dates[1]['etime'];
  93. }
  94. if(!empty($dates[2])){
  95. $info['start3'] = $dates[2]['stime'];
  96. $info['end3'] = $dates[2]['etime'];
  97. }
  98. $this->assign('info',$info);
  99. }
  100. $this->assign('title',$title);
  101. return $this->fetch();
  102. }
  103. }
  104. /**
  105. * 删除记录
  106. * @param int $id
  107. */
  108. public function del($id=0){
  109. if(!$id){
  110. $this->error('参数错误');
  111. }
  112. $res = db('attendance_class')->where('id',$id)->setField('del',1);
  113. if($res){
  114. $this->success('删除成功');
  115. }else{
  116. $this->error('删除失败');
  117. }
  118. }
  119. /**
  120. * 改变字段值
  121. * @param int $fv
  122. * @param string $fn
  123. * @param int $fv
  124. */
  125. public function changeField($id=0,$fn='',$fv=0){
  126. if(!$fn||!$id){
  127. $this->error('参数错误');
  128. }
  129. $res = db('attendance_class')->where('id',$id)->setField($fn,$fv);
  130. if($res){
  131. $this->success('操作成功');
  132. }else{
  133. $this->error('操作失败');
  134. }
  135. }
  136. }