diff --git a/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java b/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java index fda14c5..b4193bc 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CartRecordController.java @@ -14,7 +14,7 @@ import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.vo.cart.CartOrderVO; import com.cultural.heritage.model.vo.cart.CartRecordQueryVO; import com.cultural.heritage.model.vo.cart.CartRecordVO; -import com.cultural.heritage.model.vo.good.GoodVO; +import com.cultural.heritage.model.vo.cart.CartGoodVO; import com.cultural.heritage.service.good.CartRecordService; import com.cultural.heritage.service.good.GoodService; import com.cultural.heritage.service.user.UserService; @@ -61,8 +61,9 @@ public class CartRecordController { if (cartRecordAddRequest == null) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } - boolean result = cartRecordService.dealAlreadyExistGood(cartRecordAddRequest, request); - return ResultUtils.success(result); + // 更新购物车的商品属性 + cartRecordService.updateCartGoodAttribute(cartRecordAddRequest, request); + return ResultUtils.success(true); } @@ -112,8 +113,8 @@ public class CartRecordController { /** - * 展示用户购物车中的商品 - * @return + * 小程序端用户查询购物车中的商品 + * @return 商品列表信息 */ @PostMapping("/list") @Operation(summary = "小程序端用户查询购物车中的商品", description = "参数:无,权限:所有人,方法名:listUserCartRecord") @@ -129,6 +130,7 @@ public class CartRecordController { } + /** * 展示用户批量购买后的订单信息 * @param cartRecordQueryVOList 商品id和数量的集合 @@ -145,9 +147,9 @@ public class CartRecordController { Long goodId = cartRecordQueryVO.getGoodId(); Integer quantity = cartRecordQueryVO.getQuantity(); Good good = goodService.getById(goodId); - ThrowUtils.throwIf(good == null, ErrorCode.OPERATION_ERROR, "找不到该商品"); + ThrowUtils.throwIf(good == null || good.getIsShelves() == 0, ErrorCode.OPERATION_ERROR, "找不到该商品或者该商品已下架"); CartOrderVO cartOrderVO = new CartOrderVO(); - GoodVO goodVO = new GoodVO(); + CartGoodVO goodVO = new CartGoodVO(); BeanUtils.copyProperties(good, goodVO); cartOrderVO.setGoodVO(goodVO); diff --git a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java index fb7a3ad..9ae83b0 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CategoryController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CategoryController.java @@ -176,16 +176,40 @@ public class CategoryController { } + /** + * Web端用户查询商品类别 + * @return 商品类别列表 + */ + @PostMapping("/list/web") + @Operation(summary = "Web端用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategoryOnWeb") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse> listCategoryOnWeb(HttpServletRequest request) { + userService.getLoginUser(request); + List list = categoryService.list(); + return ResultUtils.success(list); + } + + + + /** * 查询所有商品类别 * @return 商品类别列表 */ @PostMapping("/list") - @Operation(summary = "(小程序端和Web端)用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory") + @Operation(summary = "小程序端用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory") public BaseResponse> listCategory(HttpServletRequest request) { userService.getLoginUser(request); List list = categoryService.list(); - return ResultUtils.success(list); + + List categoryList = list.stream().filter(category -> { + String typeName = category.getTypeName(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("type", typeName); + long count = goodService.count(queryWrapper); + return count != 0; + }).toList(); + return ResultUtils.success(categoryList); } diff --git a/src/main/java/com/cultural/heritage/controller/order/OrderController.java b/src/main/java/com/cultural/heritage/controller/order/OrderController.java index 263d377..378d4df 100644 --- a/src/main/java/com/cultural/heritage/controller/order/OrderController.java +++ b/src/main/java/com/cultural/heritage/controller/order/OrderController.java @@ -32,7 +32,10 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -220,4 +223,31 @@ public class OrderController { } + + /** + * 小程序端用户取消订单 + * @param commonRequest 订单id + * @return 是否取消成功 + */ + @PostMapping ("/cancel/id") + @Operation(summary = "小程序端用户取消订单", description = "参数:订单id,权限:所有人,方法名:cancelOrderById") + public BaseResponse cancelOrderById(@RequestBody CommonRequest commonRequest, HttpServletRequest request) { + if (commonRequest == null || commonRequest.getId() <= 0) { + throw new BusinessException(ErrorCode.PARAMS_ERROR); + } + Long id = commonRequest.getId(); + userService.getLoginUser(request); + Order order = orderService.getById(id); + ThrowUtils.throwIf(order == null, ErrorCode.OPERATION_ERROR, "订单不存在"); + order.setOrderStatus(OrderStatusConstant.TRANSACTION_CLOSED); + boolean update = orderService.updateById(order); + ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "订单状态更新失败"); + return ResultUtils.success(true); + } + + + + + + } diff --git a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java index 4923d53..45a0ff4 100644 --- a/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/cart/CartRecordAddRequest.java @@ -8,7 +8,7 @@ import java.io.Serializable; import java.math.BigDecimal; @Data -@Schema(description = "购物车记录添加请求体", requiredProperties = {"userId", "goodId", "quantity", "subtotal", "isGoodType"}) +@Schema(description = "购物车记录添加请求体", requiredProperties = {"userId", "goodId", "quantity", "subtotal"}) public class CartRecordAddRequest implements Serializable { /** @@ -29,12 +29,6 @@ public class CartRecordAddRequest implements Serializable { @Schema(description = "小计(商品单价 * 数量)", example = "60") private BigDecimal subtotal; - /** - * 是否是常规类商品 - */ - @Schema(description = "是否是常规类商品", example = "1") - private Integer isGoodType; - @Serial diff --git a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java index c3bad9e..bef895e 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/capital/OrderMainInfoAddRequest.java @@ -14,13 +14,6 @@ import java.util.List; public class OrderMainInfoAddRequest implements Serializable { -// /** -// * 用户id -// */ -// @Schema(description = "用户id(id > 0)", example = "2") -// private Long userId; - - /** * 订单类别 */ @@ -34,13 +27,6 @@ public class OrderMainInfoAddRequest implements Serializable { @Schema(description = "用户昵称", example = "Hello") private String userName; -// -// /** -// * 订单编号 -// */ -// @Schema(description = "订单编号", example = "1432442845453453") -// private String orderNumber; - /** * 地址id @@ -69,11 +55,6 @@ public class OrderMainInfoAddRequest implements Serializable { @Schema(description = "订单总金额", example = "560") private BigDecimal totalAmount; -// /** -// * 订单状态 -// */ -// @Schema(description = "订单状态", example = "已支付") -// private String orderStatus; /** * 订单备注 diff --git a/src/main/java/com/cultural/heritage/model/entity/CartRecord.java b/src/main/java/com/cultural/heritage/model/entity/CartRecord.java index 0440648..10a16c2 100644 --- a/src/main/java/com/cultural/heritage/model/entity/CartRecord.java +++ b/src/main/java/com/cultural/heritage/model/entity/CartRecord.java @@ -11,7 +11,7 @@ import java.math.BigDecimal; import java.util.Date; /** - * 购物车添加记录 + * 常规类购物车添加商品 * @TableName cart_record */ @Data @@ -57,9 +57,10 @@ public class CartRecord implements Serializable { private Date updateTime; /** - * 是否为商品类型 + * 是否删除 */ - private Integer isGoodType; + private Integer isDelete; + @Serial diff --git a/src/main/java/com/cultural/heritage/model/vo/good/GoodVO.java b/src/main/java/com/cultural/heritage/model/vo/cart/CartGoodVO.java similarity index 70% rename from src/main/java/com/cultural/heritage/model/vo/good/GoodVO.java rename to src/main/java/com/cultural/heritage/model/vo/cart/CartGoodVO.java index 9162119..907d15a 100644 --- a/src/main/java/com/cultural/heritage/model/vo/good/GoodVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/cart/CartGoodVO.java @@ -1,4 +1,4 @@ -package com.cultural.heritage.model.vo.good; +package com.cultural.heritage.model.vo.cart; import lombok.Data; @@ -7,7 +7,7 @@ import java.io.Serializable; import java.math.BigDecimal; @Data -public class GoodVO implements Serializable { +public class CartGoodVO implements Serializable { /** * 商品编号 @@ -41,17 +41,6 @@ public class GoodVO implements Serializable { private Integer inventory; - /** - * 商品标签 - */ - private String label; - - /** - * 是否是常规类商品 - */ - private Integer isGoodType; - - @Serial private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/cultural/heritage/model/vo/cart/CartOrderVO.java b/src/main/java/com/cultural/heritage/model/vo/cart/CartOrderVO.java index 5ac512d..0eb3500 100644 --- a/src/main/java/com/cultural/heritage/model/vo/cart/CartOrderVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/cart/CartOrderVO.java @@ -1,6 +1,5 @@ package com.cultural.heritage.model.vo.cart; -import com.cultural.heritage.model.vo.good.GoodVO; import lombok.Data; import java.io.Serial; @@ -13,7 +12,7 @@ public class CartOrderVO implements Serializable { /** * 商品详细信息 */ - private GoodVO goodVO; + private CartGoodVO goodVO; /** diff --git a/src/main/java/com/cultural/heritage/model/vo/cart/CartRecordVO.java b/src/main/java/com/cultural/heritage/model/vo/cart/CartRecordVO.java index 143cd75..6913a32 100644 --- a/src/main/java/com/cultural/heritage/model/vo/cart/CartRecordVO.java +++ b/src/main/java/com/cultural/heritage/model/vo/cart/CartRecordVO.java @@ -1,6 +1,5 @@ package com.cultural.heritage.model.vo.cart; -import com.cultural.heritage.model.vo.good.GoodVO; import lombok.Data; import java.io.Serial; @@ -16,11 +15,6 @@ public class CartRecordVO implements Serializable { */ private Long id; - /** - * 用户id - */ - private Long userId; - /** * 商品id */ @@ -40,13 +34,7 @@ public class CartRecordVO implements Serializable { /** * 购物车商品详情信息 */ - private GoodVO goodVO; - - /** - * 是否是常规类商品 - */ - private Integer isGoodType; - + private CartGoodVO cartGoodVO; @Serial diff --git a/src/main/java/com/cultural/heritage/service/good/CartRecordService.java b/src/main/java/com/cultural/heritage/service/good/CartRecordService.java index 5a4e991..ba1b10c 100644 --- a/src/main/java/com/cultural/heritage/service/good/CartRecordService.java +++ b/src/main/java/com/cultural/heritage/service/good/CartRecordService.java @@ -11,9 +11,9 @@ import java.util.List; public interface CartRecordService extends IService { /** - * 处理用户购物车已存在该商品 + * 更新购物车的商品属性 */ - boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request); + boolean updateCartGoodAttribute(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request); /** diff --git a/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java b/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java index 44f416b..4006ea9 100644 --- a/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java +++ b/src/main/java/com/cultural/heritage/service/good/impl/CartRecordServiceImpl.java @@ -12,7 +12,7 @@ import com.cultural.heritage.model.entity.CartRecord; import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.model.entity.User; import com.cultural.heritage.model.vo.cart.CartRecordVO; -import com.cultural.heritage.model.vo.good.GoodVO; +import com.cultural.heritage.model.vo.cart.CartGoodVO; import com.cultural.heritage.service.good.CartRecordService; import com.cultural.heritage.service.good.GoodService; import com.cultural.heritage.service.user.UserService; @@ -41,10 +41,10 @@ public class CartRecordServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("id", goodId); Good good = goodMapper.selectOne(queryWrapper); - GoodVO goodVO = new GoodVO(); + CartGoodVO goodVO = new CartGoodVO(); BeanUtils.copyProperties(good, goodVO); - cartRecordVO.setGoodVO(goodVO); + cartRecordVO.setCartGoodVO(goodVO); return cartRecordVO; }).toList(); } @@ -106,7 +108,6 @@ public class CartRecordServiceImpl extends ServiceImpl