0
0

AttendanceLeave.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\admin\controller;
  3. class AttendanceLeave 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[] = ['u.real_name','like','%'.$title.'%'];
  18. }
  19. $status = input('status',0);
  20. if($status){
  21. $map[] = ['al.status','=',$status];
  22. }
  23. $map[] = ['al.org_id','=',cur_org_id()];
  24. $map= empty($map) ? true: $map;
  25. //数据查询
  26. $lists = db('attendance_leave')
  27. ->alias('al')
  28. ->field('u.real_name,al.*')
  29. ->join('user u','u.id=al.user_id')
  30. ->limit($start,$length)
  31. ->where($map)
  32. ->order('al.id desc')
  33. ->select();
  34. foreach ($lists as $k=>$v){
  35. $startday = date('Y-m-d',strtotime($v['start_time']));
  36. if($startday.' 12:00:00' > $v['start_time']){
  37. $lists[$k]['start_time'] = $startday.' 上午';
  38. } else {
  39. $lists[$k]['start_time'] = $startday.' 下午';
  40. }
  41. $endday = date('Y-m-d',strtotime($v['end_time']));
  42. if($endday.' 12:00:00' > $v['end_time']){
  43. $lists[$k]['end_time'] = $endday.' 上午';
  44. } else {
  45. $lists[$k]['end_time'] = $endday.' 下午';
  46. }
  47. }
  48. //数据返回
  49. $totalCount = db('attendance_leave')
  50. ->alias('al')
  51. ->join('user u','u.id=al.user_id')
  52. ->where($map)
  53. ->count();
  54. $totalPage = ceil($totalCount/$length);
  55. $result['page'] = $page;
  56. $result['total'] = $totalPage;
  57. $result['records'] = $totalCount;
  58. $result['rows'] = $lists;
  59. return json($result);
  60. }else{
  61. return $this->fetch();
  62. }
  63. }
  64. /**
  65. * 新增/编辑
  66. */
  67. public function add($id=0){
  68. if(request()->isPost()){
  69. $res = model('AttendanceLeave')->updates();
  70. if($res){
  71. $this->success('操作成功',url('index'));
  72. }else{
  73. $this->error(model('AttendanceLeave')->getError());
  74. }
  75. }else{
  76. $title = '新增';
  77. if($id){
  78. $title = '编辑';
  79. $info = db('attendance_leave')->where('id',$id)->find();
  80. //上下午
  81. $start_time = date('H:i:s',strtotime($info['start_time']));
  82. if($start_time < '12:00:00'){
  83. $info['apm1'] = 1;
  84. }else{
  85. $info['apm1'] = 2;
  86. }
  87. //上下午
  88. $end_time = date('H:i:s',strtotime($info['end_time']));
  89. if($end_time < "12:00:00"){
  90. $info['apm2'] = 1;
  91. }else{
  92. $info['apm2'] = 2;
  93. }
  94. $info['start_time'] = date('Y-m-d' ,strtotime($info['start_time']));
  95. $info['end_time'] = date('Y-m-d' ,strtotime($info['end_time']));
  96. $this->assign('info',$info);
  97. }
  98. $userList = model('WorkTypeMode')->getWorkerUserApp($this->orgId);
  99. $this->assign('userList',$userList);
  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_leave')->where('id',$id)->delete();
  113. if($res){
  114. $this->success('删除成功');
  115. }else{
  116. $this->error('删除失败');
  117. }
  118. }
  119. public function check(){
  120. $id = input('id',0);
  121. if($id < 1){
  122. $this->error('参数错误');
  123. }
  124. if(request()->isPost()){
  125. $data = [
  126. 'status'=>input('status'),
  127. ];
  128. $res = db('attendance_leave')->where('id',$id)->update($data);
  129. if($res){
  130. $this->success('操作成功',url('index'));
  131. }else{
  132. $this->error('操作失败');
  133. }
  134. }
  135. $this->assign('id',$id);
  136. return $this->fetch();
  137. }
  138. }