我正在尝试查找特定用户的时间重叠,我认为我的逻辑会捕获所有圈数,但这仅在开始或结束在时间范围之间时才会捕获,但如果两者都在开始和结束之间则什么都找不到一些记录时间段!
$tempModel = clone $this; // clone model
$criteria->addCondition('
( t.user = :user AND (t.startDate >= :start AND t.startDate <= :end ))
OR
( t.user = :user AND (t.endDate >= :start AND t.endDate <= :end ))
');
$criteria->params = array(
':start' => date('Y-m-d', strtotime($tempModel->startDate)),
':end' => date('Y-m-d', strtotime($tempModel->endDate)),
':user ' => $tempModel->userID ,
);
if(!empty($tempModel->idUserTime)) // dont find updated record
$criteria->addCondition('t.idUserTime != ' . $tempModel->idUserTime);
$criteria->addCondition('t.active = 1'); // if this is an active user time
$hasRecord = Usertime::model()->findAll($criteria);
问题出在哪里?