更新了商品管理模块
This commit is contained in:
parent
d95a82c2a9
commit
c008edf059
|
@ -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);
|
||||
|
|
|
@ -176,16 +176,40 @@ public class CategoryController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Web端用户查询商品类别
|
||||
* @return 商品类别列表
|
||||
*/
|
||||
@PostMapping("/list/web")
|
||||
@Operation(summary = "Web端用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategoryOnWeb")
|
||||
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<List<Category>> listCategoryOnWeb(HttpServletRequest request) {
|
||||
userService.getLoginUser(request);
|
||||
List<Category> list = categoryService.list();
|
||||
return ResultUtils.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有商品类别
|
||||
* @return 商品类别列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "(小程序端和Web端)用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory")
|
||||
@Operation(summary = "小程序端用户查询商品类别", description = "参数:无,权限:所有人,方法名:listCategory")
|
||||
public BaseResponse<List<Category>> listCategory(HttpServletRequest request) {
|
||||
userService.getLoginUser(request);
|
||||
List<Category> list = categoryService.list();
|
||||
return ResultUtils.success(list);
|
||||
|
||||
List<Category> categoryList = list.stream().filter(category -> {
|
||||
String typeName = category.getTypeName();
|
||||
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", typeName);
|
||||
long count = goodService.count(queryWrapper);
|
||||
return count != 0;
|
||||
}).toList();
|
||||
return ResultUtils.success(categoryList);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Boolean> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 订单备注
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,9 +11,9 @@ import java.util.List;
|
|||
public interface CartRecordService extends IService<CartRecord> {
|
||||
|
||||
/**
|
||||
* 处理用户购物车已存在该商品
|
||||
* 更新购物车的商品属性
|
||||
*/
|
||||
boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request);
|
||||
boolean updateCartGoodAttribute(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<CartRecordMapper, CartRec
|
|||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 处理用户购物车已存在该商品
|
||||
* 更新购物车的商品属性
|
||||
*/
|
||||
@Override
|
||||
public boolean dealAlreadyExistGood(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request) {
|
||||
public boolean updateCartGoodAttribute(CartRecordAddRequest cartRecordAddRequest, HttpServletRequest request) {
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
Long userId = loginUser.getId();
|
||||
Long goodId = cartRecordAddRequest.getGoodId();
|
||||
|
@ -53,11 +53,13 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
|
|||
queryWrapper.eq("goodId", goodId);
|
||||
CartRecord cartRecord = this.baseMapper.selectOne(queryWrapper);
|
||||
if (cartRecord != null) {
|
||||
// 如果购物车中已存在该商品, 就叠加数量
|
||||
cartRecord.setQuantity(cartRecord.getQuantity() + cartRecordAddRequest.getQuantity());
|
||||
cartRecord.setSubtotal(cartRecord.getSubtotal().add(cartRecordAddRequest.getSubtotal()));
|
||||
boolean result = this.updateById(cartRecord);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "更新购物车商品数量失败");
|
||||
} else {
|
||||
// 如果购物车不存在该商品,就向购物车中添加一项
|
||||
CartRecord cartGood = new CartRecord();
|
||||
BeanUtils.copyProperties(cartRecordAddRequest, cartGood);
|
||||
cartGood.setUserId(userId);
|
||||
|
@ -88,9 +90,9 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
|
|||
QueryWrapper<Good> 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<CartRecordMapper, CartRec
|
|||
Long goodId = cartRecord.getGoodId();
|
||||
Integer quantity = cartRecord.getQuantity();
|
||||
BigDecimal subtotal = cartRecord.getSubtotal();
|
||||
Integer isGoodType = cartRecord.getIsGoodType();
|
||||
if (update) {
|
||||
if (userId == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
|
@ -122,9 +123,5 @@ public class CartRecordServiceImpl extends ServiceImpl<CartRecordMapper, CartRec
|
|||
if (ObjectUtils.isEmpty(subtotal) || subtotal.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "价格错误");
|
||||
}
|
||||
if (ObjectUtils.isEmpty(isGoodType) || isGoodType != 1 && isGoodType != 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请传递正确的商品类别");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user