mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
订单:
1. 拆分读写 OrderService,避免单 Service 逻辑过重。
This commit is contained in:
parent
159c74ce15
commit
a159a983a2
@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.trade.api.order;
|
||||
|
||||
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.validation.annotation.Validated;
|
||||
|
||||
@ -20,12 +20,12 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_
|
||||
public class TradeOrderApiImpl implements TradeOrderApi {
|
||||
|
||||
@Resource
|
||||
private TradeOrderService tradeOrderService;
|
||||
private TradeOrderQueryService tradeOrderQueryService;
|
||||
|
||||
@Override
|
||||
public Long validateOrder(Long userId, Long orderItemId) {
|
||||
// 校验订单项,订单项存在订单就存在
|
||||
TradeOrderItemDO item = tradeOrderService.getOrderItem(userId, orderItemId);
|
||||
TradeOrderItemDO item = tradeOrderQueryService.getOrderItem(userId, orderItemId);
|
||||
if (item == null) {
|
||||
throw exception(ORDER_ITEM_NOT_FOUND);
|
||||
}
|
||||
|
@ -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.dal.dataobject.order.TradeOrderDO;
|
||||
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.Parameter;
|
||||
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 {
|
||||
|
||||
@Resource
|
||||
private TradeOrderService tradeOrderService;
|
||||
private TradeOrderUpdateService tradeOrderUpdateService;
|
||||
@Resource
|
||||
private TradeOrderQueryService tradeOrderQueryService;
|
||||
|
||||
@Resource
|
||||
private ProductPropertyValueApi productPropertyValueApi;
|
||||
@ -51,7 +54,7 @@ public class TradeOrderController {
|
||||
@PreAuthorize("@ss.hasPermission('trade:order:query')")
|
||||
public CommonResult<PageResult<TradeOrderPageItemRespVO>> getOrderPage(TradeOrderPageReqVO reqVO) {
|
||||
// 查询订单
|
||||
PageResult<TradeOrderDO> pageResult = tradeOrderService.getOrderPage(reqVO);
|
||||
PageResult<TradeOrderDO> pageResult = tradeOrderQueryService.getOrderPage(reqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
@ -59,7 +62,7 @@ public class TradeOrderController {
|
||||
// 查询用户信息
|
||||
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));
|
||||
// 查询商品属性
|
||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
|
||||
@ -74,9 +77,9 @@ public class TradeOrderController {
|
||||
@PreAuthorize("@ss.hasPermission('trade:order:query')")
|
||||
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
|
||||
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
|
||||
@ -90,7 +93,7 @@ public class TradeOrderController {
|
||||
@Operation(summary = "发货订单")
|
||||
@PreAuthorize("@ss.hasPermission('trade:order:delivery')")
|
||||
public CommonResult<Boolean> deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) {
|
||||
tradeOrderService.deliveryOrder(getLoginUserId(), deliveryReqVO);
|
||||
tradeOrderUpdateService.deliveryOrder(getLoginUserId(), deliveryReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -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.service.delivery.DeliveryExpressService;
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
||||
public class AppTradeOrderController {
|
||||
|
||||
@Resource
|
||||
private TradeOrderService tradeOrderService;
|
||||
private TradeOrderUpdateService tradeOrderUpdateService;
|
||||
@Resource
|
||||
private TradeOrderQueryService tradeOrderQueryService;
|
||||
@Resource
|
||||
@ -60,21 +60,21 @@ public class AppTradeOrderController {
|
||||
@Operation(summary = "获得订单结算信息")
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppTradeOrderSettlementRespVO> settlementOrder(@Valid AppTradeOrderSettlementReqVO settlementReqVO) {
|
||||
return success(tradeOrderService.settlementOrder(getLoginUserId(), settlementReqVO));
|
||||
return success(tradeOrderUpdateService.settlementOrder(getLoginUserId(), settlementReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建订单")
|
||||
@PreAuthenticated
|
||||
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()));
|
||||
}
|
||||
|
||||
@PostMapping("/update-paid")
|
||||
@Operation(summary = "更新订单为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob
|
||||
public CommonResult<Boolean> updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) {
|
||||
tradeOrderService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),
|
||||
tradeOrderUpdateService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()),
|
||||
notifyReqDTO.getPayOrderId());
|
||||
return success(true);
|
||||
}
|
||||
@ -84,13 +84,13 @@ public class AppTradeOrderController {
|
||||
@Parameter(name = "id", description = "交易订单编号")
|
||||
public CommonResult<AppTradeOrderDetailRespVO> getOrder(@RequestParam("id") Long id) {
|
||||
// 查询订单
|
||||
TradeOrderDO order = tradeOrderService.getOrder(getLoginUserId(), id);
|
||||
TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id);
|
||||
if (order == null) {
|
||||
return success(null);
|
||||
}
|
||||
|
||||
// 查询订单项
|
||||
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId(order.getId());
|
||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId());
|
||||
// 查询商品属性
|
||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
|
||||
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
|
||||
@ -114,9 +114,9 @@ public class AppTradeOrderController {
|
||||
@Operation(summary = "获得交易订单分页")
|
||||
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));
|
||||
// 查询商品属性
|
||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
|
||||
@ -130,18 +130,18 @@ public class AppTradeOrderController {
|
||||
public CommonResult<Map<String, Long>> getOrderCount() {
|
||||
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));
|
||||
// 待发货
|
||||
orderCount.put("undeliveredCount", tradeOrderService.getOrderCount(getLoginUserId(),
|
||||
orderCount.put("undeliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
|
||||
TradeOrderStatusEnum.UNDELIVERED.getStatus(), null));
|
||||
// 待收货
|
||||
orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(),
|
||||
orderCount.put("deliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
|
||||
TradeOrderStatusEnum.DELIVERED.getStatus(), null));
|
||||
// 待评价
|
||||
orderCount.put("uncommentedCount", tradeOrderService.getOrderCount(getLoginUserId(),
|
||||
orderCount.put("uncommentedCount", tradeOrderQueryService.getOrderCount(getLoginUserId(),
|
||||
TradeOrderStatusEnum.COMPLETED.getStatus(), false));
|
||||
return success(orderCount);
|
||||
}
|
||||
@ -150,7 +150,7 @@ public class AppTradeOrderController {
|
||||
@Operation(summary = "确认交易订单收货")
|
||||
@Parameter(name = "id", description = "交易订单编号")
|
||||
public CommonResult<Boolean> takeOrder(@RequestParam("id") Long id) {
|
||||
tradeOrderService.receiveOrder(getLoginUserId(), id);
|
||||
tradeOrderUpdateService.receiveOrder(getLoginUserId(), id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -176,14 +176,14 @@ public class AppTradeOrderController {
|
||||
@Operation(summary = "获得交易订单项")
|
||||
@Parameter(name = "id", description = "交易订单项编号")
|
||||
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));
|
||||
}
|
||||
|
||||
@PostMapping("/item/create-comment")
|
||||
@Operation(summary = "创建交易订单项的评价")
|
||||
public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) {
|
||||
return success(tradeOrderService.createOrderItemComment(createReqVO));
|
||||
return success(tradeOrderUpdateService.createOrderItemComment(getLoginUserId(), createReqVO));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,9 +31,10 @@ public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {
|
||||
.eq(TradeOrderItemDO::getSkuId, skuIds));
|
||||
}
|
||||
|
||||
default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
|
||||
default TradeOrderItemDO selectByIdAndUserId(Long orderItemId, Long loginUserId) {
|
||||
return selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>()
|
||||
.eq(TradeOrderItemDO::getId, orderItemId)
|
||||
.eq(TradeOrderItemDO::getUserId, loginUserId));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.service.AfterSaleLogService;
|
||||
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 org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -54,7 +55,9 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
|
||||
public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSaleLogService {
|
||||
|
||||
@Resource
|
||||
private TradeOrderService tradeOrderService;
|
||||
private TradeOrderUpdateService tradeOrderUpdateService;
|
||||
@Resource
|
||||
private TradeOrderQueryService tradeOrderQueryService;
|
||||
|
||||
@Resource
|
||||
private TradeAfterSaleMapper tradeAfterSaleMapper;
|
||||
@ -92,7 +95,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
*/
|
||||
private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) {
|
||||
// 校验订单项存在
|
||||
TradeOrderItemDO orderItem = tradeOrderService.getOrderItem(userId, createReqVO.getOrderItemId());
|
||||
TradeOrderItemDO orderItem = tradeOrderQueryService.getOrderItem(userId, createReqVO.getOrderItemId());
|
||||
if (orderItem == null) {
|
||||
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) {
|
||||
throw exception(ORDER_NOT_FOUND);
|
||||
}
|
||||
@ -136,7 +139,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
afterSale.setNo(RandomUtil.randomString(10)); // TODO 芋艿:优化 no 生成逻辑
|
||||
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.setType(TradeOrderStatusEnum.isCompleted(order.getStatus())
|
||||
? TradeAfterSaleTypeEnum.AFTER_SALE.getType() : TradeAfterSaleTypeEnum.IN_SALE.getType());
|
||||
@ -144,7 +147,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
tradeAfterSaleMapper.insert(afterSale);
|
||||
|
||||
// 更新交易订单项的售后状态
|
||||
tradeOrderService.updateOrderItemAfterSaleStatus(orderItem.getId(),
|
||||
tradeOrderUpdateService.updateOrderItemAfterSaleStatus(orderItem.getId(),
|
||||
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(),
|
||||
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), null);
|
||||
|
||||
@ -196,7 +199,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
// TODO 发送售后消息
|
||||
|
||||
// 更新交易订单项的售后状态为【未申请】
|
||||
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
|
||||
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
|
||||
}
|
||||
@ -291,7 +294,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
// TODO 发送售后消息
|
||||
|
||||
// 更新交易订单项的售后状态为【未申请】
|
||||
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
|
||||
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
|
||||
}
|
||||
@ -339,7 +342,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
// TODO 发送售后消息
|
||||
|
||||
// 更新交易订单项的售后状态为【已完成】
|
||||
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
|
||||
TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), afterSale.getRefundPrice());
|
||||
}
|
||||
@ -381,7 +384,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
|
||||
// TODO 发送售后消息
|
||||
|
||||
// 更新交易订单项的售后状态为【未申请】
|
||||
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
|
||||
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(),
|
||||
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null);
|
||||
}
|
||||
|
@ -1,9 +1,17 @@
|
||||
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 java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
|
||||
/**
|
||||
* 交易订单【读】 Service 接口
|
||||
*
|
||||
@ -11,6 +19,52 @@ import java.util.List;
|
||||
*/
|
||||
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);
|
||||
|
||||
// =================== 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);
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,17 @@
|
||||
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.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.framework.delivery.core.client.ExpressClientFactory;
|
||||
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 javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
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.ORDER_NOT_FOUND;
|
||||
|
||||
@ -30,10 +40,64 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
|
||||
|
||||
@Resource
|
||||
private TradeOrderMapper tradeOrderMapper;
|
||||
@Resource
|
||||
private TradeOrderItemMapper tradeOrderItemMapper;
|
||||
|
||||
@Resource
|
||||
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
|
||||
public List<ExpressTrackRespDTO> getExpressTrackList(Long id, Long userId) {
|
||||
// 查询订单
|
||||
@ -57,4 +121,29 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
|
||||
.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
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.json.JsonUtils;
|
||||
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.enums.combination.CombinationRecordStatusEnum;
|
||||
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;
|
||||
@ -61,23 +58,23 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
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.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.trade.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 交易订单 Service 实现类
|
||||
* 交易订单【写】Service 实现类
|
||||
*
|
||||
* @author LeeYan9
|
||||
* @since 2022-08-26
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
|
||||
@Resource
|
||||
private TradeOrderMapper tradeOrderMapper;
|
||||
@ -514,65 +511,8 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
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 ===================
|
||||
|
||||
@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 void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Integer refundPrice) {
|
||||
// 如果退款成功,则 refundPrice 非空
|
||||
@ -610,40 +550,16 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
// 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
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO) {
|
||||
Long loginUserId = getLoginUserId();
|
||||
public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) {
|
||||
// 先通过订单项 ID,查询订单项是否存在
|
||||
TradeOrderItemDO orderItem = getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId);
|
||||
TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId);
|
||||
if (orderItem == null) {
|
||||
throw exception(ORDER_ITEM_NOT_FOUND);
|
||||
}
|
||||
// 校验订单相关状态
|
||||
TradeOrderDO order = getOrderByIdAndUserId(orderItem.getOrderId(), loginUserId);
|
||||
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderItem.getOrderId(), userId);
|
||||
if (order == null) {
|
||||
throw exception(ORDER_NOT_FOUND);
|
||||
}
|
||||
@ -654,14 +570,14 @@ public class TradeOrderServiceImpl implements TradeOrderService {
|
||||
throw exception(ORDER_COMMENT_STATUS_NOT_FALSE);
|
||||
}
|
||||
|
||||
// 创建评价
|
||||
// 1. 创建评价
|
||||
ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItem);
|
||||
Long comment = productCommentApi.createComment(productCommentCreateReqDTO);
|
||||
// 更新订单项评价状态
|
||||
|
||||
// 2. 更新订单项评价状态
|
||||
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))) {
|
||||
// 对于 order 来说,就是评论完,把 order 更新完合理的 status 等字段。
|
||||
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE));
|
||||
}
|
||||
return comment;
|
@ -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.TradeOrderStatusEnum;
|
||||
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.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@ -52,7 +52,7 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest {
|
||||
private TradeAfterSaleLogMapper tradeAfterSaleLogMapper;
|
||||
|
||||
@MockBean
|
||||
private TradeOrderService tradeOrderService;
|
||||
private TradeOrderUpdateService tradeOrderService;
|
||||
@MockBean
|
||||
private PayRefundApi payRefundApi;
|
||||
|
||||
|
@ -48,16 +48,16 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* {@link TradeOrderServiceImpl} 的单元测试类
|
||||
* {@link TradeOrderUpdateServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author LeeYan9
|
||||
* @since 2022-09-07
|
||||
*/
|
||||
@Import({TradeOrderServiceImpl.class, TradeOrderConfig.class})
|
||||
public class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
@Import({TradeOrderUpdateServiceImpl.class, TradeOrderConfig.class})
|
||||
public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private TradeOrderServiceImpl tradeOrderService;
|
||||
private TradeOrderUpdateServiceImpl tradeOrderUpdateService;
|
||||
|
||||
@Resource
|
||||
private TradeOrderMapper tradeOrderMapper;
|
||||
@ -150,7 +150,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
}))).thenReturn(1000L);
|
||||
|
||||
// 调用方法
|
||||
TradeOrderDO order = tradeOrderService.createOrder(userId, userIp, reqVO);
|
||||
TradeOrderDO order = tradeOrderUpdateService.createOrder(userId, userIp, reqVO);
|
||||
// 断言 TradeOrderDO 订单
|
||||
List<TradeOrderDO> tradeOrderDOs = tradeOrderMapper.selectList();
|
||||
assertEquals(tradeOrderDOs.size(), 1);
|
||||
@ -259,7 +259,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
.setMerchantOrderId("1")).setPrice(100));
|
||||
|
||||
// 调用
|
||||
tradeOrderService.updateOrderPaid(id, payOrderId);
|
||||
tradeOrderUpdateService.updateOrderPaid(id, payOrderId);
|
||||
// 断言
|
||||
TradeOrderDO dbOrder = tradeOrderMapper.selectById(id);
|
||||
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus());
|
||||
@ -282,7 +282,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
// mock 方法(支付单)
|
||||
|
||||
// 调用
|
||||
tradeOrderService.deliveryOrder(randomLongId(), deliveryReqVO);
|
||||
tradeOrderUpdateService.deliveryOrder(randomLongId(), deliveryReqVO);
|
||||
// 断言
|
||||
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
|
||||
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus());
|
||||
@ -304,7 +304,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest {
|
||||
// mock 方法(支付单)
|
||||
|
||||
// 调用
|
||||
tradeOrderService.receiveOrder(userId, id);
|
||||
tradeOrderUpdateService.receiveOrder(userId, id);
|
||||
// 断言
|
||||
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
|
||||
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());
|
Loading…
Reference in New Issue
Block a user