首页下半更改

This commit is contained in:
liuyingfang
2024-04-15 10:15:16 +08:00
parent d7dfeee159
commit 46cd954abf
8 changed files with 157 additions and 95 deletions

View File

@@ -19,11 +19,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
@@ -59,13 +57,23 @@ public class HomePageService {
} else {
beginNo = (homeDto.getPage() - 1) * homeDto.getSize();
}
//优惠卷
List<TbMerchantCoupon> tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize());
//经纬度(附近一km)
Map<String, double[]> topAndBottomMap = new HashMap<>();
List<CouAndShopVo> tbMerchantCoupons = new ArrayList<>();
if (homeDto.getOther() != null && homeDto.getOther() == 1){
topAndBottomMap = LocationUtils.returnLLSquarePoint(Double.parseDouble(homeDto.getLng()), Double.parseDouble(homeDto.getLat()), 1);
tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), topAndBottomMap.get("rightTopPoint")[0],topAndBottomMap.get("rightTopPoint")[1],
topAndBottomMap.get("leftBottomPoint")[0],topAndBottomMap.get("leftBottomPoint")[1],homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat());
}else {
tbMerchantCoupons = merchantCouponMapper.queryAllByPage(beginNo, homeDto.getSize(), null,null,null,null,
homeDto.getAddress(),homeDto.getOrderBy().toString(),homeDto.getLng(),homeDto.getLat());
}
//统计shopId以及productId
List<String> shopIds = new ArrayList<>();
List<String> productIds = new ArrayList<>();
List<Integer> productIdsInt = new ArrayList<>();
for (TbMerchantCoupon coupon : tbMerchantCoupons) {
for (CouAndShopVo coupon : tbMerchantCoupons) {
shopIds.add(coupon.getShopId());
productIds.add(coupon.getRelationIds());
productIdsInt.add(Integer.valueOf(coupon.getRelationIds()));
@@ -82,10 +90,9 @@ public class HomePageService {
//组装
List<HomeVO> homeVOList = new ArrayList<>();
for (TbMerchantCoupon o : tbMerchantCoupons) {
for (CouAndShopVo o : tbMerchantCoupons) {
HomeVO homeVO = new HomeVO();
homeVO.setId(o.getId());
homeVO.setDiscount(o.getRatio());
for (TbShopInfo tbShopInfo : shopInfo.get()) {
if (o.getShopId().equals(tbShopInfo.getId().toString())) {
homeVO.setShopName(tbShopInfo.getShopName());
@@ -104,18 +111,26 @@ public class HomePageService {
}
for (TbProduct tbProduct : product.get()) {
if (o.getRelationIds().equals(tbProduct.getId().toString())) {
homeVO.setProductName(tbProduct.getName());
homeVO.setProductName(o.getTitle());
homeVO.setImage(tbProduct.getCoverImg());
homeVO.setProductId(tbProduct.getId());
}
}
for (TbProductSku tbProductSku : productSku.get()) {
if (o.getRelationIds().equals(tbProductSku.getProductId())) {
homeVO.setOriginPrice(tbProductSku.getSalePrice());
homeVO.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber()));
Float discount = homeVO.getDiscount();
BigDecimal discountDecimal = new BigDecimal(discount);
homeVO.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1")))));
//原价
if (tbProductSku.getSalePrice().compareTo(BigDecimal.ZERO)==0){
homeVO.setOriginPrice(BigDecimal.ZERO);
homeVO.setDiscount(BigDecimal.ZERO);
}else {
homeVO.setOriginPrice(tbProductSku.getSalePrice());
homeVO.setDiscount(new BigDecimal(o.getAmount()).divide(tbProductSku.getSalePrice(),2,RoundingMode.DOWN).multiply(BigDecimal.TEN));
}
//销量
homeVO.setRealSalesNumber(new BigDecimal(o.getNumber()));
//现价
homeVO.setSalePrice(new BigDecimal(o.getAmount().toString()));
// 共省金额
homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice()));
}
}
@@ -161,7 +176,7 @@ public class HomePageService {
BigDecimal originPrice = o.getOriginPrice();
if (originPrice.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal multiply = o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(BigDecimal.TEN);
o.setDiscount(multiply.floatValue());
o.setDiscount(multiply);
} else {
o.setDiscount(null);
}