feat: 商城退款
parent
dea7cb0b77
commit
630e1d454e
|
@ -3,9 +3,11 @@ package cn.iocoder.yudao.module.shop.service.order.impl;
|
||||||
import cn.iocoder.yudao.framework.common.enums.Constants;
|
import cn.iocoder.yudao.framework.common.enums.Constants;
|
||||||
import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi;
|
import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi;
|
||||||
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
|
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
|
||||||
|
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO;
|
||||||
import cn.iocoder.yudao.module.shop.dal.mysql.order.StoreOrderMapper;
|
import cn.iocoder.yudao.module.shop.dal.mysql.order.StoreOrderMapper;
|
||||||
import cn.iocoder.yudao.module.shop.request.order.StoreOrderRefundRequest;
|
import cn.iocoder.yudao.module.shop.request.order.StoreOrderRefundRequest;
|
||||||
import cn.iocoder.yudao.module.shop.service.order.StoreOrderRefundService;
|
import cn.iocoder.yudao.module.shop.service.order.StoreOrderRefundService;
|
||||||
|
import cn.iocoder.yudao.module.shop.support.pay.WxPayStrategy;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -27,6 +29,8 @@ public class StoreOrderRefundServiceImpl extends ServiceImpl<StoreOrderMapper, S
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiConfigApi apiConfigApi;
|
private ApiConfigApi apiConfigApi;
|
||||||
|
@Autowired
|
||||||
|
private WxPayStrategy wxPayStrategy;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refund(StoreOrderRefundRequest request, StoreOrder storeOrder) {
|
public void refund(StoreOrderRefundRequest request, StoreOrder storeOrder) {
|
||||||
|
@ -70,7 +74,10 @@ public class StoreOrderRefundServiceImpl extends ServiceImpl<StoreOrderMapper, S
|
||||||
String apiDomain = apiConfigApi.getConfigKey(Constants.CONFIG_KEY_API_URL).toString();
|
String apiDomain = apiConfigApi.getConfigKey(Constants.CONFIG_KEY_API_URL).toString();
|
||||||
|
|
||||||
// TODO 微信退款
|
// TODO 微信退款
|
||||||
|
RechargeOrderDO orderDO = new RechargeOrderDO();
|
||||||
|
orderDO.setOrderId(request.getOrderNo());
|
||||||
|
orderDO.setPayPrice(request.getAmount());
|
||||||
|
wxPayStrategy.refund(orderDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1142,7 +1142,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
|
||||||
orderCheck(request);
|
orderCheck(request);
|
||||||
// 初始化订单
|
// 初始化订单
|
||||||
MemberUserRespDTO user = userService.getUser(loginUser.getId());
|
MemberUserRespDTO user = userService.getUser(loginUser.getId());
|
||||||
String code = generateBillNo("MEMBER");
|
String code = OrderUtil.generateBillNo("MEMBER");
|
||||||
RechargeOrderDO orderDO = initializeOrder(request, code, user);
|
RechargeOrderDO orderDO = initializeOrder(request, code, user);
|
||||||
// 获取支付策略
|
// 获取支付策略
|
||||||
IPayStrategy payStrategy = strategySupport.getPayStrategy(request.getPayType());
|
IPayStrategy payStrategy = strategySupport.getPayStrategy(request.getPayType());
|
||||||
|
@ -1227,7 +1227,7 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
|
||||||
// 获取支付策略
|
// 获取支付策略
|
||||||
IPayStrategy payStrategy = strategySupport.getPayStrategy(orderDO.getPayType());
|
IPayStrategy payStrategy = strategySupport.getPayStrategy(orderDO.getPayType());
|
||||||
payStrategy.refund(orderDO);
|
payStrategy.refund(orderDO);
|
||||||
return null;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1335,18 +1335,6 @@ public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOr
|
||||||
return orderDO;
|
return orderDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 订单号
|
|
||||||
*
|
|
||||||
* @param prefix
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String generateBillNo(String prefix) {
|
|
||||||
String idStr = IdWorker.getIdStr();
|
|
||||||
idStr = prefix + "_" + idStr;
|
|
||||||
return idStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void orderCheck(OrderContentRequest request) {
|
private void orderCheck(OrderContentRequest request) {
|
||||||
Assert.isTrue(!CollectionUtils.isEmpty(request.getOrderInfos()), "订单信息不能为空!");
|
Assert.isTrue(!CollectionUtils.isEmpty(request.getOrderInfos()), "订单信息不能为空!");
|
||||||
if (StringUtils.isNotBlank(request.getUserPhone()) && StringUtils.isNotBlank(request.getConfirmPhone())) {
|
if (StringUtils.isNotBlank(request.getUserPhone()) && StringUtils.isNotBlank(request.getConfirmPhone())) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration;
|
||||||
import cn.iocoder.yudao.framework.pay.properties.WxPayProperties;
|
import cn.iocoder.yudao.framework.pay.properties.WxPayProperties;
|
||||||
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO;
|
import cn.iocoder.yudao.module.shop.dal.dataobject.recharge.RechargeOrderDO;
|
||||||
import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse;
|
import cn.iocoder.yudao.module.shop.response.member.InitOrderResponse;
|
||||||
|
import cn.iocoder.yudao.module.shop.utils.OrderUtil;
|
||||||
import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
|
import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
|
||||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
||||||
import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
|
import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
|
||||||
|
@ -60,12 +61,19 @@ public class WxPayStrategy implements IPayStrategy{
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String article="MEMBER_11111";
|
||||||
|
|
||||||
|
article=article.replace("MEMBER","TUIKUAN");
|
||||||
|
System.out.println(article);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void refund(RechargeOrderDO orderDO) {
|
public void refund(RechargeOrderDO orderDO) {
|
||||||
WxPayRefundV3Request wxPayRefundV3Request = new WxPayRefundV3Request();
|
WxPayRefundV3Request wxPayRefundV3Request = new WxPayRefundV3Request();
|
||||||
wxPayRefundV3Request.setOutTradeNo(orderDO.getOrderId());
|
wxPayRefundV3Request.setOutTradeNo(orderDO.getOrderId());
|
||||||
wxPayRefundV3Request.setOutRefundNo(orderDO.getPaySerialNumber());
|
String code = OrderUtil.generateBillNo("TUIKUAN");
|
||||||
wxPayRefundV3Request.setTransactionId(orderDO.getOrderId());
|
wxPayRefundV3Request.setOutRefundNo(code);
|
||||||
|
wxPayRefundV3Request.setTransactionId(orderDO.getPaySerialNumber());
|
||||||
wxPayRefundV3Request.setReason("商品已售完");
|
wxPayRefundV3Request.setReason("商品已售完");
|
||||||
wxPayRefundV3Request.setNotifyUrl(payProperties.getRefundNotifyUrl());
|
wxPayRefundV3Request.setNotifyUrl(payProperties.getRefundNotifyUrl());
|
||||||
int sum = orderDO.getPayPrice().multiply(new BigDecimal("100")).intValue();
|
int sum = orderDO.getPayPrice().multiply(new BigDecimal("100")).intValue();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.shop.constants.SysConfigConstants;
|
||||||
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
|
import cn.iocoder.yudao.module.shop.dal.dataobject.order.StoreOrder;
|
||||||
import cn.iocoder.yudao.module.shop.service.order.StoreOrderService;
|
import cn.iocoder.yudao.module.shop.service.order.StoreOrderService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -117,4 +118,16 @@ public class OrderUtil {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单号
|
||||||
|
*
|
||||||
|
* @param prefix
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String generateBillNo(String prefix) {
|
||||||
|
String idStr = IdWorker.getIdStr();
|
||||||
|
idStr = prefix + "_" + idStr;
|
||||||
|
return idStr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue