123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class AttendanceGroupClass extends Model
- {
- public function getClassByDay($userId){
- $group = Db::name('attendance_group_user')
- ->alias('agu')
- ->join('attendance_group ag','ag.id = agu.group_id')
- ->where('agu.user_id',$userId)
- ->where('ag.del',0)
- ->field('ag.*')
- ->find();
- if(!$group){
- return false;
- }
- $day = date('Y-m-d');
- if($group['type'] == 1){ //固定班制
- $w = date('w');
- $content = json_decode($group['content'],true);
- $week = $content['week'];
- $classId = 0;
- foreach ($week as $k=>$v){
- if($w == $v['week']){
- $classId = empty($v['class_id'])?0:$v['class_id'];
- }
- }
- // 今日是否有必打卡特殊日
- $sign = $content['sign'];
- foreach ($sign as $k=>$v){
- if($day == $v['day']){
- $classId = empty($v['class_id'])?0:$v['class_id'];
- }
- }
- // 今日是否有不必打卡特殊日
- $unsign = $content['unsign'];
- foreach ($unsign as $k=>$v){
- if($day == $v['day']){
- $classId = 0;
- }
- }
- $class = [];
- if($classId > 0){
- $class = Db::name('attendance_class')->where('id',$classId)->where('del',0)->field('content,org_id,id as class_id')->find();
- if($class){
- $class['group_id'] = $group['id'];
- $class['group_name'] = $group['name'];
- $class['cate'] = $group['cate'];
- $class['addr'] = $group['addr'];
- }
- }
- }else{ // 排班制
- $class = Db::name('attendance_group')
- ->alias('ag')
- ->join('attendance_group_class agc','ag.id = agc.group_id')
- ->join('attendance_class ac','ac.id = agc.class_id')
- ->where('ag.id',$group['id'])
- ->where('agc.day',$day)
- ->field('ac.content,agc.group_id,agc.class_id,ag.org_id,ag.name as group_name,ag.cate,ag.addr')
- ->find(); // 今日排班
- }
- return $class;
- }
- }
|