订单:

1. 拆分读写 OrderService,避免单 Service 逻辑过重。
This commit is contained in:
YunaiV 2023-08-15 21:19:13 +08:00
parent 159c74ce15
commit a159a983a2
12 changed files with 333 additions and 335 deletions

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.trade.api.order; package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -20,12 +20,12 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_
public class TradeOrderApiImpl implements TradeOrderApi { public class TradeOrderApiImpl implements TradeOrderApi {
@Resource @Resource
private TradeOrderService tradeOrderService; private TradeOrderQueryService tradeOrderQueryService;
@Override @Override
public Long validateOrder(Long userId, Long orderItemId) { public Long validateOrder(Long userId, Long orderItemId) {
// 校验订单项订单项存在订单就存在 // 校验订单项订单项存在订单就存在
TradeOrderItemDO item = tradeOrderService.getOrderItem(userId, orderItemId); TradeOrderItemDO item = tradeOrderQueryService.getOrderItem(userId, orderItemId);
if (item == null) { if (item == null) {
throw exception(ORDER_ITEM_NOT_FOUND); throw exception(ORDER_ITEM_NOT_FOUND);
} }

View File

@ -14,7 +14,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReq
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -39,7 +40,9 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
public class TradeOrderController { public class TradeOrderController {
@Resource @Resource
private TradeOrderService tradeOrderService; private TradeOrderUpdateService tradeOrderUpdateService;
@Resource
private TradeOrderQueryService tradeOrderQueryService;
@Resource @Resource
private ProductPropertyValueApi productPropertyValueApi; private ProductPropertyValueApi productPropertyValueApi;
@ -51,7 +54,7 @@ public class TradeOrderController {
@PreAuthorize("@ss.hasPermission('trade:order:query')") @PreAuthorize("@ss.hasPermission('trade:order:query')")
public CommonResult<PageResult<TradeOrderPageItemRespVO>> getOrderPage(TradeOrderPageReqVO reqVO) { public CommonResult<PageResult<TradeOrderPageItemRespVO>> getOrderPage(TradeOrderPageReqVO reqVO) {
// 查询订单 // 查询订单
PageResult<TradeOrderDO> pageResult = tradeOrderService.getOrderPage(reqVO); PageResult<TradeOrderDO> pageResult = tradeOrderQueryService.getOrderPage(reqVO);
if (CollUtil.isEmpty(pageResult.getList())) { if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty()); return success(PageResult.empty());
} }
@ -59,7 +62,7 @@ public class TradeOrderController {
// 查询用户信息 // 查询用户信息
Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), TradeOrderDO::getUserId));; Map<Long, MemberUserRespDTO> userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), TradeOrderDO::getUserId));;
// 查询订单项 // 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId( List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
convertSet(pageResult.getList(), TradeOrderDO::getId)); convertSet(pageResult.getList(), TradeOrderDO::getId));
// 查询商品属性 // 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
@ -74,9 +77,9 @@ public class TradeOrderController {
@PreAuthorize("@ss.hasPermission('trade:order:query')") @PreAuthorize("@ss.hasPermission('trade:order:query')")
public CommonResult<TradeOrderDetailRespVO> getOrderDetail(@RequestParam("id") Long id) { public CommonResult<TradeOrderDetailRespVO> getOrderDetail(@RequestParam("id") Long id) {
// 查询订单 // 查询订单
TradeOrderDO order = tradeOrderService.getOrder(id); TradeOrderDO order = tradeOrderQueryService.getOrder(id);
// 查询订单项 // 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId(id); List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
// 查询商品属性 // 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
@ -90,7 +93,7 @@ public class TradeOrderController {
@Operation(summary = "发货订单") @Operation(summary = "发货订单")
@PreAuthorize("@ss.hasPermission('trade:order:delivery')") @PreAuthorize("@ss.hasPermission('trade:order:delivery')")
public CommonResult<Boolean> deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) { public CommonResult<Boolean> deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) {
tradeOrderService.deliveryOrder(getLoginUserId(), deliveryReqVO); tradeOrderUpdateService.deliveryOrder(getLoginUserId(), deliveryReqVO);
return success(true); return success(true);
} }

View File

@ -17,7 +17,7 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
public class AppTradeOrderController { public class AppTradeOrderController {
@Resource @Resource
private TradeOrderService tradeOrderService; private TradeOrderUpdateService tradeOrderUpdateService;
@Resource @Resource
private TradeOrderQueryService tradeOrderQueryService; private TradeOrderQueryService tradeOrderQueryService;
@Resource @Resource
@ -60,21 +60,21 @@ public class AppTradeOrderController {
@Operation(summary = "获得订单结算信息") @Operation(summary = "获得订单结算信息")
@PreAuthenticated @PreAuthenticated
public CommonResult<AppTradeOrderSettlementRespVO> settlementOrder(@Valid AppTradeOrderSettlementReqVO settlementReqVO) { public CommonResult<AppTradeOrderSettlementRespVO> settlementOrder(@Valid AppTradeOrderSettlementReqVO settlementReqVO) {
return success(tradeOrderService.settlementOrder(getLoginUserId(), settlementReqVO)); return success(tradeOrderUpdateService.settlementOrder(getLoginUserId(), settlementReqVO));
} }
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建订单") @Operation(summary = "创建订单")
@PreAuthenticated @PreAuthenticated
public CommonResult<AppTradeOrderCreateRespVO> createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) { public CommonResult<AppTradeOrderCreateRespVO> createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) {
TradeOrderDO order = tradeOrderService.createOrder(getLoginUserId(), getClientIP(), createReqVO); TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), getClientIP(), createReqVO);
return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId()));
} }
@PostMapping("/update-paid") @PostMapping("/update-paid")
@Operation(summary = "更新订单为已支付") // pay-module 支付服务进行回调可见 PayNotifyJob @Operation(summary = "更新订单为已支付") // pay-module 支付服务进行回调可见 PayNotifyJob
public CommonResult<Boolean> updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { public CommonResult<Boolean> updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) {
tradeOrderService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), tradeOrderUpdateService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),
notifyReqDTO.getPayOrderId()); notifyReqDTO.getPayOrderId());
return success(true); return success(true);
} }
@ -84,13 +84,13 @@ public class AppTradeOrderController {
@Parameter(name = "id", description = "交易订单编号") @Parameter(name = "id", description = "交易订单编号")
public CommonResult<AppTradeOrderDetailRespVO> getOrder(@RequestParam("id") Long id) { public CommonResult<AppTradeOrderDetailRespVO> getOrder(@RequestParam("id") Long id) {
// 查询订单 // 查询订单
TradeOrderDO order = tradeOrderService.getOrder(getLoginUserId(), id); TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id);
if (order == null) { if (order == null) {
return success(null); return success(null);
} }
// 查询订单项 // 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId(order.getId()); List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId());
// 查询商品属性 // 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
@ -114,9 +114,9 @@ public class AppTradeOrderController {
@Operation(summary = "获得交易订单分页") @Operation(summary = "获得交易订单分页")
public CommonResult<PageResult<AppTradeOrderPageItemRespVO>> getOrderPage(AppTradeOrderPageReqVO reqVO) { public CommonResult<PageResult<AppTradeOrderPageItemRespVO>> getOrderPage(AppTradeOrderPageReqVO reqVO) {
// 查询订单 // 查询订单
PageResult<TradeOrderDO> pageResult = tradeOrderService.getOrderPage(getLoginUserId(), reqVO); PageResult<TradeOrderDO> pageResult = tradeOrderQueryService.getOrderPage(getLoginUserId(), reqVO);
// 查询订单项 // 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId( List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
convertSet(pageResult.getList(), TradeOrderDO::getId)); convertSet(pageResult.getList(), TradeOrderDO::getId));
// 查询商品属性 // 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
@ -130,18 +130,18 @@ public class AppTradeOrderController {
public CommonResult<Map<String, Long>> getOrderCount() { public CommonResult<Map<String, Long>> getOrderCount() {
Map<String, Long> orderCount = Maps.newLinkedHashMapWithExpectedSize(5); Map<String, Long> orderCount = Maps.newLinkedHashMapWithExpectedSize(5);
// 全部 // 全部
orderCount.put("allCount", tradeOrderService.getOrderCount(getLoginUserId(), null, null)); orderCount.put("allCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), null, null));
// 待付款未支付 // 待付款未支付
orderCount.put("unpaidCount", tradeOrderService.getOrderCount(getLoginUserId(), orderCount.put("unpaidCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
TradeOrderStatusEnum.UNPAID.getStatus(), null)); TradeOrderStatusEnum.UNPAID.getStatus(), null));
// 待发货 // 待发货
orderCount.put("undeliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), orderCount.put("undeliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
TradeOrderStatusEnum.UNDELIVERED.getStatus(), null)); TradeOrderStatusEnum.UNDELIVERED.getStatus(), null));
// 待收货 // 待收货
orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), orderCount.put("deliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
TradeOrderStatusEnum.DELIVERED.getStatus(), null)); TradeOrderStatusEnum.DELIVERED.getStatus(), null));
// 待评价 // 待评价
orderCount.put("uncommentedCount", tradeOrderService.getOrderCount(getLoginUserId(), orderCount.put("uncommentedCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
TradeOrderStatusEnum.COMPLETED.getStatus(), false)); TradeOrderStatusEnum.COMPLETED.getStatus(), false));
return success(orderCount); return success(orderCount);
} }
@ -150,7 +150,7 @@ public class AppTradeOrderController {
@Operation(summary = "确认交易订单收货") @Operation(summary = "确认交易订单收货")
@Parameter(name = "id", description = "交易订单编号") @Parameter(name = "id", description = "交易订单编号")
public CommonResult<Boolean> takeOrder(@RequestParam("id") Long id) { public CommonResult<Boolean> takeOrder(@RequestParam("id") Long id) {
tradeOrderService.receiveOrder(getLoginUserId(), id); tradeOrderUpdateService.receiveOrder(getLoginUserId(), id);
return success(true); return success(true);
} }
@ -176,14 +176,14 @@ public class AppTradeOrderController {
@Operation(summary = "获得交易订单项") @Operation(summary = "获得交易订单项")
@Parameter(name = "id", description = "交易订单项编号") @Parameter(name = "id", description = "交易订单项编号")
public CommonResult<AppTradeOrderItemRespVO> getOrderItem(@RequestParam("id") Long id) { public CommonResult<AppTradeOrderItemRespVO> getOrderItem(@RequestParam("id") Long id) {
TradeOrderItemDO item = tradeOrderService.getOrderItem(getLoginUserId(), id); TradeOrderItemDO item = tradeOrderQueryService.getOrderItem(getLoginUserId(), id);
return success(TradeOrderConvert.INSTANCE.convert03(item)); return success(TradeOrderConvert.INSTANCE.convert03(item));
} }
@PostMapping("/item/create-comment") @PostMapping("/item/create-comment")
@Operation(summary = "创建交易订单项的评价") @Operation(summary = "创建交易订单项的评价")
public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) {
return success(tradeOrderService.createOrderItemComment(createReqVO)); return success(tradeOrderUpdateService.createOrderItemComment(getLoginUserId(), createReqVO));
} }
} }

