| @@ -105,15 +105,23 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| Integer payment = cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); | Integer payment = cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); | ||||
| Integer dChargeFee = Math.round(payment * 1.0F * payAccount.getRate() / 10000); | Integer dChargeFee = Math.round(payment * 1.0F * payAccount.getRate() / 10000); | ||||
| Integer real_payment = payment - dChargeFee; | Integer real_payment = payment - dChargeFee; | ||||
| Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount()-real_payment; | |||||
| Integer remaingAmount = cardInfo.getRemainingAmount()-record.getDeductionAmount(); | |||||
| if(remaingAmount.equals(0)) { | |||||
| // 最后一次支付时 | |||||
| real_payment = Math.min(real_payment, cardInfo.getRemainingShareFeeAmount()); | |||||
| remain_real_pament = 0; | |||||
| } | |||||
| // 6 insert card_spend | // 6 insert card_spend | ||||
| record.setId(idWorker.nextId()); | record.setId(idWorker.nextId()); | ||||
| record.setPayment(payment); | record.setPayment(payment); | ||||
| record.setRealPayment(real_payment); | record.setRealPayment(real_payment); | ||||
| record.setCardBeforeAmount(cardInfo.getRemainingAmount()); | record.setCardBeforeAmount(cardInfo.getRemainingAmount()); | ||||
| record.setCardRemainAmount(cardInfo.getRemainingAmount()-record.getDeductionAmount()); | |||||
| record.setCardRemainAmount(remaingAmount); | |||||
| record.setCardBeforeRealAmount(cardInfo.getRemainingShareFeeAmount()); | record.setCardBeforeRealAmount(cardInfo.getRemainingShareFeeAmount()); | ||||
| record.setCardRemainRealAmount(cardInfo.getRemainingShareFeeAmount()-real_payment); | |||||
| record.setCardRemainRealAmount(remain_real_pament); | |||||
| record.setCreateDate(curDate); | record.setCreateDate(curDate); | ||||
| record.setUpdateDate(curDate); | record.setUpdateDate(curDate); | ||||
| try { | try { | ||||
| @@ -124,8 +132,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| } | } | ||||
| // 7. update card info | // 7. update card info | ||||
| cardInfo.setRemainingAmount(cardInfo.getRemainingAmount()-record.getDeductionAmount()); | |||||
| cardInfo.setRemainingShareFeeAmount(cardInfo.getRemainingShareFeeAmount()-real_payment); | |||||
| cardInfo.setRemainingAmount(remaingAmount); | |||||
| cardInfo.setRemainingShareFeeAmount(remain_real_pament); | |||||
| cardInfo.setUpdateDate(curDate); | cardInfo.setUpdateDate(curDate); | ||||
| try { | try { | ||||
| wxCardInfoMapper.updateByPrimaryKey(cardInfo); | wxCardInfoMapper.updateByPrimaryKey(cardInfo); | ||||
| @@ -238,7 +246,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| shareOrder.setcUserId(cardSpend.getOwnerId()); | shareOrder.setcUserId(cardSpend.getOwnerId()); | ||||
| shareOrder.setMerchantId(cardSpend.getMerchantId()); | shareOrder.setMerchantId(cardSpend.getMerchantId()); | ||||
| shareOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); | shareOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()); | ||||
| shareOrder.setPayAmount(cardSpend.getRealPayment()); | |||||
| shareOrder.setPayAmount(cardSpend.getPayment()); | |||||
| shareOrder.setOrderId(cardSpend.getOrderId()); | shareOrder.setOrderId(cardSpend.getOrderId()); | ||||
| shareOrder.setPayTimeStart(cardSpend.getCreateDate()); | shareOrder.setPayTimeStart(cardSpend.getCreateDate()); | ||||
| shareOrder.setPayTimeEnd(cardSpend.getUpdateDate()); | shareOrder.setPayTimeEnd(cardSpend.getUpdateDate()); | ||||
| @@ -246,10 +254,14 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| shareOrder.setTransactionId(cardInfo.getTransactionId()); | shareOrder.setTransactionId(cardInfo.getTransactionId()); | ||||
| shareOrder.setShareAmount(cardSpend.getRealPayment()); | shareOrder.setShareAmount(cardSpend.getRealPayment()); | ||||
| profitSharingOrderService.createSharingOrder(shareOrder); | profitSharingOrderService.createSharingOrder(shareOrder); | ||||
| if(cardSpend.getCardRemainAmount() <= 0) { | |||||
| shareOrder.setPayAmount(cardInfo.getRemainingShareFeeAmount()); | |||||
| shareOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_FINISH.getCode()); | |||||
| profitSharingOrderService.finishSharingOrder(shareOrder); | |||||
| if(cardSpend.getCardRemainAmount().equals(0)) { | |||||
| // 卡已被抵扣,但是分账还有余额 | |||||
| if (cardSpend.getCardRemainRealAmount() > 0) { | |||||
| shareOrder.setPayAmount(0); | |||||
| shareOrder.setShareAmount(cardInfo.getRemainingShareFeeAmount()); | |||||
| shareOrder.setType(EnumProfitSharingOrderType.PROFIT_SHARING_FINISH.getCode()); | |||||
| profitSharingOrderService.finishSharingOrder(shareOrder); | |||||
| } | |||||
| } | } | ||||
| } else { | } else { | ||||
| logger.error("微信分账: 未找到payorder or merchant at orderid-" + orderId); | logger.error("微信分账: 未找到payorder or merchant at orderid-" + orderId); | ||||