1. 分账测试
This commit is contained in:
parent
13397d5c78
commit
5172cb184b
|
@ -19,6 +19,7 @@ import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
import com.ruoyi.common.utils.onenet.Token;
|
import com.ruoyi.common.utils.onenet.Token;
|
||||||
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.domain.*;
|
||||||
import com.ruoyi.system.domain.vo.AttachVo;
|
import com.ruoyi.system.domain.vo.AttachVo;
|
||||||
|
import com.ruoyi.system.mapper.AsDeviceMapper;
|
||||||
import com.ruoyi.system.mapper.AsUserMapper;
|
import com.ruoyi.system.mapper.AsUserMapper;
|
||||||
import com.ruoyi.system.mapper.SysUserMapper;
|
import com.ruoyi.system.mapper.SysUserMapper;
|
||||||
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.service.*;
|
||||||
|
@ -45,6 +46,8 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,15 +97,22 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
@Resource
|
@Resource
|
||||||
private AsUserMapper asUserMapper;
|
private AsUserMapper asUserMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AsDeviceMapper asDeviceMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付回调
|
* 微信支付回调
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
@Transactional
|
@Transactional
|
||||||
public void weChat(HttpServletRequest request) {
|
public void weChat(HttpServletRequest request) {
|
||||||
String body = HttpUtils.getBody(request);
|
String body = HttpUtils.getBody(request);
|
||||||
logger.info("【微信支付回调】接收对象 : " + JSON.toJSONString(body));
|
logger.info("【微信支付回调】接收对象(未验签) : " + JSON.toJSONString(body));
|
||||||
// 解析通知数据
|
// 解析通知数据
|
||||||
Notification notification = JSON.parseObject(body, Notification.class);
|
Notification notification = JSON.parseObject(body, Notification.class);
|
||||||
String outTradeNo;
|
String outTradeNo;
|
||||||
|
@ -113,6 +123,8 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
Transaction transaction = checkAndParse(request, body, Transaction.class);
|
Transaction transaction = checkAndParse(request, body, Transaction.class);
|
||||||
if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) {
|
if (Transaction.TradeStateEnum.SUCCESS.equals(transaction.getTradeState())) {
|
||||||
// 充值成功后的业务处理
|
// 充值成功后的业务处理
|
||||||
|
logger.info("【微信支付回调】交易对象(验签后) : " + JSON.toJSONString(transaction));
|
||||||
|
String transactionId = transaction.getTransactionId();
|
||||||
AttachVo attachVo = JSONObject.parseObject(transaction.getAttach(),AttachVo.class);
|
AttachVo attachVo = JSONObject.parseObject(transaction.getAttach(),AttachVo.class);
|
||||||
logger.info("【微信支付回调】附加信息 : " + JSON.toJSONString(attachVo));
|
logger.info("【微信支付回调】附加信息 : " + JSON.toJSONString(attachVo));
|
||||||
outTradeNo = transaction.getOutTradeNo();
|
outTradeNo = transaction.getOutTradeNo();
|
||||||
|
@ -123,7 +135,7 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
/** 支付回调逻辑 1. 处理预约还是开锁 电压 */
|
/** 支付回调逻辑 1. 处理预约还是开锁 电压 */
|
||||||
AsDevice asDevice = null;
|
AsDevice asDevice = null;
|
||||||
if(StrUtil.isNotBlank(order.getSn())){
|
if(StrUtil.isNotBlank(order.getSn())){
|
||||||
asDevice = asDeviceService.selectAsDeviceBySn(order.getSn());
|
asDevice = asDeviceMapper.selectAsDeviceBySn(order.getSn());
|
||||||
}
|
}
|
||||||
//先判断是骑行订单还是押金,如果是骑行订单
|
//先判断是骑行订单还是押金,如果是骑行订单
|
||||||
// 还要区分是取消预约支付
|
// 还要区分是取消预约支付
|
||||||
|
@ -148,11 +160,9 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
Integer autoRefundDeposit = rule.getAutoRefundDeposit();
|
Integer autoRefundDeposit = rule.getAutoRefundDeposit();
|
||||||
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
||||||
if(autoRefundDeposit!=null && autoRefundDeposit>0){
|
if(autoRefundDeposit!=null && autoRefundDeposit>0){
|
||||||
//创建一个定时器TimerTask,计算出退还时间后,执行退款操作
|
//创建一个定时器,计算出退还时间后,执行退款操作
|
||||||
Timer timer = new Timer();
|
// 往后推autoRefundDeposit小时执行
|
||||||
TimerTask task = new TimerTask() {
|
scheduledExecutorService.schedule(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// 退款
|
// 退款
|
||||||
Long userId = order.getUserId();
|
Long userId = order.getUserId();
|
||||||
EtOrder etOrder = new EtOrder();
|
EtOrder etOrder = new EtOrder();
|
||||||
|
@ -179,24 +189,19 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
if(i>0){
|
if(i>0){
|
||||||
logger.info("【自动退款】保存退款对象成功");
|
logger.info("【自动退款】保存退款对象成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增资金流水记录
|
// 新增资金流水记录
|
||||||
capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND);
|
capitalFlowRecords(newestOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND);
|
||||||
} else {
|
} else {
|
||||||
throw new ServiceException("没有找到押金充值记录");
|
throw new ServiceException("没有找到押金充值记录");
|
||||||
}
|
}
|
||||||
|
}, autoRefundDeposit, TimeUnit.HOURS);
|
||||||
}
|
}
|
||||||
};
|
logger.info("=================【微信支付回调】10秒后开始请求分账==================");
|
||||||
// 往后推autoRefundDeposit小时执行
|
// 30秒后请求分账
|
||||||
Date refundTime = DateUtils.getTimeAfterXHours(order.getPayTime(), autoRefundDeposit);
|
scheduledExecutorService.schedule(() -> {
|
||||||
timer.schedule(task, refundTime);
|
logger.info("=================【微信支付回调】开始请求分账==================");
|
||||||
}
|
logger.info("区域对象====="+JSON.toJSONString(area));
|
||||||
// 一分钟后请求分账
|
logger.info("订单对象====="+JSON.toJSONString(order));
|
||||||
Timer timer = new Timer();
|
|
||||||
TimerTask task = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
logger.info("【微信支付回调】开始请求分账------------");
|
|
||||||
// 请求分账
|
// 请求分账
|
||||||
List<CreateOrderReceiver> receivers = new ArrayList<>();
|
List<CreateOrderReceiver> receivers = new ArrayList<>();
|
||||||
// 获取到合伙人的openid
|
// 获取到合伙人的openid
|
||||||
|
@ -204,36 +209,43 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
sysUser.setUserType("03");
|
sysUser.setUserType("03");
|
||||||
sysUser.setAreaId(area.getAreaId());
|
sysUser.setAreaId(area.getAreaId());
|
||||||
List<SysUser> sysUsers = userMapper.selectUserList(sysUser);
|
List<SysUser> sysUsers = userMapper.selectUserList(sysUser);
|
||||||
BigDecimal dividendAmount = BigDecimal.ZERO;
|
|
||||||
for (SysUser sysUser1 : sysUsers){
|
for (SysUser sysUser1 : sysUsers){
|
||||||
AsUser asUser1 = userService.selectUserById(sysUser1.getAppUserId());
|
AsUser asUser1 = asUserMapper.selectUserById(sysUser1.getAppUserId());
|
||||||
if(asUser1!=null && asUser1.getWxopenid()!=null){
|
if(asUser1!=null && asUser1.getWxopenid()!=null){
|
||||||
|
BigDecimal dividendAmount = BigDecimal.ZERO;
|
||||||
|
logger.info("=============系统用户:sysUser1============"+JSON.toJSONString(sysUser1));
|
||||||
CreateOrderReceiver receiver = new CreateOrderReceiver();
|
CreateOrderReceiver receiver = new CreateOrderReceiver();
|
||||||
receiver.setType(ReceiverType.PERSONAL_OPENID.name());
|
receiver.setType(ReceiverType.PERSONAL_OPENID.name());
|
||||||
receiver.setAccount(asUser1.getWxopenid());
|
receiver.setAccount(asUser1.getWxopenid());
|
||||||
String dividendItem = sysUser1.getDividendItem();
|
String dividendItem = sysUser1.getDividendItem();
|
||||||
|
logger.info("=================分账项目:dividendItem=================="+dividendItem);
|
||||||
if(dividendItem.contains("1")){
|
if(dividendItem.contains("1")){
|
||||||
dividendAmount.add(order.getRidingFee().add(order.getAppointmentFee()));//1-骑行费(骑行费+预约费)
|
logger.info("=================骑行费(骑行费+预约费)==================");
|
||||||
}else if(dividendItem.contains("2")){
|
dividendAmount = dividendAmount.add(order.getRidingFee().add(order.getAppointmentFee()));//1-骑行费(骑行费+预约费)
|
||||||
dividendAmount.add(order.getManageFee().add(order.getManageFee()));//2-调度费(调度费+管理费)
|
|
||||||
}
|
}
|
||||||
BigDecimal multiply = dividendAmount.multiply(new BigDecimal(sysUser1.getDividendProportion()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)).multiply(new BigDecimal(100));
|
if(dividendItem.contains("2")){
|
||||||
|
logger.info("=================调度费(调度费+管理费)==================");
|
||||||
|
dividendAmount = dividendAmount.add(order.getManageFee().add(order.getDispatchFee()));//2-调度费(调度费+管理费)
|
||||||
|
}
|
||||||
|
logger.info("=================分账金额:dividendAmount=================="+dividendAmount);
|
||||||
|
BigDecimal divide = new BigDecimal(sysUser1.getDividendProportion()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
logger.info("=================分账比例%=================="+divide);
|
||||||
|
BigDecimal multiply = dividendAmount.multiply(divide);
|
||||||
logger.info(sysUser1.getUserName()+"分账比例:"+sysUser1.getDividendProportion()+"%,分账金额:"+multiply);
|
logger.info(sysUser1.getUserName()+"分账比例:"+sysUser1.getDividendProportion()+"%,分账金额:"+multiply);
|
||||||
receiver.setAmount(multiply.longValue());
|
receiver.setAmount(multiply.multiply(new BigDecimal(100)).longValue());
|
||||||
receiver.setDescription("系统自动分账");
|
receiver.setDescription("系统自动分账");
|
||||||
receivers.add(receiver);
|
receivers.add(receiver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OrdersEntity ordersEntity = wxPayService.createOrder(outTradeNo,receivers);
|
OrdersEntity ordersEntity = wxPayService.createOrder(transactionId,receivers);
|
||||||
if(ordersEntity!=null){
|
if(ordersEntity!=null){
|
||||||
logger.info("【微信支付回调】发起分账响应:【{}】",JSON.toJSON(ordersEntity));
|
logger.info("【微信支付回调】发起分账响应:【{}】",JSON.toJSON(ordersEntity));
|
||||||
}else{
|
}else{
|
||||||
logger.info("【微信支付回调】发起分账失败");
|
logger.info("【微信支付回调】发起分账失败");
|
||||||
throw new ServiceException("发起分账失败");
|
throw new ServiceException("发起分账失败");
|
||||||
}
|
}
|
||||||
}
|
}, 10, TimeUnit.SECONDS);
|
||||||
};
|
|
||||||
timer.schedule(task, new Date(System.currentTimeMillis() + 30000));// 30秒后发起分账
|
|
||||||
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_APPOINTMENT)){
|
}else if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_APPOINTMENT)){
|
||||||
logger.info("【微信支付回调】取消预约支付");
|
logger.info("【微信支付回调】取消预约支付");
|
||||||
// 2-取消预约支付
|
// 2-取消预约支付
|
||||||
|
@ -268,11 +280,13 @@ public class CallbackServiceImpl implements CallbackService {
|
||||||
throw new ServiceException("【微信支付回调】更新车辆状态失败");
|
throw new ServiceException("【微信支付回调】更新车辆状态失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.info("=================【微信支付回调】开始更新订单信息==================");
|
||||||
int updateEtOrder = orderService.updateEtOrder(order);
|
int updateEtOrder = orderService.updateEtOrder(order);
|
||||||
if(updateEtOrder==0){
|
if(updateEtOrder==0){
|
||||||
logger.error("【微信支付回调】更新订单信息失败");
|
logger.error("【微信支付回调】更新订单信息失败");
|
||||||
throw new ServiceException("【微信支付回调】更新订单信息失败");
|
throw new ServiceException("【微信支付回调】更新订单信息失败");
|
||||||
}
|
}
|
||||||
|
logger.info("=================【微信支付回调】开始更新用户信息==================");
|
||||||
int updateUser = userService.updateUser(asUser);
|
int updateUser = userService.updateUser(asUser);
|
||||||
if(updateUser==0){
|
if(updateUser==0){
|
||||||
logger.error("【微信支付回调】更新用户押金失败");
|
logger.error("【微信支付回调】更新用户押金失败");
|
||||||
|
|
|
@ -74,6 +74,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="userType != null and userType != ''">
|
<if test="userType != null and userType != ''">
|
||||||
AND u.user_type = #{userType}
|
AND u.user_type = #{userType}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="areaId != null">
|
||||||
|
AND u.area_id = #{areaId}
|
||||||
|
</if>
|
||||||
<if test="userName != null and userName != ''">
|
<if test="userName != null and userName != ''">
|
||||||
AND u.user_name like concat('%', #{userName}, '%')
|
AND u.user_name like concat('%', #{userName}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user