From 2c5a0e133b64bb0a46b1419c48e9b62a4779e268 Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期一, 09 十二月 2024 16:13:17 +0800 Subject: [PATCH] add: 供应商子账号 --- src/main/java/com/mzl/flower/service/BaseService.java | 82 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/BaseService.java b/src/main/java/com/mzl/flower/service/BaseService.java index 94c2d4c..def7248 100644 --- a/src/main/java/com/mzl/flower/service/BaseService.java +++ b/src/main/java/com/mzl/flower/service/BaseService.java @@ -12,15 +12,19 @@ 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; import com.mzl.flower.entity.payment.OrderSalesItem; import com.mzl.flower.entity.supplier.Supplier; +import com.mzl.flower.entity.supplier.SupplierSub; 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.supplier.SupplierSubMapper; import com.mzl.flower.mapper.system.UserMapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -29,8 +33,10 @@ import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -52,6 +58,9 @@ protected SupplierMapper supplierMapper; @Autowired + protected SupplierSubMapper supplierSubMapper; + + @Autowired protected PartnerMapper partnerMapper; @Autowired @@ -62,6 +71,13 @@ @Autowired private FlowerCategoryMapper flowerCategoryMapper; + + @Autowired + private MemberMapper memberMapper; + + protected Member getMember(Long levelId){ + return memberMapper.selectById(levelId); + } @Autowired private StringCacheClient stringCacheClient; @@ -133,12 +149,14 @@ BigDecimal feePlatformPack = getAmount(s.getFeePlatformPack()); BigDecimal feePlatformCheck = getAmount(s.getFeePlatformCheck()); BigDecimal feePlatformTransport = getAmount(s.getFeePlatformTransport()); + BigDecimal feePackingTransport = getAmount(s.getFeePackingTransport()); BigDecimal b = platformSalesMap.get(orderItemId); if (b == null) { b = new BigDecimal(0); } - b = b.add(feePlatform).add(feePlatformPack).add(feePlatformCheck).add(feePlatformTransport); + b = b.add(feePlatform).add(feePlatformPack).add(feePlatformCheck) + .add(feePlatformTransport).add(feePackingTransport); platformSalesMap.put(orderItemId, b); } } @@ -479,6 +497,55 @@ 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)); + if(p == null){ + throw new ValidationException("客户不存在"); + } + + return p; + } + + protected Customer getCustomer(Long id){ + Customer p = customerMapper.selectById(id); + + if(p == null){ + throw new ValidationException("商户不存在"); + } + + return p; + } + public Partner getCurrentPartner(){ String userId = SecurityUtils.getUserId(); Partner p = partnerMapper.selectOne(new QueryWrapper<Partner>() @@ -491,14 +558,19 @@ return p; } - public Supplier getCurrentSupplier(){ + public Supplier getCurrentSupplier() { String userId = SecurityUtils.getUserId(); Supplier s = supplierMapper.selectOne(new QueryWrapper<Supplier>() .eq("user_id", userId)); - if(s == null){ - throw new ValidationException("供应商信息未认证,请到个人中心进行认证"); + if (s == null) { + SupplierSub sub = supplierSubMapper.getCurrentSupplier(SecurityUtils.getUserId()); + if (!ObjectUtils.isEmpty(sub)) { + s = supplierMapper.selectById(sub.getSupplierId()); + return s; + } else { + throw new ValidationException("供应商信息未认证,请到个人中心进行认证"); + } } - return s; } -- Gitblit v1.9.3