注释用户删除订单功能

This commit is contained in:
wuchunlei
2025-10-12 15:12:26 +08:00
parent 41c47c89e8
commit 534975b4bb

View File

@@ -664,28 +664,28 @@ public class BuyOrderController {
@RequestMapping(value = "/cancelOrder", method = RequestMethod.GET)
@Transactional
public R appDelete(@RequestParam("orderSn") String orderSn) {
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){
buyOrder.setCouponId(null);
buyOrderService.updateById(buyOrder);
}
// 库存回滚
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(buyOrderProductQueryWrapper);
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
Integer productId = buyOrderProduct.getProductId();
ShopProduct product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
shopProductService.updateById(product);
}
buyOrderService.removeById(buyOrder.getOrderId());
// 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){
// buyOrder.setCouponId(null);
// buyOrderService.updateById(buyOrder);
// }
// // 库存回滚
// QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
// buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
// List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(buyOrderProductQueryWrapper);
// for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
// Integer productId = buyOrderProduct.getProductId();
// ShopProduct product = shopProductService.getById(productId);
// product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
// shopProductService.updateById(product);
// }
// buyOrderService.removeById(buyOrder.getOrderId());
return R.ok();
}
@@ -703,9 +703,9 @@ public class BuyOrderController {
*/
@RequestMapping("/delete")
public R delete(@RequestBody List<String> orderSnList) {
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.in("order_sn", orderSnList);
buyOrderService.remove(queryWrapper);
// QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
// queryWrapper.in("order_sn", orderSnList);
// buyOrderService.remove(queryWrapper);
return R.ok();
}
@@ -717,24 +717,24 @@ public class BuyOrderController {
@Transactional
public R appDelete(@RequestParam("orderId") Integer orderId) {
//1. 判断订单状态
BuyOrder buyOrder = buyOrderService.getById(orderId);
if (buyOrder != null) {
//回滚优惠卷
if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
buyOrder.setCouponId(null);
buyOrderService.updateById(buyOrder);
}
// 库存回滚
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", buyOrder.getOrderId()));
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
Integer productId = buyOrderDetailEntity.getProductId();
ShopProduct product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderDetailEntity.getQuantity());
shopProductService.updateById(product);
}
buyOrderService.removeById(orderId);
}
// BuyOrder buyOrder = buyOrderService.getById(orderId);
// if (buyOrder != null) {
// //回滚优惠卷
// if (buyOrder.getCouponId()!=null&&buyOrder.getCouponId()!=0){
// buyOrder.setCouponId(null);
// buyOrderService.updateById(buyOrder);
// }
// // 库存回滚
// List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
// .eq("order_id", buyOrder.getOrderId()));
// for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
// Integer productId = buyOrderDetailEntity.getProductId();
// ShopProduct product = shopProductService.getById(productId);
// product.setProductStock(product.getProductStock() + buyOrderDetailEntity.getQuantity());
// shopProductService.updateById(product);
// }
// buyOrderService.removeById(orderId);
// }
return R.ok();
}