| @@ -114,6 +114,62 @@ 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 | |||
| public WxPayOrder handleWxOrderQuery(WxPayOrder oldRecord,WxOrder order,WxAppinfo appInfo,WxPayAccount payAccount,IdWorker idworker) { | |||
| int wxpaystatus = WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); | |||
| if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode()==wxpaystatus) { | |||
| 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); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经支付,请勿重复支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_REFUND.getCode()==wxpaystatus) { | |||
| 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_PAYING.getCode(),"该订单已经退款,无法支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_CLOSE.getCode()==wxpaystatus) { | |||
| 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_PAYING.getCode(),"该订单已经关闭,无法支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_REVERSE.getCode()==wxpaystatus) { | |||
| 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_PAYING.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.intValue() <=0) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!"); | |||
| } | |||
| 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; | |||
| } | |||
| @Override | |||
| public ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| @@ -237,55 +293,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_EXIST); | |||
| //如果是支付中的,则调用微信接口查询支付状态 | |||
| }else if (oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_WAIT.getCode()) { | |||
| int wxpaystatus = WxPayOrderServiceHelper.wxOrderPayStatus(oldRecord, order, appInfo, payAccount); | |||
| if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode()==wxpaystatus) { | |||
| 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); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"该订单已经支付,请勿重复支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_REFUND.getCode()==wxpaystatus) { | |||
| 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_PAYING.getCode(),"该订单已经退款,无法支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_CLOSE.getCode()==wxpaystatus) { | |||
| 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_PAYING.getCode(),"该订单已经关闭,无法支付!"); | |||
| }else if (EnumPayStatus.PAY_STATUS_REVERSE.getCode()==wxpaystatus) { | |||
| 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_PAYING.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.intValue() <=0) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单支付流水号生成失败!"); | |||
| } | |||
| oldRecord.setPayOrderNo(String.valueOf(payno)); | |||
| int sqlRow0 =wxPayOrderMapper.updateById(oldRecord); | |||
| if (sqlRow0 != 1) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| record = oldRecord; | |||
| record = handleWxOrderQuery(oldRecord,order,appInfo,payAccount,idworker); | |||
| if (null == record) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_PAYING.getCode(),"订单微信查询支付状态失败!"); | |||
| } | |||
| //如果是支付错误,可以重新支付 | |||
| }else if(oldRecord.getPayOrderStatus()==EnumPayStatus.PAY_STATUS_FAIL.getCode()) { | |||