feat:订单多次退款
This commit is contained in:
1 parent
189cb4a3e4
commit
d695a2c63b
5 files changed
+54
-25
No files matched your search
+7
-2
@@ -150,8 +150,13 @@ public class HardAfterSaleController {
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('hard_hardAfterSale_view')")
|
||||
public R getHardAfterSalePage(@ParameterObject Page page, @ParameterObject HardAfterSaleEntity hardAfterSale) {
|
||||
LambdaQueryWrapper<HardAfterSaleEntity> wrapper = Wrappers.lambdaQuery();
|
||||
public R getHardAfterSalePage(@ParameterObject Page page, @ParameterObject HardAfterSaleDto dto) {
|
||||
LambdaQueryWrapper<HardAfterSaleEntity> wrapper = new LambdaQueryWrapper<HardAfterSaleEntity>()
|
||||
.eq(HardAfterSaleEntity::getOrderId, dto.getOrderId())
|
||||
.eq(HardAfterSaleEntity::getUserId, dto.getUserId())
|
||||
.eq(HardAfterSaleEntity::getStatus, dto.getStatus())
|
||||
.orderByDesc(HardAfterSaleEntity::getCreateTime)
|
||||
.orderByDesc(HardAfterSaleEntity::getOrderId);
|
||||
return R.ok(hardAfterSaleService.page(page, wrapper));
|
||||
}
|
||||
|
||||
|
||||
+20
-3
@@ -40,6 +40,7 @@ import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
|
||||
import com.bsd.pjcloud.hard.service.HardOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayVoStatusEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundDto;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargeService;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeVo;
|
||||
@@ -228,6 +229,11 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
if (ObjectUtil.isEmpty(refundPrice)) {
|
||||
refundPrice = order.getPayPrice();
|
||||
}
|
||||
// 总的退款金额
|
||||
Integer refundTotalPrice = order.getRefundPrice();
|
||||
if (ObjectUtil.isEmpty(refundTotalPrice)) {
|
||||
refundTotalPrice = 0;
|
||||
}
|
||||
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(refundPrice).build();
|
||||
R<WalletRechargeVo> walletRefundResult = walletRechargeService.refund(hardRefundDto);
|
||||
if (walletRefundResult.getCode() != 0 || ObjectUtil.isEmpty(walletRefundResult.getData())) {
|
||||
@@ -239,7 +245,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(walletRefund.getId())
|
||||
.refundPrice(refundPrice)
|
||||
.refundPrice(refundTotalPrice + refundPrice)
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
@@ -319,8 +325,19 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
throw new RuntimeException("该订单类型不支持退款");
|
||||
}
|
||||
// 校验订单是否已退款
|
||||
if (ObjectUtil.isNotEmpty(order.getPayRefundId())) {
|
||||
throw new RuntimeException("发起退款失败,订单已退款");
|
||||
// if (ObjectUtil.isNotEmpty(order.getPayRefundId())) {
|
||||
// throw new RuntimeException("发起退款失败,订单已退款");
|
||||
// }
|
||||
// 查询所有成功的退款
|
||||
List<HardAfterSaleEntity> afterList = baseMapper.selectList(new LambdaQueryWrapper<HardAfterSaleEntity>()
|
||||
.eq(HardAfterSaleEntity::getOrderId, order.getId())
|
||||
.eq(HardAfterSaleEntity::getType, HardSaleTypeEnum.AFTER_SALE.getType())
|
||||
.in(HardAfterSaleEntity::getStatus, List.of(HardSaleStatusEnum.APPLY.getStatus(), HardSaleStatusEnum.COMPLETE.getStatus()))
|
||||
);
|
||||
// 退款金额
|
||||
int totalPrice = afterList.stream().filter(v -> ObjectUtil.isNotEmpty(v.getRefundPrice())).map(HardAfterSaleEntity::getRefundPrice).reduce(0, Integer::sum);
|
||||
if (totalPrice > order.getPayPrice()) {
|
||||
throw new RuntimeException("退款总金额大于支付总金额");
|
||||
}
|
||||
return orderVo;
|
||||
}
|
||||
|
||||
+20
-14
@@ -185,15 +185,27 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
|
||||
try {
|
||||
String orderType = getOrderType(soureType);
|
||||
// 订单是否存在
|
||||
long orderCount = hardOrderService.count(new LambdaQueryWrapper<HardOrderEntity>()
|
||||
HardOrderEntity orderEntity = hardOrderService.getOne(new LambdaQueryWrapper<HardOrderEntity>()
|
||||
.eq(HardOrderEntity::getId, dto.getPlatformOrderId())
|
||||
.eq(HardOrderEntity::getOrderType, orderType)
|
||||
.eq(HardOrderEntity::getOrderStatus, HardOrderStatusEnum.PAY.getType())
|
||||
);
|
||||
if (orderCount <= 0) {
|
||||
if (ObjectUtil.isEmpty(orderEntity)) {
|
||||
baseVo.set(ThirdPayVoStatusEnum.ORDER_EXIST);
|
||||
return baseVo;
|
||||
}
|
||||
// 查询所有成功的退款
|
||||
List<HardAfterSaleEntity> afterList = hardAfterSaleService.list(new LambdaQueryWrapper<HardAfterSaleEntity>()
|
||||
.eq(HardAfterSaleEntity::getOrderId, orderEntity.getId())
|
||||
.eq(HardAfterSaleEntity::getType, HardSaleTypeEnum.AFTER_SALE.getType())
|
||||
.eq(HardAfterSaleEntity::getStatus, HardSaleStatusEnum.COMPLETE.getStatus())
|
||||
);
|
||||
// 退款金额
|
||||
int totalPrice = afterList.stream().filter(v -> ObjectUtil.isNotEmpty(v.getRefundPrice())).map(HardAfterSaleEntity::getRefundPrice).reduce(0, Integer::sum);
|
||||
int executeTotalPrice = totalPrice + dto.getPrice();
|
||||
if (executeTotalPrice > orderEntity.getPayPrice()) {
|
||||
baseVo.set(ThirdPayVoStatusEnum.REFUND_TOTAL_PRICE);
|
||||
return baseVo;
|
||||
}
|
||||
// 退款id是否重复
|
||||
long refundCount = hardAfterSaleService.count(new LambdaQueryWrapper<HardAfterSaleEntity>()
|
||||
.eq(HardAfterSaleEntity::getNo, dto.getThirdRefundId())
|
||||
@@ -204,21 +216,15 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
|
||||
baseVo.set(ThirdPayVoStatusEnum.ORDER_HAVE_REFUND);
|
||||
return baseVo;
|
||||
}
|
||||
// 是否已退款
|
||||
HardOrderVo order = hardAfterSaleService.validateOrderCanRefund(Long.valueOf(dto.getPlatformOrderId()));
|
||||
if (ObjectUtil.isEmpty(order)) {
|
||||
baseVo.set(ThirdPayVoStatusEnum.ORDER_HAVE_REFUND);
|
||||
return baseVo;
|
||||
}
|
||||
// 添加售后订单
|
||||
HardAfterSaleEntity saveObj = BeanUtils.toBean(dto, HardAfterSaleEntity.class);
|
||||
saveObj.setType(HardSaleTypeEnum.AFTER_SALE.getType());
|
||||
saveObj.setStatus(HardSaleStatusEnum.COMPLETE.getStatus());
|
||||
saveObj.setNo(dto.getThirdRefundId());
|
||||
saveObj.setWay("10");
|
||||
saveObj.setOrderId(order.getId());
|
||||
saveObj.setOrderId(orderEntity.getId());
|
||||
saveObj.setRefundPrice(dto.getPrice());
|
||||
saveObj.setUserId(order.getUserId());
|
||||
saveObj.setUserId(orderEntity.getUserId());
|
||||
saveObj.setAuditUserId(null);
|
||||
saveObj.setAuditTime(LocalDateTime.now());
|
||||
saveObj.setApplyReason("宁波银行(美好生活)api退款");
|
||||
@@ -228,9 +234,9 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
|
||||
// 添加售后进度
|
||||
HardAfterSaleLogEntity saveLogObj = HardAfterSaleLogEntity.builder()
|
||||
.afterSaleId(saveObj.getId())
|
||||
.userId(order.getUserId())
|
||||
.userId(orderEntity.getUserId())
|
||||
.operateType(HardAfterSaleOperateTypeEnum.ADMIN_REFUND.getType())
|
||||
.beforeStatus(order.getOrderStatus())
|
||||
.beforeStatus(orderEntity.getOrderStatus())
|
||||
.afterStatus(HardSaleStatusEnum.COMPLETE.getStatus())
|
||||
.content(HardSaleStatusEnum.COMPLETE.getContent())
|
||||
.build();
|
||||
@@ -240,7 +246,7 @@ public class HardThirdPayServiceImpl implements HardThirdPayService {
|
||||
// 返回
|
||||
RefundVo refundVo = new RefundVo();
|
||||
refundVo.setRefundTime(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
refundVo.setThirdOrderId(order.getOrderNo());
|
||||
refundVo.setThirdOrderId(orderEntity.getOrderNo());
|
||||
refundVo.setThirdRefundId(dto.getThirdRefundId());
|
||||
refundVo.setPlatformOrderId(dto.getPlatformOrderId());
|
||||
refundVo.setPlatformRefundId(String.valueOf(saveObj.getId()));
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ public enum ThirdPayVoStatusEnum {
|
||||
ORDER_HAVE_PAY(506, "订单已支付"),
|
||||
ORDER_HAVE_REFUND(507, "订单已退款"),
|
||||
DETAIL_ITEM_NOT_ONE(508, "查询详情条目不为一"),
|
||||
REFUND_TOTAL_PRICE(509, "退款总金额大于支付总金额"),
|
||||
UNKNOWN_ERROR(599, "未知错误,请联系管理员"),
|
||||
;
|
||||
|
||||
|
||||
+6
-6
@@ -29,8 +29,8 @@ import java.util.Map;
|
||||
@SpringBootTest(classes = ThirdPartyApp.class)
|
||||
public class PayTest {
|
||||
|
||||
private final String baseUrl = "http://123.156.230.15:8089/api";
|
||||
// private final String baseUrl = "http://127.0.0.1:9999";
|
||||
// private final String baseUrl = "http://123.156.230.15:8089/api";
|
||||
private final String baseUrl = "http://127.0.0.1:9999";
|
||||
|
||||
private final String walletInfoUrl = "/third/third-pay-api/user-wallet";
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PayTest {
|
||||
Map<String, Object> paramsMap = new HashMap<>();
|
||||
paramsMap.put("userId", 1875049673022279681L);
|
||||
paramsMap.put("thirdOrderId", System.currentTimeMillis());
|
||||
paramsMap.put("price", 100);
|
||||
paramsMap.put("price", 1000);
|
||||
paramsMap.put("products", null);
|
||||
String body = JSONUtil.toJsonStr(paramsMap);
|
||||
// 发送请求
|
||||
@@ -119,9 +119,9 @@ public class PayTest {
|
||||
public void walletRefund() throws Exception {
|
||||
ThirdKeyManageEntity config = getLbConfig();
|
||||
Map<String, Object> paramsMap = new HashMap<>();
|
||||
paramsMap.put("platformOrderId", "1919704180908027905");
|
||||
paramsMap.put("thirdRefundId", "10");
|
||||
paramsMap.put("price", "1000");
|
||||
paramsMap.put("platformOrderId", "1928019909587054593");
|
||||
paramsMap.put("thirdRefundId", System.currentTimeMillis());
|
||||
paramsMap.put("price", "300");
|
||||
String body = JSONUtil.toJsonStr(paramsMap);
|
||||
// 发送请求
|
||||
String res = HttpRequest.post(baseUrl + walletRefundUrl).contentType("application/json").header(apiCountersign(body)).body(body).execute().body();
|
||||
|
||||
Reference in new issue
Block a user