thinkphp5 多表查询条件 or 和and 查询匿名函数

需要这样的sql效果

SELECT `a`.*,`user_name`,`dept_id` FROM `studentwork_leave` `a` LEFT JOIN `users` `u` ON `a`.`stu_id`=`u`.`user_id` WHERE ( ( `time_start` BETWEEN '2022-03-20 08:35' AND '2022-03-21 22:35' OR `time_end` BETWEEN '2022-03-20 08:35' AND '2022-03-21 22:35' ) OR ( (UNIX_TIMESTAMP(time_start)<=1647736500 AND UNIX_TIMESTAMP(time_end)>=1647873300) ) )

查询请假的数据 时间有穿插的问题

$model = model('Studentleave');
  $model->where('handle_status', 'lt', 2);

time_start 开始请假时间筛选 

$model->where(function ($query) use ($data) {
    $query->whereOr("time_start|time_end","between", [$data['time_start'],$data['time_end']]);
    $query->whereor('(UNIX_TIMESTAMP(time_start)<=' . strtotime($data['time_start']) . ' AND UNIX_TIMESTAMP(time_end)>=' . strtotime($data['time_end']) . ')');
});

你可能感兴趣的:(mysql,thinkphp5,mysql)