|
@@ -10,6 +10,7 @@
|
|
|
|
|
|
package com.yami.shop.api.controller;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.yami.shop.bean.app.dto.*;
|
|
|
import com.yami.shop.bean.enums.OrderStatus;
|
|
@@ -18,20 +19,19 @@ import com.yami.shop.bean.model.OrderItem;
|
|
|
import com.yami.shop.bean.model.ShopDetail;
|
|
|
import com.yami.shop.bean.model.UserAddrOrder;
|
|
|
import com.yami.shop.common.exception.YamiShopBindException;
|
|
|
+import com.yami.shop.common.response.ServerResponseEntity;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.common.util.PageParam;
|
|
|
import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
import com.yami.shop.service.*;
|
|
|
-import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Parameters;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import com.yami.shop.common.response.ServerResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -46,7 +46,6 @@ public class MyOrderController {
|
|
|
|
|
|
private final OrderService orderService;
|
|
|
|
|
|
-
|
|
|
|
|
|
private final UserAddrOrderService userAddrOrderService;
|
|
|
|
|
@@ -65,9 +64,9 @@ public class MyOrderController {
|
|
|
* 订单详情信息接口
|
|
|
*/
|
|
|
@GetMapping("/orderDetail")
|
|
|
- @Operation(summary = "订单详情信息" , description = "根据订单号获取订单详情信息")
|
|
|
- @Parameter(name = "orderNumber", description = "订单号" , required = true)
|
|
|
- public ServerResponseEntity<OrderShopDto> orderDetail(@RequestParam(value = "orderNumber", required = true) String orderNumber) {
|
|
|
+ @Operation(summary = "订单详情信息", description = "根据订单号获取订单详情信息")
|
|
|
+ @Parameter(name = "orderNumber", description = "订单号", required = true)
|
|
|
+ public ServerResponseEntity<OrderShopDto> orderDetail(@RequestParam(value = "orderNumber") String orderNumber) {
|
|
|
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
OrderShopDto orderShopDto = new OrderShopDto();
|
|
@@ -85,13 +84,13 @@ public class MyOrderController {
|
|
|
UserAddrOrder userAddrOrder = userAddrOrderService.getById(order.getAddrOrderId());
|
|
|
UserAddrDto userAddrDto = BeanUtil.copyProperties(userAddrOrder, UserAddrDto.class);
|
|
|
List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(orderNumber);
|
|
|
- List<OrderItemDto> orderItemDtos = BeanUtil.copyToList(orderItems, OrderItemDto.class);
|
|
|
+ List<OrderItemDto> orderItemList = BeanUtil.copyToList(orderItems, OrderItemDto.class);
|
|
|
|
|
|
orderShopDto.setShopId(shopDetail.getShopId());
|
|
|
orderShopDto.setShopName(shopDetail.getShopName());
|
|
|
orderShopDto.setActualTotal(order.getActualTotal());
|
|
|
orderShopDto.setUserAddrDto(userAddrDto);
|
|
|
- orderShopDto.setOrderItemDtos(orderItemDtos);
|
|
|
+ orderShopDto.setOrderItemDtos(orderItemList);
|
|
|
orderShopDto.setTransfee(order.getFreightAmount());
|
|
|
orderShopDto.setReduceAmount(order.getReduceAmount());
|
|
|
orderShopDto.setCreateTime(order.getCreateTime());
|
|
@@ -115,12 +114,11 @@ public class MyOrderController {
|
|
|
* 订单列表接口
|
|
|
*/
|
|
|
@GetMapping("/myOrder")
|
|
|
- @Operation(summary = "订单列表信息" , description = "根据订单状态获取订单列表信息,状态为0时获取所有订单")
|
|
|
+ @Operation(summary = "订单列表信息", description = "根据订单状态获取订单列表信息,状态为0时获取所有订单")
|
|
|
@Parameters({
|
|
|
@Parameter(name = "status", description = "订单状态 1:待付款 2:待发货 3:待收货 4:待评价 5:成功 6:失败")
|
|
|
})
|
|
|
- public ServerResponseEntity<IPage<MyOrderDto>> myOrder(@RequestParam(value = "status") Integer status,PageParam<MyOrderDto> page) {
|
|
|
-
|
|
|
+ public ServerResponseEntity<IPage<MyOrderDto>> myOrder(@RequestParam(value = "status") Integer status, PageParam<MyOrderDto> page) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
IPage<MyOrderDto> myOrderDtoIpage = myOrderService.pageMyOrderByUserIdAndStatus(page, userId, status);
|
|
|
return ServerResponseEntity.success(myOrderDtoIpage);
|
|
@@ -130,8 +128,8 @@ public class MyOrderController {
|
|
|
* 取消订单
|
|
|
*/
|
|
|
@PutMapping("/cancel/{orderNumber}")
|
|
|
- @Operation(summary = "根据订单号取消订单" , description = "根据订单号取消订单")
|
|
|
- @Parameter(name = "orderNumber", description = "订单号" , required = true)
|
|
|
+ @Operation(summary = "根据订单号取消订单", description = "根据订单号取消订单")
|
|
|
+ @Parameter(name = "orderNumber", description = "订单号", required = true)
|
|
|
public ServerResponseEntity<String> cancel(@PathVariable("orderNumber") String orderNumber) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
Order order = orderService.getOrderByOrderNumber(orderNumber);
|
|
@@ -144,12 +142,12 @@ public class MyOrderController {
|
|
|
List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(orderNumber);
|
|
|
order.setOrderItems(orderItems);
|
|
|
// 取消订单
|
|
|
- orderService.cancelOrders(Arrays.asList(order));
|
|
|
+ orderService.cancelOrders(Collections.singletonList(order));
|
|
|
|
|
|
// 清除缓存
|
|
|
for (OrderItem orderItem : orderItems) {
|
|
|
productService.removeProductCacheByProdId(orderItem.getProdId());
|
|
|
- skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
|
|
|
+ skuService.removeSkuCacheBySkuId(orderItem.getSkuId(), orderItem.getProdId());
|
|
|
}
|
|
|
return ServerResponseEntity.success();
|
|
|
}
|
|
@@ -159,7 +157,7 @@ public class MyOrderController {
|
|
|
* 确认收货
|
|
|
*/
|
|
|
@PutMapping("/receipt/{orderNumber}")
|
|
|
- @Operation(summary = "根据订单号确认收货" , description = "根据订单号确认收货")
|
|
|
+ @Operation(summary = "根据订单号确认收货", description = "根据订单号确认收货")
|
|
|
public ServerResponseEntity<String> receipt(@PathVariable("orderNumber") String orderNumber) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
Order order = orderService.getOrderByOrderNumber(orderNumber);
|
|
@@ -172,11 +170,11 @@ public class MyOrderController {
|
|
|
List<OrderItem> orderItems = orderItemService.getOrderItemsByOrderNumber(orderNumber);
|
|
|
order.setOrderItems(orderItems);
|
|
|
// 确认收货
|
|
|
- orderService.confirmOrder(Arrays.asList(order));
|
|
|
+ orderService.confirmOrder(Collections.singletonList(order));
|
|
|
|
|
|
for (OrderItem orderItem : orderItems) {
|
|
|
productService.removeProductCacheByProdId(orderItem.getProdId());
|
|
|
- skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
|
|
|
+ skuService.removeSkuCacheBySkuId(orderItem.getSkuId(), orderItem.getProdId());
|
|
|
}
|
|
|
return ServerResponseEntity.success();
|
|
|
}
|
|
@@ -185,8 +183,8 @@ public class MyOrderController {
|
|
|
* 删除订单
|
|
|
*/
|
|
|
@DeleteMapping("/{orderNumber}")
|
|
|
- @Operation(summary = "根据订单号删除订单" , description = "根据订单号删除订单")
|
|
|
- @Parameter(name = "orderNumber", description = "订单号" , required = true)
|
|
|
+ @Operation(summary = "根据订单号删除订单", description = "根据订单号删除订单")
|
|
|
+ @Parameter(name = "orderNumber", description = "订单号", required = true)
|
|
|
public ServerResponseEntity<String> delete(@PathVariable("orderNumber") String orderNumber) {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
|
|
@@ -197,12 +195,12 @@ public class MyOrderController {
|
|
|
if (!Objects.equals(order.getUserId(), userId)) {
|
|
|
throw new YamiShopBindException("你没有权限获取该订单信息");
|
|
|
}
|
|
|
- if (!Objects.equals(order.getStatus(), OrderStatus.SUCCESS.value()) && !Objects.equals(order.getStatus(), OrderStatus.CLOSE.value()) ) {
|
|
|
+ if (!Objects.equals(order.getStatus(), OrderStatus.SUCCESS.value()) && !Objects.equals(order.getStatus(), OrderStatus.CLOSE.value())) {
|
|
|
throw new YamiShopBindException("订单未完成或未关闭,无法删除订单");
|
|
|
}
|
|
|
|
|
|
// 删除订单
|
|
|
- orderService.deleteOrders(Arrays.asList(order));
|
|
|
+ orderService.deleteOrders(Collections.singletonList(order));
|
|
|
|
|
|
return ServerResponseEntity.success("删除成功");
|
|
|
}
|
|
@@ -211,7 +209,7 @@ public class MyOrderController {
|
|
|
* 获取我的订单订单数量
|
|
|
*/
|
|
|
@GetMapping("/orderCount")
|
|
|
- @Operation(summary = "获取我的订单订单数量" , description = "获取我的订单订单数量")
|
|
|
+ @Operation(summary = "获取我的订单订单数量", description = "获取我的订单订单数量")
|
|
|
public ServerResponseEntity<OrderCountData> getOrderCount() {
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
OrderCountData orderCountMap = orderService.getOrderCount(userId);
|