优惠卷
复读
This commit is contained in:
@@ -20,6 +20,8 @@ import com.peanut.modules.book.vo.response.OrderAddressResponseVo;
|
||||
import com.peanut.modules.common.dao.JfTransactionDetailsDao;
|
||||
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
|
||||
import com.peanut.modules.pay.weChatPay.service.WxpayService;
|
||||
import com.peanut.modules.sys.entity.SysConfigEntity;
|
||||
@@ -30,7 +32,6 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -89,6 +90,10 @@ public class BuyOrderController {
|
||||
private UserCourseBuyDao userCourseBuyDao;
|
||||
@Autowired
|
||||
private JfTransactionDetailsDao jfTransactionDetailsDao;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@RequestMapping(value = "/decomposeShipment", method = RequestMethod.POST)
|
||||
public R decomposeShipment(@RequestBody BuyOrderListRequestVo requestVo) {
|
||||
@@ -195,7 +200,10 @@ public class BuyOrderController {
|
||||
*/
|
||||
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
|
||||
@Transactional
|
||||
public R placeOrder(@RequestBody BuyOrder buyOrder) throws IOException {
|
||||
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);
|
||||
@@ -237,7 +245,27 @@ public class BuyOrderController {
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
//商品价格减去优惠券的优惠金额
|
||||
// totalPrice = totalPrice.subtract(0);
|
||||
if (buyOrder!=null&&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("优惠券使用时间未到");
|
||||
}
|
||||
}
|
||||
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||
if (coupon != null){
|
||||
if (new BigDecimal(coupon.getUseLevel()).compareTo(totalPrice)>0){
|
||||
return R.error("未达到优惠券使用门槛");
|
||||
}
|
||||
couponHistory.setOrderId(buyOrder.getOrderId());
|
||||
couponService.useCouponAmount(couponHistory);
|
||||
totalPrice = totalPrice.subtract(coupon.getCouponAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//加上运费金额
|
||||
totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
|
||||
@@ -251,8 +279,6 @@ 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());
|
||||
@@ -269,7 +295,7 @@ public class BuyOrderController {
|
||||
}
|
||||
}
|
||||
buyOrder.setOrderStatus("0");
|
||||
buyOrderService.save(buyOrder);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
|
||||
//解决购物车相关问题
|
||||
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
|
||||
@@ -301,6 +327,11 @@ public class BuyOrderController {
|
||||
//消费用户积分并记录用户积分消费记录
|
||||
addEbookToUser(buyOrderProductList, buyOrder, 0);
|
||||
addCourseToUser(buyOrder);
|
||||
//发放优惠卷
|
||||
List<Integer> collect = buyOrderProductService.list(new LambdaQueryWrapper<BuyOrderProduct>()
|
||||
.eq(BuyOrderProduct::getOrderId, buyOrder.getOrderId()))
|
||||
.stream().map(BuyOrderProduct::getProductId).collect(Collectors.toList());
|
||||
couponService.insertCouponHistoryByProductId(collect);
|
||||
} else {
|
||||
return R.error(500, "天医币余额不足!");
|
||||
}
|
||||
@@ -459,10 +490,15 @@ public class BuyOrderController {
|
||||
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_sn", orderSn);
|
||||
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
|
||||
|
||||
if (buyOrder == null) {
|
||||
return R.error("订单不存在");
|
||||
}
|
||||
//回滚优惠卷
|
||||
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||
buyOrder.setCouponId(null);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
}
|
||||
// 库存回滚
|
||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
|
||||
@@ -500,18 +536,22 @@ public class BuyOrderController {
|
||||
|
||||
/**
|
||||
* app 端 取消订单
|
||||
* TODO 新版本上线后此方法删除
|
||||
*/
|
||||
@RequestMapping("/appDelete")
|
||||
@Transactional
|
||||
public R appDelete(@RequestParam("orderId") Integer orderId) {
|
||||
|
||||
//1. 判断订单状态
|
||||
BuyOrder byId = buyOrderService.getById(orderId);
|
||||
if (byId != null) {
|
||||
BuyOrder buyOrder = buyOrderService.getById(orderId);
|
||||
if (buyOrder != null) {
|
||||
//回滚优惠卷
|
||||
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
|
||||
couponService.rollbackCoupon(buyOrder.getCouponId());
|
||||
buyOrder.setCouponId(null);
|
||||
buyOrderService.updateById(buyOrder);
|
||||
}
|
||||
// 库存回滚
|
||||
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", byId.getOrderId()));
|
||||
.eq("order_id", buyOrder.getOrderId()));
|
||||
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
|
||||
Integer productId = buyOrderDetailEntity.getProductId();
|
||||
ShopProduct product = shopProductService.getById(productId);
|
||||
|
||||
Reference in New Issue
Block a user