|
@@ -1,12 +1,45 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+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.Optional;
|
|
|
+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.apache.commons.lang3.StringUtils;
|
|
|
+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.StudentPaymentRouteOrder;
|
|
|
+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;
|
|
@@ -15,24 +48,6 @@ import com.ym.mec.util.date.DateUtil;
|
|
|
import com.ym.mec.util.http.HttpUtil;
|
|
|
import com.ym.mec.util.json.JsonUtil;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-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.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;
|
|
|
-
|
|
|
/**
|
|
|
* @author hgw
|
|
|
* Created by 2021-12-22
|
|
@@ -43,6 +58,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private TenantPaymentOrderService tenantPaymentOrderService;
|
|
|
@Autowired
|
|
@@ -51,6 +67,9 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private RedissonClient redissonClient;
|
|
|
@Autowired
|
|
|
private CloudTeacherOrderService cloudTeacherOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantConfigService tenantConfigService;
|
|
|
|
|
|
@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 {
|
|
@@ -69,6 +88,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
//机构开通、续费付款
|
|
|
TenantOrderRecord tenantOrderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
|
|
|
.hasEq("order_no_", payParam.getOrderNo()).queryWrapper());
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantOrderRecord,
|
|
|
TenantOrderRecord::getEnumOrderState,
|
|
@@ -85,6 +105,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
if (tenantOrderRecord.getOrderState() == 1) {
|
|
|
throw new Exception("订单已支付, 订单号:" + payParam.getOrderNo());
|
|
|
}
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantOrderRecord,
|
|
|
TenantOrderRecord::getEnumOrderState,
|
|
@@ -102,6 +123,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
if (tenantOrderRecord.getOrderState() == 1) {
|
|
|
throw new Exception("订单已支付, 订单号:" + payParam.getOrderNo());
|
|
|
}
|
|
|
+ payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantOrderRecord,
|
|
|
TenantOrderRecord::getEnumOrderState,
|
|
@@ -114,6 +136,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
delayCheckTenantRecharge(tenantOrderRecord);
|
|
|
} else if (platform.equals("teacher")) {
|
|
|
TenantPaymentOrder tenantPaymentOrder = tenantPaymentOrderService.queryByOrderNo(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(1);
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantPaymentOrder,
|
|
|
TenantPaymentOrder::getStatus,
|
|
@@ -123,6 +146,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
);
|
|
|
} else {
|
|
|
StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
|
|
|
+ payParam.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
studentPaymentOrder,
|
|
|
StudentPaymentOrder::getStatus,
|
|
@@ -245,22 +269,37 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
paymentParams.put("goods_title", payParam.getOrderSubject());
|
|
|
paymentParams.put("goods_desc", payParam.getOrderBody());
|
|
|
|
|
|
- //延时分账
|
|
|
- //paymentParams.put("pay_mode", "delay");
|
|
|
-
|
|
|
- //实时分账
|
|
|
- List<Map<String,Object>> divMemberList = new ArrayList<Map<String,Object>>();
|
|
|
- Map<String,Object> divMember = new HashMap<String, Object>();
|
|
|
- //divMember.put("member_id", value);
|
|
|
- //divMember.put("amount", value);
|
|
|
- divMember.put("fee_flag", "N");
|
|
|
-
|
|
|
- divMemberList.add(divMember);
|
|
|
-
|
|
|
- paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
|
|
|
+ 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", "O");
|
|
|
+ paymentParams.put("fee_mode", "I");
|
|
|
return paymentParams;
|
|
|
}
|
|
|
|
|
@@ -348,6 +387,8 @@ 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) {
|
|
@@ -433,6 +474,14 @@ 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;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|