|
@@ -1,35 +1,50 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.BiPredicate;
|
|
|
+import java.util.function.Consumer;
|
|
|
+import java.util.function.Function;
|
|
|
+
|
|
|
+import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.TenantConfig;
|
|
|
import com.ym.mec.biz.dal.entity.TenantOrderRecord;
|
|
|
import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
-import com.ym.mec.biz.service.*;
|
|
|
+import com.ym.mec.biz.service.CloudTeacherOrderService;
|
|
|
+import com.ym.mec.biz.service.OrderPayOpsService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.TenantConfigService;
|
|
|
+import com.ym.mec.biz.service.TenantOrderRecordService;
|
|
|
+import com.ym.mec.biz.service.TenantPaymentOrderService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.WrapperUtil;
|
|
|
import com.ym.mec.thirdparty.adapay.ConfigInit;
|
|
|
import com.ym.mec.thirdparty.adapay.Payment;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
-import org.redisson.api.RBucket;
|
|
|
-import org.redisson.api.RedissonClient;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.DigestUtils;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.function.BiPredicate;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.function.Function;
|
|
|
+import com.ym.mec.util.json.JsonUtil;
|
|
|
|
|
|
/**
|
|
|
* @author hgw
|
|
@@ -49,6 +64,9 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private RedissonClient redissonClient;
|
|
|
@Autowired
|
|
|
private CloudTeacherOrderService cloudTeacherOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantConfigService tenantConfigService;
|
|
|
|
|
|
//支付类型
|
|
|
private static final Map<String, Function<PaymentParam, Map<String, Object>>> checkOrderType = new HashMap<>();
|
|
@@ -100,6 +118,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private Map<String, Object> teacher(PaymentParam payParam) {
|
|
|
Map<String, Object> payment;
|
|
|
TenantPaymentOrder tenantPaymentOrder = tenantPaymentOrderService.queryByOrderNo(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(1);
|
|
|
try {
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantPaymentOrder,
|
|
@@ -118,6 +137,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private Map<String, Object> tenantRecharge(PaymentParam payParam) {
|
|
|
Map<String, Object> payment;
|
|
|
TenantOrderRecord tenantOrderRecord = getTenantOrderRecord(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
payment = checkOrderGetPayment(payParam, tenantOrderRecord);
|
|
|
//主动延迟检查订单
|
|
|
log.info("executePayment delayCheckTenantRecharge >>>>> ");
|
|
@@ -128,6 +148,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
// 云教练支付
|
|
|
private Map<String, Object> cloudTeacherOrder(PaymentParam payParam) {
|
|
|
TenantOrderRecord tenantOrderRecord = getTenantOrderRecord(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
Map<String, Object> payment = checkOrderGetPayment(payParam, tenantOrderRecord);
|
|
|
// 云教练支付 主动延迟检查订单
|
|
|
log.info("executePayment delayCheckCloudTeacherOrder >>>>> ");
|
|
@@ -138,6 +159,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
//机构开通、续费付款
|
|
|
private Map<String, Object> openOrRenew(PaymentParam payParam) {
|
|
|
TenantOrderRecord tenantOrderRecord = getTenantOrderRecord(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
Map<String, Object> payment = checkOrderGetPayment(payParam, tenantOrderRecord);
|
|
|
//主动延迟检查订单
|
|
|
delayCheckTenant();
|
|
@@ -270,7 +292,39 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
paymentParams.put("pay_amt", payParam.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
paymentParams.put("goods_title", payParam.getOrderSubject());
|
|
|
paymentParams.put("goods_desc", payParam.getOrderBody());
|
|
|
- paymentParams.put("pay_mode", "delay");
|
|
|
+
|
|
|
+ if (payParam.getTenantId() == 1) {
|
|
|
+ // 延时分账
|
|
|
+ paymentParams.put("pay_mode", "delay");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ StudentPaymentOrder paymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
|
|
|
+ if (paymentOrder == null) {
|
|
|
+ throw new BizException("订单[{}]找不到", payParam.getOrderNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ TenantConfig tenantConfig = tenantConfigService.queryByTenantId(payParam.getTenantId());
|
|
|
+ if (tenantConfig == null) {
|
|
|
+ throw new BizException("机构[{}]信息找不到", payParam.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 实时分账
|
|
|
+ List<Map<String, Object>> divMemberList = new ArrayList<Map<String, Object>>();
|
|
|
+ Map<String, Object> divMember = new HashMap<String, Object>();
|
|
|
+ divMember.put("member_id", paymentOrder.getMerNos());
|
|
|
+ divMember.put("amount",
|
|
|
+ paymentOrder.getActualAmount().multiply(tenantConfig.getChargeRate()).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ divMember.put("fee_flag", "Y");
|
|
|
+
|
|
|
+ divMemberList.add(divMember);
|
|
|
+
|
|
|
+ paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //手续费收取模式:O-商户手续费账户扣取手续费,I-交易金额中扣取手续费;值为空时,默认值为I;若为O时,分账对象列表中不支持传入手续费承担方
|
|
|
+ paymentParams.put("fee_mode", "I");
|
|
|
+
|
|
|
return paymentParams;
|
|
|
}
|
|
|
|
|
@@ -359,6 +413,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private String sign;
|
|
|
private String code;
|
|
|
private String platform;
|
|
|
+ private Integer tenantId;
|
|
|
|
|
|
PaymentParam(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject,
|
|
|
String orderBody, String sign, String code, String platform) {
|
|
@@ -444,6 +499,15 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
public void setPlatform(String platform) {
|
|
|
this.platform = platform;
|
|
|
}
|
|
|
+
|
|
|
+ public Integer getTenantId() {
|
|
|
+ return tenantId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTenantId(Integer tenantId) {
|
|
|
+ this.tenantId = tenantId;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|