新增优惠券使用
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -40,3 +40,5 @@ build/
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
/file/
|
||||
/websoft-modules.log
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ShopUserCoupon implements Serializable {
|
||||
private LocalDateTime useTime;
|
||||
|
||||
@Schema(description = "使用订单ID")
|
||||
private Long orderId;
|
||||
private Integer orderId;
|
||||
|
||||
@Schema(description = "是否已使用")
|
||||
private Integer isUse;
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -46,6 +47,8 @@ public class OrderBusinessService {
|
||||
|
||||
@Resource
|
||||
private ShopUserAddressService shopUserAddressService;
|
||||
@Resource
|
||||
private ShopUserCouponService shopUserCouponService;
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
@@ -274,6 +277,29 @@ public class OrderBusinessService {
|
||||
shopOrder.setPayType(1); // 默认微信支付
|
||||
}
|
||||
|
||||
// 优惠券
|
||||
if (shopOrder.getCouponId() != null && shopOrder.getCouponId() > 0) {
|
||||
ShopUserCoupon coupon = shopUserCouponService.getById(shopOrder.getCouponId());
|
||||
if (coupon != null) {
|
||||
BigDecimal reducePrice = BigDecimal.ZERO;
|
||||
boolean doReduce = true;
|
||||
if (coupon.getType().equals(10)) {
|
||||
reducePrice = coupon.getReducePrice();
|
||||
if (shopOrder.getTotalPrice().compareTo(coupon.getMinPrice()) < 0) doReduce = false;
|
||||
} else if (coupon.getType().equals(20)) {
|
||||
reducePrice = shopOrder.getTotalPrice()
|
||||
.multiply(BigDecimal.valueOf(coupon.getDiscount()).divide(new BigDecimal(100), RoundingMode.HALF_UP));
|
||||
} else if (coupon.getType().equals(30)) {
|
||||
reducePrice = shopOrder.getTotalPrice();
|
||||
}
|
||||
if (doReduce) {
|
||||
shopOrder.setReducePrice(shopOrder.getReducePrice().add(reducePrice));
|
||||
shopOrder.setPayPrice(shopOrder.getPayPrice().subtract(reducePrice));
|
||||
}
|
||||
// todo 商品/分类限制
|
||||
}
|
||||
}
|
||||
|
||||
return shopOrder;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -74,6 +75,8 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
|
||||
private WechatPayCertificateDiagnostic certificateDiagnostic;
|
||||
@Resource
|
||||
private ShopOrderUpdate10550Service shopOrderUpdate10550Service;
|
||||
@Resource
|
||||
private ShopUserCouponService shopUserCouponService;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -249,6 +252,18 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder
|
||||
@Override
|
||||
public void updateByOutTradeNo(ShopOrder order) {
|
||||
baseMapper.updateByOutTradeNo(order);
|
||||
// 使用优惠券
|
||||
if (order.getCouponId() != null && order.getCouponId() > 0) {
|
||||
ShopUserCoupon coupon = shopUserCouponService.getById(order.getCouponId());
|
||||
if (coupon != null) {
|
||||
coupon.setStatus(1);
|
||||
coupon.setIsUse(1);
|
||||
coupon.setUseTime(LocalDateTime.now());
|
||||
coupon.setOrderId(order.getOrderId());
|
||||
coupon.setOrderNo(order.getOrderNo());
|
||||
shopUserCouponService.updateById(coupon);
|
||||
}
|
||||
}
|
||||
if (order.getTenantId().equals(10550)) {
|
||||
shopOrderUpdate10550Service.update(order);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user