更新了商品类别
This commit is contained in:
parent
04a727d66f
commit
c969bf0ef5
|
@ -31,10 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cart")
|
||||
|
@ -106,6 +103,7 @@ public class CartRecordController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户删除购物车的物品
|
||||
* @param idList 删除的商品id列表
|
||||
|
@ -124,6 +122,7 @@ public class CartRecordController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序端用户查询购物车中的商品
|
||||
* @return 商品列表信息
|
||||
|
@ -136,6 +135,7 @@ public class CartRecordController {
|
|||
Long userId = loginUser.getId();
|
||||
QueryWrapper<CartRecord> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId", userId);
|
||||
queryWrapper.orderByDesc("id");
|
||||
List<CartRecord> list = cartRecordService.list(queryWrapper);
|
||||
// 封装用户购物车中的商品信息
|
||||
List<CartRecordVO> cartRecordVOList = cartRecordService.transformToCartRecordVOList(list);
|
||||
|
@ -215,6 +215,7 @@ public class CartRecordController {
|
|||
cartOrderVO.setQuantity(quantity);
|
||||
cartOrderVOList.add(cartOrderVO);
|
||||
}
|
||||
Collections.reverse(cartOrderVOList);
|
||||
return ResultUtils.success(cartOrderVOList);
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,10 @@ public class CategoryController {
|
|||
if (StringUtils.isBlank(typeName)) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
List<Good> goodList = goodService.getGoodListByTypeName(typeName);
|
||||
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("type", typeName);
|
||||
queryWrapper.orderByDesc("id");
|
||||
List<Good> goodList = goodService.list(queryWrapper);
|
||||
Map<Long, List<Good>> map = new HashMap<>();
|
||||
map.put(id, goodList);
|
||||
return ResultUtils.success(map);
|
||||
|
|
|
@ -39,10 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
|
@ -106,13 +103,15 @@ public class OrderController {
|
|||
queryWrapper.in("id", cartIds);
|
||||
List<CartRecord> cartRecordList = cartRecordService.list(queryWrapper);
|
||||
|
||||
// 计算订单总金额
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
for (CartRecord cartRecord : cartRecordList) {
|
||||
totalAmount = totalAmount.add(cartRecord.getSubtotal());
|
||||
List<Long> goodIds = cartRecordList.stream().map(CartRecord::getGoodId).toList();
|
||||
QueryWrapper<Good> goodQueryWrapper = new QueryWrapper<>();
|
||||
goodQueryWrapper.in("id", goodIds);
|
||||
List<Good> goodList = goodService.list(goodQueryWrapper);
|
||||
// 封装map集合(键:商品id, 值:商品信息)
|
||||
Map<Long, Good> goodMap = new HashMap<>();
|
||||
for (Good good : goodList) {
|
||||
goodMap.put(good.getId(), good);
|
||||
}
|
||||
orderMainInfoAddRequest.setTotalAmount(totalAmount);
|
||||
|
||||
// 封装成一个map集合(键:购物车id, 值:购物车商品数量)
|
||||
Map<Long, Integer> map = new HashMap<>();
|
||||
for (CartOrderItemAddRequest cartOrderItemAddRequest : cartOrderItemAddRequestList) {
|
||||
|
@ -120,6 +119,18 @@ public class OrderController {
|
|||
Integer quantity = cartOrderItemAddRequest.getQuantity();
|
||||
map.put(cartRecordId, quantity);
|
||||
}
|
||||
|
||||
// 计算订单总金额
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
for (CartRecord cartRecord : cartRecordList) {
|
||||
Long goodId = cartRecord.getGoodId();
|
||||
Good good = goodMap.get(goodId);
|
||||
Long cartRecordId = cartRecord.getId();
|
||||
Integer quantity = map.get(cartRecordId);
|
||||
totalAmount = totalAmount.add(good.getPrice().multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
|
||||
orderMainInfoAddRequest.setTotalAmount(totalAmount);
|
||||
// 封装成订单明细主要信息请求体列表
|
||||
List<OrderItemMainInfoAddRequest> orderItemMainInfoAddRequestList = new ArrayList<>();
|
||||
OrderItemMainInfoAddRequest orderItemMainInfoAddRequest;
|
||||
|
@ -156,6 +167,9 @@ public class OrderController {
|
|||
Long userId = loginUser.getId();
|
||||
// 校验单独购买的商品数据是否准确
|
||||
orderService.validSingleGoodOrder(orderMainInfoAddRequest);
|
||||
// 计算单个商品购买的总金额
|
||||
BigDecimal totalAmount = orderService.calculateTotalAmount(orderMainInfoAddRequest);
|
||||
orderMainInfoAddRequest.setTotalAmount(totalAmount);
|
||||
// 创建通用订单(常规类和服务类商品)
|
||||
Long orderId = orderService.createCommonOrder(orderMainInfoAddRequest, userId, false, null);
|
||||
return ResultUtils.success(orderId);
|
||||
|
@ -214,6 +228,7 @@ public class OrderController {
|
|||
Long id = loginUser.getId();
|
||||
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId", id);
|
||||
queryWrapper.orderByDesc("id");
|
||||
List<Order> orders = orderService.list(queryWrapper);
|
||||
List<OrderVO> orderVOS = orders.stream().map(order -> {
|
||||
Long orderId = order.getId();
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.cultural.heritage.model.dto.order.OrderQueryRequest;
|
|||
import com.cultural.heritage.model.dto.order.capital.OrderMainInfoAddRequest;
|
||||
import com.cultural.heritage.model.entity.Order;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderService extends IService<Order> {
|
||||
|
@ -41,4 +42,11 @@ public interface OrderService extends IService<Order> {
|
|||
* 校验单独购买的商品数据是否准确
|
||||
*/
|
||||
void validSingleGoodOrder(OrderMainInfoAddRequest orderMainInfoAddRequest);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 计算单个商品购买的总金额
|
||||
*/
|
||||
BigDecimal calculateTotalAmount(OrderMainInfoAddRequest orderMainInfoAddRequest);
|
||||
}
|
||||
|
|
|
@ -286,6 +286,19 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* 计算单个商品购买的总金额
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal calculateTotalAmount(OrderMainInfoAddRequest orderMainInfoAddRequest) {
|
||||
List<OrderItemMainInfoAddRequest> orderItemMainInfoAddRequestList = orderMainInfoAddRequest.getOrderItemMainInfoAddRequestList();
|
||||
OrderItemMainInfoAddRequest orderItemMainInfoAddRequest = orderItemMainInfoAddRequestList.get(0);
|
||||
Integer quantity = orderItemMainInfoAddRequest.getQuantity();
|
||||
Long goodId = orderItemMainInfoAddRequest.getGoodId();
|
||||
Good good = goodService.getById(goodId);
|
||||
return good.getPrice().multiply(BigDecimal.valueOf(quantity));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取订单(地址,联系人,优惠券,商品)信息
|
||||
|
|
Loading…
Reference in New Issue
Block a user