|
@@ -1,19 +1,19 @@
|
|
|
package com.zsElectric.boot.business.service.impl;
|
|
package com.zsElectric.boot.business.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
|
import com.zsElectric.boot.business.mapper.*;
|
|
import com.zsElectric.boot.business.mapper.*;
|
|
|
-import com.zsElectric.boot.business.model.entity.RechargeLevel;
|
|
|
|
|
-import com.zsElectric.boot.business.model.entity.UserAccount;
|
|
|
|
|
-import com.zsElectric.boot.business.model.entity.UserAccountLog;
|
|
|
|
|
|
|
+import com.zsElectric.boot.business.model.entity.*;
|
|
|
import com.zsElectric.boot.business.model.form.applet.LevelOrderForm;
|
|
import com.zsElectric.boot.business.model.form.applet.LevelOrderForm;
|
|
|
import com.zsElectric.boot.business.model.form.applet.UserPayForm;
|
|
import com.zsElectric.boot.business.model.form.applet.UserPayForm;
|
|
|
import com.zsElectric.boot.business.model.vo.UserInfoVO;
|
|
import com.zsElectric.boot.business.model.vo.UserInfoVO;
|
|
|
import com.zsElectric.boot.business.service.*;
|
|
import com.zsElectric.boot.business.service.*;
|
|
|
import com.zsElectric.boot.common.constant.SystemConstants;
|
|
import com.zsElectric.boot.common.constant.SystemConstants;
|
|
|
|
|
+import com.zsElectric.boot.core.exception.BusinessException;
|
|
|
import com.zsElectric.boot.core.pay.WXPayUtility;
|
|
import com.zsElectric.boot.core.pay.WXPayUtility;
|
|
|
import com.zsElectric.boot.core.pay.WechatConstants;
|
|
import com.zsElectric.boot.core.pay.WechatConstants;
|
|
|
import com.zsElectric.boot.core.pay.WechatPayV3Utils;
|
|
import com.zsElectric.boot.core.pay.WechatPayV3Utils;
|
|
@@ -27,7 +27,6 @@ import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.zsElectric.boot.business.model.entity.UserOrderInfo;
|
|
|
|
|
import com.zsElectric.boot.business.model.form.UserOrderInfoForm;
|
|
import com.zsElectric.boot.business.model.form.UserOrderInfoForm;
|
|
|
import com.zsElectric.boot.business.model.query.UserOrderInfoQuery;
|
|
import com.zsElectric.boot.business.model.query.UserOrderInfoQuery;
|
|
|
import com.zsElectric.boot.business.model.vo.UserOrderInfoVO;
|
|
import com.zsElectric.boot.business.model.vo.UserOrderInfoVO;
|
|
@@ -70,6 +69,8 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
|
|
|
|
|
private final WechatPayV3Utils wechatPayV3Utils;
|
|
private final WechatPayV3Utils wechatPayV3Utils;
|
|
|
|
|
|
|
|
|
|
+ private final ChargeOrderInfoMapper chargeOrderInfoMapper;
|
|
|
|
|
+
|
|
|
// 声明一个可重入锁
|
|
// 声明一个可重入锁
|
|
|
private final ReentrantLock lock = new ReentrantLock();
|
|
private final ReentrantLock lock = new ReentrantLock();
|
|
|
|
|
|
|
@@ -198,7 +199,7 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public String orderQuery(String orderNo) {
|
|
|
|
|
|
|
+ public String orderQuery(String orderNo) throws Exception {
|
|
|
//查询订单
|
|
//查询订单
|
|
|
UserOrderInfo orderInfo = this.getById(Wrappers.<UserOrderInfo>lambdaQuery().eq(UserOrderInfo::getOrderNo, orderNo).last("limit 1"));
|
|
UserOrderInfo orderInfo = this.getById(Wrappers.<UserOrderInfo>lambdaQuery().eq(UserOrderInfo::getOrderNo, orderNo).last("limit 1"));
|
|
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
|
@@ -210,10 +211,12 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
// String s = "SUCCESS";
|
|
// String s = "SUCCESS";
|
|
|
if ("SUCCESS".equals(s)) {
|
|
if ("SUCCESS".equals(s)) {
|
|
|
if (ObjectUtil.isNotEmpty(orderInfo) && Objects.equals(orderInfo.getOrderStatus(), SystemConstants.STATUS_ONE)) {
|
|
if (ObjectUtil.isNotEmpty(orderInfo) && Objects.equals(orderInfo.getOrderStatus(), SystemConstants.STATUS_ONE)) {
|
|
|
- orderInfo.setOrderStatus(SystemConstants.STATUS_TWO);
|
|
|
|
|
- orderInfo.setPayTime(LocalDateTime.now());
|
|
|
|
|
- orderInfo.setOutTradeNo(res.get("transaction_id").getAsString());
|
|
|
|
|
- this.updateById(orderInfo);
|
|
|
|
|
|
|
+ String transactionId = res.get("transaction_id").getAsString();
|
|
|
|
|
+ LocalDateTime payTime = LocalDateTime.now();
|
|
|
|
|
+ BigDecimal payMoney = new BigDecimal(res.get("amount").getAsJsonObject().get("total").getAsString());
|
|
|
|
|
+
|
|
|
|
|
+ //执行业务操作
|
|
|
|
|
+ this.successPayOrder(orderInfo, transactionId, payTime, payMoney);
|
|
|
}
|
|
}
|
|
|
return "100001";//支付成功
|
|
return "100001";//支付成功
|
|
|
}
|
|
}
|
|
@@ -322,6 +325,27 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
accountLog.setAccountType(SystemConstants.ACCOUNT_TYPE_PERSONAL);
|
|
accountLog.setAccountType(SystemConstants.ACCOUNT_TYPE_PERSONAL);
|
|
|
accountLog.setChangeBalance(finalBalance);
|
|
accountLog.setChangeBalance(finalBalance);
|
|
|
userAccountLogMapper.insert(accountLog);
|
|
userAccountLogMapper.insert(accountLog);
|
|
|
|
|
+
|
|
|
|
|
+ //平订单超充金额
|
|
|
|
|
+ orderBackTax(userAccount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void orderBackTax(UserAccount userAccount) {
|
|
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
|
|
+ //查询超充订单
|
|
|
|
|
+ List<ChargeOrderInfo> chargeOrderInfoList = chargeOrderInfoMapper.selectList(Wrappers.<ChargeOrderInfo>lambdaQuery()
|
|
|
|
|
+ .eq(ChargeOrderInfo::getUserId, userId)
|
|
|
|
|
+ .eq(ChargeOrderInfo::getMaspStatus, SystemConstants.STATUS_ONE)
|
|
|
|
|
+ .orderByAsc(ChargeOrderInfo::getCreateTime)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (CollUtil.isNotEmpty(chargeOrderInfoList)) {
|
|
|
|
|
+ BigDecimal balance = userAccount.getBalance();
|
|
|
|
|
+ for (ChargeOrderInfo chargeOrderInfo : chargeOrderInfoList) {
|
|
|
|
|
+ balance = balance.subtract(chargeOrderInfo.getTotalMaspMoney());
|
|
|
|
|
+ //todo
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -343,6 +367,39 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return "取消失败,请刷新后重试!";
|
|
return "取消失败,请刷新后重试!";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 账户退款
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public String refundOrder() throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ //查询账户余额
|
|
|
|
|
+ UserAccount userAccount = userAccountMapper.selectOne(Wrappers.<UserAccount>lambdaQuery().eq(UserAccount::getUserId, SecurityUtils.getUserId()).last("limit 1"));
|
|
|
|
|
+ if(userAccount.getBalance().compareTo(BigDecimal.ZERO) == 0){
|
|
|
|
|
+ throw new BusinessException("账户余额为 0");
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal refundMoney = userAccount.getBalance();
|
|
|
|
|
+
|
|
|
|
|
+ //账户变动及日志记录
|
|
|
|
|
+ UserAccountLog accountLog = new UserAccountLog();
|
|
|
|
|
+ accountLog.setBeforeBalance(userAccount.getBalance());
|
|
|
|
|
+ //账户余额清空
|
|
|
|
|
+ userAccount.setBalance(BigDecimal.ZERO);
|
|
|
|
|
+ userAccountMapper.updateById(userAccount);
|
|
|
|
|
+ //日志
|
|
|
|
|
+ accountLog.setUserId(SecurityUtils.getUserId());
|
|
|
|
|
+ accountLog.setChangeType(SystemConstants.CHANGE_TYPE_REDUCE);
|
|
|
|
|
+ accountLog.setChangeNote(SystemConstants.ACCOUNT_LOG_REFUND_NOTE);
|
|
|
|
|
+ //accountLog.setChangeId();
|
|
|
|
|
+ accountLog.setAccountType(SystemConstants.ACCOUNT_TYPE_PERSONAL);
|
|
|
|
|
+ accountLog.setChangeBalance(BigDecimal.ZERO);
|
|
|
|
|
+ userAccountLogMapper.insert(accountLog);
|
|
|
|
|
+
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 通过商户订单号查询订单在微信侧支付状态
|
|
* 通过商户订单号查询订单在微信侧支付状态
|
|
|
*
|
|
*
|