AttendanceGroup.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class AttendanceGroup extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','id','trim'); //排序列
  14. $sort = input('sord','desc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $title = input('title','','trim');
  17. if($title){
  18. $map[] = ['title','like','%'.$title.'%'];
  19. }
  20. $map[] = ['del','=',0];
  21. $map[] = ['org_id','=',cur_org_id()];
  22. $map= empty($map) ? true: $map;
  23. //数据查询
  24. $lists = db('attendance_group')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
  25. //数据返回
  26. $totalCount = db('attendance_group')->where($map)->count();
  27. $totalPage = ceil($totalCount/$length);
  28. $result['page'] = $page;
  29. $result['total'] = $totalPage;
  30. $result['records'] = $totalCount;
  31. $result['rows'] = $lists;
  32. return json($result);
  33. }else{
  34. return $this->fetch();
  35. }
  36. }
  37. /**
  38. * 新增/编辑
  39. */
  40. public function add($id=0){
  41. if(request()->isPost()){
  42. $res = model('AttendanceGroup')->updates();
  43. if($res){
  44. $this->success('操作成功',url('index'));
  45. }else{
  46. $this->error(model('AttendanceGroup')->getError());
  47. }
  48. }else{
  49. $title = '新增';
  50. if($id){
  51. $title = '编辑';
  52. }
  53. $info = model('AttendanceGroup')->info($id);
  54. $this->assign('info',$info);
  55. $users = model('WorkTypeMode')->getWorkerUserApp($this->orgId,-1);
  56. $classes = db('attendance_class')->where('org_id',$this->orgId)->where('del',0)->select();
  57. $addrs= db('attendance_addr')->where('org_id',$this->orgId)->where('del',0)->where('enable',1)->select();
  58. $this->assign('users',$users);
  59. $this->assign('classes',$classes);
  60. $this->assign('addrs',$addrs);
  61. $this->assign('title',$title);
  62. return $this->fetch();
  63. }
  64. }
  65. /**
  66. * 删除记录
  67. * @param int $id
  68. */
  69. public function del($id=0){
  70. if(!$id){
  71. $this->error('参数错误');
  72. }
  73. $res = db('attendance_group')->where('id',$id)->setField('del',1);
  74. if($res){
  75. $this->success('删除成功');
  76. }else{
  77. $this->error('删除失败');
  78. }
  79. }
  80. /*
  81. * 排班*/
  82. public function scheduling(){
  83. $id = input('id',0);
  84. $this->assign('id',$id);
  85. return $this->fetch();
  86. }
  87. public function pbjson(){
  88. $id = input('id');
  89. $start = input('start');
  90. $end = input('end');
  91. $data = array();
  92. if(!$start||!$end||$start>$end){
  93. header('Content-Type:application/json; charset=utf-8');
  94. exit(json_encode($data));
  95. }
  96. $start = date('Y-m-d',strtotime($start));
  97. $end = date('Y-m-d',strtotime($end));
  98. $list = db('attendance_group_class')
  99. ->alias('gc')
  100. ->join('attendance_class c','c.id = gc.class_id')
  101. ->where('gc.day','>=',$start)
  102. ->where('gc.day','<=',$end)
  103. ->where('gc.group_id',$id)
  104. ->field('c.name,gc.*')
  105. ->select();
  106. foreach ($list as $k=>$v){
  107. $arr = array(
  108. 'taskid' => $v['id'],
  109. 'title' => $v['name'],
  110. 'status' => 1,
  111. 'start' => $v['day'].' 00:00:00',
  112. 'end' => $v['day'].' 23:59:59'
  113. );
  114. $arr['color'] = '#478fca';
  115. $data[] = $arr;
  116. }
  117. header('Content-Type:application/json; charset=utf-8');
  118. exit(json_encode($data));
  119. }
  120. public function addGroupClass(){
  121. $gid = input('id');
  122. if(request()->isPost()){
  123. $res = model('AttendanceGroup')->groupUpdates();
  124. if($res){
  125. $this->success('操作成功',url('addGroupClass'));
  126. }else{
  127. $this->error(model('AttendanceGroup')->getError());
  128. }
  129. }else{
  130. $start = input('start');
  131. $start = date('Y-m-d',strtotime($start));
  132. $info = model('AttendanceGroup')->showOne($gid);
  133. $content = json_decode($info['content'],true);
  134. $circle = $content['circle'];
  135. $classids = $info['class_id']?explode(',',$info['class_id']):[];
  136. $class = [];
  137. if($classids){
  138. $class = db('attendance_class')->whereIn('id',$classids)->select();
  139. }
  140. $this->assign('gid',$gid);
  141. $this->assign('classList',$class);
  142. $this->assign('weekList',$circle);
  143. $this->assign('day',$start);
  144. return $this->fetch();
  145. }
  146. }
  147. }