View File

@ -31,9 +31,10 @@ public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {
.eq(TradeOrderItemDO::getSkuId, skuIds)); .eq(TradeOrderItemDO::getSkuId, skuIds));
} }
default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) { default TradeOrderItemDO selectByIdAndUserId(Long orderItemId, Long loginUserId) {
return selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>() return selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>()
.eq(TradeOrderItemDO::getId, orderItemId) .eq(TradeOrderItemDO::getId, orderItemId)
.eq(TradeOrderItemDO::getUserId, loginUserId)); .eq(TradeOrderItemDO::getUserId, loginUserId));
} }
} }

View File

@ -27,7 +27,8 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO;
import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -54,7 +55,9 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSaleLogService { public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSaleLogService {
@Resource @Resource
private TradeOrderService tradeOrderService; private TradeOrderUpdateService tradeOrderUpdateService;
@Resource
private TradeOrderQueryService tradeOrderQueryService;
@Resource @Resource
private TradeAfterSaleMapper tradeAfterSaleMapper; private TradeAfterSaleMapper tradeAfterSaleMapper;
@ -92,7 +95,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
*/ */
private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) { private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) {
// 校验订单项存在 // 校验订单项存在
TradeOrderItemDO orderItem = tradeOrderService.getOrderItem(userId, createReqVO.getOrderItemId()); TradeOrderItemDO orderItem = tradeOrderQueryService.getOrderItem(userId, createReqVO.getOrderItemId());
if (orderItem == null) { if (orderItem == null) {
throw exception(ORDER_ITEM_NOT_FOUND); throw exception(ORDER_ITEM_NOT_FOUND);
} }
@ -108,7 +111,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
} }
// 校验订单存在 // 校验订单存在
TradeOrderDO order = tradeOrderService.getOrder(userId, orderItem.getOrderId()); TradeOrderDO order = tradeOrderQueryService.getOrder(userId, orderItem.getOrderId());
if (order == null) { if (order == null) {
throw exception(ORDER_NOT_FOUND); throw exception(ORDER_NOT_FOUND);
} }
@ -136,7 +139,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
afterSale.setNo(RandomUtil.randomString(10)); // TODO 芋艿优化 no 生成逻辑 afterSale.setNo(RandomUtil.randomString(10)); // TODO 芋艿优化 no 生成逻辑
afterSale.setStatus(TradeAfterSaleStatusEnum.APPLY.getStatus()); afterSale.setStatus(TradeAfterSaleStatusEnum.APPLY.getStatus());
// 标记是售中还是售后 // 标记是售中还是售后
TradeOrderDO order = tradeOrderService.getOrder(orderItem.getUserId(), orderItem.getOrderId()); TradeOrderDO order = tradeOrderQueryService.getOrder(orderItem.getUserId(), orderItem.getOrderId());
afterSale.setOrderNo(order.getNo()); // 记录 orderNo 订单流水方便后续检索 afterSale.setOrderNo(order.getNo()); // 记录 orderNo 订单流水方便后续检索
afterSale.setType(TradeOrderStatusEnum.isCompleted(order.getStatus()) afterSale.setType(TradeOrderStatusEnum.isCompleted(order.getStatus())
? TradeAfterSaleTypeEnum.AFTER_SALE.getType() : TradeAfterSaleTypeEnum.IN_SALE.getType()); ? TradeAfterSaleTypeEnum.AFTER_SALE.getType() : TradeAfterSaleTypeEnum.IN_SALE.getType());
@ -144,7 +147,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
tradeAfterSaleMapper.insert(afterSale); tradeAfterSaleMapper.insert(afterSale);
// 更新交易订单项的售后状态 // 更新交易订单项的售后状态
tradeOrderService.updateOrderItemAfterSaleStatus(orderItem.getId(), tradeOrderUpdateService.updateOrderItemAfterSaleStatus(orderItem.getId(),
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), null); TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), null);
@ -196,7 +199,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
// TODO 发送售后消息 // TODO 发送售后消息
// 更新交易订单项的售后状态为未申请 // 更新交易订单项的售后状态为未申请
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
} }
@ -291,7 +294,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
// TODO 发送售后消息 // TODO 发送售后消息
// 更新交易订单项的售后状态为未申请 // 更新交易订单项的售后状态为未申请
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
} }
@ -339,7 +342,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
// TODO 发送售后消息 // TODO 发送售后消息
// 更新交易订单项的售后状态为已完成 // 更新交易订单项的售后状态为已完成
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), afterSale.getRefundPrice()); TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), afterSale.getRefundPrice());
} }
@ -381,7 +384,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
// TODO 发送售后消息 // TODO 发送售后消息
// 更新交易订单项的售后状态为未申请 // 更新交易订单项的售后状态为未申请
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
} }

