From 04474ac0e4253a9b1b69c4dfbfecb470ce5a4778 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Mon, 18 Mar 2024 11:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=89=B9=E5=8F=91=E4=BB=B7?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderRepository.php | 32 +++++++++++++++++-- .../store/product/SpuRepository.php | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 8c96674e..89a9cdf3 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2628,7 +2628,8 @@ class StoreOrderRepository extends BaseRepository if ($money < $end[0]['price']) { $list = $end; } else { - $list = array_merge($end, $end);//满足2条数据 + $end[0]['num'] =2; + $list = $end;//满足2条数据 } } else { //在1 或者 2区间 @@ -2636,7 +2637,9 @@ class StoreOrderRepository extends BaseRepository $list = $this->findNearestPriceProductDg($deal, $minMoney, $range, $newArray, $money, $money); } - $count = count($list); + +// $count = array_sum(array_column($list, 'num')); //重复拿 + $count = count($list);//计算数量的 return compact('count', 'list'); } else { @@ -2646,6 +2649,26 @@ class StoreOrderRepository extends BaseRepository + //合并数组相同value_id + public function mergeSameValueIds($array) { + $result = []; + foreach ($array as $item) { + // 如果$result中已经有相同的value_id,则增加num并移除旧数组中的项 + if (isset($result[$item['value_id']])) { + $result[$item['value_id']]['num'] += $item['num']; + } else { + // 否则,直接添加到结果数组中 + $result[$item['value_id']] = $item; + } + } + + // 将键值数组转换回索引数组 + return array_values($result); + } + + + + public function getRangeNumber($price, $ranges = [[0, 100], [100, 500], [500, PHP_INT_MAX]]) { @@ -2707,6 +2730,9 @@ class StoreOrderRepository extends BaseRepository $nearestProduct = $product; } } + if($nearestProduct){ + $nearestProduct['num']=1; + } return $nearestProduct; } @@ -2729,7 +2755,7 @@ class StoreOrderRepository extends BaseRepository $nearestProduct = $product; } } - + $nearestProduct['num'] = 1; $newArray[] = $nearestProduct; $remarkId = $nearestProduct['value_id']; $totalPrice = array_sum(array_column($newArray, 'price')); //本次全部的价格之和 diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 25ad3a6a..78a0958e 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -34,7 +34,7 @@ class SpuRepository extends BaseRepository { public $dao; public $merchantFiled = 'mer_id,mer_name,mer_avatar,is_trader,mer_info,mer_keyword,type_id'; - public $productFiled = 'P.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,P.sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,S.ot_price,svip_price_type,P.stock,mer_svip_status'; + public $productFiled = 'P.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,P.sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,S.ot_price,svip_price_type,P.stock,mer_svip_status,P.wholesale_price'; public function __construct(SpuDao $dao) { $this->dao = $dao;