|
@@ -8,6 +8,8 @@ import java.util.*;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.annotation.DataScope;
|
|
|
import com.fs.common.annotation.Log;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
@@ -30,15 +32,13 @@ import com.fs.course.service.IFsCourseRedPacketLogService;
|
|
|
import com.fs.course.service.IFsUserCourseOrderService;
|
|
|
import com.fs.course.service.IFsUserVipOrderService;
|
|
|
import com.fs.erp.dto.ErpRefundUpdateRequest;
|
|
|
-import com.fs.his.domain.FsExportTask;
|
|
|
-import com.fs.his.domain.FsPayConfig;
|
|
|
-import com.fs.his.domain.FsStorePayment;
|
|
|
-import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.domain.*;
|
|
|
import com.fs.his.dto.PayConfigDTO;
|
|
|
import com.fs.his.enums.PaymentMethodEnum;
|
|
|
import com.fs.his.mapper.FsExportTaskMapper;
|
|
|
import com.fs.his.mapper.FsStorePaymentMapper;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.mapper.FsUserWxMapper;
|
|
|
import com.fs.his.param.FsStoreOrderParam;
|
|
|
import com.fs.his.param.FsStorePaymentParam;
|
|
|
import com.fs.his.param.PayOrderParam;
|
|
@@ -149,6 +149,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
private CompanyConfigMapper companyConfigMapper;
|
|
|
@Autowired
|
|
|
private FsUserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsUserWxMapper userWxMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询支付明细
|
|
@@ -541,6 +543,12 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
|
|
|
// 内部方法:处理旧版本的发红包逻辑
|
|
|
private R sendRedPacketLegacyInternal(WxSendRedPacketParam param, RedPacketConfig config) {
|
|
|
+ //如果服务号的配置存在,小程序红包接口可以使用服务号来发红包,重新赋值
|
|
|
+ //仅老商户支持
|
|
|
+ if (param.getUser().getMpOpenId()!=null && StringUtils.isNotEmpty(param.getMpAppId())){
|
|
|
+ config.setAppId(param.getMpAppId());
|
|
|
+ param.setOpenId(param.getUser().getMpOpenId());
|
|
|
+ }
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
BeanUtils.copyProperties(config, payConfig);
|
|
|
WxPayService wxPayService = new WxPayServiceImpl();
|
|
@@ -550,6 +558,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
TransferBatchesRequest request = new TransferBatchesRequest();
|
|
|
request.setAppid(config.getAppId());
|
|
|
|
|
|
+
|
|
|
// todo 如果未配置负载均衡请还原原本的单号方式
|
|
|
// String code = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
String code = OrderCodeUtils.getOrderSn();
|
|
@@ -817,17 +826,17 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
throw new CustomException("用户不存在");
|
|
|
}
|
|
|
|
|
|
+ String json = configService.selectConfigByKey("his.pay");
|
|
|
+ logger.debug("支付配置 his.pay: {}", json);
|
|
|
+ FsPayConfig payConfig = JSONUtil.toBean(json, FsPayConfig.class);
|
|
|
+
|
|
|
if (isWechatPayment(payOrderParam.getPaymentMethod())) {
|
|
|
- String openId = getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod());
|
|
|
+ String openId = getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod(), payConfig);
|
|
|
if (StringUtils.isBlank(openId)){
|
|
|
throw new CustomException("用户OPENID不存在");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String json = configService.selectConfigByKey("his.pay");
|
|
|
- logger.debug("支付配置 his.pay: {}", json);
|
|
|
- FsPayConfig payConfig = JSONUtil.toBean(json, FsPayConfig.class);
|
|
|
-
|
|
|
// 创建记录
|
|
|
FsStorePayment storePayment = createStorePayment(payConfig, user, payOrderParam);
|
|
|
|
|
@@ -841,13 +850,13 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
private R createThirdPartyPayment(FsPayConfig payConfig, FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
switch (payConfig.getType()) {
|
|
|
case "wx":
|
|
|
- return createWxPayment(payConfig, storePayment, user, payOrderParam);
|
|
|
+ return createWxPayment(storePayment, user, payOrderParam, payConfig);
|
|
|
case "yb":
|
|
|
- return createYbPayment(storePayment, user, payOrderParam);
|
|
|
+ return createYbPayment(storePayment, user, payOrderParam, payConfig);
|
|
|
case "tz":
|
|
|
- return createTzPayment(storePayment, user, payOrderParam);
|
|
|
+ return createTzPayment(storePayment, user, payOrderParam, payConfig);
|
|
|
case "hf":
|
|
|
- return createHfPayment(storePayment, user, payOrderParam);
|
|
|
+ return createHfPayment(storePayment, user, payOrderParam, payConfig);
|
|
|
default:
|
|
|
throw new CustomException("不支持的支付方式");
|
|
|
}
|
|
@@ -856,7 +865,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 汇付
|
|
|
*/
|
|
|
- private R createHfPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
+ private R createHfPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam, FsPayConfig payConfig) {
|
|
|
logger.debug("创建汇付订单");
|
|
|
|
|
|
HuiFuCreateOrder order = new HuiFuCreateOrder();
|
|
@@ -867,7 +876,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
|
|
|
// 微信支付需要设置openid
|
|
|
if (isWechatPayment(payOrderParam.getPaymentMethod())) {
|
|
|
- order.setOpenid(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod()));
|
|
|
+ order.setOpenid(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod(), payConfig));
|
|
|
}
|
|
|
|
|
|
HuifuCreateOrderResult result = huiFuService.createOrder(order);
|
|
@@ -897,8 +906,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 台州银行
|
|
|
*/
|
|
|
- private R createTzPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
- PayCreateOrder payOrder = buildTzPayOrder(storePayment, user, payOrderParam);
|
|
|
+ private R createTzPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam, FsPayConfig payConfig) {
|
|
|
+ PayCreateOrder payOrder = buildTzPayOrder(storePayment, user, payOrderParam, payConfig);
|
|
|
TzBankResult<PayCreateOrderResult> result = tzBankService.createOrder(payOrder);
|
|
|
|
|
|
updateStorePaymentTradeNo(storePayment.getPaymentId(), result.getBody().getOrderFlowNo());
|
|
@@ -908,7 +917,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 构建台州银行支付
|
|
|
*/
|
|
|
- private PayCreateOrder buildTzPayOrder(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
+ private PayCreateOrder buildTzPayOrder(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam, FsPayConfig payConfig) {
|
|
|
PayCreateOrder payOrder = new PayCreateOrder();
|
|
|
payOrder.setOrderNo(payOrderParam.getBusinessType().getPrefix() + "-" + storePayment.getPayCode());
|
|
|
payOrder.setTrxAmt(storePayment.getPayMoney().doubleValue());
|
|
@@ -929,7 +938,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
}
|
|
|
|
|
|
if (isWechatPayment(payOrderParam.getPaymentMethod())) {
|
|
|
- payOrder.setOpenId(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod()));
|
|
|
+ payOrder.setOpenId(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod(), payConfig));
|
|
|
}
|
|
|
|
|
|
return payOrder;
|
|
@@ -980,7 +989,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 易宝支付
|
|
|
*/
|
|
|
- private R createYbPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
+ private R createYbPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam, FsPayConfig payConfig) {
|
|
|
PaymentMethodEnum paymentMethod = payOrderParam.getPaymentMethod();
|
|
|
if (paymentMethod == PaymentMethodEnum.ALIPAY || paymentMethod == PaymentMethodEnum.H5_ALIPAY
|
|
|
|| paymentMethod == PaymentMethodEnum.H5_WECHAT) {
|
|
@@ -992,7 +1001,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
payDto.setLowOrderId(payOrderParam.getBusinessType().getPrefix() + "-" + storePayment.getPayCode());
|
|
|
payDto.setBody(payOrderParam.getBusinessType().getDesc());
|
|
|
payDto.setIsMinipg("1");
|
|
|
- payDto.setOpenId(getOpenIdForPaymentMethod(user, paymentMethod));
|
|
|
+ payDto.setOpenId(getOpenIdForPaymentMethod(user, paymentMethod, payConfig));
|
|
|
payDto.setAttach("");
|
|
|
payDto.setStoreid("0");
|
|
|
|
|
@@ -1020,7 +1029,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 微信支付
|
|
|
*/
|
|
|
- private R createWxPayment(FsPayConfig payConfig, FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam) {
|
|
|
+ private R createWxPayment(FsStorePayment storePayment, FsUser user, PayOrderParam payOrderParam, FsPayConfig payConfig) {
|
|
|
PaymentMethodEnum paymentMethod = payOrderParam.getPaymentMethod();
|
|
|
if (paymentMethod != PaymentMethodEnum.MINIAPP_WECHAT) {
|
|
|
logger.debug("微信支付 PaymentMethod: {}", paymentMethod.name());
|
|
@@ -1031,7 +1040,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
wxPayService.setConfig(wxPayConfig);
|
|
|
|
|
|
WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
- orderRequest.setOpenid(getOpenIdForPaymentMethod(user, paymentMethod));
|
|
|
+ orderRequest.setOpenid(getOpenIdForPaymentMethod(user, paymentMethod, payConfig));
|
|
|
orderRequest.setBody(payOrderParam.getBusinessType().getDesc());
|
|
|
orderRequest.setOutTradeNo(payOrderParam.getBusinessType().getPrefix() + "-" + storePayment.getPayCode());
|
|
|
orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));
|
|
@@ -1074,15 +1083,30 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
/**
|
|
|
* 根据支付方式获取对应的openId
|
|
|
*/
|
|
|
- private String getOpenIdForPaymentMethod(FsUser user, PaymentMethodEnum method) {
|
|
|
+ private String getOpenIdForPaymentMethod(FsUser user, PaymentMethodEnum method, FsPayConfig payConfig) {
|
|
|
+ String openId;
|
|
|
switch (method) {
|
|
|
case MINIAPP_WECHAT:
|
|
|
- return user.getMaOpenId();
|
|
|
+ openId = user.getMaOpenId();
|
|
|
+ break;
|
|
|
case H5_WECHAT:
|
|
|
- return user.getMpOpenId();
|
|
|
+ openId = user.getMpOpenId();
|
|
|
+ break;
|
|
|
default:
|
|
|
- return null;
|
|
|
+ openId = null;
|
|
|
}
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(openId)) {
|
|
|
+ Wrapper<FsUserWx> queryWrapper = Wrappers.<FsUserWx>lambdaQuery()
|
|
|
+ .eq(FsUserWx::getFsUserId, user.getUserId())
|
|
|
+ .eq(FsUserWx::getAppId, payConfig.getAppId());
|
|
|
+ FsUserWx fsUserWx = userWxMapper.selectOne(queryWrapper);
|
|
|
+ if (Objects.nonNull(fsUserWx)) {
|
|
|
+ openId = fsUserWx.getOpenId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return openId;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1112,7 +1136,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
|
|
|
|
|
|
// 设置openId(如果是微信支付)
|
|
|
if (isWechatPayment(payOrderParam.getPaymentMethod())) {
|
|
|
- storePayment.setOpenId(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod()));
|
|
|
+ storePayment.setOpenId(getOpenIdForPaymentMethod(user, payOrderParam.getPaymentMethod(), payConfig));
|
|
|
}
|
|
|
|
|
|
if (fsStorePaymentMapper.insertFsStorePayment(storePayment) <= 0) {
|