11
This commit is contained in:
1 parent
e19bc4a7ef
commit
2e02b87555
8 files changed
+163
-10
No files matched your search
+6
@@ -30,6 +30,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 第三方订单号
|
||||
*/
|
||||
@Schema(description = "第三方订单号")
|
||||
private String thirdPayNo;
|
||||
|
||||
/**
|
||||
* 支付平台类型
|
||||
*/
|
||||
|
||||
+2
-1
@@ -2,12 +2,13 @@ package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.wechat.pay.java.service.profitsharing.model.OrdersEntity;
|
||||
|
||||
public interface ThirdAppPlusWechatFzService {
|
||||
|
||||
/**
|
||||
* 发起分账
|
||||
*/
|
||||
void create(ThirdPayOrderEntity orderEntity);
|
||||
OrdersEntity create(ThirdPayOrderEntity orderEntity);
|
||||
|
||||
}
|
||||
+13
-3
@@ -16,6 +16,7 @@ import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.*;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.appplus.fz.lifecycle.ThirdAppPlusWechatFzLifecycle;
|
||||
import com.bsd.pjcloud.thirdparty.utils.pay.wechat.ThirdAppPlusWechantPayConstant;
|
||||
import com.bsd.pjcloud.thirdparty.vo.appplus.pay.wechat.*;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
@@ -36,7 +37,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.net.ssl.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -63,6 +63,7 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
private final RefundService refundService;
|
||||
private final NotificationParser notificationParser;
|
||||
private final ProfitsharingService profitsharingService;
|
||||
private final ThirdAppPlusWechatFzLifecycle appPlusWechatFzLifecycle;
|
||||
|
||||
/**
|
||||
* APP支付
|
||||
@@ -274,11 +275,16 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
|
||||
// 更新订单状态
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
updateObj.setThirdPayNo(transaction.getTransactionId());
|
||||
updateObj.setId(payOrderEntity.getId());
|
||||
updateObj.setPayCallbackRes(JSONUtil.toJsonStr(transaction));
|
||||
updateObj.setStatus(paySucess ? ThirdPayOrderStatusEnum.PAY_SUCCESS.getType() : ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
return thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
|
||||
ThirdPayOrderEntity result = thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
// 订单支付成功
|
||||
appPlusWechatFzLifecycle.orderPaySuccess(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +343,11 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
updateObj.setRefundCallbackRes(JSONUtil.toJsonStr(refundNotification));
|
||||
updateObj.setStatus(refundSuccess ? ThirdPayOrderStatusEnum.REFUND_SUCCESS.getType() : ThirdPayOrderStatusEnum.REFUND_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
return thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
|
||||
ThirdPayOrderEntity result = thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
// 订单退款后
|
||||
appPlusWechatFzLifecycle.afterOrderRefund(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.appplus.common;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* app支付的生命周期
|
||||
*/
|
||||
public interface AppPlusOrderLifecycle {
|
||||
|
||||
/**
|
||||
* 订单创建前
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void beforeOrderCreate(ThirdPayOrderEntity order) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建后
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void afterOrderCreate(ThirdPayOrderEntity order) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付成功
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void orderPaySuccess(ThirdPayOrderEntity order) {}
|
||||
|
||||
/**
|
||||
* 订单退款前
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void beforeOrderRefund(ThirdPayOrderEntity order) {}
|
||||
|
||||
/**
|
||||
* 订单退款后
|
||||
* @param order 支付订单
|
||||
*/
|
||||
default void afterOrderRefund(ThirdPayOrderEntity order) {
|
||||
}
|
||||
|
||||
}
|
||||
+11
-5
@@ -44,11 +44,16 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
* 发起分账
|
||||
*/
|
||||
@Override
|
||||
public void create(ThirdPayOrderEntity orderEntity) {
|
||||
public OrdersEntity create(ThirdPayOrderEntity orderEntity) {
|
||||
// 获取配置
|
||||
if (ObjectUtil.isEmpty(orderEntity.getMchPaySettingJson())) {
|
||||
throw new RuntimeException("支付配置不存在");
|
||||
}
|
||||
// 总金额小毛直接返回(不分账)
|
||||
if (orderEntity.getPrice() < 10) {
|
||||
log.info("|{}|订单金额太小,无需分账,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
ThirdFzOrderEntity fzOrderEntity = new ThirdFzOrderEntity();
|
||||
fzOrderEntity.setFzTime(LocalDateTime.now());
|
||||
fzOrderEntity.setStatus(ThirdFzOrderStatusEnum.FZ_UNPAID.getType());
|
||||
@@ -61,7 +66,6 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
String outOrderNo = "fz" + orderEntity.getPayNo();
|
||||
// 最少分账1分
|
||||
Long amount = BigDecimal.valueOf(orderEntity.getPrice())
|
||||
.divide(BigDecimal.valueOf(100))
|
||||
.multiply(BigDecimal.valueOf(mchPaySetting.getFzRatio()))
|
||||
.setScale(2, RoundingMode.HALF_UP)
|
||||
.multiply(BigDecimal.valueOf(100))
|
||||
@@ -73,7 +77,7 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
// 请求参数
|
||||
CreateOrderRequest createDto = new CreateOrderRequest();
|
||||
createDto.setSubAppid(wechatPaySetting.getSubMchid());
|
||||
createDto.setTransactionId("");
|
||||
createDto.setTransactionId(orderEntity.getThirdPayNo());
|
||||
createDto.setOutOrderNo(outOrderNo);
|
||||
CreateOrderReceiver zaxReceiver = new CreateOrderReceiver();
|
||||
zaxReceiver.setType("MERCHANT_ID");
|
||||
@@ -86,11 +90,13 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
try {
|
||||
fzOrderEntity.setCreateReq(JSONUtil.toJsonStr(createDto));
|
||||
OrdersEntity orderRes = profitsharingService.createOrder(createDto);
|
||||
fzOrderEntity.setCreateRes(JSONUtil.toJsonStr(createDto));
|
||||
fzOrderEntity.setCreateRes(JSONUtil.toJsonStr(orderRes));
|
||||
return orderRes;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fzOrderEntity.setCreateError(JSONUtil.toJsonStr(e));
|
||||
fzOrderEntity.setCreateError(e.getMessage());
|
||||
log.error("|{}|发起分账意外的错误,error:|{}|", TAG, e.getMessage());
|
||||
return null;
|
||||
} finally {
|
||||
thirdFzOrderMapper.insert(fzOrderEntity);
|
||||
}
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.appplus.fz.lifecycle;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.appplus.common.AppPlusOrderLifecycle;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdAppPlusWechatFzLifecycle implements AppPlusOrderLifecycle {
|
||||
|
||||
private final ThirdAppPlusWechatFzService appPlusWechatFzService;
|
||||
|
||||
/**
|
||||
* 订单创建前
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void beforeOrderCreate(ThirdPayOrderEntity order) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建后
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void afterOrderCreate(ThirdPayOrderEntity order) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付成功
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void orderPaySuccess(ThirdPayOrderEntity order) {
|
||||
// 发起分账
|
||||
appPlusWechatFzService.create(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款前
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void beforeOrderRefund(ThirdPayOrderEntity order) {
|
||||
AppPlusOrderLifecycle.super.beforeOrderRefund(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款后
|
||||
*
|
||||
* @param order 支付订单
|
||||
*/
|
||||
@Override
|
||||
public void afterOrderRefund(ThirdPayOrderEntity order) {
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -2,11 +2,13 @@ package com.bsd.pjcloud.wallet.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.core.constant.CacheConstants;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.wallet.api.dto.mch.MchPaySettingDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,6 +20,12 @@ public interface MchPaySettingService extends IService<MchPaySettingEntity> {
|
||||
|
||||
Long create(MchPaySettingDto dto);
|
||||
|
||||
@CacheEvict(
|
||||
value = CacheConstants.WALLET_VIEWS_CANTEEN_MCH,
|
||||
condition = "#dto.getMchId() != null",
|
||||
beforeInvocation = true,
|
||||
allEntries = true
|
||||
)
|
||||
MchPaySettingEntity edit(MchPaySettingDto dto);
|
||||
|
||||
/**
|
||||
|
||||
+11
-1
@@ -350,7 +350,17 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
|
||||
if (ObjectUtil.isEmpty(walletMchDeptView) || ObjectUtil.isEmpty(walletMchDeptView.getDeptId())) {
|
||||
return null;
|
||||
}
|
||||
return baseMapper.join(walletMchDeptView.getMchId());
|
||||
MchManageVo result = baseMapper.join(walletMchDeptView.getMchId());
|
||||
|
||||
MchPaySettingDto paySettingDto = new MchPaySettingDto();
|
||||
paySettingDto.setMchId(result.getId());
|
||||
paySettingDto.setEnable(YesNoEnum.YES.getCode());
|
||||
List<MchPaySettingVo> paySettingList = paySettingService.pageList(paySettingDto, null);
|
||||
if (ObjectUtil.isNotEmpty(paySettingList)) {
|
||||
result.setPaySettingList(paySettingList);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user