处理价格不在区间范围内但是又有设置的商品匹配返回
This commit is contained in:
parent
aac0774b9c
commit
f59249a6ba
@ -2690,6 +2690,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
$merInfo = Merchant::getDB()->where('mer_id',$merId)->value('mer_name');
|
$merInfo = Merchant::getDB()->where('mer_id',$merId)->value('mer_name');
|
||||||
if ($count) {
|
if ($count) {
|
||||||
$range = $this->getRangeNumber($money); //减少一般的区间
|
$range = $this->getRangeNumber($money); //减少一般的区间
|
||||||
|
$baseList = $list;
|
||||||
$deal = $this->dealArr($list);
|
$deal = $this->dealArr($list);
|
||||||
//平均2个左右 0 1 2 阶梯往上查寻找
|
//平均2个左右 0 1 2 阶梯往上查寻找
|
||||||
[$products, $minNum] = $this->getRange($deal, $range);
|
[$products, $minNum] = $this->getRange($deal, $range);
|
||||||
@ -2697,6 +2698,10 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
if (!empty($products)) {
|
if (!empty($products)) {
|
||||||
$list = $this->findNearestPriceProduct($products, $money, $minNum);
|
$list = $this->findNearestPriceProduct($products, $money, $minNum);
|
||||||
}
|
}
|
||||||
|
if(empty($list) && $baseList){
|
||||||
|
$list = $this->findProductByPrice($money,$baseList);
|
||||||
|
}
|
||||||
|
|
||||||
$count = count($list);//计算数量的
|
$count = count($list);//计算数量的
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
@ -2705,6 +2710,36 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
'merInfo' => $merInfo,
|
'merInfo' => $merInfo,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
public function findProductByPrice($inputPrice, $products) {
|
||||||
|
$totalNum = 0;
|
||||||
|
$matchedProduct = null;
|
||||||
|
|
||||||
|
foreach ($products as $product) {
|
||||||
|
if ($product['price'] >= $inputPrice) {
|
||||||
|
$matchedProduct = $product;
|
||||||
|
$matchedProduct['num'] = 1;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$totalNum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$matchedProduct) { // 如果没有找到满足条件的商品
|
||||||
|
foreach ($products as &$product) {
|
||||||
|
|
||||||
|
$product['num'] = (int)ceil($inputPrice / $product['price']);
|
||||||
|
$totalNum += $product['num'];
|
||||||
|
if ($totalNum >= 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $matchedProduct ?? reset($products); // 返回匹配到的商品或数组的第一个商品
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getRange($array, $range)
|
public function getRange($array, $range)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user