AttendanceGroupClass.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class AttendanceGroupClass extends Model
  8. {
  9. public function getClassByDay($userId){
  10. $group = Db::name('attendance_group_user')
  11. ->alias('agu')
  12. ->join('attendance_group ag','ag.id = agu.group_id')
  13. ->where('agu.user_id',$userId)
  14. ->where('ag.del',0)
  15. ->field('ag.*')
  16. ->find();
  17. if(!$group){
  18. return false;
  19. }
  20. $day = date('Y-m-d');
  21. if($group['type'] == 1){ //固定班制
  22. $w = date('w');
  23. $content = json_decode($group['content'],true);
  24. $week = $content['week'];
  25. $classId = 0;
  26. foreach ($week as $k=>$v){
  27. if($w == $v['week']){
  28. $classId = empty($v['class_id'])?0:$v['class_id'];
  29. }
  30. }
  31. // 今日是否有必打卡特殊日
  32. $sign = $content['sign'];
  33. foreach ($sign as $k=>$v){
  34. if($day == $v['day']){
  35. $classId = empty($v['class_id'])?0:$v['class_id'];
  36. }
  37. }
  38. // 今日是否有不必打卡特殊日
  39. $unsign = $content['unsign'];
  40. foreach ($unsign as $k=>$v){
  41. if($day == $v['day']){
  42. $classId = 0;
  43. }
  44. }
  45. $class = [];
  46. if($classId > 0){
  47. $class = Db::name('attendance_class')->where('id',$classId)->where('del',0)->field('content,org_id,id as class_id')->find();
  48. if($class){
  49. $class['group_id'] = $group['id'];
  50. $class['group_name'] = $group['name'];
  51. $class['cate'] = $group['cate'];
  52. $class['addr'] = $group['addr'];
  53. }
  54. }
  55. }else{ // 排班制
  56. $class = Db::name('attendance_group')
  57. ->alias('ag')
  58. ->join('attendance_group_class agc','ag.id = agc.group_id')
  59. ->join('attendance_class ac','ac.id = agc.class_id')
  60. ->where('ag.id',$group['id'])
  61. ->where('agc.day',$day)
  62. ->field('ac.content,agc.group_id,agc.class_id,ag.org_id,ag.name as group_name,ag.cate,ag.addr')
  63. ->find(); // 今日排班
  64. }
  65. return $class;
  66. }
  67. }