修正获取服务包内某一药品的剩余数量计算
This commit is contained in:
@@ -1271,24 +1271,62 @@ class OrderServicePackageService extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务包内某一药品的剩余数量
|
||||
* @param string|int $order_service_id
|
||||
* 获取服务包内某一药品的总数量
|
||||
* @param string|int $product_id
|
||||
* @return int
|
||||
*/
|
||||
public function getOrderServiceProductRemainingQuantity(string|int $order_service_id,string|int $product_id): int
|
||||
public function getOrderServiceProductTotalQuantity(string|int $product_id): int
|
||||
{
|
||||
$total_quantity = 0;
|
||||
|
||||
// 获取健康包内容
|
||||
$params = array();
|
||||
$health_package = HealthPackage::getOne($params);
|
||||
if (empty($health_package)){
|
||||
return $total_quantity;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['package_id'] = $health_package['package_id'];
|
||||
$params['product_id'] = $product_id;
|
||||
$health_package_product = HealthPackage::getOne($params);
|
||||
if (empty($health_package_product)){
|
||||
return $total_quantity;
|
||||
}
|
||||
|
||||
return $health_package_product['quantity'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务包内某一药品的可使用数量
|
||||
* @param string|int $order_service_id
|
||||
* @param string|int $product_id
|
||||
* @param string|int $total_quantity
|
||||
* @return int
|
||||
*/
|
||||
public function getOrderServiceProductCanUseQuantity(string|int $order_service_id,string|int $product_id,string|int $total_quantity): int
|
||||
{
|
||||
$remaining_quantity = 0;
|
||||
|
||||
$params = array();
|
||||
$params['order_service_id'] = $order_service_id;
|
||||
$params['product_id'] = $product_id;
|
||||
$order_service_package_product = OrderServicePackageProduct::getOne($params);
|
||||
if (!empty($order_service_package_product)){
|
||||
$remaining_quantity = $order_service_package_product['quantity'] - $order_service_package_product['used_quantity'];
|
||||
if ($remaining_quantity < 0){
|
||||
$remaining_quantity = 0;
|
||||
}
|
||||
$order_service_package_products = OrderServicePackageProduct::getList($params);
|
||||
if (empty($order_service_package_products)){
|
||||
return $remaining_quantity;
|
||||
}
|
||||
|
||||
// 订单使用数量
|
||||
$used_quantity = 0;
|
||||
foreach ($order_service_package_products as $order_service_package_product){
|
||||
$used_quantity = $used_quantity + $order_service_package_product['used_quantity'];
|
||||
}
|
||||
|
||||
// 剩余数量 = 总数量-使用数量
|
||||
$remaining_quantity = $total_quantity - $used_quantity;
|
||||
|
||||
if ($remaining_quantity < 0){
|
||||
$remaining_quantity = 0;
|
||||
}
|
||||
|
||||
return $remaining_quantity;
|
||||
@@ -1339,6 +1377,13 @@ class OrderServicePackageService extends BaseService
|
||||
*/
|
||||
public function checkOrderServiceRemainingProduct(string|int $order_no): bool
|
||||
{
|
||||
// 获取健康包内容
|
||||
$params = array();
|
||||
$health_package = HealthPackage::getOne($params);
|
||||
if (empty($health_package)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取服务包关联商品
|
||||
$params = array();
|
||||
$params['order_service_no'] = $order_no;
|
||||
@@ -1348,10 +1393,26 @@ class OrderServicePackageService extends BaseService
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||||
$order_service_package_products = OrderServicePackageProduct::getList($params);
|
||||
foreach ($order_service_package_products as $order_service_package_product){
|
||||
$remaining_quantity = $order_service_package_product['quantity'] - $order_service_package_product['used_quantity'];
|
||||
$params['package_id'] = $health_package['package_id'];
|
||||
$health_package_products = HealthPackage::getList($params);
|
||||
if (empty($health_package_products)){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($health_package_products as $health_package_product){
|
||||
$params = array();
|
||||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||||
$params['product_id'] = $health_package_product['product_id'];
|
||||
$order_service_package_products = OrderServicePackageProduct::getList($params);
|
||||
|
||||
$used_quantity = 0;
|
||||
foreach ($order_service_package_products as $order_service_package_product){
|
||||
$used_quantity = $used_quantity + $order_service_package_product['used_quantity'];
|
||||
}
|
||||
|
||||
$remaining_quantity = $health_package_product['quantity'] - $used_quantity;
|
||||
|
||||
// 存在一个可使用商品数量即返回
|
||||
if ($remaining_quantity > 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user