@TOC

代码如下

$map = [
            ['status', '=', 1],
            ['type', '=', 1],
            ['start_time', '<', time()],
            ['end_time', '>', time()],
        ];

        $res = model('article')->where($map)
                ->whereOr(function($query) {
                    $query->where([
                        ['status', '=', 1],
                        ['type', '=', 1],
                        ['start_time', '=', 0],
                        ['end_time', '>', time()],
                    ]);
                })
                ->whereOr(function($query) {
                    $query->where([
                        ['status', '=', 1],
                        ['type', '=', 1],
                        ['start_time', '<', time()],
                        ['end_time', '=', 0],
                    ]);
                })
                ->order('sorts asc')
                ->page($page, $pageSize)
                ->select();

sql语句如下

SELECT
	*
FROM
	`s_article`
WHERE
	`status` = 1
AND `type` = 1
AND `start_time` < 1587009710
AND `end_time` > 1587009710
OR (
	`status` = 1
	AND `type` = 1
	AND `start_time` = 0
	AND `end_time` > 1587009710
)
OR (
	`status` = 1
	AND `type` = 1
	AND `start_time` < 1587009710
	AND `end_time` = 0
)
ORDER BY
	`sorts` ASC
LIMIT 0,
 1

书写完毕