feat: 商城支付退款

pull/2/head
tangqian 2023-05-18 09:45:29 +08:00
parent 711b61ca25
commit d958f5d012
2 changed files with 43 additions and 5 deletions

View File

@ -46,4 +46,6 @@ public class OrderPayRequest {
@Schema(description = "下单时小程序的场景值") @Schema(description = "下单时小程序的场景值")
private Integer scene; private Integer scene;
@Schema(description = "openid")
private String openid;
} }

View File

@ -5,6 +5,9 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.Constants; import cn.iocoder.yudao.framework.common.enums.Constants;
import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.util.date.DateUtils; import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.framework.pay.config.WxPayOneAutoConfiguration;
import cn.iocoder.yudao.framework.pay.properties.WxPayProperties;
import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi; import cn.iocoder.yudao.module.infra.api.config.ApiConfigApi;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserBillDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserBillDTO;
@ -22,12 +25,18 @@ import cn.iocoder.yudao.module.shop.service.product.StoreProductService;
import cn.iocoder.yudao.module.shop.utils.OrderUtil; import cn.iocoder.yudao.module.shop.utils.OrderUtil;
import cn.iocoder.yudao.module.shop.utils.RedisUtil; import cn.iocoder.yudao.module.shop.utils.RedisUtil;
import cn.iocoder.yudao.module.shop.vo.order.WxPayJsResultVo; import cn.iocoder.yudao.module.shop.vo.order.WxPayJsResultVo;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
import com.github.binarywang.wxpay.service.WxPayService;
import lombok.Data; import lombok.Data;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.Assert;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
@ -86,6 +95,12 @@ public class OrderPayServiceImpl implements OrderPayService {
@Autowired @Autowired
private ApiConfigApi apiConfigApi; private ApiConfigApi apiConfigApi;
@Autowired
private WxPayOneAutoConfiguration wxPayOneAutoConfiguration;
@Autowired
private WxPayProperties payProperties;
/** /**
* *
@ -135,6 +150,7 @@ public class OrderPayServiceImpl implements OrderPayService {
/** /**
* *
*
* @param storeOrder * @param storeOrder
* @return Boolean Boolean * @return Boolean Boolean
*/ */
@ -229,7 +245,7 @@ public class OrderPayServiceImpl implements OrderPayService {
// 微信支付,调用微信预下单,返回拉起微信支付需要的信息 // 微信支付,调用微信预下单,返回拉起微信支付需要的信息
if (storeOrder.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) { if (storeOrder.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) {
// 预下单 // 预下单
Map<String, String> unifiedorder = unifiedorder(storeOrder, ip); Map<String, String> unifiedorder = unifiedorder(storeOrder, ip, orderPayRequest.getOpenid());
response.setStatus(true); response.setStatus(true);
WxPayJsResultVo vo = new WxPayJsResultVo(); WxPayJsResultVo vo = new WxPayJsResultVo();
vo.setAppId(unifiedorder.get("appId")); vo.setAppId(unifiedorder.get("appId"));
@ -266,11 +282,12 @@ public class OrderPayServiceImpl implements OrderPayService {
/** /**
* *
*
* @param storeOrder * @param storeOrder
* @param ip ip * @param ip ip
* @return * @return
*/ */
private Map<String, String> unifiedorder(StoreOrder storeOrder, String ip) { private Map<String, String> unifiedorder(StoreOrder storeOrder, String ip,String openid) {
// 获取用户openId // 获取用户openId
// 根据订单支付类型来判断获取公众号openId还是小程序openId // 根据订单支付类型来判断获取公众号openId还是小程序openId
@ -314,6 +331,25 @@ public class OrderPayServiceImpl implements OrderPayService {
// if (storeOrder.getIsChannel() == 2) { // if (storeOrder.getIsChannel() == 2) {
// map.put("mweb_url", responseVo.getMWebUrl()); // map.put("mweb_url", responseVo.getMWebUrl());
// } // }
WxPayService wxPayService = wxPayOneAutoConfiguration.wxPayOneService();
Assert.notNull(wxPayService, "获取微信支付配置失败!");
WxPayUnifiedOrderV3Request wxPayRequest = new WxPayUnifiedOrderV3Request();
int sum = storeOrder.getPayPrice().multiply(new BigDecimal("100")).intValue();
wxPayRequest.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(sum));
wxPayRequest.setDescription("会员充值");
wxPayRequest.setOutTradeNo(storeOrder.getOrderId());
wxPayRequest.setNotifyUrl(payProperties.getNotifyUrl());
wxPayRequest.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(openid));
wxPayRequest.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(ip));
wxPayRequest.setAppid(payProperties.getAppId());
wxPayRequest.setMchid(payProperties.getMchId());
try {
WxPayUnifiedOrderV3Result wxPayUnifiedOrderV3Result = wxPayService.unifiedOrderV3(TradeTypeEnum.JSAPI, wxPayRequest);
map.put("mweb_url",wxPayUnifiedOrderV3Result.getH5Url());
} catch (Exception e) {
e.getMessage();
}
return map; return map;
} }
} }