|
|
|
@@ -1137,7 +1137,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { |
|
|
|
|
|
|
|
WxRefundOrder record = new WxRefundOrder(); |
|
|
|
record.updateTenantInfo(wxOrder); |
|
|
|
record.setPayOrderNo(String.valueOf(cardSend.getId()));//卡没有支付订单 |
|
|
|
record.setPayOrderNo(String.valueOf(cardSend.getId())); |
|
|
|
record.setOrderId(wxOrder.getId()); |
|
|
|
record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode()); |
|
|
|
|
|
|
|
@@ -1210,15 +1210,6 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { |
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); |
|
|
|
if(cAppInfo == null){ |
|
|
|
throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); |
|
|
|
if(payAccount == null){ |
|
|
|
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
|
|
|
|
WxCardSpend record = new WxCardSpend(); |
|
|
|
@@ -1330,35 +1321,61 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { |
|
|
|
subsidyFee = subsidyD.intValue(); |
|
|
|
|
|
|
|
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); |
|
|
|
merchantSubsidy.setId(idWorker.nextId()); |
|
|
|
merchantSubsidy.updateTenantInfo(record); |
|
|
|
merchantSubsidy.setOrderId(wxOrder.getId()); |
|
|
|
merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); |
|
|
|
WxMerchantSubsidy wxMerchantSubsidy = wxMerchantSubsidyMapper.selectOne(new QueryWrapper<>(merchantSubsidy)); |
|
|
|
if(wxMerchantSubsidy == null){ |
|
|
|
logger.error("未找到补贴数据 error"); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "未找到补贴数据 插入出错!"); |
|
|
|
merchantSubsidy.setMerchantId(record.getMerchantId()); |
|
|
|
merchantSubsidy.setBTenantId(record.getTenantId()); |
|
|
|
merchantSubsidy.setCouponOrderId(cardInfo.getId()); |
|
|
|
merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); |
|
|
|
merchantSubsidy.setOrderPayment(0-record.getDeductionAmount()); |
|
|
|
merchantSubsidy.setReceiverPayment(0-refund); |
|
|
|
merchantSubsidy.setRealPayment(0-real_refund); |
|
|
|
merchantSubsidy.setSubsidy(0-subsidyFee); |
|
|
|
merchantSubsidy.setRealSubsidy(0-subsidyFee); |
|
|
|
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); |
|
|
|
|
|
|
|
merchantSubsidy.setType(EnumMerchantSubsidyType.MANUAL.getCode()); |
|
|
|
merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode()); |
|
|
|
|
|
|
|
//如果是有价卡,并且有补贴,则该记录不能显示在卡消费列表里面 |
|
|
|
if (cardInfo.getSaleAmount()>0 && subsidyFee > 0) { |
|
|
|
merchantSubsidy.setCardSpendListShow(0); |
|
|
|
} |
|
|
|
|
|
|
|
Double realSubsidyD = 1.0 * cardSend.getRealPayment() * refundFee / cardSend.getDeductionAmount(); |
|
|
|
Integer realSubsidyFee = realSubsidyD.intValue(); |
|
|
|
|
|
|
|
if(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode().equals(wxMerchantSubsidy.getStatus())){ |
|
|
|
wxMerchantSubsidy.setOrderPayment(wxMerchantSubsidy.getOrderPayment()-record.getDeductionAmount()); |
|
|
|
wxMerchantSubsidy.setReceiverPayment(wxMerchantSubsidy.getReceiverPayment()-refund); |
|
|
|
wxMerchantSubsidy.setRealPayment(wxMerchantSubsidy.getRealPayment()-real_refund); |
|
|
|
wxMerchantSubsidy.setSubsidy(wxMerchantSubsidy.getSubsidy()-subsidyFee); |
|
|
|
wxMerchantSubsidy.setRealSubsidy(wxMerchantSubsidy.getRealSubsidy()-realSubsidyFee); |
|
|
|
wxMerchantSubsidy.setUpdateDate(currentDate); |
|
|
|
try { |
|
|
|
wxMerchantSubsidyMapper.updateById(wxMerchantSubsidy); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("退补贴数据 修改失败info update error"); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "merchantSubsidy info 修改出错!"); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
logger.error("补贴数据已结算 无法退款 error"); |
|
|
|
throw new MallinkException(ErrorCode.SYS_METHOD_NOT_SUPPORT.getCode(), "补贴数据已结算"); |
|
|
|
merchantSubsidy.setCreateDate(currentDate); |
|
|
|
merchantSubsidy.setUpdateDate(currentDate); |
|
|
|
try { |
|
|
|
wxMerchantSubsidyMapper.insert(merchantSubsidy); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("merchantSubsidy info insert error"); |
|
|
|
return new ResultData(ErrorCode.DB_FAIL.getCode(), "merchantSubsidy info 插入出错!"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(refund > 0){ |
|
|
|
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); |
|
|
|
merchantSubsidy.setId(idWorker.nextId()); |
|
|
|
merchantSubsidy.updateTenantInfo(record); |
|
|
|
merchantSubsidy.setOrderId(record.getOrderId()); |
|
|
|
merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); |
|
|
|
merchantSubsidy.setMerchantId(record.getMerchantId()); |
|
|
|
merchantSubsidy.setBTenantId(record.getTenantId()); |
|
|
|
merchantSubsidy.setCouponOrderId(record.getCardId()); |
|
|
|
merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); |
|
|
|
merchantSubsidy.setOrderPayment(0-record.getPayment()); |
|
|
|
merchantSubsidy.setReceiverPayment(0-record.getPayment()); |
|
|
|
merchantSubsidy.setRealPayment(0-record.getRealPayment()); |
|
|
|
merchantSubsidy.setSubsidy(0-record.getPayment()); |
|
|
|
merchantSubsidy.setRealSubsidy(0-record.getRealPayment()); |
|
|
|
merchantSubsidy.setCreateDate(currentDate); |
|
|
|
merchantSubsidy.setUpdateDate(currentDate); |
|
|
|
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode()); |
|
|
|
merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode()); |
|
|
|
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); |
|
|
|
wxMerchantSubsidyMapper.insert(merchantSubsidy); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
@@ -1373,5 +1390,65 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public ResultData refundCardOrderFail(WxRefundOrder refundOrder, WxOrder wxOrder) { |
|
|
|
Long cardSpendId = Long.parseLong(refundOrder.getPayOrderNo()); |
|
|
|
WxCardSpend cardSend = wxCardSpendMapper.selectById(cardSpendId); |
|
|
|
if(cardSend == null){ |
|
|
|
logger.error("付款订单未找到, e:"); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); |
|
|
|
} |
|
|
|
WxCardInfo cardInfo = wxCardInfoMapper.selectById(cardSend.getCardId()); |
|
|
|
if (cardInfo == null) { |
|
|
|
logger.error("card not found: " + cardSend.getCardId()); |
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
Date currentDate = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
WxRefundOrder updateOrder = new WxRefundOrder(); |
|
|
|
updateOrder.setId(refundOrder.getId()); |
|
|
|
updateOrder.setOrderId(refundOrder.getOrderId()); |
|
|
|
updateOrder.setUpdateTime(currentDate); |
|
|
|
updateOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_FAIL.getCode()); |
|
|
|
// updateOrder.setTransactionId(transactionId); |
|
|
|
// updateOrder.setRefundId(record.getId().toString()); |
|
|
|
// 修改退款订单状态 |
|
|
|
try { |
|
|
|
int i = wxRefundOrderMapper.updateById(updateOrder); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); |
|
|
|
} |
|
|
|
|
|
|
|
WxOrder refOrder = new WxOrder(); |
|
|
|
refOrder.setId(updateOrder.getId()); |
|
|
|
refOrder.updateTenantInfo(wxOrder); |
|
|
|
refOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); |
|
|
|
refOrder.setUpdateDate(currentDate); |
|
|
|
try { |
|
|
|
int i = wxOrderMapper.updateById(refOrder); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("订单状态更新失败, e:" + e.getMessage(),e); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); |
|
|
|
} |
|
|
|
|
|
|
|
WxCardSpend cardSpendUpd = new WxCardSpend(); |
|
|
|
cardSpendUpd.setId(cardSend.getId()); |
|
|
|
cardSpendUpd.updateTenantInfo(cardSend); |
|
|
|
cardSpendUpd.setPayStatus(EnumCardSpendStatus.NOT_PAY.getCode()); |
|
|
|
cardSpendUpd.setUpdateDate(currentDate); |
|
|
|
try { |
|
|
|
wxCardSpendMapper.updateById(cardSpendUpd); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("卡退款订单修改出错: " + cardSpendUpd.toString()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |