获取并匹配未来15天的数据

时间:2019-04-29 05:15:41

标签: php codeigniter

我正在使用Codeigniter,我有两个表(商店信息和预订信息),我想在30分钟后获取数据 商店开了,想检查那个时候的商店是否被预订,我正在获取并成功完成30分钟的时段,但是我如何获得即将到来的15天记录和匹配? 表示我想获取并比较今天日期之后的15天数据,该怎么办?

我想要这样的数据(预订了9:00到09:30)

"availability": [
            {
                "id": 1,
                "date": "29-Apr-2019",
                "arrTimeSlots": [
                    {
                        "id": 1,
                        "time": "09:00 AM",
                        "alreadyBooked": true
                    },
                    {
                        "id": 2,
                        "time": "09:30 AM",
                        "alreadyBooked": true
                    },
                    {
                        "id": 3,
                        "time": "10:00 AM",
                        "alreadyBooked": false
                    },
                "date": "30-Apr-2019",
                "arrTimeSlots": [
                    {
                        "id": 1,
                        "time": "09:00 AM",
                        "alreadyBooked": false
                    },
                    {
                        "id": 2,
                        "time": "09:30 AM",
                        "alreadyBooked": false
                    },
                    {
                        "id": 3,
                        "time": "10:00 AM",
                        "alreadyBooked": false
                    },  
            }

这是我当前的代码,我该怎么办?

$add_data['shop_id'] = ($this->input->post('shop_id') && !empty($this->input->post('shop_id'))) ? $this->input->post('shop_id') : NULL;     

                $this->db->select('*');
                $this->db->from('additional_info');
                $this->db->where('shop_id',$add_data['shop_id']);
                $query = $this->db->get();
                if ( $query->num_rows() > 0 )
                    {
                        $row = $query->row_array();
                        $start=$row['shop_open_time'];
                        $end=$row['shop_close_time'];
                        $start_time=substr($start, 0, -10);
                        $end_time=substr($end, 0, -10);
                        $start_time = new DateTime($start_time);
                        $close_time = new DateTime($end_time);
                        $periods = new DatePeriod($start_time, new DateInterval('PT30M'), $close_time);
                        foreach ($periods as $period) {
                            $times[] = $period->format('H:i');
                        }
                        $times[] = $close_time->format('H:i');
                        //print_r($times);

                        $availability = array_fill_keys($times, 'available');
                        function book(&$availability, $start, $end)
                        {
                            foreach($availability as $k => $v)
                                if(strtotime($k) >= strtotime($start) && strtotime($k) <= strtotime($end))
                                    $availability[$k] = 'booked';
                        }                       

                $this->db->select('*');
                $this->db->from('usr_booking');
                $this->db->where('shop_id',$add_data['shop_id']);
                $queryc = $this->db->get();
                foreach($queryc->result_array() as $results)
                    {
                        //print_R($results);            
                             $s=$results['start_time'];
                          $e=$results['end_time'];
                        book($availability, $s, $e);
                    }
                echo "<pre>";print_r($availability);

0 个答案:

没有答案