我使用 Laravel Lumen 框架和 jenssegers/laravel-mongodb 包,我在项目中的查询是:
$time_5_min_ago = Carbon::now()->subMinute(5);
$time_10_min_ago = Carbon::now()->subMinute(10);
$time_15_min_ago = Carbon::now()->subMinute(15);
$time_20_min_ago = Carbon::now()->subMinute(20);
return Order::where(function ($query) use ($maxLat_try_one,$minLat_try_one,$maxLon_try_one,$minLon_try_one,$time_5_min_ago,$time_10_min_ago) {
$query->whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
->whereBetween('source_latitude', [$minLat_try_one,$maxLat_try_one])
->where('status', '=', 'pending')
->where('created_at', '<', $time_5_min_ago)
->where('created_at', '>=', $time_10_min_ago);
})->orWhere(function ($query) use ($maxLat_try_two,$minLat_try_two,$maxLon_try_two,$minLon_try_two,$time_10_min_ago,$time_15_min_ago) {
$query->whereBetween('source_longitude', [$minLon_try_two, $maxLon_try_two])
->whereBetween('source_latitude', [$minLat_try_two,$maxLat_try_two])
->where('status', '=', 'pending')
->where('created_at', '<', $time_10_min_ago)
->where('created_at', '>=', $time_15_min_ago);
})->orWhere(function ($query) use ($maxLat_try_three,$minLat_try_three,$maxLon_try_three,$minLon_try_three,$time_15_min_ago,$time_20_min_ago) {
$query->whereBetween('source_longitude', [$minLon_try_three, $maxLon_try_three])
->whereBetween('source_latitude', [$minLat_try_three,$maxLat_try_three])
->where('status', '=', 'pending')
->where('created_at', '<', $time_15_min_ago)
->where('created_at', '>=', $time_20_min_ago);
})->get($fields);
我想在顶部查询中存在任何订单,在最后一个orWehere
查询中,订单 created_at 是 < 20 分钟前,状态仍处于等待状态,订单状态已更新为暂停