|
@@ -1,17 +1,5 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.chelvc.cloud.vehicle.api.service.UserInviteService;
|
|
|
-import com.chelvc.cloud.vehicle.server.dao.OmsOrderMapper;
|
|
|
-import com.chelvc.cloud.vehicle.server.entity.OmsOrder;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.*;
|
|
|
-import com.chelvc.framework.base.exception.ResourceUnavailableException;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
@@ -27,6 +15,22 @@ import java.security.cert.X509Certificate;
|
|
|
import java.util.Date;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.chelvc.cloud.vehicle.api.service.UserInviteService;
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.OmsOrderMapper;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.OmsOrder;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.AssetService;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.BalanceDetailService;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.OrderHandleService;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.PlatformProfitRatioService;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.UserProfitRatioService;
|
|
|
+import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class OderHandleServiceImpl implements OrderHandleService {
|
|
@@ -36,13 +40,14 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
private final PlatformProfitRatioService platformProfitRatioService;
|
|
|
private final AssetService assetService;
|
|
|
private final BalanceDetailService balanceDetailService;
|
|
|
+
|
|
|
@Override
|
|
|
public void orderPay(Long orderId) {
|
|
|
LambdaQueryWrapper<OmsOrder> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(OmsOrder::getId, orderId);
|
|
|
wrapper.eq(OmsOrder::getStatus, 0);
|
|
|
OmsOrder omsOrder = omsOrderMapper.selectOne(wrapper);
|
|
|
- if(omsOrder == null){
|
|
|
+ if (omsOrder == null) {
|
|
|
return;
|
|
|
}
|
|
|
StringBuilder sb = new StringBuilder();
|
|
@@ -73,7 +78,7 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
omsOrder.setReceiveTime(new Date());
|
|
|
omsOrder.setUpdateTime(new Date());
|
|
|
int i = omsOrderMapper.updateById(omsOrder);
|
|
|
- if(i != 1){
|
|
|
+ if (i != 1) {
|
|
|
throw new ResourceUnavailableException("处理失败");
|
|
|
}
|
|
|
//分佣逻辑=====================================
|
|
@@ -90,20 +95,20 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
.multiply(payAmount).setScale(2, RoundingMode.UP);
|
|
|
//用户抽佣----查看消费用户上级
|
|
|
Long inviteUserId = userInviteService.queryUserByTarget(userId, 1);
|
|
|
- if(inviteUserId != null){
|
|
|
+ if (inviteUserId != null) {
|
|
|
//用户分佣
|
|
|
int userRatio = userProfitRatioService.queryRatio(inviteUserId, 1);
|
|
|
- if(userRatio > 0){
|
|
|
+ if (userRatio > 0) {
|
|
|
userAmount = new BigDecimal(userRatio).divide(new BigDecimal("100"), 2, RoundingMode.UP)
|
|
|
.multiply(platformAmount).setScale(2, RoundingMode.UP);
|
|
|
}
|
|
|
}
|
|
|
//商户抽佣----查看消费用户上级
|
|
|
Long inviteMerchantId = userInviteService.queryUserByTarget(merchantId, 2);
|
|
|
- if(inviteMerchantId != null){
|
|
|
+ if (inviteMerchantId != null) {
|
|
|
//商户分佣
|
|
|
int merchantRatio = userProfitRatioService.queryRatio(inviteMerchantId, 2);
|
|
|
- if(merchantRatio > 0){
|
|
|
+ if (merchantRatio > 0) {
|
|
|
merchantAmount = new BigDecimal(merchantRatio).divide(new BigDecimal("100"), 2, RoundingMode.UP)
|
|
|
.multiply(platformAmount).setScale(2, RoundingMode.UP);
|
|
|
}
|
|
@@ -113,20 +118,25 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
BigDecimal surplusAmount = assetService.updateAsset(0, operateAmount, merchantId, 2);
|
|
|
balanceDetailService.recordFlow(omsOrder.getId(), 2, merchantId, operateAmount, surplusAmount, 0, 1, userId);
|
|
|
BigDecimal platformSurplusAmount = assetService.updateAsset(1, operateAmount, 1L, 0);
|
|
|
- balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, operateAmount, platformSurplusAmount, 1, 1, merchantId);
|
|
|
+ balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, operateAmount, platformSurplusAmount, 1, 1,
|
|
|
+ merchantId);
|
|
|
//邀请用户---分得佣金
|
|
|
- if(userAmount.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ if (userAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal userSurplusAmount = assetService.updateAsset(0, userAmount, inviteUserId, 1);
|
|
|
- balanceDetailService.recordFlow(omsOrder.getId(), 1, inviteUserId, userAmount, userSurplusAmount, 0, 1, userId);
|
|
|
+ balanceDetailService.recordFlow(omsOrder.getId(), 1, inviteUserId, userAmount, userSurplusAmount, 0, 1,
|
|
|
+ userId);
|
|
|
BigDecimal platformSurplusAmount1 = assetService.updateAsset(1, userAmount, 1L, 0);
|
|
|
- balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, userAmount, platformSurplusAmount1, 1, 1, inviteUserId);
|
|
|
+ balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, userAmount, platformSurplusAmount1, 1, 1,
|
|
|
+ inviteUserId);
|
|
|
}
|
|
|
//邀请商家---分得佣金
|
|
|
- if(merchantAmount.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ if (merchantAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
BigDecimal merchantSurplusAmount2 = assetService.updateAsset(0, merchantAmount, inviteMerchantId, 1);
|
|
|
- balanceDetailService.recordFlow(omsOrder.getId(), 1, inviteMerchantId, merchantAmount, merchantSurplusAmount2, 0, 1, merchantId);
|
|
|
+ balanceDetailService.recordFlow(omsOrder.getId(), 1, inviteMerchantId, merchantAmount,
|
|
|
+ merchantSurplusAmount2, 0, 1, merchantId);
|
|
|
BigDecimal platformSurplusAmount2 = assetService.updateAsset(1, merchantAmount, 1L, 0);
|
|
|
- balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, merchantAmount, platformSurplusAmount2, 1, 1, inviteMerchantId);
|
|
|
+ balanceDetailService.recordFlow(omsOrder.getId(), 0, 1L, merchantAmount, platformSurplusAmount2, 1, 1,
|
|
|
+ inviteMerchantId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -135,7 +145,8 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
public void paySuccess(OmsOrder order) {
|
|
|
omsOrderMapper.updateById(order);
|
|
|
BigDecimal surplusAmount = assetService.updateAsset(0, order.getPayAmount(), 1L, 0);
|
|
|
- balanceDetailService.recordFlow(order.getId(), 0, 1L, order.getPayAmount(), surplusAmount, 0, 1, order.getUserId());
|
|
|
+ balanceDetailService.recordFlow(order.getId(), 0, 1L, order.getPayAmount(), surplusAmount, 0, 1,
|
|
|
+ order.getUserId());
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
@@ -159,7 +170,10 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
sb.append("fee=").append("0").append("&");
|
|
|
sb.append("payResult=").append("10");
|
|
|
String base64 = "";
|
|
|
- String SignMsgVal="merchantAcctId=1001292117101&version=v2.0&language=1&signType=4&payType=21&bankId=QTYH&orderId=KQ20220609155005&orderTime=20220609155005&orderAmount=1&bindCard=6222027781&bindMobile=1662653&dealId=104964327&bankDealId=9841654761026121342&dealTime=20220609155546&payAmount=1&fee=0&payResult=10";
|
|
|
+ String SignMsgVal = "merchantAcctId=1001292117101&version=v2" +
|
|
|
+ ".0&language=1&signType=4&payType=21&bankId=QTYH&orderId=KQ20220609155005&orderTime=20220609155005" +
|
|
|
+ "&orderAmount=1&bindCard=6222027781&bindMobile=1662653&dealId=104964327&bankDealId" +
|
|
|
+ "=9841654761026121342&dealTime=20220609155546&payAmount=1&fee=0&payResult=10";
|
|
|
|
|
|
//人民币网关账号,该账号为11位人民币网关商户编号+01,该参数必填。
|
|
|
String merchantAcctId = "1001295168301";
|
|
@@ -170,40 +184,40 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
//服务器接收支付结果的后台地址,该参数务必填写,不能为空。
|
|
|
String bgUrl = "http://www.99bill.com/";
|
|
|
//网关版本,固定值:mobile1.0,该参数必填。
|
|
|
- String version = "mobile1.0";
|
|
|
+ String version = "mobile1.0";
|
|
|
//移动网关版本 phone代表手机版移动网关,pad代表平板移动网关,默认为phone
|
|
|
- String mobileGateway="";
|
|
|
+ String mobileGateway = "";
|
|
|
//语言种类,1代表中文显示,2代表英文显示。默认为1,该参数必填。
|
|
|
- String language = "1";
|
|
|
+ String language = "1";
|
|
|
//签名类型,该值为4,代表PKI加密方式,该参数必填。
|
|
|
- String signType = "4";
|
|
|
+ String signType = "4";
|
|
|
//支付人姓名,可以为空。
|
|
|
- String payerName= "";
|
|
|
+ String payerName = "";
|
|
|
//支付人联系类型,1 代表电子邮件方式;2 代表手机联系方式。可以为空。
|
|
|
- String payerContactType = "";
|
|
|
+ String payerContactType = "";
|
|
|
//支付人联系方式,与payerContactType设置对应,payerContactType为1,则填写邮箱地址;payerContactType为2,则填写手机号码。可以为空。
|
|
|
- String payerContact = "";
|
|
|
+ String payerContact = "";
|
|
|
//指定付款人,可以为空
|
|
|
- String payerIdType = "";
|
|
|
+ String payerIdType = "";
|
|
|
//付款人标识,可以为空
|
|
|
- String payerId = "";
|
|
|
+ String payerId = "";
|
|
|
//付款人IP,可以为空
|
|
|
- String payerIP = "";
|
|
|
+ String payerIP = "";
|
|
|
//商家的终端ip,支持Ipv4和Ipv6
|
|
|
- String terminalIp = "192.168.1.1";
|
|
|
+ String terminalIp = "192.168.1.1";
|
|
|
//网络交易平台简称,英文或中文字符串,除微信支付宝支付外其他交易方式必传
|
|
|
- String tdpformName = "";
|
|
|
+ String tdpformName = "";
|
|
|
//商户订单号,以下采用时间来定义订单号,商户可以根据自己订单号的定义规则来定义该值,不能为空。
|
|
|
- String orderId = "KQ"+new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
|
|
|
+ String orderId = "KQ" + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
|
|
|
//订单金额,金额以“分”为单位,商户测试以1分测试即可,切勿以大金额测试。该参数必填。
|
|
|
String orderAmount = "1";
|
|
|
//订单提交时间,格式:yyyyMMddHHmmss,如:20071117020101,不能为空。
|
|
|
String orderTime = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
|
|
|
//String orderTime = "20220224145101";
|
|
|
//快钱时间戳,格式:yyyyMMddHHmmss,如:20071117020101, 可以为空
|
|
|
- String orderTimestamp= "";//new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());;
|
|
|
+ String orderTimestamp = "";//new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());;
|
|
|
//商品名称,可以为空。
|
|
|
- String productName= "测试商品";
|
|
|
+ String productName = "测试商品";
|
|
|
//商品数量,可以为空。
|
|
|
String productNum = "1";
|
|
|
//商品代码,可以为空。
|
|
@@ -225,7 +239,7 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
//订单超时时间(秒),可为空。
|
|
|
String orderTimeOut = "";
|
|
|
//聚合支付参数
|
|
|
- String aggregatePay="26-3:[appId=wx44377c7a02caaac9,openId=oxr7946y03Ui9LjsR4zGFi8OssbY,limitPay=0]";
|
|
|
+ String aggregatePay = "26-3:[appId=wx44377c7a02caaac9,openId=oxr7946y03Ui9LjsR4zGFi8OssbY,limitPay=0]";
|
|
|
|
|
|
//signMsg 签名字符串 不可空,生成加密签名串
|
|
|
String signMsgVal = "";
|
|
@@ -235,9 +249,9 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
signMsgVal = appendParam(signMsgVal, "version", version);
|
|
|
signMsgVal = appendParam(signMsgVal, "language", language);
|
|
|
signMsgVal = appendParam(signMsgVal, "signType", signType);
|
|
|
- signMsgVal = appendParam(signMsgVal, "merchantAcctId",merchantAcctId);
|
|
|
+ signMsgVal = appendParam(signMsgVal, "merchantAcctId", merchantAcctId);
|
|
|
signMsgVal = appendParam(signMsgVal, "payerName", payerName);
|
|
|
- signMsgVal = appendParam(signMsgVal, "payerContactType",payerContactType);
|
|
|
+ signMsgVal = appendParam(signMsgVal, "payerContactType", payerContactType);
|
|
|
signMsgVal = appendParam(signMsgVal, "payerContact", payerContact);
|
|
|
signMsgVal = appendParam(signMsgVal, "payerIdType", payerIdType);
|
|
|
signMsgVal = appendParam(signMsgVal, "payerId", payerId);
|
|
@@ -265,11 +279,13 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
KeyStore ks = KeyStore.getInstance("PKCS12");
|
|
|
|
|
|
//读取密钥仓库(相对路径)
|
|
|
- String file = Objects.requireNonNull(OderHandleServiceImpl.class.getClassLoader().getResource("payUtils/10012951683.pfx")).getPath().replaceAll("%20", " ");
|
|
|
+ String file = Objects.requireNonNull(OderHandleServiceImpl.class.getClassLoader().getResource("payUtils" +
|
|
|
+ "/10012951683.pfx")).getPath().replaceAll("%20", " ");
|
|
|
System.out.println(file);
|
|
|
|
|
|
FileInputStream ksfis = new FileInputStream(file);
|
|
|
- //InputStream inputStream = PayServiceImpl.class.getClassLoader().getResourceAsStream("payUtils/10012951683.pfx");
|
|
|
+ //InputStream inputStream = PayServiceImpl.class.getClassLoader().getResourceAsStream
|
|
|
+ // ("payUtils/10012951683.pfx");
|
|
|
BufferedInputStream ksbufin = new BufferedInputStream(ksfis);
|
|
|
//证书密码
|
|
|
char[] keyPwd = "123456".toCharArray();
|
|
@@ -285,17 +301,21 @@ public class OderHandleServiceImpl implements OrderHandleService {
|
|
|
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
|
|
|
base64 = encoder.encode(signature.sign());
|
|
|
|
|
|
- } catch(FileNotFoundException e){
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
System.out.println("123");
|
|
|
- }catch (Exception ex) {
|
|
|
+ } catch (Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
- System.out.println("test = "+base64);
|
|
|
- String signMsg="Yku7O/TyRnCErbGwvo/EQxgNLgR61YJ9WQrxpD0I6HxIumGVRxQo4eQ/hn5CS57xM2GnJ7qtkWM3J/g9CRcK22S7EJ4E1zK2HuqYiScaFLolHWNszGe7kOPk3PovTFl4nGYUSW8vMzZEZgRTMdHNSpmib57o6Mrjq0+6xA1gSBBRqpaL6SO4IBfB6yldWHpkJN0RJlKlkGGRJjMEpLJPn8lTGPcOfJuNxmMq+qjbvdLyoxn7v0vK8bAPFT45bCdvGG+0HwUCYxtPPhFReZMXP/yJYEZ/TODSMlPhGM1dZXXbnZ5Sc4KJSWNB9CKgyKWcycMbfTlsraWtpsCwOr8k0g==";
|
|
|
+ System.out.println("test = " + base64);
|
|
|
+ String signMsg = "Yku7O/TyRnCErbGwvo/EQxgNLgR61YJ9WQrxpD0I6HxIumGVRxQo4eQ/hn5CS57xM2GnJ7qtkWM3J" +
|
|
|
+ "/g9CRcK22S7EJ4E1zK2HuqYiScaFLolHWNszGe7kOPk3PovTFl4nGYUSW8vMzZEZgRTMdHNSpmib57o6Mrjq0" +
|
|
|
+ "+6xA1gSBBRqpaL6SO4IBfB6yldWHpkJN0RJlKlkGGRJjMEpLJPn8lTGPcOfJuNxmMq+qjbvdLyoxn7v0vK8bAPFT45bCdvGG" +
|
|
|
+ "+0HwUCYxtPPhFReZMXP/yJYEZ/TODSMlPhGM1dZXXbnZ5Sc4KJSWNB9CKgyKWcycMbfTlsraWtpsCwOr8k0g==";
|
|
|
try {
|
|
|
//快钱公钥
|
|
|
//String file = Pkipair.class.getResource("99bill.RSA.cer").toURI().getPath();
|
|
|
- String file = Objects.requireNonNull(OderHandleServiceImpl.class.getClassLoader().getResource("payUtils/CFCA_sandbox.cer")).toURI().getPath();
|
|
|
+ String file = Objects.requireNonNull(OderHandleServiceImpl.class.getClassLoader().getResource("payUtils" +
|
|
|
+ "/CFCA_sandbox.cer")).toURI().getPath();
|
|
|
//System.out.println(file);
|
|
|
FileInputStream inStream = new FileInputStream(file);
|
|
|
|