diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index d90da6e9..ba26c633 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2572,18 +2572,37 @@ class StoreOrderRepository extends BaseRepository } - public function dealGoodsList($where,$money) + public function dealDataDiv($where,$_where) { $data = ProductAttrValue::alias('a') ->leftJoin('store_product p', 'a.product_id = p.product_id') ->where($where) + ->where($_where) ->field('a.value_id,a.product_id,a.mer_id,a.sku,a.stock,a.image,a.price, a.svip_price, - a.unique,p.store_name,p.store_info'); + a.unique,p.store_name,p.store_info') + ->limit(50)->select(); + + return $data; + } - $list = $data->limit(100)->select(); - $count = $data->count(); + + public function dealGoodsList($where,$money) + { + //拆分2种方式 大于该金额的 50 +小于该金额的50条 + $greaterWhere = function ($query) use ($money) { + $query->where('a.price', '>', $money); + }; + $maxData = $this->dealDataDiv($where,$greaterWhere); + + $lessWhere = function ($query) use ($money) { + $query->where('a.price', '<=', $money); + }; + $mixData = $this->dealDataDiv($where,$lessWhere); + + $list = array_merge($maxData->toArray(), $mixData->toArray()); + $count = count($list); $minMoney = bcsub($money, 600, 2); if ($count) { @@ -2597,7 +2616,7 @@ class StoreOrderRepository extends BaseRepository return app('json')->fail('不在区间情况中'); } } - $deal = $this->dealArr($list->toArray()); + $deal = $this->dealArr($list); //平均2个左右 0 1 2 阶梯往上查寻找 $end = array($this->findNearestPriceProduct($deal[$range]['items'], $minMoney));//17jiji if ($range == 0 && $deal[$range]['quantity'] = 1) { //第一个并且只有一条数据