|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|