1 回答
TA贡献1820条经验 获得超9个赞
解决了:
public function check_datetime_range($where)
{
$this->db->where('freelancer_id', $where['freelancer_id']);
$this->db->where("DATE_FORMAT(app_date_start, '%Y-%m-%d') = ", date('Y-m-d', strtotime($where['app_date_start'])));
$this->db->group_start();
// Example:
// start time = 7:00pm, end time = 8:00pm, date = 15-01-2020 (Existing Appointment)
//1. Prevents overlapping time with an existing appointment
// start time = 7:00pm, end time = 8:00pm, date = 15-01-2020
// OR
// start time = 6:00pm, end time = 9:00pm, date = 15-01-2020
$this->db->group_start();
$this->db->where('app_date_start >=', $where['app_date_start']);
$this->db->where('app_date_end <=', $where['app_date_end']);
$this->db->group_end();
//2. Prevents overlapping time from within an existing appointment
// start time = 7:15pm, end time = 7:45pm, date = 15-01-2020
$this->db->or_group_start();
$this->db->where('app_date_start <=', $where['app_date_start']);
$this->db->where('app_date_end >=', $where['app_date_end']);
$this->db->group_end();
//3. Prevents overlapping end time inside an existing appointment
// start time = 6:45pm, end time = 7:45pm, date = 15-01-2020
$this->db->or_group_start();
$this->db->where('app_date_start >', $where['app_date_start']);
$this->db->where('app_date_start <', $where['app_date_end']);
$this->db->where('app_date_end >', $where['app_date_end']);
$this->db->group_end();
//4. Prevents overlapping start time inside an existing appointment
// start time = 7:45pm, end time = 8:45pm, date = 15-01-2020
$this->db->or_group_start();
$this->db->where('app_date_start <', $where['app_date_start']);
$this->db->where('app_date_start <', $where['app_date_end']);
$this->db->where('app_date_end >', $where['app_date_start']);
$this->db->where('app_date_end <', $where['app_date_end']);
$this->db->group_end();
//5. Prevents start time > end time
// start time = 7:00pm, end time = 6:00pm
$this->db->or_group_start();
$this->db->where('app_date_start >', $where['app_date_end']);
$this->db->group_end();
$this->db->group_end();
return $this->db->get($this->_table_name)->num_rows();
}
- 1 回答
- 0 关注
- 82 浏览
添加回答
举报