View File

@ -1,9 +1,17 @@
package cn.iocoder.yudao.module.trade.service.order; package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import java.util.Collection;
import java.util.List; import java.util.List;
import static java.util.Collections.singleton;
/** /**
* 交易订单 Service 接口 * 交易订单 Service 接口
* *
@ -11,6 +19,52 @@ import java.util.List;
*/ */
public interface TradeOrderQueryService { public interface TradeOrderQueryService {
// =================== Order ===================
/**
* 获得指定编号的交易订单
*
* @param id 交易订单编号
* @return 交易订单
*/
TradeOrderDO getOrder(Long id);
/**
* 获得指定用户指定的交易订单
*
* @param userId 用户编号
* @param id 交易订单编号
* @return 交易订单
*/
TradeOrderDO getOrder(Long userId, Long id);
/**
* 管理员获得交易订单分页
*
* @param reqVO 分页请求
* @return 交易订单
*/
PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO);
/**
* 会员获得交易订单分页
*
* @param userId 用户编号
* @param reqVO 分页请求
* @return 交易订单
*/
PageResult<TradeOrderDO> getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO);
/**
* 会员获得交易订单数量
*
* @param userId 用户编号
* @param status 订单状态如果为空则不进行筛选
* @param commonStatus 评价状态如果为空则不进行筛选
* @return 订单数量
*/
Long getOrderCount(Long userId, Integer status, Boolean commonStatus);
/** /**
* 获得订单的物流轨迹 * 获得订单的物流轨迹
* *
@ -20,4 +74,41 @@ public interface TradeOrderQueryService {
*/ */
List<ExpressTrackRespDTO> getExpressTrackList(Long id, Long userId); List<ExpressTrackRespDTO> getExpressTrackList(Long id, Long userId);
// =================== Order Item ===================
/**
* 获得指定用户指定的交易订单项
*
* @param userId 用户编号
* @param itemId 交易订单项编号
* @return 交易订单项
*/
TradeOrderItemDO getOrderItem(Long userId, Long itemId);
/**
* 根据交易订单项编号数组查询交易订单项
*
* @param ids 交易订单项编号数组
* @return 交易订单项数组
*/
List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids);
/**
* 根据交易订单编号查询交易订单项
*
* @param orderId 交易订单编号
* @return 交易订单项数组
*/
default List<TradeOrderItemDO> getOrderItemListByOrderId(Long orderId) {
return getOrderItemListByOrderId(singleton(orderId));
}
/**
* 根据交易订单编号数组查询交易订单项
*
* @param orderIds 交易订单编号数组
* @return 交易订单项数组
*/
List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
} }

