|
|
@@ -1,33 +1,45 @@ |
|
|
package com.iformall.schedule; |
|
|
package com.iformall.schedule; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.aop.framework.AopContext; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.ErrorCode; |
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
import com.iformall.domain.po.WxAppinfo; |
|
|
|
|
|
import com.iformall.domain.po.WxCUser; |
|
|
import com.iformall.domain.po.WxOrder; |
|
|
import com.iformall.domain.po.WxOrder; |
|
|
|
|
|
import com.iformall.domain.po.WxPayAccount; |
|
|
|
|
|
import com.iformall.domain.po.WxPayOrder; |
|
|
import com.iformall.enums.EnumAppType; |
|
|
import com.iformall.enums.EnumAppType; |
|
|
import com.iformall.enums.EnumOrderStatus; |
|
|
import com.iformall.enums.EnumOrderStatus; |
|
|
import com.iformall.enums.EnumOrderType; |
|
|
import com.iformall.enums.EnumOrderType; |
|
|
|
|
|
import com.iformall.enums.EnumPayStatus; |
|
|
import com.iformall.enums.EnumRefundStatus; |
|
|
import com.iformall.enums.EnumRefundStatus; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.mapper.WxAppinfoMapper; |
|
|
import com.iformall.mapper.WxAppinfoMapper; |
|
|
|
|
|
import com.iformall.mapper.WxCUserMapper; |
|
|
import com.iformall.mapper.WxCouponMapper; |
|
|
import com.iformall.mapper.WxCouponMapper; |
|
|
import com.iformall.mapper.WxOrderGroupMapper; |
|
|
import com.iformall.mapper.WxOrderGroupMapper; |
|
|
import com.iformall.mapper.WxOrderMapper; |
|
|
import com.iformall.mapper.WxOrderMapper; |
|
|
|
|
|
import com.iformall.mapper.WxPayAccountMapper; |
|
|
|
|
|
import com.iformall.mapper.WxPayOrderMapper; |
|
|
|
|
|
import com.iformall.service.WxAppinfoService; |
|
|
import com.iformall.service.WxOrderService; |
|
|
import com.iformall.service.WxOrderService; |
|
|
|
|
|
import com.iformall.service.WxPayOrderService; |
|
|
import com.iformall.service.WxRefundOrderService; |
|
|
import com.iformall.service.WxRefundOrderService; |
|
|
|
|
|
import com.iformall.service.helper.WxPayOrderServiceHelper; |
|
|
import com.iformall.utils.DateUtils; |
|
|
import com.iformall.utils.DateUtils; |
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
@Component |
|
|
public class OrderExpiringSchedule { |
|
|
public class OrderExpiringSchedule { |
|
|
@@ -53,7 +65,22 @@ public class OrderExpiringSchedule { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponMapper wxCouponMapper; |
|
|
WxCouponMapper wxCouponMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxPayOrderMapper wxPayOrderMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxCUserMapper wxCUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxPayAccountMapper wxPayAccountMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxPayOrderService wxPayOrderService; |
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 |
|
|
@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 |
|
|
//@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 |
|
|
//@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 |
|
|
public void orderExpireSchedule() { |
|
|
public void orderExpireSchedule() { |
|
|
@@ -62,13 +89,16 @@ public class OrderExpiringSchedule { |
|
|
Date curDate = new Date(); |
|
|
Date curDate = new Date(); |
|
|
Date expireDate = new Date(curDate.getTime() - NORMAL_TIME_OUT ); |
|
|
Date expireDate = new Date(curDate.getTime() - NORMAL_TIME_OUT ); |
|
|
|
|
|
|
|
|
|
|
|
//直接调用不会触发事务,spring事务基于AOP代理 |
|
|
|
|
|
OrderExpiringSchedule proxy = (OrderExpiringSchedule) AopContext.currentProxy(); |
|
|
|
|
|
|
|
|
// 券相关订单, 15分钟未支付, 订单过期 |
|
|
// 券相关订单, 15分钟未支付, 订单过期 |
|
|
dateMap.put("type", EnumOrderType.COUPON.getCode()); |
|
|
dateMap.put("type", EnumOrderType.COUPON.getCode()); |
|
|
dateMap.put("endDate", expireDate); |
|
|
dateMap.put("endDate", expireDate); |
|
|
List<WxOrder> orderCoupons = wxOrderMapper.findListOfUnpaidOrderByDate(dateMap); |
|
|
List<WxOrder> orderCoupons = wxOrderMapper.findListOfUnpaidOrderByDate(dateMap); |
|
|
orderCoupons.stream().forEach( o -> { |
|
|
orderCoupons.stream().forEach( o -> { |
|
|
try { |
|
|
try { |
|
|
orderExpired(o); |
|
|
|
|
|
|
|
|
proxy.orderExpired(o); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("券过期失败" + e.getMessage()); |
|
|
logger.error("券过期失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -82,7 +112,7 @@ public class OrderExpiringSchedule { |
|
|
List<WxOrder> orderPresss = wxOrderMapper.findListOfCompleteUnPaidPressOrderByDate(dateMap); |
|
|
List<WxOrder> orderPresss = wxOrderMapper.findListOfCompleteUnPaidPressOrderByDate(dateMap); |
|
|
orderPresss.stream().forEach( o -> { |
|
|
orderPresss.stream().forEach( o -> { |
|
|
try { |
|
|
try { |
|
|
orderPressExpired(o, true); |
|
|
|
|
|
|
|
|
proxy.orderPressExpired(o, true); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("砍价券支付过期失败" + e.getMessage()); |
|
|
logger.error("砍价券支付过期失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -93,7 +123,7 @@ public class OrderExpiringSchedule { |
|
|
orderPresss = wxOrderMapper.findListOfUnpaidPressOrderByDate(dateMap); |
|
|
orderPresss = wxOrderMapper.findListOfUnpaidPressOrderByDate(dateMap); |
|
|
orderPresss.stream().forEach( o -> { |
|
|
orderPresss.stream().forEach( o -> { |
|
|
try { |
|
|
try { |
|
|
orderPressExpired(o, false); |
|
|
|
|
|
|
|
|
proxy.orderPressExpired(o, false); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("砍价券过期失败" +e.getMessage()); |
|
|
logger.error("砍价券过期失败" +e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -105,7 +135,7 @@ public class OrderExpiringSchedule { |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode()); |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode()); |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
try { |
|
|
try { |
|
|
orderGroupExpired((WxOrder) o); |
|
|
|
|
|
|
|
|
proxy.orderGroupExpired((WxOrder) o); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("拼团取消失败" + e.getMessage()); |
|
|
logger.error("拼团取消失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -117,7 +147,7 @@ public class OrderExpiringSchedule { |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_OVERTIME.getCode()); |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_OVERTIME.getCode()); |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
try { |
|
|
try { |
|
|
returnMoney((WxOrder) o); |
|
|
|
|
|
|
|
|
proxy.returnMoney((WxOrder) o); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("拼团过期退款失败" + e.getMessage()); |
|
|
logger.error("拼团过期退款失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -128,7 +158,7 @@ public class OrderExpiringSchedule { |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
try { |
|
|
try { |
|
|
returnMoney((WxOrder) o); |
|
|
|
|
|
|
|
|
proxy.returnMoney((WxOrder) o); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("拼团券下架退款失败" + e.getMessage()); |
|
|
logger.error("拼团券下架退款失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -138,7 +168,7 @@ public class OrderExpiringSchedule { |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); |
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
wxOrderMapper.selectList(new QueryWrapper(order)).stream().forEach(o -> { |
|
|
try { |
|
|
try { |
|
|
returnMoney((WxOrder) o); |
|
|
|
|
|
|
|
|
proxy.returnMoney((WxOrder) o); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("参团失败退款失败" + e.getMessage()); |
|
|
logger.error("参团失败退款失败" + e.getMessage()); |
|
|
} |
|
|
} |
|
|
@@ -147,9 +177,49 @@ public class OrderExpiringSchedule { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean wxPaySuccess(WxOrder order) { |
|
|
|
|
|
WxPayOrder payOrderq = new WxPayOrder(); |
|
|
|
|
|
payOrderq.setOrderId(order.getId()); |
|
|
|
|
|
List<WxPayOrder> payorderlist = wxPayOrderMapper.findList(payOrderq); |
|
|
|
|
|
if (null == payorderlist || payorderlist.size() <=0 ) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
WxPayOrder wxpayOrder = payorderlist.get(0); |
|
|
|
|
|
if (null == wxpayOrder) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
WxCUser user = wxCUserMapper.selectById(wxpayOrder.getCUserId()); |
|
|
|
|
|
//找不到用户,问题单,不能删 |
|
|
|
|
|
if (null == user) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getByAppId(user.getAppId()); |
|
|
|
|
|
//找不到appInfo,问题单,不能删 |
|
|
|
|
|
if(appInfo == null) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); |
|
|
|
|
|
//找不到appInfo,问题单,不能删 |
|
|
|
|
|
if (null == payAccount) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, String> retMap = WxPayOrderServiceHelper.wxOrderPayStatusMap(wxpayOrder, order, appInfo, payAccount); |
|
|
|
|
|
int status = WxPayOrderServiceHelper.getPayStatusFromMap(retMap, wxpayOrder.getPayOrderNo()); |
|
|
|
|
|
//如果是支付成功,则更新信息 |
|
|
|
|
|
if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode() == status) { |
|
|
|
|
|
wxPayOrderService.handleSuccessOrder(wxpayOrder, order, retMap); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public void orderExpired(WxOrder order) { |
|
|
public void orderExpired(WxOrder order) { |
|
|
|
|
|
|
|
|
|
|
|
if (wxPaySuccess(order)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
// 库存退回 |
|
|
// 库存退回 |
|
|
wxOrderService.stockBack(order); |
|
|
wxOrderService.stockBack(order); |
|
|
|
|
|
|
|
|
@@ -168,6 +238,10 @@ public class OrderExpiringSchedule { |
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public void orderPressExpired(WxOrder order, boolean payExpired) { |
|
|
public void orderPressExpired(WxOrder order, boolean payExpired) { |
|
|
|
|
|
if (wxPaySuccess(order)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Date curDate = new Date(); |
|
|
Date curDate = new Date(); |
|
|
WxOrder updateOrder = new WxOrder(); |
|
|
WxOrder updateOrder = new WxOrder(); |
|
|
updateOrder.setId(order.getId()); |
|
|
updateOrder.setId(order.getId()); |
|
|
@@ -188,7 +262,11 @@ public class OrderExpiringSchedule { |
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public void orderGroupExpired(WxOrder order) { |
|
|
public void orderGroupExpired(WxOrder order) { |
|
|
Date curDate = new Date(); |
|
|
|
|
|
|
|
|
if (wxPaySuccess(order)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Date curDate = new Date(); |
|
|
WxOrder updateOrder = new WxOrder(); |
|
|
WxOrder updateOrder = new WxOrder(); |
|
|
updateOrder.setId(order.getId()); |
|
|
updateOrder.setId(order.getId()); |
|
|
updateOrder.updateTenantInfo(order); |
|
|
updateOrder.updateTenantInfo(order); |
|
|
@@ -205,7 +283,10 @@ public class OrderExpiringSchedule { |
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public void returnMoney(WxOrder order) { |
|
|
public void returnMoney(WxOrder order) { |
|
|
|
|
|
|
|
|
|
|
|
//支付成功的才退款 |
|
|
|
|
|
if (!wxPaySuccess(order)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
//获取APP信息 |
|
|
//获取APP信息 |
|
|
WxAppinfo appinfo = new WxAppinfo(); |
|
|
WxAppinfo appinfo = new WxAppinfo(); |
|
|
appinfo.updateTenantInfo(order); |
|
|
appinfo.updateTenantInfo(order); |
|
|
|