trade:增加管理员审批

pull/2/head
YunaiV 2022-11-16 22:17:07 +08:00
parent 10f2dbc8cd
commit 92dbf093ea
20 changed files with 381 additions and 82 deletions

View File

@ -21,6 +21,7 @@ public interface ErrorCodeConstants {
ErrorCode ORDER_ITEM_NOT_FOUND = new ErrorCode(1011000010, "交易订单项不存在");
ErrorCode ORDER_NOT_FOUND = new ErrorCode(1011000010, "交易订单不存在");
ErrorCode ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL = new ErrorCode(1011000011, "交易订单项更新售后状态失败,请重试");
// ========== After Sale 模块 1-011-000-000 ==========
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");
@ -29,9 +30,10 @@ public interface ErrorCodeConstants {
ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_STATUS_NO_PAID = new ErrorCode(1011000103, "订单未支付,无法申请售后");
ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_STATUS_NO_DELIVERED = new ErrorCode(1011000104, "订单未发货,无法申请【退货退款】售后");
ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_ITEM_APPLIED = new ErrorCode(1011000105, "订单项已申请售后,无法重复申请");
ErrorCode AFTER_SALE_AUDIT_FAIL_STATUS_NOT_APPLY = new ErrorCode(1011000106, "审批失败,售后状态不处于审批中");
ErrorCode AFTER_SALE_UPDATE_STATUS_FAIL = new ErrorCode(1011000106, "操作售后单失败,请刷新后重试");
// ========== Cart 模块 1-011-001-000 ==========
ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1011002000, "购物车项不存在");
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.trade.controller.admin.aftersale;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Api(tags = "管理后台 - 交易售后")
@RestController
@RequestMapping("/trade/after-sale")
@Validated
@Slf4j
public class TradeAfterSaleController {
@Resource
private TradeAfterSaleService afterSaleService;
@PutMapping("/audit")
@ApiOperation("审批售后")
@PreAuthorize("@ss.hasPermission('trade:after-sale:audit')")
public CommonResult<Boolean> auditAfterSale(@RequestBody TradeAfterSaleAuditReqVO auditReqVO) {
afterSaleService.auditAfterSale(getLoginUserId(), getClientIP(), auditReqVO);
return success(true);
}
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ApiModel("管理后台 - 交易售后审批 Request VO")
@Data
public class TradeAfterSaleAuditReqVO {
@ApiModelProperty(value = "售后编号", required = true, example = "1024")
@NotNull(message = "售后编号不能为空")
private Long id;
@ApiModelProperty(value = "审批结果", required = true, example = "true",
notes = "true - 通过false - 不通过")
@NotNull(message = "审批结果不能为空")
private Boolean audit;
@ApiModelProperty(value = "审批备注", example = "你猜")
private String auditReason;
}

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.trade.controller.app.aftersale;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -22,14 +22,14 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
@RequestMapping("/trade/after-sale")
@Validated
@Slf4j
public class AppAfterSaleController {
public class AppTradeAfterSaleController {
@Resource
private TradeAfterSaleService afterSaleService;
@PostMapping(value = "/create")
@ApiOperation(value = "申请售后")
private CommonResult<Long> createAfterSale(@RequestBody AppAfterSaleCreateReqVO createReqVO) {
private CommonResult<Long> createAfterSale(@RequestBody AppTradeAfterSaleCreateReqVO createReqVO) {
return success(afterSaleService.createAfterSale(getLoginUserId(), createReqVO));
}

View File

@ -12,7 +12,7 @@ import java.util.List;
@ApiModel("用户 App - 交易售后创建 Request VO")
@Data
public class AppAfterSaleCreateReqVO {
public class AppTradeAfterSaleCreateReqVO {
@ApiModelProperty(name = "订单项编号", required = true, example = "1024")
@NotNull(message = "订单项编号不能为空")

View File

@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.trade.convert.aftersale;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
@ -20,6 +22,14 @@ public interface TradeAfterSaleConvert {
@Mapping(target = "creator", ignore = true),
@Mapping(target = "updater", ignore = true),
})
TradeAfterSaleDO convert(AppAfterSaleCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItem);
TradeAfterSaleDO convert(AppTradeAfterSaleCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItem);
@Mappings({
@Mapping(source = "afterSale.orderId", target = "merchantOrderId"),
@Mapping(source = "afterSale.applyReason", target = "reason"),
@Mapping(source = "afterSale.refundPrice", target = "amount")
})
PayRefundCreateReqDTO convert(String userIp, TradeAfterSaleDO afterSale,
TradeOrderProperties orderProperties);
}

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.trade.convert.order;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.pay.api.order.PayOrderInfoCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
@ -71,9 +71,9 @@ public interface TradeOrderConvert {
ProductSkuUpdateStockReqDTO.Item convert(TradeOrderItemDO bean);
List<ProductSkuUpdateStockReqDTO.Item> convertList(List<TradeOrderItemDO> list);
default PayOrderInfoCreateReqDTO convert(TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> tradeOrderItemDOs,
List<ProductSpuRespDTO> spus, TradeOrderProperties tradeOrderProperties) {
PayOrderInfoCreateReqDTO createReqDTO = new PayOrderInfoCreateReqDTO()
default PayOrderCreateReqDTO convert(TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> tradeOrderItemDOs,
List<ProductSpuRespDTO> spus, TradeOrderProperties tradeOrderProperties) {
PayOrderCreateReqDTO createReqDTO = new PayOrderCreateReqDTO()
.setAppId(tradeOrderProperties.getAppId()).setUserIp(tradeOrderDO.getUserIp());
// 商户相关字段
createReqDTO.setMerchantOrderId(String.valueOf(tradeOrderDO.getId()));

View File

@ -2,9 +2,15 @@ package cn.iocoder.yudao.module.trade.dal.mysql.aftersale;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TradeAfterSaleMapper extends BaseMapperX<TradeAfterSaleDO> {
default int updateByIdAndStatus(Long id, Integer status, TradeAfterSaleDO update) {
return update(update, new LambdaUpdateWrapper<TradeAfterSaleDO>()
.eq(TradeAfterSaleDO::getId, id).eq(TradeAfterSaleDO::getStatus, status));
}
}

View File

@ -2,8 +2,15 @@ package cn.iocoder.yudao.module.trade.dal.mysql.order;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {
default int updateAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus) {
return update(new TradeOrderItemDO().setAfterSaleStatus(newAfterSaleStatus),
new LambdaUpdateWrapper<>(new TradeOrderItemDO().setId(id).setAfterSaleStatus(oldAfterSaleStatus)));
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.trade.service.aftersale;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
/**
* Service
@ -14,10 +15,18 @@ public interface TradeAfterSaleService {
* <p>
*
*
* @param userId
* @param createReqVO Request
* @param userId
* @param createReqVO Request
* @return
*/
Long createAfterSale(Long userId, AppAfterSaleCreateReqVO createReqVO);
Long createAfterSale(Long userId, AppTradeAfterSaleCreateReqVO createReqVO);
/**
*
*
* @param userId
* @param userIp IP
* @param auditReqVO Request
*/
void auditAfterSale(Long userId, String userIp, TradeAfterSaleAuditReqVO auditReqVO);
}

View File

@ -1,7 +1,10 @@
package cn.iocoder.yudao.module.trade.service.aftersale;
import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleAuditReqVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
@ -11,12 +14,18 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleTypeEnum;
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 org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
@ -35,8 +44,15 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
@Resource
private TradeAfterSaleMapper tradeAfterSaleMapper;
@Resource
private PayRefundApi payRefundApi;
@Resource
private TradeOrderProperties tradeOrderProperties;
@Override
public Long createAfterSale(Long userId, AppAfterSaleCreateReqVO createReqVO) {
@Transactional(rollbackFor = Exception.class)
public Long createAfterSale(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) {
// 第一步,前置校验
TradeOrderItemDO tradeOrderItem = validateOrderItemApplicable(userId, createReqVO);
@ -45,7 +61,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
return afterSale.getId();
}
private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppAfterSaleCreateReqVO createReqVO) {
private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) {
// 校验订单项存在
TradeOrderItemDO orderItem = tradeOrderService.getOrderItem(userId, createReqVO.getOrderItemId());
if (orderItem == null) {
@ -84,7 +100,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
return orderItem;
}
private TradeAfterSaleDO createAfterSale(AppAfterSaleCreateReqVO createReqVO,
private TradeAfterSaleDO createAfterSale(AppTradeAfterSaleCreateReqVO createReqVO,
TradeOrderItemDO tradeOrderItem) {
// 创建售后单
TradeAfterSaleDO afterSale = TradeAfterSaleConvert.INSTANCE.convert(createReqVO, tradeOrderItem);
@ -93,10 +109,94 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService {
// TODO 退还积分
tradeAfterSaleMapper.insert(afterSale);
// 更新交易订单项的售后状态 TODO
// 更新交易订单项的售后状态
tradeOrderService.updateOrderItemAfterSaleStatus(tradeOrderItem.getId(),
TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus());
// 发送售后消息
// TODO 记录售后日志
// TODO 发送售后消息
return afterSale;
}
@Override
@Transactional
public void auditAfterSale(Long userId, String userIp,
TradeAfterSaleAuditReqVO auditReqVO) {
// 校验售后单存在,并状态未审批
TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(auditReqVO.getId());
if (afterSale == null) {
throw exception(AFTER_SALE_NOT_FOUND);
}
if (afterSale.getStatus().equals(TradeAfterSaleStatusEnum.APPLY.getStatus())) {
throw exception(AFTER_SALE_AUDIT_FAIL_STATUS_NOT_APPLY);
}
// 进行审批
if (auditReqVO.getAudit()) {
auditAfterSalePass(userId, userIp, auditReqVO, afterSale);
} else {
auditAfterSaleReject(userId, auditReqVO, afterSale);
}
}
private void auditAfterSalePass(Long userId, String userIp,
TradeAfterSaleAuditReqVO auditReqVO, TradeAfterSaleDO afterSale) {
// 更新售后单的状态
// 情况一:退款:标记为 WAIT_REFUND 状态。后续等退款发起成功后,在标记为 COMPLETE 状态
// 情况二:退货退款:需要等用户退货后,才能发起退款
Integer newStatus = afterSale.getType().equals(TradeAfterSaleTypeEnum.REFUND.getType()) ?
TradeAfterSaleStatusEnum.WAIT_REFUND.getStatus() : TradeAfterSaleStatusEnum.SELLER_PASS.getStatus();
updateAfterSaleStatus(afterSale.getId(), TradeAfterSaleStatusEnum.APPLY.getStatus(), new TradeAfterSaleDO()
.setStatus(newStatus).setAuditUserId(userId)
.setAuditReason(auditReqVO.getAuditReason()).setAuditTime(LocalDateTime.now()));
// 如果直接退款,则发起售后退款
if (afterSale.getType().equals(TradeAfterSaleTypeEnum.REFUND.getType())) {
createPayRefund(userIp, afterSale);
}
// TODO 记录售后日志
// TODO 发送售后消息
}
private void auditAfterSaleReject(Long userId,
TradeAfterSaleAuditReqVO auditReqVO, TradeAfterSaleDO afterSale) {
// 更新售后单的状态
Integer newStatus = TradeAfterSaleStatusEnum.SELLER_REFUSE.getStatus();
updateAfterSaleStatus(afterSale.getId(), TradeAfterSaleStatusEnum.APPLY.getStatus(), new TradeAfterSaleDO()
.setStatus(newStatus).setAuditUserId(userId)
.setAuditReason(auditReqVO.getAuditReason()).setAuditTime(LocalDateTime.now()));
// 更新交易订单项的售后状态为【未申请】
tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(),
TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus());
// TODO 记录售后日志
// TODO 发送售后消息
}
private void createPayRefund(String userIp, TradeAfterSaleDO afterSale) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
// 创建退款单
PayRefundCreateReqDTO createReqDTO = TradeAfterSaleConvert.INSTANCE.convert(userIp, afterSale, tradeOrderProperties);
Long payRefundId = payRefundApi.createPayRefund(createReqDTO);
// 更新售后单的退款单号
tradeAfterSaleMapper.updateById(new TradeAfterSaleDO().setId(afterSale.getId()).setPayRefundId(payRefundId));
}
});
}
private void updateAfterSaleStatus(Long id, Integer status, TradeAfterSaleDO updateObj) {
int updateCount = tradeAfterSaleMapper.updateByIdAndStatus(id, status, updateObj);
if (updateCount == 0) {
throw exception(AFTER_SALE_UPDATE_STATUS_FAIL);
}
}
}

View File

@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
*/
public interface TradeOrderService {
// =================== Order ===================
/**
*
*
@ -22,6 +24,17 @@ public interface TradeOrderService {
*/
Long createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO);
/**
*
*
* @param userId
* @param orderId
* @return
*/
TradeOrderDO getOrder(Long userId, Long orderId);
// =================== Order Item ===================
/**
*
*
@ -32,12 +45,11 @@ public interface TradeOrderService {
TradeOrderItemDO getOrderItem(Long userId, Long itemId);
/**
*
*
*
* @param userId
* @param orderId
* @return
* @param id
* @param oldAfterSaleStatus
* @param newAfterSaleStatus
*/
TradeOrderDO getOrder(Long userId, Long orderId);
void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus);
}

View File

@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.member.api.address.AddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
import cn.iocoder.yudao.module.pay.api.order.PayOrderInfoCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
@ -42,8 +42,7 @@ import java.util.Set;
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.trade.enums.ErrorCodeConstants.ORDER_CREATE_SKU_NOT_SALE;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_CREATE_SPU_NOT_FOUND;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
/**
* Service
@ -75,6 +74,8 @@ public class TradeOrderServiceImpl implements TradeOrderService {
@Resource
private TradeOrderProperties tradeOrderProperties;
// =================== Order ===================
@Override
@Transactional(rollbackFor = Exception.class)
public Long createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) {
@ -99,16 +100,6 @@ public class TradeOrderServiceImpl implements TradeOrderService {
return tradeOrderDO.getId();
}
@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 TradeOrderDO getOrder(Long userId, Long orderId) {
TradeOrderDO order = tradeOrderMapper.selectById(orderId);
@ -240,7 +231,7 @@ public class TradeOrderServiceImpl implements TradeOrderService {
private void createPayOrder(TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> tradeOrderItemDOs,
List<ProductSpuRespDTO> spus) {
// 创建支付单,用于后续的支付
PayOrderInfoCreateReqDTO payOrderCreateReqDTO = TradeOrderConvert.INSTANCE.convert(
PayOrderCreateReqDTO payOrderCreateReqDTO = TradeOrderConvert.INSTANCE.convert(
tradeOrderDO, tradeOrderItemDOs, spus, tradeOrderProperties);
Long payOrderId = payOrderApi.createPayOrder(payOrderCreateReqDTO);
@ -248,4 +239,24 @@ public class TradeOrderServiceImpl implements TradeOrderService {
tradeOrderMapper.updateById(new TradeOrderDO().setId(tradeOrderDO.getId()).setPayOrderId(payOrderId));
}
// =================== Order ===================
@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) {
int updateCount = tradeOrderItemMapper.updateAfterSaleStatus(id, oldAfterSaleStatus, newAfterSaleStatus);
if (updateCount <= 0) {
throw exception(ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL);
}
}
}

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.pay.api.order;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import javax.validation.Valid;
/**
@ -16,6 +18,6 @@ public interface PayOrderApi {
* @param reqDTO
* @return
*/
Long createPayOrder(@Valid PayOrderInfoCreateReqDTO reqDTO);
Long createPayOrder(@Valid PayOrderCreateReqDTO reqDTO);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.pay.api.order;
package cn.iocoder.yudao.module.pay.api.order.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
@ -15,7 +15,7 @@ import java.time.LocalDateTime;
* @author LeeYan9
*/
@Data
public class PayOrderInfoCreateReqDTO implements Serializable {
public class PayOrderCreateReqDTO implements Serializable {
/**
*

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.pay.api.refund;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import javax.validation.Valid;
/**
* 退 API
*
* @author
*/
public interface PayRefundApi {
/**
* 退
*
* @param reqDTO
* @return 退
*/
Long createPayRefund(@Valid PayRefundCreateReqDTO reqDTO);
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.pay.api.refund.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
/**
* 退 Request DTO
*
* @author
*/
@Data
public class PayRefundCreateReqDTO {
/**
*
*/
@NotNull(message = "应用编号不能为空")
private Long appId;
/**
* IP
*/
@NotEmpty(message = "用户 IP 不能为空")
private String userIp;
// ========== 商户相关字段 ==========
/**
*
*/
@NotEmpty(message = "商户订单编号不能为空")
private String merchantOrderId;
/**
* 退
*/
@NotEmpty(message = "退款描述不能为空")
@Length(max = 128, message = "退款描述长度不能超过128")
private String reason;
// ========== 订单相关字段 ==========
/**
* 退
*/
@NotNull(message = "退款金额不能为空")
@Min(value = 1, message = "退款金额必须大于零")
private Integer amount;
}

View File

@ -1,18 +0,0 @@
package cn.iocoder.yudao.module.pay.api;
import cn.iocoder.yudao.module.pay.api.order.PayOrderApi;
import cn.iocoder.yudao.module.pay.api.order.PayOrderInfoCreateReqDTO;
import org.springframework.stereotype.Service;
/**
* TODO
*/
@Service
public class PayOrderApiImpl implements PayOrderApi {
@Override
public Long createPayOrder(PayOrderInfoCreateReqDTO reqDTO) {
return null;
}
}

View File

@ -1,19 +1,17 @@
//package cn.iocoder.yudao.module.pay.api.order;
//
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
///**
// * @author LeeYan9
// * @since 2022-09-06
// */
//@Service
//public class PayOrderApiImpl implements PayOrderApi {
//
// @Override
// @Transactional(rollbackFor = Exception.class)
// public Long createPayOrder(PayOrderInfoCreateReqDTO reqDTO) {
// return null;
// }
//
//}
package cn.iocoder.yudao.module.pay.api.order;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import org.springframework.stereotype.Service;
/**
* TODO
*/
@Service
public class PayOrderApiImpl implements PayOrderApi {
@Override
public Long createPayOrder(PayOrderCreateReqDTO reqDTO) {
return null;
}
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.pay.api.refund;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
/**
* 退 API
*
* @author
*/
@Service
@Validated
public class PayRefundApiImpl implements PayRefundApi {
@Override
public Long createPayRefund(PayRefundCreateReqDTO reqDTO) {
// TODO 芋艿:暂未实现
return null;
}
}