使用优惠券处理
This commit is contained in:
@@ -201,9 +201,6 @@ public class BuyOrderController {
|
||||
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
|
||||
@Transactional
|
||||
public R placeOrder(@RequestBody BuyOrder buyOrder) {
|
||||
String orderSn = IdWorker.getTimeId().substring(0, 32);
|
||||
buyOrder.setOrderSn(orderSn);
|
||||
buyOrderService.save(buyOrder);
|
||||
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
|
||||
// 订单实收金额
|
||||
BigDecimal totalPrice = new BigDecimal(0);
|
||||
@@ -245,21 +242,27 @@ public class BuyOrderController {
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
//商品价格减去优惠券的优惠金额
|
||||
if (buyOrder!=null&&buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
CouponHistory couponHistory = couponHistoryService.getById(buyOrder.getCouponId());
|
||||
if (couponHistory!=null){
|
||||
if (couponHistory.getEffectType()!=0){
|
||||
if (couponHistory.getStartTime().getTime()<new Date().getTime()&&
|
||||
couponHistory.getEndTime().getTime()>new Date().getTime()){
|
||||
}else {
|
||||
return R.error("优惠券使用时间未到");
|
||||
if (couponHistory.getStatus()==0){
|
||||
if (couponHistory.getEffectType()!=0){
|
||||
if (couponHistory.getStartTime().getTime()<new Date().getTime()&&
|
||||
couponHistory.getEndTime().getTime()>new Date().getTime()){
|
||||
}else {
|
||||
return R.error("优惠券使用时间未到");
|
||||
}
|
||||
}
|
||||
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||
if (coupon != null){
|
||||
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
|
||||
}
|
||||
}else {
|
||||
if (couponHistory.getStatus()==1){
|
||||
return R.error("优惠券已被使用");
|
||||
}else if (couponHistory.getStatus() == 2){
|
||||
return R.error("优惠券已过期");
|
||||
}
|
||||
}
|
||||
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||
if (coupon != null){
|
||||
couponHistory.setOrderId(buyOrder.getOrderId());
|
||||
couponService.useCouponAmount(couponHistory);
|
||||
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,6 +279,8 @@ public class BuyOrderController {
|
||||
return R.error("系统错误订单金额异常!");
|
||||
}
|
||||
|
||||
String orderSn = IdWorker.getTimeId().substring(0, 32);
|
||||
buyOrder.setOrderSn(orderSn);
|
||||
if(buyOrder.getAddressId()!=0){
|
||||
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", buyOrder.getAddressId());
|
||||
@@ -292,7 +297,7 @@ public class BuyOrderController {
|
||||
}
|
||||
}
|
||||
buyOrder.setOrderStatus("0");
|
||||
buyOrderService.updateById(buyOrder);
|
||||
buyOrderService.save(buyOrder);
|
||||
|
||||
//解决购物车相关问题
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
@@ -492,7 +497,6 @@ public class BuyOrderController {
|
||||
}
|
||||
//回滚优惠卷
|
||||
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||
buyOrder.setCouponId(null);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
}
|
||||
@@ -542,7 +546,6 @@ public class BuyOrderController {
|
||||
if (buyOrder != null) {
|
||||
//回滚优惠卷
|
||||
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||
buyOrder.setCouponId(null);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user