View File

@ -1,7 +1,17 @@
package cn.iocoder.yudao.module.trade.service.order; package cn.iocoder.yudao.module.trade.service.order;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
@ -10,10 +20,10 @@ import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collections; import java.util.*;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_NOT_EXISTS; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_NOT_EXISTS;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
@ -30,10 +40,64 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@Resource
private TradeOrderItemMapper tradeOrderItemMapper;
@Resource @Resource
private DeliveryExpressService deliveryExpressService; private DeliveryExpressService deliveryExpressService;
@Resource
private MemberUserApi memberUserApi;
// =================== Order ===================
@Override
public TradeOrderDO getOrder(Long id) {
return tradeOrderMapper.selectById(id);
}
@Override
public TradeOrderDO getOrder(Long userId, Long id) {
TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order != null
&& ObjectUtil.notEqual(order.getUserId(), userId)) {
return null;
}
return order;
}
@Override
public PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO) {
// 获得 userId 相关的查询
Set<Long> userIds = new HashSet<>();
if (StrUtil.isNotEmpty(reqVO.getUserMobile())) {
MemberUserRespDTO user = memberUserApi.getUserByMobile(reqVO.getUserMobile());
if (user == null) { // 没查询到用户说明肯定也没他的订单
return new PageResult<>();
}
userIds.add(user.getId());
}
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(reqVO.getUserNickname());
if (CollUtil.isEmpty(users)) { // 没查询到用户说明肯定也没他的订单
return new PageResult<>();
}
userIds.addAll(convertSet(users, MemberUserRespDTO::getId));
}
// 分页查询
return tradeOrderMapper.selectPage(reqVO, userIds);
}
@Override
public PageResult<TradeOrderDO> getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO) {
return tradeOrderMapper.selectPage(reqVO, userId);
}
@Override
public Long getOrderCount(Long userId, Integer status, Boolean commentStatus) {
return tradeOrderMapper.selectCountByUserIdAndStatus(userId, status, commentStatus);
}
@Override @Override
public List<ExpressTrackRespDTO> getExpressTrackList(Long id, Long userId) { public List<ExpressTrackRespDTO> getExpressTrackList(Long id, Long userId) {
// 查询订单 // 查询订单
@ -57,4 +121,29 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
.setPhone(order.getReceiverMobile())); .setPhone(order.getReceiverMobile()));
} }
// =================== Order Item ===================
@Override
public TradeOrderItemDO getOrderItem(Long userId, Long itemId) {
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId);
if (orderItem != null
&& ObjectUtil.notEqual(orderItem.getUserId(), userId)) {
return null;
}
return orderItem;
}
@Override
public List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids) {
return tradeOrderItemMapper.selectBatchIds(ids);
}
@Override
public List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds) {
if (CollUtil.isEmpty(orderIds)) {
return Collections.emptyList();
}
return tradeOrderItemMapper.selectListByOrderId(orderIds);
}
} }

