post(); $result = validate('AttendanceLeave')->check($data,[],''); if(true !== $result){ $this->error = validate('AttendanceLeave')->getError(); return false; } if($data['start_time'] > $data['end_time']){ $this->error = '开始时间不能小于结束时间'; return false; } //当天上午 if($data['start_time'] == $data['start_time'] && $data['apm1']== $data['apm2'] && $data['apm1']==1){ $start_time = $data['start_time'].' 00:00:00'; $end_time = $data['end_time'].' 11:59:59'; } //当天下午 if($data['start_time'] == $data['start_time'] && $data['apm1']== $data['apm2'] && $data['apm1']==2){ $start_time = $data['start_time'].' 12:00:00'; $end_time = $data['end_time'].' 23:59:59'; } //当天 if($data['start_time'] == $data['start_time']&& $data['apm1'] != $data['apm2']){ $start_time = $data['start_time'].' 00:00:00'; $end_time = $data['end_time'].' 23:59:59'; } //跨天上午 if($data['start_time'] < $data['end_time'] && $data['apm1'] == $data['apm2'] && $data['apm1']==1){ $start_time = $data['start_time'].' 00:00:00'; $end_time = $data['end_time'].' 11:59:59'; } //跨天下午 if($data['start_time'] < $data['end_time'] && $data['apm1'] == $data['apm2'] && $data['apm1']==2){ $start_time = $data['start_time'].' 12:00:00'; $end_time = $data['end_time'].' 23:59:59'; } //跨天整天 if($data['start_time'] < $data['end_time'] && $data['apm1'] != $data['apm2']){ $start_time = $data['start_time'].' 00:00:00'; $end_time = $data['end_time'].' 23:59:59'; } $startdate = strtotime($start_time); $enddate = strtotime($end_time); $curDays = round(($enddate-$startdate)/3600/24,1) ; $curData = [ 'user_id'=>$data['user_id'], 'org_id'=>cur_org_id(), 'start_time'=>$start_time, 'end_time'=>$end_time, 'leave_type'=>$data['leave_type'], 'days'=>$data['days'], 'cur_days'=>$curDays, 'status'=>0, ]; $id = $data['id']; unset($data['id']); if($id > 0){ $curData['update_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($curData,['id'=>$id]); }else{ $curData['create_time'] = date('Y-m-d H:i:s'); $ret = $this->allowField(true)->save($curData); } if(!$ret){ $this->error = '操作失败'; return false; } return true; } }