|
@@ -5,13 +5,14 @@ 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.RechargeLevelMapper;
|
|
|
|
|
|
|
+import com.zsElectric.boot.business.mapper.*;
|
|
|
import com.zsElectric.boot.business.model.entity.RechargeLevel;
|
|
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.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.RechargeLevelService;
|
|
|
|
|
-import com.zsElectric.boot.business.service.UserInfoService;
|
|
|
|
|
|
|
+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.pay.WXPayUtility;
|
|
import com.zsElectric.boot.core.pay.WXPayUtility;
|
|
|
import com.zsElectric.boot.core.pay.WechatConstants;
|
|
import com.zsElectric.boot.core.pay.WechatConstants;
|
|
@@ -26,8 +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.mapper.UserOrderInfoMapper;
|
|
|
|
|
-import com.zsElectric.boot.business.service.UserOrderInfoService;
|
|
|
|
|
import com.zsElectric.boot.business.model.entity.UserOrderInfo;
|
|
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;
|
|
@@ -46,6 +45,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 用户支付订单信息服务实现类
|
|
* 用户支付订单信息服务实现类
|
|
@@ -60,10 +60,14 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
|
|
|
|
|
private final UserOrderInfoConverter userOrderInfoConverter;
|
|
private final UserOrderInfoConverter userOrderInfoConverter;
|
|
|
|
|
|
|
|
- private final UserInfoService userInfoService;
|
|
|
|
|
|
|
+ private final UserInfoMapper userInfoMapper;
|
|
|
|
|
|
|
|
private final RechargeLevelMapper rechargeLevelMapper;
|
|
private final RechargeLevelMapper rechargeLevelMapper;
|
|
|
|
|
|
|
|
|
|
+ private final UserAccountMapper userAccountMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserAccountLogMapper userAccountLogMapper;
|
|
|
|
|
+
|
|
|
private final WechatPayV3Utils wechatPayV3Utils;
|
|
private final WechatPayV3Utils wechatPayV3Utils;
|
|
|
|
|
|
|
|
// 声明一个可重入锁
|
|
// 声明一个可重入锁
|
|
@@ -137,10 +141,15 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return this.removeByIds(idList);
|
|
return this.removeByIds(idList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建订单
|
|
|
|
|
+ * @param levelOrderForm
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public UserPayForm createOrder(LevelOrderForm levelOrderForm) {
|
|
public UserPayForm createOrder(LevelOrderForm levelOrderForm) {
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
- String userOpenId = userInfoService.getAppletUserInfo().getOpenid();
|
|
|
|
|
|
|
+ String userOpenId = userInfoMapper.getAppletUserInfo(userId).getOpenid();
|
|
|
String orderNo = createOrderNo("SP",userId);
|
|
String orderNo = createOrderNo("SP",userId);
|
|
|
//创建订单
|
|
//创建订单
|
|
|
UserOrderInfo orderInfo = new UserOrderInfo();
|
|
UserOrderInfo orderInfo = new UserOrderInfo();
|
|
@@ -163,6 +172,11 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return payForm;
|
|
return payForm;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 支付订单
|
|
|
|
|
+ * @param orderId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public UserPayForm payOrder(String orderId) {
|
|
public UserPayForm payOrder(String orderId) {
|
|
|
UserOrderInfo orderInfo = this.getById(orderId);
|
|
UserOrderInfo orderInfo = this.getById(orderId);
|
|
@@ -178,6 +192,11 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return payForm;
|
|
return payForm;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 订单查询
|
|
|
|
|
+ * @param orderNo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public String orderQuery(String orderNo) {
|
|
public String orderQuery(String orderNo) {
|
|
|
//查询订单
|
|
//查询订单
|
|
@@ -209,6 +228,12 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return "100004";//支付失败
|
|
return "100004";//支付失败
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信支付回调
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, String> wechatPayNotify(HttpServletRequest request, HttpServletResponse response) {
|
|
public Map<String, String> wechatPayNotify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
|
@@ -235,16 +260,12 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
if (Objects.equals(orderInfo.getOrderStatus(), SystemConstants.STATUS_ONE)) {
|
|
if (Objects.equals(orderInfo.getOrderStatus(), SystemConstants.STATUS_ONE)) {
|
|
|
- orderInfo.setOrderStatus(SystemConstants.STATUS_TWO);
|
|
|
|
|
- orderInfo.setOrderType(SystemConstants.STATUS_ONE);
|
|
|
|
|
- orderInfo.setTransactionId(res.get("transaction_id").getAsString());
|
|
|
|
|
- orderInfo.setPayTime(LocalDateTime.now());
|
|
|
|
|
-// orderInfo.setPayTime(dealDateFormat(res.getString("success_time")));
|
|
|
|
|
|
|
+ String transactionId = res.get("transaction_id").getAsString();
|
|
|
|
|
+ LocalDateTime payTime = LocalDateTime.now();
|
|
|
|
|
+ BigDecimal payMoney = new BigDecimal(res.get("amount").getAsJsonObject().get("total").getAsString());
|
|
|
|
|
|
|
|
- this.updateById(orderInfo);
|
|
|
|
|
- //todo 发送延迟消息 15分钟超时未支付
|
|
|
|
|
-
|
|
|
|
|
- //todo 异步增加积分
|
|
|
|
|
|
|
+ //执行业务操作
|
|
|
|
|
+ this.successPayOrder(orderInfo, transactionId, payTime, payMoney);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
result.put("code", "SUCCESS");
|
|
result.put("code", "SUCCESS");
|
|
@@ -265,6 +286,49 @@ public class UserOrderInfoServiceImpl extends ServiceImpl<UserOrderInfoMapper, U
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 支付成功业务处理
|
|
|
|
|
+ * @param orderInfo
|
|
|
|
|
+ * @param transactionId
|
|
|
|
|
+ * @param payTime
|
|
|
|
|
+ * @param orderMoney
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ protected void successPayOrder(UserOrderInfo orderInfo, String transactionId, LocalDateTime payTime, BigDecimal orderMoney) throws Exception{
|
|
|
|
|
+ //修改订单状态为已支付
|
|
|
|
|
+ orderInfo.setOrderStatus(SystemConstants.STATUS_TWO);
|
|
|
|
|
+ orderInfo.setPayTime(payTime);
|
|
|
|
|
+ orderInfo.setTransactionId(transactionId);
|
|
|
|
|
+ orderInfo.setPayMoney(orderMoney);
|
|
|
|
|
+ this.updateById(orderInfo);
|
|
|
|
|
+
|
|
|
|
|
+ //账户变动及日志记录
|
|
|
|
|
+ Long userId = orderInfo.getUserId();
|
|
|
|
|
+ UserAccount userAccount = userAccountMapper.selectById(userId);
|
|
|
|
|
+ //账户变动日志
|
|
|
|
|
+ UserAccountLog accountLog = new UserAccountLog();
|
|
|
|
|
+ accountLog.setBeforeBalance(userAccount.getBalance());
|
|
|
|
|
+ //增加
|
|
|
|
|
+ BigDecimal finalBalance = BigDecimal.ZERO;
|
|
|
|
|
+ finalBalance = userAccount.getBalance().add(orderMoney);
|
|
|
|
|
+ userAccount.setBalance(finalBalance);
|
|
|
|
|
+ userAccountMapper.updateById(userAccount);
|
|
|
|
|
+ //日志
|
|
|
|
|
+ accountLog.setUserId(userId);
|
|
|
|
|
+ accountLog.setChangeType(SystemConstants.CHANGE_TYPE_ADD);
|
|
|
|
|
+ accountLog.setChangeNote(SystemConstants.ACCOUNT_LOG_PAY_NOTE);
|
|
|
|
|
+ accountLog.setChangeId(orderInfo.getId());
|
|
|
|
|
+ accountLog.setAccountType(SystemConstants.ACCOUNT_TYPE_PERSONAL);
|
|
|
|
|
+ accountLog.setChangeBalance(finalBalance);
|
|
|
|
|
+ userAccountLogMapper.insert(accountLog);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消订单
|
|
|
|
|
+ * @param orderId
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public String cancelOrder(String orderId) {
|
|
public String cancelOrder(String orderId) {
|
|
|
UserOrderInfo orderInfo = this.getById(orderId);
|
|
UserOrderInfo orderInfo = this.getById(orderId);
|