From 74cbfef69e96e5b4805af556b307db72c7f08de3 Mon Sep 17 00:00:00 2001 From: codeliu <1873441552@qq.com> Date: Sat, 23 Mar 2024 11:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 6ee41e9e..b50a2034 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2699,8 +2699,8 @@ class StoreOrderRepository extends BaseRepository $list = $this->findNearestPriceProduct($products, $money, $minNum); } $count = count($list);//计算数量的 - if(empty($list) && $baseList){ - $list = $this->findProductByPrice($money,$baseList); + if(empty($count)){ + $list = [$this->findProductByPrice($money,$baseList)]; $count = count($list);//计算数量的 } @@ -2712,6 +2712,13 @@ class StoreOrderRepository extends BaseRepository 'merInfo' => $merInfo, ]; } + + + + + + + public function findProductByPrice($inputPrice, $products) { $totalNum = 0; $matchedProduct = null; @@ -2839,9 +2846,12 @@ class StoreOrderRepository extends BaseRepository $product['num'] = (int)ceil($targetPrice / $product['price']); } else { $product['num'] = 1; - } + } //dump($product); $targetPrice -= $product['price']; - $nearestProduct[] = $product; + if ($product['num'] >0) { + $nearestProduct[] = $product; + } + $currentNum++; } return $nearestProduct;