|
|
|
@@ -115,6 +115,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
"\"REQUIRE_POST_METHOD\":{\"detail\":\"请使用post方法\",\"reason\":\"未使用post传递参数\",\"resolution\":\"请检查请求参数是否通过post方法提交\"}," + |
|
|
|
"\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); |
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
private void handleSuccessOrder(WxPayOrder oldRecord,WxOrder order,Map<String, String> retMap) { |
|
|
|
Date curDate = new Date(); |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { |
|
|
|
@@ -172,59 +173,39 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public WxPayOrder handleWxOrderQuery(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount,IdWorker idworker) { |
|
|
|
public WxPayOrder handleWxOrderQuery(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount,IdWorker idworker,boolean repeatPay) { |
|
|
|
//int wxpaystatus = WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); |
|
|
|
Map<String, String> retMap = WxPayOrderServiceHelper.wxOrderPayStatusMap(oldRecord, order, appInfo, payAccount); |
|
|
|
int wxpaystatus = WxPayOrderServiceHelper.getPayStatusFromMap(retMap, oldRecord.getPayOrderNo()); |
|
|
|
if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode()==wxpaystatus) { |
|
|
|
handleSuccessOrder(oldRecord,order,retMap); |
|
|
|
//直接调用不会触发事务,spring事务基于AOP代理 |
|
|
|
WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
proxy.handleSuccessOrder(oldRecord,order,retMap); |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经支付,请勿重复支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_REFUND.getCode()==wxpaystatus) { |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_REFUND.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REFUND.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
} |
|
|
|
if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode()) { |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS.getCode()); |
|
|
|
wxOrderMapper.updateById(order); |
|
|
|
} |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_REFUND.getCode(),"该订单已经退款,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_CLOSE.getCode()==wxpaystatus) { |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_CLOSE.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_CLOSE.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
} |
|
|
|
if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()) { |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); |
|
|
|
wxOrderMapper.updateById(order); |
|
|
|
} |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_CLOSED.getCode(),"该订单已经关闭,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_REVERSE.getCode()==wxpaystatus) { |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_REVERSE.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_REVERSE.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
} |
|
|
|
if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()) { |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); |
|
|
|
wxOrderMapper.updateById(order); |
|
|
|
} |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_REVERSE.getCode(),"该订单已撤销,无法支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_WAIT.getCode()==wxpaystatus) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单支付中,请勿重复支付!"); |
|
|
|
}else if (EnumPayStatus.PAY_STATUS_NOTPAY.getCode()==wxpaystatus || EnumPayStatus.PAY_STATUS_FAIL.getCode()==wxpaystatus) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
Long payno = idworker.nextId(); |
|
|
|
if (null == payno || payno.longValue() <=0) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!handleWxOrderQuery:oldRecord:"+oldRecord+":wxstatus:"+wxpaystatus); |
|
|
|
} |
|
|
|
oldRecord.setPayOrderNo(String.valueOf(payno)); |
|
|
|
|
|
|
|
int sqlRow0 =wxPayOrderMapper.updateById(oldRecord); |
|
|
|
if (sqlRow0 != 1) { |
|
|
|
logger.error("pay order update error: " + oldRecord.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
//支付调用,支付遇到问题,可以重复支付 |
|
|
|
if (repeatPay) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); |
|
|
|
Long payno = idworker.nextId(); |
|
|
|
if (null == payno || payno.longValue() <=0) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!handleWxOrderQuery:oldRecord:"+oldRecord+":wxstatus:"+wxpaystatus); |
|
|
|
} |
|
|
|
oldRecord.setPayOrderNo(String.valueOf(payno)); |
|
|
|
|
|
|
|
int sqlRow0 =wxPayOrderMapper.updateById(oldRecord); |
|
|
|
if (sqlRow0 != 1) { |
|
|
|
logger.error("pay order update error: " + oldRecord.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
return oldRecord; |
|
|
|
} |
|
|
|
return null; |
|
|
|
@@ -354,9 +335,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_EXIST); |
|
|
|
//如果是支付中的,则调用微信接口查询支付状态 |
|
|
|
}else if (oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_WAIT.getCode()) { |
|
|
|
//TODO 直接调用不会触发事务,spring事务基于AOP代理 |
|
|
|
WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
record = proxy.handleWxOrderQuery(oldRecord,order,appInfo,payAccount,idworker); |
|
|
|
record = handleWxOrderQuery(oldRecord,order,appInfo,payAccount,idworker,true); |
|
|
|
if (null == record) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单微信查询支付状态失败!"); |
|
|
|
} |
|
|
|
|