View File

@ -1,190 +0,0 @@
package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import java.util.Collection;
import java.util.List;
import static java.util.Collections.singleton;
/**
* 交易订单 Service 接口
*
* @author LeeYan9
* @since 2022-08-26
*/
public interface TradeOrderService {
// =================== Order ===================
/**
* 获得订单结算信息
*
* @param userId 登录用户
* @param settlementReqVO 订单结算请求
* @return 订单结算结果
*/
AppTradeOrderSettlementRespVO settlementOrder(Long userId, AppTradeOrderSettlementReqVO settlementReqVO);
/**
* 会员创建交易订单
*
* @param userId 登录用户
* @param userIp 用户 IP 地址
* @param createReqVO 创建交易订单请求模型
* @return 交易订单的
*/
TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO);
/**
* 更新交易订单已支付
*
* @param id 交易订单编号
* @param payOrderId 支付订单编号
*/
void updateOrderPaid(Long id, Long payOrderId);
/**
* 管理员发货交易订单
*
* @param userId 管理员编号
* @param deliveryReqVO 发货请求
*/
void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO);
/**
* 会员收货交易订单
*
* @param userId 用户编号
* @param id 订单编号
*/
void receiveOrder(Long userId, Long id);
/**
* 获得指定编号的交易订单
*
* @param id 交易订单编号
* @return 交易订单
*/
TradeOrderDO getOrder(Long id);
/**
* 获得指定用户指定的交易订单
*
* @param userId 用户编号
* @param id 交易订单编号
* @return 交易订单
*/
TradeOrderDO getOrder(Long userId, Long id);
/**
* 管理员获得交易订单分页
*
* @param reqVO 分页请求
* @return 交易订单
*/
PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO);
/**
* 会员获得交易订单分页
*
* @param userId 用户编号
* @param reqVO 分页请求
* @return 交易订单
*/
PageResult<TradeOrderDO> getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO);
/**
* 会员获得交易订单数量
*
* @param userId 用户编号
* @param status 订单状态如果为空则不进行筛选
* @param commonStatus 评价状态如果为空则不进行筛选
* @return 订单数量
*/
Long getOrderCount(Long userId, Integer status, Boolean commonStatus);
// =================== Order Item ===================
/**
* 获得指定用户指定的交易订单项
*
* @param userId 用户编号
* @param itemId 交易订单项编号
* @return 交易订单项
*/
TradeOrderItemDO getOrderItem(Long userId, Long itemId);
/**
* 更新交易订单项的售后状态
*
* @param id 交易订单项编号
* @param oldAfterSaleStatus 当前售后状态如果不符更新后会抛出异常
* @param newAfterSaleStatus 目标售后状态
* @param refundPrice 退款金额当订单项退款成功时必须传递该值
*/
void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus,
Integer newAfterSaleStatus, Integer refundPrice);
/**
* 根据交易订单项编号数组查询交易订单项
*
* @param ids 交易订单项编号数组
* @return 交易订单项数组
*/
List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids);
/**
* 根据交易订单编号查询交易订单项
*
* @param orderId 交易订单编号
* @return 交易订单项数组
*/
default List<TradeOrderItemDO> getOrderItemListByOrderId(Long orderId) {
return getOrderItemListByOrderId(singleton(orderId));
}
/**
* 根据交易订单编号数组查询交易订单项
*
* @param orderIds 交易订单编号数组
* @return 交易订单项数组
*/
List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
/**
* 得到订单项通过 订单项 id 和用户 id
*
* @param orderItemId 订单项 id
* @param loginUserId 登录用户 id
* @return 得到订单项
*/
TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId);
/**
* 得到订单通过 id 用户 id
*
* @param orderId 订单 id
* @param loginUserId 登录用户 id
* @return 得到订单
*/
TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId);
/**
* 创建订单项的评论
*
* @param createReqVO 创建请求
* @return 得到评价 id
*/
Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO);
}

