|
|
|
@@ -22,6 +22,7 @@ import com.iformall.utils.*; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.aop.framework.AopContext; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
@@ -114,19 +115,66 @@ 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 |
|
|
|
private void handleSuccessOrder(WxPayOrder oldRecord,WxOrder order,Map<String, String> retMap) { |
|
|
|
//更新wxPayOrder |
|
|
|
Date curDate = new Date(); |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
String timEndStr = retMap.get("time_end"); |
|
|
|
Date timeEnd = null; |
|
|
|
try { |
|
|
|
timeEnd = Utility.getDateFromString(timEndStr); |
|
|
|
} catch (ParseException e) { |
|
|
|
logger.error("解析timeEnd失败"); |
|
|
|
timeEnd = new Date(); |
|
|
|
} |
|
|
|
oldRecord.setPayTimeEnd(timeEnd); |
|
|
|
oldRecord.setPayEndFrom(EnumPayEndFrom.QUERY.getCode()); |
|
|
|
String transactionId = retMap.get("transaction_id"); |
|
|
|
oldRecord.setTransactionId(transactionId); |
|
|
|
oldRecord.setUpdateTime(curDate); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
} |
|
|
|
WxCoupon wxCoupon = wxCouponMapper.selectById(order.getProductId()); |
|
|
|
if(wxCoupon != null) { |
|
|
|
if (isOrderGroupCoupon(oldRecord, wxCoupon)) { |
|
|
|
// 如果是Coupon是拼团, 创建拼团信息, 不创建COUPON_ORDER |
|
|
|
try { |
|
|
|
wxOrderGroupService.createOrderGroup(order, wxCoupon); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("参团失败" + e.getMessage()); |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); |
|
|
|
order.setUpdateDate(new Date()); |
|
|
|
wxOrderMapper.updateById(order); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 普通券, 修改订单状态 |
|
|
|
try { |
|
|
|
wxOrderService.couponOrderSuccess(order); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); |
|
|
|
} |
|
|
|
// 下订单完成,发送内部消息 |
|
|
|
try { |
|
|
|
wxOrderService.sendOrderSuccessActionMsg(order); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("内部消息发送失败: " + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public WxPayOrder handleWxOrderQuery(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount,IdWorker idworker) { |
|
|
|
int wxpaystatus = WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); |
|
|
|
//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) { |
|
|
|
if (oldRecord.getPayOrderStatus() != EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { |
|
|
|
oldRecord.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); |
|
|
|
wxPayOrderMapper.updateById(oldRecord); |
|
|
|
} |
|
|
|
if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { |
|
|
|
order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); |
|
|
|
wxOrderMapper.updateById(order); |
|
|
|
} |
|
|
|
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()) { |
|
|
|
@@ -302,7 +350,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_EXIST); |
|
|
|
//如果是支付中的,则调用微信接口查询支付状态 |
|
|
|
}else if (oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_WAIT.getCode()) { |
|
|
|
record = handleWxOrderQuery(oldRecord,order,appInfo,payAccount,idworker); |
|
|
|
//TODO 直接调用不会触发事务,spring事务基于AOP代理 |
|
|
|
WxPayOrderServiceImpl proxy = (WxPayOrderServiceImpl) AopContext.currentProxy(); |
|
|
|
record = proxy.handleWxOrderQuery(oldRecord,order,appInfo,payAccount,idworker); |
|
|
|
if (null == record) { |
|
|
|
throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单微信查询支付状态失败!"); |
|
|
|
} |
|
|
|
|