php - 这是检查该值是否为空的最有效方法吗?
问题描述
我正在对我们的费率表进行查询,如您所见。如果值返回为空。它再次检查并使用不同的用例一遍又一遍地执行此操作。我只是想确保这是最有效的检查方式。
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '$branch' AND location_from = '$location_from_id' AND location_to = '$location_to_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
if(empty($rates))
{
//IF THERE IS MASTER, NO BRANCH, YES LOCATION
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '-1' AND location_from = '$location_from_id' AND location_to = '$location_to_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
if($region_from_id !='' && $region_to_id !='')
{
if(empty($rates)) { // IF RESTRICTED IS PICKUP
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '$branch' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '1' AND restricted_location_id = '$location_from_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) { // IF RESTRICTED IS DELIVERY
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '$branch' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '2' AND restricted_location_id = '$location_to_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) {
// IF THERE IS NO RESTRICTION
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '$branch' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '0' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) { // IF RESTRICTED IS PICKUP
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '1' AND restricted_location_id = '$location_from_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) { // IF RESTRICTED IS DELIVERY
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '2' AND restricted_location_id = '$location_to_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) {
// IF THERE IS NO RESTRICTION
$rates = Rates::find()->where("status_active = 'active' AND master_account = '$account' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '0' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) { // IF RESTRICTED IS PICKUP
$rates = Rates::find()->where("status_active = 'active' AND master_account = '-1' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '1' AND restricted_location_id = '$location_from_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) { // IF RESTRICTED IS DELIVERY
$rates = Rates::find()->where("status_active = 'active' AND master_account = '-1' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '2' AND restricted_location_id = '$location_to_id' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
if(empty($rates)) {
// IF THERE IS NO RESTRICTION
$rates = Rates::find()->where("status_active = 'active' AND master_account = '-1' AND branch_id = '-1' AND region_from = '$region_from_id' AND region_to = '$region_to_id' AND restricted = '0' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by")->all();
}
}
}
解决方案
推荐阅读
- c# - 如何在不使用 c# 中的内置函数的情况下获得投球手的最低和最高分数
- apache-nifi - 基于列表的RouteOnAttribute
- javascript - Firebase 身份验证
- angular - 可以在控制台中看到的数据未显示在视图中
- javascript - 在 JavaScript 中使用 CustomEvents 发布/订阅
- javascript - 如何使用 Reactjs&Redux 实现 fifo 队列
- javascript - 如何在 XML 视图中连接属性值
- macos - 在 CMake 中使用通过 brew 安装的 Qwt
- python - Python:Youtube DATA API循环刷新播放列表
- openssl - openssl:创建带有昵称的证书