View File

@ -0,0 +1,85 @@
package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
/**
* 交易订单Service 接口
*
* @author LeeYan9
* @since 2022-08-26
*/
public interface TradeOrderUpdateService {
// =================== Order ===================
/**
* 获得订单结算信息
*
* @param userId 登录用户
* @param settlementReqVO 订单结算请求
* @return 订单结算结果
*/
AppTradeOrderSettlementRespVO settlementOrder(Long userId, AppTradeOrderSettlementReqVO settlementReqVO);
/**
* 会员创建交易订单
*
* @param userId 登录用户
* @param userIp 用户 IP 地址
* @param createReqVO 创建交易订单请求模型
* @return 交易订单的
*/
TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO);
/**
* 更新交易订单已支付
*
* @param id 交易订单编号
* @param payOrderId 支付订单编号
*/
void updateOrderPaid(Long id, Long payOrderId);
/**
* 管理员发货交易订单
*
* @param userId 管理员编号
* @param deliveryReqVO 发货请求
*/
void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO);
/**
* 会员收货交易订单
*
* @param userId 用户编号
* @param id 订单编号
*/
void receiveOrder(Long userId, Long id);
// =================== Order Item ===================
/**
* 更新交易订单项的售后状态
*
* @param id 交易订单项编号
* @param oldAfterSaleStatus 当前售后状态如果不符更新后会抛出异常
* @param newAfterSaleStatus 目标售后状态
* @param refundPrice 退款金额当订单项退款成功时必须传递该值
*/
void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus,
Integer newAfterSaleStatus, Integer refundPrice);
/**
* 创建订单项的评论
*
* @param userId 用户编号
* @param createReqVO 创建请求
* @return 得到评价 id
*/
Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO);
}

