订单管理:添加修改备注、订单调价、修改地址接口

This commit is contained in:
puhui999 2023-08-22 12:19:25 +08:00
parent 716f11e80b
commit d29c5a556c
8 changed files with 163 additions and 41 deletions

View File

@ -25,7 +25,6 @@ import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 交易订单")
@RestController
@ -78,17 +77,33 @@ public class TradeOrderController {
@PostMapping("/delivery")
@Operation(summary = "发货订单")
@PreAuthorize("@ss.hasPermission('trade:order:delivery')")
@PreAuthorize("@ss.hasPermission('trade:order:update')")
public CommonResult<Boolean> deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) {
tradeOrderUpdateService.deliveryOrder(getLoginUserId(), deliveryReqVO);
tradeOrderUpdateService.deliveryOrder(deliveryReqVO);
return success(true);
}
@PostMapping("/remark")
@Operation(summary = "发货订单")
@PreAuthorize("@ss.hasPermission('trade:order:remark')")
public CommonResult<Boolean> remarkOrder(@RequestBody TradeOrderRemarkReqVO remarkReqVO) {
tradeOrderUpdateService.remarkOrder(getLoginUserId(), remarkReqVO);
@PreAuthorize("@ss.hasPermission('trade:order:update')")
public CommonResult<Boolean> remarkOrder(@RequestBody TradeOrderRemarkReqVO reqVO) {
tradeOrderUpdateService.remarkOrder(reqVO);
return success(true);
}
@PostMapping("/adjust-price")
@Operation(summary = "发货订单")
@PreAuthorize("@ss.hasPermission('trade:order:update')")
public CommonResult<Boolean> adjustPrice(@RequestBody TradeOrderAdjustPriceReqVO reqVO) {
tradeOrderUpdateService.adjustPrice(reqVO);
return success(true);
}
@PostMapping("/adjust-address")
@Operation(summary = "发货订单")
@PreAuthorize("@ss.hasPermission('trade:order:update')")
public CommonResult<Boolean> adjustAddress(@RequestBody TradeOrderAdjustAddressReqVO reqVO) {
tradeOrderUpdateService.adjustAddress(reqVO);
return success(true);
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.trade.controller.admin.order.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 订单修改地址 Request VO")
@Data
public class TradeOrderAdjustAddressReqVO {
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "订单编号不能为空")
private Long id;
@Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "z张三")
@NotEmpty(message = "收件人名称不能为空")
private String receiverName;
@Schema(description = "收件人手机", requiredMode = Schema.RequiredMode.REQUIRED, example = "19988188888")
@NotEmpty(message = "收件人手机不能为空")
private String receiverMobile;
@Schema(description = "收件人地区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "7310")
@NotNull(message = "收件人地区编号不能为空")
private Integer receiverAreaId;
@Schema(description = "收件人详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "昆明市五华区xxx小区xxx")
@NotEmpty(message = "收件人详细地址不能为空")
private String receiverDetailAddress;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.trade.controller.admin.order.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 订单改价 Request VO")
@Data
public class TradeOrderAdjustPriceReqVO {
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "订单编号不能为空")
private Long id;
@Schema(description = "订单调价,单位:分 正数,加价;负数,减价", requiredMode = Schema.RequiredMode.REQUIRED, example = "-100")
@NotNull(message = "订单调价价格不能为空")
private Integer adjustPrice;
}

View File

@ -17,8 +17,7 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.*;
import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.*;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
@ -278,4 +277,10 @@ public interface TradeOrderConvert {
List<AppOrderExpressTrackRespDTO> convertList02(List<ExpressTrackRespDTO> list);
TradeOrderDO convert(TradeOrderAdjustAddressReqVO reqVO);
TradeOrderDO convert(TradeOrderAdjustPriceReqVO reqVO);
TradeOrderDO convert(TradeOrderRemarkReqVO reqVO);
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderAdjustAddressReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderAdjustPriceReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
@ -21,7 +23,7 @@ public interface TradeOrderUpdateService {
/**
* 获得订单结算信息
*
* @param userId 登录用户
* @param userId 登录用户
* @param settlementReqVO 订单结算请求
* @return 订单结算结果
*/
@ -30,8 +32,8 @@ public interface TradeOrderUpdateService {
/**
* 会员创建交易订单
*
* @param userId 登录用户
* @param userIp 用户 IP 地址
* @param userId 登录用户
* @param userIp 用户 IP 地址
* @param createReqVO 创建交易订单请求模型
* @return 交易订单的
*/
@ -40,7 +42,7 @@ public interface TradeOrderUpdateService {
/**
* 更新交易订单已支付
*
* @param id 交易订单编号
* @param id 交易订单编号
* @param payOrderId 支付订单编号
*/
void updateOrderPaid(Long id, Long payOrderId);
@ -48,10 +50,9 @@ public interface TradeOrderUpdateService {
/**
* 管理员发货交易订单
*
* @param userId 管理员编号
* @param deliveryReqVO 发货请求
*/
void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO);
void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO);
/**
* 会员收货交易订单
@ -64,17 +65,30 @@ public interface TradeOrderUpdateService {
/**
* 管理员交易订单备注
*
* @param loginUserId 管理员编号
* @param remarkReqVO 备注请求
* @param reqVO 请求
*/
void remarkOrder(Long loginUserId, TradeOrderRemarkReqVO remarkReqVO);
void remarkOrder(TradeOrderRemarkReqVO reqVO);
/**
* 调整价格
*
* @param reqVO 请求
*/
void adjustPrice(TradeOrderAdjustPriceReqVO reqVO);
/**
* 调整地址
*
* @param reqVO 请求
*/
void adjustAddress(TradeOrderAdjustAddressReqVO reqVO);
// =================== Order Item ===================
/**
* 更新交易订单项的售后状态
*
* @param id 交易订单项编号
* @param id 交易订单项编号
* @param oldAfterSaleStatus 当前售后状态如果不符更新后会抛出异常
* @param newAfterSaleStatus 目标售后状态
*/
@ -85,11 +99,11 @@ public interface TradeOrderUpdateService {
/**
* 更新交易订单项的售后状态
*
* @param id 交易订单项编号
* @param id 交易订单项编号
* @param oldAfterSaleStatus 当前售后状态如果不符更新后会抛出异常
* @param newAfterSaleStatus 目标售后状态
* @param afterSaleId 售后单编号当订单项发起售后时必须传递该字段
* @param refundPrice 退款金额当订单项退款成功时必须传递该值
* @param afterSaleId 售后单编号当订单项发起售后时必须传递该字段
* @param refundPrice 退款金额当订单项退款成功时必须传递该值
*/
void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus,
Long afterSaleId, Integer refundPrice);

View File

@ -29,6 +29,8 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUp
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.TradeOrderAdjustAddressReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderAdjustPriceReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
@ -54,6 +56,7 @@ import cn.iocoder.yudao.module.trade.service.price.TradePriceService;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -65,6 +68,7 @@ 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.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_PAID_NO_ADJUST_PRICE;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
/**
@ -346,10 +350,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
*/
private KeyValue<TradeOrderDO, PayOrderRespDTO> validateOrderPayable(Long id, Long payOrderId) {
// 校验订单是否存在
TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
TradeOrderDO order = validateOrder(id);
// 校验订单未支付
if (!TradeOrderStatusEnum.isUnpaid(order.getStatus()) || order.getPayStatus()) {
log.error("[validateOrderPaid][order({}) 不处于待支付状态请进行处理order 数据是:{}]",
@ -392,7 +393,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Override
@Transactional(rollbackFor = Exception.class)
public void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO) {
public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) {
// TODO @puhui999只有选择快递的才可以发货
// 1.1 校验并获得交易订单可发货
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
@ -424,7 +425,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
// 发送站内信
tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId())
.setUserId(userId).setMessage(null));
.setUserId(order.getUserId()).setMessage(null));
// TODO 芋艿OrderLog
// TODO 设计lili是不是发货后才支持售后
@ -439,11 +440,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
* @return 交易订单
*/
private TradeOrderDO validateOrderDeliverable(Long id) {
// 校验订单是否存在
TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
TradeOrderDO order = validateOrder(id);
// 校验订单是否是待发货状态
if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())) {
throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED);
@ -469,6 +466,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
return order;
}
@NotNull
private TradeOrderDO validateOrder(Long id) {
// 校验订单是否存在
TradeOrderDO order = tradeOrderMapper.selectById(id);
if (order == null) {
throw exception(ORDER_NOT_FOUND);
}
return order;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void receiveOrder(Long userId, Long id) {
@ -489,14 +496,39 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
}
@Override
public void remarkOrder(Long loginUserId, TradeOrderRemarkReqVO remarkReqVO) {
public void remarkOrder(TradeOrderRemarkReqVO reqVO) {
// 校验并获得交易订单
validateOrderDeliverable(remarkReqVO.getId());
validateOrder(reqVO.getId());
TradeOrderDO updateOrderObj = new TradeOrderDO();
updateOrderObj.setId(remarkReqVO.getId());
updateOrderObj.setRemark(remarkReqVO.getRemark());
tradeOrderMapper.updateById(updateOrderObj);
// 更新
TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(reqVO);
tradeOrderMapper.updateById(order);
}
@Override
public void adjustPrice(TradeOrderAdjustPriceReqVO reqVO) {
// 校验交易订单
TradeOrderDO order = validateOrder(reqVO.getId());
if (order.getPayStatus()) {
throw exception(ORDER_PAID_NO_ADJUST_PRICE);
}
// 更新
TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO);
update.setPayPrice(update.getPayPrice() + update.getAdjustPrice());
tradeOrderMapper.updateById(update);
}
@Override
public void adjustAddress(TradeOrderAdjustAddressReqVO reqVO) {
// 校验交易订单
validateOrder(reqVO.getId());
// TODO 是否需要校验订单是否发货
// TODO 发货后是否支持修改收货地址
// 更新
TradeOrderDO update = TradeOrderConvert.INSTANCE.convert(reqVO);
tradeOrderMapper.updateById(update);
}
/**

View File

@ -23,7 +23,10 @@ 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.enums.order.*;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderRefundStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderConfig;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import org.junit.jupiter.api.BeforeEach;
@ -38,7 +41,6 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.*;
@ -282,7 +284,7 @@ public class TradeOrderUpdateServiceTest extends BaseDbUnitTest {
// mock 方法支付单
// 调用
tradeOrderUpdateService.deliveryOrder(randomLongId(), deliveryReqVO);
tradeOrderUpdateService.deliveryOrder(deliveryReqVO);
// 断言
TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L);
assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus());

View File

@ -27,6 +27,7 @@ public interface ErrorCodeConstants {
ErrorCode ORDER_IS_EXPIRED = new ErrorCode(1007002003, "支付订单已经过期");
ErrorCode ORDER_SUBMIT_CHANNEL_ERROR = new ErrorCode(1007002004, "发起支付报错,错误码:{},错误提示:{}");
ErrorCode ORDER_REFUND_FAIL_STATUS_ERROR = new ErrorCode(1007002005, "支付订单退款失败,原因:状态不是已支付或已退款");
ErrorCode ORDER_PAID_NO_ADJUST_PRICE = new ErrorCode(1007002006, "支付订单调价失败,原因:支付订单已付款,不能调价");
// ========== ORDER 模块(拓展单) 1007003000 ==========
ErrorCode ORDER_EXTENSION_NOT_FOUND = new ErrorCode(1007003000, "支付交易拓展单不存在");