src/main/java/com/mzl/flower/dto/response/flower/FlowerCartListDTO.java
@@ -26,4 +26,10 @@ private Long paramId; private Integer realSales;//真实销量 @ApiModelProperty(value = "会员价") private BigDecimal priceMember; @ApiModelProperty(value = "会员价总价") private BigDecimal totalMember; } src/main/java/com/mzl/flower/dto/response/flower/FlowerCartListWrapDTO.java
@@ -14,7 +14,7 @@ @ApiModelProperty(value = "供应商名称") private String supplierName; @ApiModelProperty(value = "供应商名称") @ApiModelProperty(value = "商品列表") private List<FlowerCartListDTO> flowerList; } src/main/java/com/mzl/flower/dto/response/flower/FlowerCategoryTreeDTO.java
@@ -51,6 +51,12 @@ @ApiModelProperty(value = "最高价") private BigDecimal priceHigh; @ApiModelProperty(value = "最低价(会员)") private BigDecimal priceLowMember; @ApiModelProperty(value = "最高价(会员)") private BigDecimal priceHighMember; @ApiModelProperty(value = "库存") private Integer stock; src/main/java/com/mzl/flower/dto/response/flower/FlowerShowDTO.java
@@ -3,6 +3,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; @Data public class FlowerShowDTO extends FlowerSupplierDTO { @@ -29,4 +31,7 @@ private Integer shopnum; private Integer realSales;//真实销量 @ApiModelProperty(value = "会员价") private BigDecimal priceMember; } src/main/java/com/mzl/flower/dto/response/flower/FlowerShowListDTO.java
@@ -3,6 +3,8 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; @Data public class FlowerShowListDTO extends FlowerSupplierListDTO { @@ -24,4 +26,7 @@ @ApiModelProperty(value = "是否推荐") private Boolean recommend; @ApiModelProperty(value = "会员价") private BigDecimal priceMember; } src/main/java/com/mzl/flower/service/BaseService.java
@@ -10,6 +10,7 @@ import com.mzl.flower.dto.response.payment.OrderSalesItemChargeDTO; import com.mzl.flower.entity.customer.Customer; import com.mzl.flower.entity.flower.*; import com.mzl.flower.entity.menber.Member; import com.mzl.flower.entity.partner.Partner; import com.mzl.flower.entity.payment.FeeService; import com.mzl.flower.entity.payment.OrderItemSales; @@ -17,6 +18,7 @@ import com.mzl.flower.entity.supplier.Supplier; import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.mapper.flower.FlowerCategoryMapper; import com.mzl.flower.mapper.member.MemberMapper; import com.mzl.flower.mapper.partner.PartnerMapper; import com.mzl.flower.mapper.supplier.SupplierMapper; import com.mzl.flower.mapper.system.UserMapper; @@ -25,6 +27,7 @@ import org.springframework.data.redis.core.RedisTemplate; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -56,6 +59,13 @@ @Autowired private FlowerCategoryMapper flowerCategoryMapper; @Autowired private MemberMapper memberMapper; protected Member getMember(Long levelId){ return memberMapper.selectById(levelId); } protected double getServiceFeeRate(List<FeeService> fees, Integer saleCount){ int sc = saleCount == null ? 0 : saleCount; @@ -463,6 +473,35 @@ return p; } /** * 计算会员单价 * * @param price * @param member * @return */ protected BigDecimal calculateMemberPrice(BigDecimal price, Member member){ if(price == null || member == null){ return price; } BigDecimal r = price; String discountType = member.getDiscountType(); if(Constants.DISCOUNT_TYPE.ratio.name().equals(discountType)){ BigDecimal discountRatio = getAmount(member.getDiscountRatio()); r = price.multiply(discountRatio).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); } else if (Constants.DISCOUNT_TYPE.amount.name().equals(discountType)){ BigDecimal discountAmount = getAmount(member.getDiscountAmount()); r = price.subtract(discountAmount); } if(r.doubleValue() < 0){ r = new BigDecimal(0); } return r; } protected Customer getCustomerByUserId(String userId){ Customer p = customerMapper.selectOne(new QueryWrapper<Customer>() .eq("user_id", userId)); src/main/java/com/mzl/flower/service/flower/FlowerCategoryService.java
@@ -13,12 +13,15 @@ import com.mzl.flower.dto.response.flower.FlowerCategoryDTO; import com.mzl.flower.dto.response.flower.FlowerCategoryShowDTO; import com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO; import com.mzl.flower.entity.customer.Customer; import com.mzl.flower.entity.flower.Flower; import com.mzl.flower.entity.flower.FlowerCategory; import com.mzl.flower.entity.flower.FlowerCategoryDaily; import com.mzl.flower.entity.menber.Member; import com.mzl.flower.mapper.flower.FlowerCategoryDailyMapper; import com.mzl.flower.mapper.flower.FlowerCategoryMapper; import com.mzl.flower.mapper.flower.FlowerMapper; import com.mzl.flower.mapper.member.MemberMapper; import com.mzl.flower.service.BaseService; import com.mzl.flower.utils.TreeBuilderUtil; import io.micrometer.core.instrument.util.StringUtils; @@ -154,7 +157,11 @@ List<FlowerCategoryTreeDTO> treeList = new ArrayList<>(); List<FlowerCategoryTreeDTO> result = new ArrayList<>(); if(tLs != null && tLs.size() > 0){ Long partnerId = getCurrentCustomerPartner(); Customer p = getCurrentCustomerWithoutCheck(); Long partnerId = p == null ? null : p.getPartnerId(); Long levelId = p == null ? null : p.getLevelId(); Member member = getMember(levelId); for(FlowerCategoryTreeDTO t : tLs){ if(t.getParentId() != null && t.getFlowerCount() == 0){ continue; @@ -165,6 +172,8 @@ JSONObject o = parseObject(ppp, JSONObject.class); t.setPriceLow(o.getBigDecimal("priceLow")); t.setPriceHigh(o.getBigDecimal("priceHigh")); t.setPriceLowMember(calculateMemberPrice(t.getPriceLow(), member)); t.setPriceHighMember(calculateMemberPrice(t.getPriceHigh(), member)); } treeList.add(t); src/main/java/com/mzl/flower/service/flower/FlowerService.java
@@ -11,6 +11,7 @@ import com.mzl.flower.entity.customer.Collect; import com.mzl.flower.entity.customer.Customer; import com.mzl.flower.entity.flower.*; import com.mzl.flower.entity.menber.Member; import com.mzl.flower.entity.payment.Cart; import com.mzl.flower.entity.payment.Order; import com.mzl.flower.entity.payment.OrderItem; @@ -467,20 +468,7 @@ dto.setUserId(SecurityUtils.getUserId()); dto.setParamId(paramService.getParamIdByCategoryId(dto.getCategory())); List<FlowerShowListDTO> ls = flowerMapper.selectFlowerShowList(page, dto); if(ls != null && ls.size() > 0){ Long partnerId = getCurrentCustomerPartner(); for(FlowerShowListDTO s : ls){ BigDecimal price = getFinalPrice(partnerId, s.getCategory() , s.getId(), s.getPrice(), s.getLevel()); s.setPrice(price); s.setCollection(s.getCollectCount() > 0); s.setShopnum(s.getShopnum() == null ? 0 : s.getShopnum()); if(s.getSales() != null && s.getRealSales() != null){ s.setSales(s.getSales() + s.getRealSales()); } } } prepareShowList(ls); page.setRecords(ls); @@ -507,10 +495,14 @@ if(pId == null){ pId = getCurrentCustomerPartner(); } Customer p = getCurrentCustomerWithoutCheck(); Long levelId = p == null ? null : p.getLevelId(); Member member = getMember(levelId); BigDecimal price = getFinalPrice(pId, dto.getCategory() , s.getId(), dto.getPrice(), dto.getLevel()); dto.setPrice(price); dto.setPriceMember(calculateMemberPrice(price, member)); String userId = SecurityUtils.getUserId(); if(StringUtils.isNotEmpty(userId)) { @@ -611,8 +603,33 @@ dto.setParamId(paramService.getParamIdByCategoryId(dto.getCategory())); List<FlowerShowListDTO> flowerShowListDTOS = flowerMapper.myCollect(page, dto); prepareShowList(flowerShowListDTOS); page.setRecords(flowerShowListDTOS); return page; } private void prepareShowList(List<FlowerShowListDTO> ls){ if(ls != null && ls.size() > 0){ Customer p = getCurrentCustomerWithoutCheck(); Long partnerId = p == null ? null : p.getPartnerId(); Long levelId = p == null ? null : p.getLevelId(); Member member = getMember(levelId); for(FlowerShowListDTO s : ls){ BigDecimal price = getFinalPrice(partnerId, s.getCategory() , s.getId(), s.getPrice(), s.getLevel()); s.setPrice(price); s.setPriceMember(calculateMemberPrice(price, member)); s.setCollection(s.getCollectCount() > 0); s.setShopnum(s.getShopnum() == null ? 0 : s.getShopnum()); if(s.getSales() != null && s.getRealSales() != null){ s.setSales(s.getSales() + s.getRealSales()); } } } } public Page<FlowerShowListDTO> myBrowseHistory(Page page, FlowerShowQueryDTO dto) { @@ -626,6 +643,8 @@ }*/ dto.setParamId(paramService.getParamIdByCategoryId(dto.getCategory())); List<FlowerShowListDTO> flowerShowListDTOS = flowerMapper.myBrowseHistory(page, dto); prepareShowList(flowerShowListDTOS); page.setRecords(flowerShowListDTOS); return page; } @@ -634,7 +653,8 @@ if(dto.getZoneId()!=null && dto.getZoneId().size()>0){//添加专区 for (Long zoneId : dto.getZoneId()) { for(Long flowerId : dto.getIds()) { FlowerZoneMap fzp = flowerZoneMapMapper.selectOne(new QueryWrapper<FlowerZoneMap>().eq("flower_id", flowerId).eq("zone_id", zoneId)); FlowerZoneMap fzp = flowerZoneMapMapper.selectOne(new QueryWrapper<FlowerZoneMap>() .eq("flower_id", flowerId).eq("zone_id", zoneId)); if(fzp==null){ fzp = new FlowerZoneMap(); fzp.setFlowerId(flowerId); src/main/java/com/mzl/flower/service/payment/OrderService.java
@@ -24,6 +24,7 @@ import com.mzl.flower.entity.customer.Address; import com.mzl.flower.entity.customer.Customer; import com.mzl.flower.entity.flower.FlowerSupplierSaleNum; import com.mzl.flower.entity.menber.Member; import com.mzl.flower.entity.partner.Partner; import com.mzl.flower.entity.payment.*; import com.mzl.flower.entity.supplier.Station; @@ -211,13 +212,18 @@ if (ls != null && ls.size() > 0) { Customer customer = getCurrentCustomer(); Long partnerId = customer.getPartnerId(); Long levelId = customer.getLevelId(); Member member = getMember(levelId); Map<Long, FlowerCartListWrapDTO> map = new HashMap<>(); for (FlowerCartListDTO c : ls) { BigDecimal price = getFinalPrice(partnerId, c.getCategory() , c.getId(), c.getPrice(), c.getLevel()); c.setPrice(price); c.setPriceMember(calculateMemberPrice(price, member)); c.setTotal(price.multiply(new BigDecimal(c.getNum()))); c.setTotalMember(c.getPriceMember().multiply(new BigDecimal(c.getNum()))); if (c.getSales() != null && c.getRealSales() != null) { c.setSales(c.getSales() + c.getRealSales()); @@ -265,6 +271,8 @@ List<FlowerCartListDTO> ls = flowerMapper.selectFlowerOrderList(ids); Customer customer = getCurrentCustomer(); Long partnerId = customer.getPartnerId(); Long levelId = customer.getLevelId(); Member member = getMember(levelId); double totalWeight = 0D; int num = 0; @@ -288,7 +296,10 @@ , c.getId(), c.getPrice(), c.getLevel()); BigDecimal price = priceDTO.getPrice(); c.setPrice(price); c.setPriceMember(calculateMemberPrice(price, member)); c.setTotal(price.multiply(new BigDecimal(c.getNum()))); c.setTotalMember(c.getPriceMember().multiply(new BigDecimal(c.getNum())));//使用会员价计算总价 if (priceMap != null) { priceMap.put(c.getId(), priceDTO); @@ -348,6 +359,8 @@ deliveryName = d.getName(); } //TODO 优惠券和会员价相关修改 String userId = SecurityUtils.getUserId(); Order order = new Order(); order.setId(UUIDGenerator.getUUID());