View File

@ -8,7 +8,6 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.AddressApi;
@ -31,9 +30,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
@ -61,23 +58,23 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
/** /**
* 交易订单 Service 实现类 * 交易订单Service 实现类
* *
* @author LeeYan9 * @author LeeYan9
* @since 2022-08-26 * @since 2022-08-26
*/ */
@Service @Service
@Slf4j @Slf4j
public class TradeOrderServiceImpl implements TradeOrderService { public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@ -514,65 +511,8 @@ public class TradeOrderServiceImpl implements TradeOrderService {
return order; return order;
} }
@Override
public TradeOrderDO getOrder(Long id) {
return tradeOrderMapper.selectById(id);
}
@Override
public TradeOrderDO getOrder(Long userId, Long id) {
TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order != null
&& ObjectUtil.notEqual(order.getUserId(), userId)) {
return null;
}
return order;
}
@Override
public PageResult<TradeOrderDO> getOrderPage(TradeOrderPageReqVO reqVO) {
// 获得 userId 相关的查询
Set<Long> userIds = new HashSet<>();
if (StrUtil.isNotEmpty(reqVO.getUserMobile())) {
MemberUserRespDTO user = memberUserApi.getUserByMobile(reqVO.getUserMobile());
if (user == null) { // 没查询到用户说明肯定也没他的订单
return new PageResult<>();
}
userIds.add(user.getId());
}
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
List<MemberUserRespDTO> users = memberUserApi.getUserListByNickname(reqVO.getUserNickname());
if (CollUtil.isEmpty(users)) { // 没查询到用户说明肯定也没他的订单
return new PageResult<>();
}
userIds.addAll(convertSet(users, MemberUserRespDTO::getId));
}
// 分页查询
return tradeOrderMapper.selectPage(reqVO, userIds);
}
@Override
public PageResult<TradeOrderDO> getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO) {
return tradeOrderMapper.selectPage(reqVO, userId);
}
@Override
public Long getOrderCount(Long userId, Integer status, Boolean commentStatus) {
return tradeOrderMapper.selectCountByUserIdAndStatus(userId, status, commentStatus);
}
// =================== Order Item =================== // =================== Order Item ===================
@Override
public TradeOrderItemDO getOrderItem(Long userId, Long itemId) {
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId);
if (orderItem != null
&& ObjectUtil.notEqual(orderItem.getUserId(), userId)) {
return null;
}
return orderItem;
}
@Override @Override
public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Integer refundPrice) { public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Integer refundPrice) {
// 如果退款成功 refundPrice 非空 // 如果退款成功 refundPrice 非空
@ -610,40 +550,16 @@ public class TradeOrderServiceImpl implements TradeOrderService {
// TODO 芋艿未来如果有分佣需要更新相关分佣订单为已失效 // TODO 芋艿未来如果有分佣需要更新相关分佣订单为已失效
} }
@Override
public List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids) {
return tradeOrderItemMapper.selectBatchIds(ids);
}
@Override
public List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds) {
if (CollUtil.isEmpty(orderIds)) {
return Collections.emptyList();
}
return tradeOrderItemMapper.selectListByOrderId(orderIds);
}
@Override
public TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
return tradeOrderItemMapper.selectOrderItemByIdAndUserId(orderItemId, loginUserId);
}
@Override
public TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId) {
return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId);
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO) { public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) {
Long loginUserId = getLoginUserId();
// 先通过订单项 ID查询订单项是否存在 // 先通过订单项 ID查询订单项是否存在
TradeOrderItemDO orderItem = getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId);
if (orderItem == null) { if (orderItem == null) {
throw exception(ORDER_ITEM_NOT_FOUND); throw exception(ORDER_ITEM_NOT_FOUND);
} }
// 校验订单相关状态 // 校验订单相关状态
TradeOrderDO order = getOrderByIdAndUserId(orderItem.getOrderId(), loginUserId); TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderItem.getOrderId(), userId);
if (order == null) { if (order == null) {
throw exception(ORDER_NOT_FOUND); throw exception(ORDER_NOT_FOUND);
} }
@ -654,14 +570,14 @@ public class TradeOrderServiceImpl implements TradeOrderService {
throw exception(ORDER_COMMENT_STATUS_NOT_FALSE); throw exception(ORDER_COMMENT_STATUS_NOT_FALSE);
} }
// 创建评价 // 1. 创建评价
ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItem); ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItem);
Long comment = productCommentApi.createComment(productCommentCreateReqDTO); Long comment = productCommentApi.createComment(productCommentCreateReqDTO);
// 更新订单项评价状态
// 2. 更新订单项评价状态
tradeOrderItemMapper.updateById(new TradeOrderItemDO().setId(orderItem.getId()).setCommentStatus(Boolean.TRUE)); tradeOrderItemMapper.updateById(new TradeOrderItemDO().setId(orderItem.getId()).setCommentStatus(Boolean.TRUE));
List<TradeOrderItemDO> orderItems = getOrderItemListByOrderId(CollUtil.newArrayList(order.getId())); List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId());
if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) { if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) {
// 对于 order 来说就是评论完 order 更新完合理的 status 等字段
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE));
} }
return comment; return comment;

