xhxu 5 лет назад
Родитель
Сommit
8b640daf18
2 измененных файлов: 60 добавлений и 30 удалений
  1. +57
    -30
      mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java
  2. +3
    -0
      mallinkTTCApi/src/main/java/com/iformall/controller/TtUserGrantController.java

+ 57
- 30
mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java Просмотреть файл

@@ -19,10 +19,14 @@ import com.iformall.exception.MallinkException;
import com.iformall.mapper.*; import com.iformall.mapper.*;
import com.iformall.service.*; import com.iformall.service.*;
import com.iformall.service.tt.TtOrderService; import com.iformall.service.tt.TtOrderService;
import com.iformall.utils.RedisLock;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.*; import java.util.*;


@@ -34,6 +38,11 @@ public class TtOrderServiceImpl implements TtOrderService {


private final Integer time_out = 30*60; private final Integer time_out = 30*60;


private final String TT_ORDER_KEY = "ORDER:TT:";

@Autowired
RedisLock redisLock;

@Autowired @Autowired
private TtOrderMapper ttOrderMapper; private TtOrderMapper ttOrderMapper;


@@ -130,7 +139,6 @@ public class TtOrderServiceImpl implements TtOrderService {
order.setCreateDate(now); order.setCreateDate(now);
order.setUpdateDate(now); order.setUpdateDate(now);
ttOrderMapper.insert(order); ttOrderMapper.insert(order);
ttcouponMapper.addSellCount(coupon.getId());
return new ResultData(order); return new ResultData(order);
} catch (MallinkException e) { } catch (MallinkException e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
@@ -288,52 +296,71 @@ public class TtOrderServiceImpl implements TtOrderService {
} }


@Override @Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData updateOrderStatus(Long orderId, WxAppinfo appInfo, WxPayAccount payAccount) { public ResultData updateOrderStatus(Long orderId, WxAppinfo appInfo, WxPayAccount payAccount) {
TtOrder order = ttOrderMapper.selectById(orderId);
if (null == order) {
logger.error("pay order, order not allow, orderId: " + orderId);
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
if(appInfo == null || payAccount == null) {
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
}
if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){
logger.info("订单支付中: " + order.toString());
OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null);
if(orderQueryResult == null){
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"查询单号不存在");
String lockKey = StringUtils.join(TT_ORDER_KEY,orderId, ":", "lock");
long time = System.currentTimeMillis() + 5000;
String timeStr = String.valueOf(time);
if (redisLock.lock2(lockKey, timeStr)) {

TtOrder order = ttOrderMapper.selectById(orderId);
if (null == order) {
logger.error("pay order, order not allow, orderId: " + orderId);
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
}
if(appInfo == null || payAccount == null) {
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
} }
String trade_state = orderQueryResult.getOrderStatus();
if ("PROCESSING".equals(trade_state)) {//处理中
return new ResultData(ErrorCode.PAY_ORDER_PAYING);
}else if ("SUCCESS".equals(trade_state)) {//成功
TtOrder orderSuc = new TtOrder();
orderSuc.setId(order.getId());
orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode());
orderSuc.setWay(orderQueryResult.getWay());
orderSuc.setPaymentTime(orderQueryResult.getPayTime());
orderSuc.setUpdateDate(new Date());
ttOrderMapper.updateById(orderSuc);
if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){
logger.info("订单支付中: " + order.toString());
OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null);
if(orderQueryResult == null){
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"查询单号不存在");
}
String trade_state = orderQueryResult.getOrderStatus();
if ("PROCESSING".equals(trade_state)) {//处理中
return new ResultData(ErrorCode.PAY_ORDER_PAYING);
}else if ("SUCCESS".equals(trade_state)) {//成功
TtOrder orderSuc = new TtOrder();
orderSuc.setId(order.getId());
orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode());
orderSuc.setWay(orderQueryResult.getWay());
orderSuc.setPaymentTime(orderQueryResult.getPayTime());
orderSuc.setUpdateDate(new Date());
ttOrderMapper.updateById(orderSuc);
// return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!"); // return new ResultData(ErrorCode.PAY_ORDER_EXIST,"该订单已经支付,请勿重复支付!");
return new ResultData();
}else if ("FAIL".equals(trade_state)) {//失败
return new ResultData();
}else if ("FAIL".equals(trade_state)) {//失败
// TtOrder orderSuc = new TtOrder(); // TtOrder orderSuc = new TtOrder();
// orderSuc.setId(order.getId()); // orderSuc.setId(order.getId());
// orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); // orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode());
// orderSuc.setUpdateDate(new Date()); // orderSuc.setUpdateDate(new Date());
// ttOrderMapper.updateById(orderSuc); // ttOrderMapper.updateById(orderSuc);
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付失败");
}else if ("TIMEOUT".equals(trade_state)) {//超时
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付失败");
}else if ("TIMEOUT".equals(trade_state)) {//超时
// TtOrder orderSuc = new TtOrder(); // TtOrder orderSuc = new TtOrder();
// orderSuc.setId(order.getId()); // orderSuc.setId(order.getId());
// orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); // orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode());
// orderSuc.setUpdateDate(new Date()); // orderSuc.setUpdateDate(new Date());
// ttOrderMapper.updateById(orderSuc); // ttOrderMapper.updateById(orderSuc);
// return new ResultData(ErrorCode.PAY_ORDER_CLOSED); // return new ResultData(ErrorCode.PAY_ORDER_CLOSED);
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付超时");
return new ResultData(ErrorCode.PAY_ORDER_ERROR,"支付超时");
}
}

redisLock.unlock(lockKey, timeStr);
}else {
logger.debug("CacheAspect 读库等待中, key:{}: " + lockKey);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
redisLock.unlock(lockKey, timeStr);
} }
} }
return new ResultData(); return new ResultData();

} }


@Override @Override


+ 3
- 0
mallinkTTCApi/src/main/java/com/iformall/controller/TtUserGrantController.java Просмотреть файл

@@ -3,6 +3,7 @@ package com.iformall.controller;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.iformall.annotation.AuthIgnore; import com.iformall.annotation.AuthIgnore;
import com.iformall.annotation.TenantIgnore; import com.iformall.annotation.TenantIgnore;
@@ -256,6 +257,8 @@ public class TtUserGrantController extends BaseController {
String session_key = user.getSessionKey(); String session_key = user.getSessionKey();
try { try {
// 解密用户信息 // 解密用户信息
String decrypt = WxMaCryptUtils.decrypt(session_key, encryptedData, iv);
logger.info("111111"+decrypt);
WxMaUserInfo userInfo = ttMaService.getUserService().getUserInfo(session_key, encryptedData, iv); WxMaUserInfo userInfo = ttMaService.getUserService().getUserInfo(session_key, encryptedData, iv);
if (userInfo != null) { if (userInfo != null) {
logger.debug(userInfo.toString()); logger.debug(userInfo.toString());


Загрузка…
Отмена
Сохранить