Commit 5dd6e5bee8ebc65a684a996f6a2d39aadb9be726
1 parent
d3c02f2a
营销:
1. 售后订单,增加对 afterSaleId 的更新
Showing
10 changed files
with
74 additions
and
42 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java
| ... | ... | @@ -30,7 +30,7 @@ public class AppDecorateController { |
| 30 | 30 | @Resource |
| 31 | 31 | private DecorateComponentService decorateComponentService; |
| 32 | 32 | |
| 33 | - @GetMapping("/get-component-list") | |
| 33 | + @GetMapping("/list") | |
| 34 | 34 | @Operation(summary = "获取指定页面的组件列表") |
| 35 | 35 | @Parameter(name = "page", description = "页面编号", required = true) |
| 36 | 36 | public CommonResult<List<AppDecorateComponentRespVO>> getDecorateComponentListByPage( | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.decorate; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 4 | -import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 5 | 4 | import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.DecorateComponentMapper; |
| 6 | 5 | import org.junit.jupiter.api.BeforeEach; |
| 7 | -import org.junit.jupiter.api.Test; | |
| 8 | 6 | import org.mockito.InjectMocks; |
| 9 | 7 | import org.mockito.Mock; |
| 10 | -import org.mockito.Mockito; | |
| 11 | - | |
| 12 | -import java.util.ArrayList; | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_NEWS; | |
| 16 | -import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX; | |
| 17 | -import static org.mockito.ArgumentMatchers.eq; | |
| 18 | 8 | |
| 19 | 9 | // TODO @芋艿:后续 review 下 |
| 20 | 10 | /** |
| ... | ... | @@ -33,14 +23,14 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest { |
| 33 | 23 | |
| 34 | 24 | } |
| 35 | 25 | |
| 36 | - @Test | |
| 37 | - void testResp(){ | |
| 38 | - List<DecorateComponentDO> list = new ArrayList<>(1); | |
| 39 | - DecorateComponentDO decorateDO = new DecorateComponentDO() | |
| 40 | - .setPage(INDEX.getPage()).setValue("") | |
| 41 | - .setCode(ROLLING_NEWS.getCode()).setId(1L); | |
| 42 | - list.add(decorateDO); | |
| 43 | - //mock 方法 | |
| 44 | - Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list); | |
| 45 | - } | |
| 26 | +// @Test | |
| 27 | +// void testResp(){ | |
| 28 | +// List<DecorateComponentDO> list = new ArrayList<>(1); | |
| 29 | +// DecorateComponentDO decorateDO = new DecorateComponentDO() | |
| 30 | +// .setPage(INDEX.getPage()).setValue("") | |
| 31 | +// .setCode(ROLLING_NEWS.getCode()).setId(1L); | |
| 32 | +// list.add(decorateDO); | |
| 33 | +// //mock 方法 | |
| 34 | +// Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list); | |
| 35 | +// } | |
| 46 | 36 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/aftersale/AppTradeAfterSaleController.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSa |
| 7 | 7 | import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSalePageItemRespVO; |
| 8 | 8 | import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO; |
| 9 | 9 | import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleOperateTypeEnum; |
| 10 | +import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; | |
| 10 | 11 | import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.annotations.AfterSaleLog; |
| 11 | 12 | import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; |
| 12 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -19,6 +20,8 @@ import org.springframework.web.bind.annotation.*; |
| 19 | 20 | import javax.annotation.Resource; |
| 20 | 21 | import java.time.LocalDateTime; |
| 21 | 22 | import java.util.Arrays; |
| 23 | +import java.util.List; | |
| 24 | +import java.util.Objects; | |
| 22 | 25 | |
| 23 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | 27 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| ... | ... | @@ -78,6 +81,17 @@ public class AppTradeAfterSaleController { |
| 78 | 81 | // return success(afterSaleService.getAfterSalePage(getLoginUserId())); |
| 79 | 82 | } |
| 80 | 83 | |
| 84 | + // TODO 芋艿:待实现 | |
| 85 | + @GetMapping(value = "/get-reason-list") | |
| 86 | + @Operation(summary = "获得售后原因") | |
| 87 | + @Parameter(name = "way", description = "售后类型", required = true, example = "10") | |
| 88 | + public CommonResult<List<String>> getAfterSaleReasonList(@RequestParam("way") Integer way) { | |
| 89 | + if (Objects.equals(TradeAfterSaleWayEnum.REFUND.getWay(), way)) { | |
| 90 | + return success(Arrays.asList("不想要了", "商品质量问题", "商品描述不符")); | |
| 91 | + } | |
| 92 | + return success(Arrays.asList("不想要了", "商品质量问题", "商品描述不符", "商品错发漏发", "商品包装破损")); | |
| 93 | + } | |
| 94 | + | |
| 81 | 95 | @PostMapping(value = "/create") |
| 82 | 96 | @Operation(summary = "申请售后") |
| 83 | 97 | @AfterSaleLog(id = "#info.data", content = "'申请售后:售后编号['+#info.data+'],订单编号['+#createReqVO.orderItemId+'], '", operateType = AfterSaleOperateTypeEnum.APPLY) | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/item/AppTradeOrderItemRespVO.java
| ... | ... | @@ -43,6 +43,9 @@ public class AppTradeOrderItemRespVO { |
| 43 | 43 | @Schema(description = "商品原价(单)", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") |
| 44 | 44 | private Integer price; |
| 45 | 45 | |
| 46 | + @Schema(description = "应付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") | |
| 47 | + private Integer payPrice; | |
| 48 | + | |
| 46 | 49 | // ========== 营销基本信息 ========== |
| 47 | 50 | |
| 48 | 51 | // TODO 芋艿:在捉摸一下 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java
| ... | ... | @@ -145,12 +145,17 @@ public class TradeOrderItemDO extends BaseDO { |
| 145 | 145 | private Integer pointPrice; |
| 146 | 146 | |
| 147 | 147 | // ========== 售后基本信息 ========== |
| 148 | + | |
| 149 | + /** | |
| 150 | + * 售后单编号 | |
| 151 | + * | |
| 152 | + * 关联 {@link TradeAfterSaleDO#getId()} 字段 | |
| 153 | + */ | |
| 154 | + private Long afterSaleId; | |
| 148 | 155 | /** |
| 149 | 156 | * 售后状态 |
| 150 | 157 | * |
| 151 | 158 | * 枚举 {@link TradeOrderItemAfterSaleStatusEnum} |
| 152 | - * | |
| 153 | - * @see TradeAfterSaleDO | |
| 154 | 159 | */ |
| 155 | 160 | private Integer afterSaleStatus; |
| 156 | 161 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java
| ... | ... | @@ -12,8 +12,9 @@ import java.util.List; |
| 12 | 12 | @Mapper |
| 13 | 13 | public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> { |
| 14 | 14 | |
| 15 | - default int updateAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus) { | |
| 16 | - return update(new TradeOrderItemDO().setAfterSaleStatus(newAfterSaleStatus), | |
| 15 | + default int updateAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, | |
| 16 | + Long afterSaleId) { | |
| 17 | + return update(new TradeOrderItemDO().setAfterSaleStatus(newAfterSaleStatus).setAfterSaleId(afterSaleId), | |
| 17 | 18 | new LambdaUpdateWrapper<>(new TradeOrderItemDO().setId(id).setAfterSaleStatus(oldAfterSaleStatus))); |
| 18 | 19 | } |
| 19 | 20 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java
| ... | ... | @@ -148,8 +148,8 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa |
| 148 | 148 | |
| 149 | 149 | // 更新交易订单项的售后状态 |
| 150 | 150 | tradeOrderUpdateService.updateOrderItemAfterSaleStatus(orderItem.getId(), |
| 151 | - TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), | |
| 152 | - TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), null); | |
| 151 | + TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), | |
| 152 | + afterSale.getId(), null); | |
| 153 | 153 | |
| 154 | 154 | // 记录售后日志 |
| 155 | 155 | createAfterSaleLog(orderItem.getUserId(), UserTypeEnum.MEMBER.getValue(), |
| ... | ... | @@ -200,8 +200,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa |
| 200 | 200 | |
| 201 | 201 | // 更新交易订单项的售后状态为【未申请】 |
| 202 | 202 | tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), |
| 203 | - TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), | |
| 204 | - TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); | |
| 203 | + TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus()); | |
| 205 | 204 | } |
| 206 | 205 | |
| 207 | 206 | /** |
| ... | ... | @@ -295,8 +294,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa |
| 295 | 294 | |
| 296 | 295 | // 更新交易订单项的售后状态为【未申请】 |
| 297 | 296 | tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), |
| 298 | - TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), | |
| 299 | - TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); | |
| 297 | + TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus()); | |
| 300 | 298 | } |
| 301 | 299 | |
| 302 | 300 | /** |
| ... | ... | @@ -343,8 +341,8 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa |
| 343 | 341 | |
| 344 | 342 | // 更新交易订单项的售后状态为【已完成】 |
| 345 | 343 | tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), |
| 346 | - TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), | |
| 347 | - TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), afterSale.getRefundPrice()); | |
| 344 | + TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), | |
| 345 | + null, afterSale.getRefundPrice()); | |
| 348 | 346 | } |
| 349 | 347 | |
| 350 | 348 | private void createPayRefund(String userIp, TradeAfterSaleDO afterSale) { |
| ... | ... | @@ -385,8 +383,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa |
| 385 | 383 | |
| 386 | 384 | // 更新交易订单项的售后状态为【未申请】 |
| 387 | 385 | tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), |
| 388 | - TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), | |
| 389 | - TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); | |
| 386 | + TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus()); | |
| 390 | 387 | } |
| 391 | 388 | |
| 392 | 389 | @Deprecated | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
| ... | ... | @@ -68,10 +68,22 @@ public interface TradeOrderUpdateService { |
| 68 | 68 | * @param id 交易订单项编号 |
| 69 | 69 | * @param oldAfterSaleStatus 当前售后状态;如果不符,更新后会抛出异常 |
| 70 | 70 | * @param newAfterSaleStatus 目标售后状态 |
| 71 | + */ | |
| 72 | + default void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus) { | |
| 73 | + updateOrderItemAfterSaleStatus(id, oldAfterSaleStatus, newAfterSaleStatus, null, null); | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 更新交易订单项的售后状态 | |
| 78 | + * | |
| 79 | + * @param id 交易订单项编号 | |
| 80 | + * @param oldAfterSaleStatus 当前售后状态;如果不符,更新后会抛出异常 | |
| 81 | + * @param newAfterSaleStatus 目标售后状态 | |
| 82 | + * @param afterSaleId 售后单编号;当订单项发起售后时,必须传递该字段 | |
| 71 | 83 | * @param refundPrice 退款金额;当订单项退款成功时,必须传递该值 |
| 72 | 84 | */ |
| 73 | - void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, | |
| 74 | - Integer newAfterSaleStatus, Integer refundPrice); | |
| 85 | + void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, | |
| 86 | + Long afterSaleId, Integer refundPrice); | |
| 75 | 87 | |
| 76 | 88 | /** |
| 77 | 89 | * 创建订单项的评论 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -514,15 +514,22 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 514 | 514 | // =================== Order Item =================== |
| 515 | 515 | |
| 516 | 516 | @Override |
| 517 | - public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Integer refundPrice) { | |
| 517 | + @Transactional(rollbackFor = Exception.class) | |
| 518 | + public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, | |
| 519 | + Long afterSaleId, Integer refundPrice) { | |
| 518 | 520 | // 如果退款成功,则 refundPrice 非空 |
| 519 | 521 | if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus()) |
| 520 | 522 | && refundPrice == null) { |
| 521 | 523 | throw new IllegalArgumentException(StrUtil.format("id({}) 退款成功,退款金额不能为空", id)); |
| 522 | 524 | } |
| 525 | + // 如果退款发起,则 afterSaleId 非空 | |
| 526 | + if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus()) | |
| 527 | + && afterSaleId == null) { | |
| 528 | + throw new IllegalArgumentException(StrUtil.format("id({}) 退款发起,售后单编号不能为空", id)); | |
| 529 | + } | |
| 523 | 530 | |
| 524 | 531 | // 更新订单项 |
| 525 | - int updateCount = tradeOrderItemMapper.updateAfterSaleStatus(id, oldAfterSaleStatus, newAfterSaleStatus); | |
| 532 | + int updateCount = tradeOrderItemMapper.updateAfterSaleStatus(id, oldAfterSaleStatus, newAfterSaleStatus, afterSaleId); | |
| 526 | 533 | if (updateCount <= 0) { |
| 527 | 534 | throw exception(ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL); |
| 528 | 535 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java
| ... | ... | @@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; |
| 18 | 18 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; |
| 19 | 19 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; |
| 20 | 20 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 21 | +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; | |
| 21 | 22 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; |
| 22 | 23 | import org.junit.jupiter.api.Test; |
| 23 | 24 | import org.springframework.boot.test.mock.mockito.MockBean; |
| ... | ... | @@ -52,7 +53,9 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest { |
| 52 | 53 | private TradeAfterSaleLogMapper tradeAfterSaleLogMapper; |
| 53 | 54 | |
| 54 | 55 | @MockBean |
| 55 | - private TradeOrderUpdateService tradeOrderService; | |
| 56 | + private TradeOrderUpdateService tradeOrderUpdateService; | |
| 57 | + @Resource | |
| 58 | + private TradeOrderQueryService tradeOrderQueryService; | |
| 56 | 59 | @MockBean |
| 57 | 60 | private PayRefundApi payRefundApi; |
| 58 | 61 | |
| ... | ... | @@ -72,12 +75,12 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest { |
| 72 | 75 | o.setOrderId(111L).setUserId(userId).setPayPrice(200); |
| 73 | 76 | o.setAfterSaleStatus(TradeOrderItemAfterSaleStatusEnum.NONE.getStatus()); |
| 74 | 77 | }); |
| 75 | - when(tradeOrderService.getOrderItem(eq(1024L), eq(1L))) | |
| 78 | + when(tradeOrderQueryService.getOrderItem(eq(1024L), eq(1L))) | |
| 76 | 79 | .thenReturn(orderItem); |
| 77 | 80 | // mock 方法(交易订单) |
| 78 | 81 | TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> o.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) |
| 79 | 82 | .setNo("202211301234")); |
| 80 | - when(tradeOrderService.getOrder(eq(1024L), eq(111L))).thenReturn(order); | |
| 83 | + when(tradeOrderQueryService.getOrder(eq(1024L), eq(111L))).thenReturn(order); | |
| 81 | 84 | |
| 82 | 85 | // 调用 |
| 83 | 86 | Long afterSaleId = tradeAfterSaleService.createAfterSale(userId, createReqVO); | ... | ... |