View File

@ -18,7 +18,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@ -52,7 +52,7 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
private TradeAfterSaleLogMapper tradeAfterSaleLogMapper; private TradeAfterSaleLogMapper tradeAfterSaleLogMapper;
@MockBean @MockBean
private TradeOrderService tradeOrderService; private TradeOrderUpdateService tradeOrderService;
@MockBean @MockBean
private PayRefundApi payRefundApi; private PayRefundApi payRefundApi;

View File

@ -48,16 +48,16 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* {@link TradeOrderServiceImpl} 的单元测试类 * {@link TradeOrderUpdateServiceImpl} 的单元测试类
* *
* @author LeeYan9 * @author LeeYan9
* @since 2022-09-07 * @since 2022-09-07
*/ */
@Import({TradeOrderServiceImpl.class, TradeOrderConfig.class}) @Import({TradeOrderUpdateServiceImpl.class, TradeOrderConfig.class})
public class TradeOrderServiceTest extends BaseDbUnitTest { public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
@Resource @Resource
private TradeOrderServiceImpl tradeOrderService; private TradeOrderUpdateServiceImpl tradeOrderUpdateService;
@Resource @Resource
private TradeOrderMapper tradeOrderMapper; private TradeOrderMapper tradeOrderMapper;
@ -150,7 +150,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
}))).thenReturn(1000L); }))).thenReturn(1000L);
// 调用方法 // 调用方法
TradeOrderDO order = tradeOrderService.createOrder(userId, userIp, reqVO); TradeOrderDO order = tradeOrderUpdateService.createOrder(userId, userIp, reqVO);
// 断言 TradeOrderDO 订单 // 断言 TradeOrderDO 订单
List<TradeOrderDO> tradeOrderDOs = tradeOrderMapper.selectList(); List<TradeOrderDO> tradeOrderDOs = tradeOrderMapper.selectList();
assertEquals(tradeOrderDOs.size(), 1); assertEquals(tradeOrderDOs.size(), 1);
@ -259,7 +259,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
.setMerchantOrderId("1")).setPrice(100)); .setMerchantOrderId("1")).setPrice(100));
// 调用 // 调用
tradeOrderService.updateOrderPaid(id, payOrderId); tradeOrderUpdateService.updateOrderPaid(id, payOrderId);
// 断言 // 断言
TradeOrderDO dbOrder = tradeOrderMapper.selectById(id); TradeOrderDO dbOrder = tradeOrderMapper.selectById(id);
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus()); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus());
@ -282,7 +282,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
// mock 方法支付单 // mock 方法支付单
// 调用 // 调用
tradeOrderService.deliveryOrder(randomLongId(), deliveryReqVO); tradeOrderUpdateService.deliveryOrder(randomLongId(), deliveryReqVO);
// 断言 // 断言
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus()); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus());
@ -304,7 +304,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
// mock 方法支付单 // mock 方法支付单
// 调用 // 调用
tradeOrderService.receiveOrder(userId, id); tradeOrderUpdateService.receiveOrder(userId, id);
// 断言 // 断言
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus()); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());