|
@@ -58,6 +58,8 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
|
|
|
//tenant 机构开通、续费付款、 cloudTeacherOrder 团练宝激活支付、tenantRecharge 机构充值
|
|
|
private static final String[] tenantPlatform = {"tenant", "cloudTeacherOrder", "tenantRecharge"};
|
|
|
+ //校验订单状态
|
|
|
+ private static final BiPredicate<Object, DealStatusEnum> predicate = (o, s) -> Objects.nonNull(o) && !DealStatusEnum.ING.equals(s);
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> executePayment(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception {
|
|
@@ -87,21 +89,47 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
return payment;
|
|
|
}
|
|
|
|
|
|
- //platform is null 或者 student
|
|
|
- private Map<String, Object> student(PaymentParam payParam) throws Exception {
|
|
|
- Map<String, Object> payment;
|
|
|
- StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
|
|
|
- if (Objects.isNull(studentPaymentOrder)) {
|
|
|
+ private void checkSing(PaymentParam param) {
|
|
|
+ Map<String, Object> signParams = new LinkedHashMap<>();
|
|
|
+ signParams.put("appId", ConfigInit.appId);
|
|
|
+ signParams.put("amount", param.getAmount().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ signParams.put("orderNo", param.getOrderNo());
|
|
|
+ signParams.put("orderSubject", param.getOrderSubject());
|
|
|
+ signParams.put("orderBody", param.getOrderBody());
|
|
|
+ signParams.put("wxAppId", ConfigInit.wxAppId);
|
|
|
+ String originalStr = JSONObject.toJSONString(signParams);
|
|
|
+ String newSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
|
|
|
+ if (!newSign.equals(param.getSign())) {
|
|
|
+ log.info("executePayment >>>>>> checkSing : {}", newSign);
|
|
|
+ throw new BizException("请勿非法请求");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //机构开通、续费付款、 团练宝激活支付、机构充值
|
|
|
+ private Map<String, Object> tenantPlatformOrder(PaymentParam payParam) {
|
|
|
+ //查询订单
|
|
|
+ TenantOrderRecord tenantOrderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
|
|
|
+ .hasEq("order_no_", payParam.getOrderNo()).queryWrapper());
|
|
|
+ if (Objects.isNull(tenantOrderRecord)) {
|
|
|
throw new BizException("订单不存在");
|
|
|
}
|
|
|
- payParam.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
- payment = checkOrderAndGetParam(payParam,
|
|
|
- studentPaymentOrder,
|
|
|
- StudentPaymentOrder::getStatus,
|
|
|
- StudentPaymentOrder::getCreateTime,
|
|
|
- studentPaymentOrder::setTransNo,
|
|
|
- studentPaymentOrderService::update
|
|
|
- );
|
|
|
+ if (tenantOrderRecord.getOrderState() != 0) {
|
|
|
+ throw new BizException("订单已处理!");
|
|
|
+ }
|
|
|
+ //获取支付数据
|
|
|
+ Map<String, Object> payment;
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
+ try {
|
|
|
+ payment = checkOrderAndGetParam(payParam,
|
|
|
+ tenantOrderRecord,
|
|
|
+ TenantOrderRecord::getEnumOrderState,
|
|
|
+ TenantOrderRecord::getCreatedTime,
|
|
|
+ tenantOrderRecord::setTransNo,
|
|
|
+ tenantOrderRecordService::updateById
|
|
|
+ );
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException(e.getMessage());
|
|
|
+ }
|
|
|
return payment;
|
|
|
}
|
|
|
|
|
@@ -127,59 +155,24 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
return payment;
|
|
|
}
|
|
|
|
|
|
- //机构开通、续费付款、 团练宝激活支付、机构充值
|
|
|
- private Map<String, Object> tenantPlatformOrder(PaymentParam payParam) {
|
|
|
- TenantOrderRecord tenantOrderRecord = getTenantOrderRecord(payParam.getOrderNo());
|
|
|
- if (tenantOrderRecord.getOrderState() != 0) {
|
|
|
- throw new BizException("订单已处理!");
|
|
|
- }
|
|
|
- return checkOrderGetPayment(payParam, tenantOrderRecord);
|
|
|
- }
|
|
|
-
|
|
|
- //查询订单
|
|
|
- private TenantOrderRecord getTenantOrderRecord(String orderNo) {
|
|
|
- TenantOrderRecord orderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
|
|
|
- .hasEq("order_no_", orderNo).queryWrapper());
|
|
|
- if (Objects.isNull(orderRecord)) {
|
|
|
- throw new BizException("订单不存在");
|
|
|
- }
|
|
|
- return orderRecord;
|
|
|
- }
|
|
|
-
|
|
|
- //获取支付数据
|
|
|
- private Map<String, Object> checkOrderGetPayment(PaymentParam payParam, TenantOrderRecord tenantOrderRecord) {
|
|
|
+ //platform is null 或者 student
|
|
|
+ private Map<String, Object> student(PaymentParam payParam) throws Exception {
|
|
|
Map<String, Object> payment;
|
|
|
- payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
- try {
|
|
|
- payment = checkOrderAndGetParam(payParam,
|
|
|
- tenantOrderRecord,
|
|
|
- TenantOrderRecord::getEnumOrderState,
|
|
|
- TenantOrderRecord::getCreatedTime,
|
|
|
- tenantOrderRecord::setTransNo,
|
|
|
- tenantOrderRecordService::updateById
|
|
|
- );
|
|
|
- } catch (Exception e) {
|
|
|
- throw new BizException(e.getMessage());
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
|
|
|
+ if (Objects.isNull(studentPaymentOrder)) {
|
|
|
+ throw new BizException("订单不存在");
|
|
|
}
|
|
|
+ payParam.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
+ payment = checkOrderAndGetParam(payParam,
|
|
|
+ studentPaymentOrder,
|
|
|
+ StudentPaymentOrder::getStatus,
|
|
|
+ StudentPaymentOrder::getCreateTime,
|
|
|
+ studentPaymentOrder::setTransNo,
|
|
|
+ studentPaymentOrderService::update
|
|
|
+ );
|
|
|
return payment;
|
|
|
}
|
|
|
|
|
|
- private void checkSing(PaymentParam param) {
|
|
|
- Map<String, Object> signParams = new LinkedHashMap<>();
|
|
|
- signParams.put("appId", ConfigInit.appId);
|
|
|
- signParams.put("amount", param.getAmount().setScale(2, RoundingMode.HALF_UP));
|
|
|
- signParams.put("orderNo", param.getOrderNo());
|
|
|
- signParams.put("orderSubject", param.getOrderSubject());
|
|
|
- signParams.put("orderBody", param.getOrderBody());
|
|
|
- signParams.put("wxAppId", ConfigInit.wxAppId);
|
|
|
- String originalStr = JSONObject.toJSONString(signParams);
|
|
|
- String newSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
|
|
|
- if (!newSign.equals(param.getSign())) {
|
|
|
- log.info("executePayment >>>>>> checkSing : {}", newSign);
|
|
|
- throw new BizException("请勿非法请求");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private <T> Map<String, Object> checkOrderAndGetParam(PaymentParam payParam, T clazz,
|
|
|
Function<T, DealStatusEnum> enumFunc, Function<T, Date> dateFunc,
|
|
|
Consumer<String> setOption, Consumer<T> action) throws Exception {
|
|
@@ -207,7 +200,6 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
}
|
|
|
|
|
|
private <T> void checkOrderState(T obj, Function<T, DealStatusEnum> func) {
|
|
|
- BiPredicate<Object, DealStatusEnum> predicate = (o, s) -> Objects.nonNull(o) && !DealStatusEnum.ING.equals(s);
|
|
|
DealStatusEnum em = func.apply(obj);
|
|
|
if (predicate.test(obj, em)) {
|
|
|
String msg = em.equals(DealStatusEnum.SUCCESS) ? "订单已支付,请勿重复支付" : "订单已关闭,不能支付";
|
|
@@ -284,7 +276,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
|
|
|
|
|
|
StudentPaymentOrder st = (StudentPaymentOrder) clazz;
|
|
|
- BigDecimal amount = amountTo.apply(st.getActualAmount()).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal amount = amountTo.apply(st.getActualAmount());
|
|
|
|
|
|
List<Map<String, Object>> divMemberList = new ArrayList<>();
|
|
|
// 实时分账
|