CouponServiceImpl.java 811 B

1234567891011121314151617181920212223242526
  1. package conm.zhentao.service.impl;
  2. import conm.zhentao.service.CouponService;
  3. import org.springframework.stereotype.Service;
  4. import java.math.BigDecimal;
  5. @Service
  6. public class CouponServiceImpl implements CouponService {
  7. @Override
  8. public BigDecimal calculateDiscount(Long couponId, BigDecimal totalAmount) {
  9. // 这里实现优惠券折扣计算逻辑
  10. // 示例:假设优惠券是满100减10
  11. if (totalAmount.compareTo(new BigDecimal("100")) >= 0) {
  12. return new BigDecimal("10");
  13. }
  14. return BigDecimal.ZERO;
  15. }
  16. @Override
  17. public void useCoupon(Long couponId, Long userId) {
  18. // 这里实现优惠券使用逻辑
  19. // 示例:更新优惠券状态为已使用
  20. // couponMapper.updateStatus(couponId, userId, 1);
  21. }
  22. }