|  | @@ -296,84 +296,6 @@ class DiscountService
 | 
											
												
													
														|  |          ];
 |  |          ];
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -     /**
 |  | 
 | 
											
												
													
														|  | -     * 获取商品的折扣信息
 |  | 
 | 
											
												
													
														|  | -     * @param $value
 |  | 
 | 
											
												
													
														|  | -     * @param $data
 |  | 
 | 
											
												
													
														|  | -     * @return array|null
 |  | 
 | 
											
												
													
														|  | -     */
 |  | 
 | 
											
												
													
														|  | -    public function getDiscountInfoAttr($value, $data)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        if (!isset($data['id'])) {
 |  | 
 | 
											
												
													
														|  | -            return null;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        // 静态缓存,避免重复查询
 |  | 
 | 
											
												
													
														|  | -        static $discountCache = [];
 |  | 
 | 
											
												
													
														|  | -        $goodsId = $data['id'];
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if (!isset($discountCache[$goodsId])) {
 |  | 
 | 
											
												
													
														|  | -            $discountCache[$goodsId] = \app\common\Service\DiscountService::getBatchGoodsDiscountInfo([$goodsId]);
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        return isset($discountCache[$goodsId][$goodsId]) ? $discountCache[$goodsId][$goodsId] : [];
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    /**
 |  | 
 | 
											
												
													
														|  | -     * 检查商品是否有活动折扣
 |  | 
 | 
											
												
													
														|  | -     * @param int $skuId 规格ID,单规格商品传0
 |  | 
 | 
											
												
													
														|  | -     * @return bool
 |  | 
 | 
											
												
													
														|  | -     */
 |  | 
 | 
											
												
													
														|  | -    public function hasDiscount($skuId = 0)
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        return self::hasActiveDiscount($this->id, $skuId);
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    /**
 |  | 
 | 
											
												
													
														|  | -     * 获取商品的最低折扣价格
 |  | 
 | 
											
												
													
														|  | -     * @return float|null
 |  | 
 | 
											
												
													
														|  | -     */
 |  | 
 | 
											
												
													
														|  | -    public function getMinDiscountPrice()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        $discountInfo = $this->discount_info;
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if (empty($discountInfo)) {
 |  | 
 | 
											
												
													
														|  | -            return null;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        $minPrice = null;
 |  | 
 | 
											
												
													
														|  | -        foreach ($discountInfo as $item) {
 |  | 
 | 
											
												
													
														|  | -            $price = floatval($item['discount_price']);
 |  | 
 | 
											
												
													
														|  | -            if ($minPrice === null || $price < $minPrice) {
 |  | 
 | 
											
												
													
														|  | -                $minPrice = $price;
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        return $minPrice;
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    
 |  | 
 | 
											
												
													
														|  | -    /**
 |  | 
 | 
											
												
													
														|  | -     * 获取商品的最大折扣力度
 |  | 
 | 
											
												
													
														|  | -     * @return float|null
 |  | 
 | 
											
												
													
														|  | -     */
 |  | 
 | 
											
												
													
														|  | -    public function getMaxDiscount()
 |  | 
 | 
											
												
													
														|  | -    {
 |  | 
 | 
											
												
													
														|  | -        $discountInfo = $this->discount_info;
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        if (empty($discountInfo)) {
 |  | 
 | 
											
												
													
														|  | -            return null;
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        $maxDiscount = null;
 |  | 
 | 
											
												
													
														|  | -        foreach ($discountInfo as $item) {
 |  | 
 | 
											
												
													
														|  | -            $discount = floatval($item['discount']);
 |  | 
 | 
											
												
													
														|  | -            if ($maxDiscount === null || $discount < $maxDiscount) { // 折扣越小力度越大
 |  | 
 | 
											
												
													
														|  | -                $maxDiscount = $discount;
 |  | 
 | 
											
												
													
														|  | -            }
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | -        return $maxDiscount;
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +   
 | 
											
												
													
														|  | 
 |  | +   
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  | -} 
 |  | 
 |