orgId; $map['status'] = 2; $map['advanced'] = 6; $lists = Db::name('apply') ->where($map) ->field('id,apply_sn,title,form_json,create_time') ->limit($start,$length) ->order('id desc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $formJson = json_decode($v['form_json'],true); $date = ''; $startTime = ''; $endTime = ''; $room = ''; $sn = ''; $dep = ''; $user = ''; $phone = ''; $nums = ''; foreach ($formJson as $kk=>$vv){ if($vv['componentName'] == 'ddmeetingroomfield'){ foreach ($vv['components'] as $kkk=>$vvv){ if($vvv['idx'] === 4){ $startTime = $vvv['values2'][0]; $endTime = $vvv['values2'][0]; } else if($vvv['idx'] === 6){ $room = $vvv['values']; } else if($vvv['idx'] === 0){ $sn = $vvv['values']; } else if($vvv['idx'] === 1){ $dep = $vvv['values']; } else if($vvv['idx'] === 2){ $phone = $vvv['values']; } else if($vvv['idx'] === 3){ $date = $vvv['values']; } else if($vvv['idx'] === 5){ $nums = $vvv['values']; } } break; } } $lists[$k]['date'] = $date; $lists[$k]['yytime'] = $date.' '.$startTime.'~'.$date.' '.$endTime; $lists[$k]['room'] = $room; $lists[$k]['sn'] = $sn; $lists[$k]['user'] = $user; $lists[$k]['phone'] = $phone; $lists[$k]['nums'] = $nums; $lists[$k]['dep'] = $dep; unset($lists[$k]['form_json']); } $total = Db::name('apply')->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; ajax_return_ok($data); } public function book(){ $applys = $this->getApplyList(6,1); $date = input('date','','trim'); if(!$date){ $date = date('Y-m-d'); } $days = $this->getDays($date); $prev = date('Y-m-d',strtotime($date) - 7*24*60*60); $next = date('Y-m-d',strtotime($date) + 7*24*60*60); $data1 = [ 'title' => '会议室', 'day1' => [['id' => 0,'title' => $days[0].' '.$this->getWeek($days[0])]], 'day2' => [['id' => 0,'title' => $days[1].' '.$this->getWeek($days[1])]], 'day3' => [['id' => 0,'title' => $days[2].' '.$this->getWeek($days[2])]], 'day4' => [['id' => 0,'title' => $days[3].' '.$this->getWeek($days[3])]], 'day5' => [['id' => 0,'title' => $days[4].' '.$this->getWeek($days[4])]], 'day6' => [['id' => 0,'title' => $days[5].' '.$this->getWeek($days[5])]], 'day7' => [['id' => 0,'title' => $days[6].' '.$this->getWeek($days[6])]], ]; $data2 = [ 'title' => '大会议室', 'day1' => [], 'day2' => [], 'day3' => [], 'day4' => [], 'day5' => [], 'day6' => [], 'day7' => [], ]; $data3 = [ 'title' => '小会议室', 'day1' => [], 'day2' => [], 'day3' => [], 'day4' => [], 'day5' => [], 'day6' => [], 'day7' => [], ]; foreach ($applys as $k=>$v){ $d = [ 'id' => $v['id'], 'title' => '['.$v['startTime'].'~'.$v['endTime'].']'.$v['title'] ]; if($v['room'] === $data2['title']){ if($v['date'] == $days[0]){ $data2['day1'][] = $d; } else if($v['date'] == $days[1]){ $data2['day2'][] = $d; } else if($v['date'] == $days[2]){ $data2['day3'][] = $d; } else if($v['date'] == $days[3]){ $data2['day4'][] = $d; } else if($v['date'] == $days[4]){ $data2['day5'][] = $d; } else if($v['date'] == $days[5]){ $data2['day6'][] = $d; } else if($v['date'] == $days[6]){ $data2['day7'][] = $d; } }else if($v['room'] === $data3['title']){ if($v['date'] == $days[0]){ $data3['day1'][] = $d; } else if($v['date'] == $days[1]){ $data3['day2'][] = $d; } else if($v['date'] == $days[2]){ $data3['day3'][] = $d; } else if($v['date'] == $days[3]){ $data3['day4'][] = $d; } else if($v['date'] == $days[4]){ $data3['day5'][] = $d; } else if($v['date'] == $days[5]){ $data3['day6'][] = $d; } else if($v['date'] == $days[6]){ $data3['day7'][] = $d; } } } $json = [ 'prev' => $prev, 'next' => $next, 'list' => [$data1,$data2,$data3] ]; ajax_return_ok($json); } private function getWeek($date){ $weeks = ['周日','周一','周二','周三','周四','周五','周六']; $time = strtotime($date); $w = date('w',$time); return $weeks[$w]; } private function getDays($date){ $curTime = strtotime($date); $days = []; $days[] = $date; for ($i=1;$i<7;$i++){ $days[] = date('Y-m-d',$curTime + $i*24*60*60); } return $days; } public function checktime(){ $startTime = input('start','','trim'); $endTime = input('end','','trim'); $room = input('room','','trim'); $date = input('date','','trim'); $lists = $this->getApplyList(6); $flag = true; foreach ($lists as $k=>$v){ if($v['room'] == $room && $v['date'] === $date){ if($v['startTime'] <= $startTime && $v['endTime'] > $startTime){ $flag = false; break; }else if($v['startTime'] <= $endTime && $v['startTime'] >= $startTime){ $flag = false; break; } } } if(!$flag){ ajax_return_error('该时间段已有预约'); }else{ ajax_return_ok([],'可预约'); } } private function getApplyList($advanced,$type=0){ if($type == 1){ $status = '2'; }else{ $status = '1,2'; } $lists = Db::name('apply') ->where('status','in',$status) ->where('advanced',$advanced) ->where('org_id',$this->orgId) ->field('id,title,apply_sn,form_json') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $formJson = json_decode($v['form_json'],true); $startTime = ''; $endTime = ''; $room = ''; $date = ''; foreach ($formJson as $kk=>$vv){ if($vv['componentName'] == 'ddmeetingroomfield'){ foreach ($vv['components'] as $kkk=>$vvv){ if($vvv['idx'] === 4){ $startTime = $vvv['values2'][0]; $endTime = $vvv['values2'][1]; } else if($vvv['idx'] === 6){ $room = $vvv['values']; } else if($vvv['idx'] === 3){ $date = $vvv['values']; } } break; } } $lists[$k]['startTime'] = $startTime; $lists[$k]['endTime'] = $endTime; $lists[$k]['room'] = $room; $lists[$k]['date'] = $date; unset($lists[$k]['form_json']); } return $lists; } }