Last active
July 31, 2017 09:09
-
-
Save pulading1988/dc80278d7a84c887baa1d1a20d2cf6ad to your computer and use it in GitHub Desktop.
laravel查询参数分组
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM `market_list` | |
WHERE `id` IN ('1', '2') | |
AND `status` = '1' | |
AND (`start_time` IS NULL | |
OR `start_time` <= '2017-07-31 17:05:57') | |
AND (`end_time` IS NULL | |
OR `end_time` >= '2017-07-31 17:05:57') | |
ORDER BY `priority` DESC | |
LIMIT 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$market = MarketListModel::whereIn('id', $ids) | |
->where('status', '=', MarketListModel::STATUS_VALID) | |
->where(function($query) use($now) { | |
$query->whereNull('start_time')->orWhere('start_time', '<=', $now); | |
}) | |
->where(function($query) use($now) { | |
$query->whereNull('end_time')->orWhere('end_time', '>=', $now); | |
}) | |
->orderBy('priority', 'desc') | |
->limit(5) | |
->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment