gongzuming
2024-09-19 a768dc3daa04d35fedfbe75c0a59b9b2545b85c4
src/main/java/com/mzl/flower/service/BaseService.java
@@ -12,6 +12,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;
@@ -19,6 +20,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;
@@ -31,6 +33,7 @@
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -62,6 +65,13 @@
    @Autowired
    private FlowerCategoryMapper flowerCategoryMapper;
    @Autowired
    private MemberMapper memberMapper;
    protected Member getMember(Long levelId){
        return memberMapper.selectById(levelId);
    }
    @Autowired
    private StringCacheClient stringCacheClient;
@@ -479,6 +489,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>()