|
|
@@ -170,16 +170,22 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 7. update card info |
|
|
// 7. update card info |
|
|
cardInfo.setRemainingAmount(remaingAmount); |
|
|
|
|
|
cardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
|
|
|
cardInfo.setUpdateDate(curDate); |
|
|
|
|
|
|
|
|
WxCardInfo updateCardInfo = new WxCardInfo(); |
|
|
|
|
|
updateCardInfo.setId(cardInfo.getId()); |
|
|
|
|
|
updateCardInfo.setRemainingAmount(remaingAmount); |
|
|
|
|
|
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
|
|
|
updateCardInfo.setUpdateDate(curDate); |
|
|
|
|
|
// 7.1、消费后修改卡转赠状态 |
|
|
|
|
|
if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
|
|
|
updateCardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
|
|
|
} |
|
|
try { |
|
|
try { |
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(cardInfo); |
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(cardInfo); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
logger.error("card info update error"); |
|
|
logger.error("card info update error"); |
|
|
return new ResultData(ErrorCode.DB_FAIL.getCode(), "card info 更新出错!"); |
|
|
return new ResultData(ErrorCode.DB_FAIL.getCode(), "card info 更新出错!"); |
|
|
} |
|
|
} |
|
|
// 7.1 update coupon card status |
|
|
|
|
|
|
|
|
// 7.2 update coupon card status |
|
|
if(cardInfo.getRemainingAmount().equals(0)) { |
|
|
if(cardInfo.getRemainingAmount().equals(0)) { |
|
|
if (cardFinished(curDate, cardInfo)) { |
|
|
if (cardFinished(curDate, cardInfo)) { |
|
|
return new ResultData(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!"); |
|
|
return new ResultData(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!"); |
|
|
@@ -241,14 +247,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//10、消费后修改卡转赠状态 |
|
|
|
|
|
WxCardInfo wxCardInfo = new WxCardInfo(); |
|
|
|
|
|
wxCardInfo.setId(record.getCardId()); |
|
|
|
|
|
wxCardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
|
|
|
if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
|
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(wxCardInfo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 成长值 |
|
|
// 成长值 |
|
|
try { |
|
|
try { |
|
|
orderUpdate.setPayment(real_payment); |
|
|
orderUpdate.setPayment(real_payment); |
|
|
@@ -617,7 +615,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
cardInfo.setRemainingAmount(remaingAmount); |
|
|
cardInfo.setRemainingAmount(remaingAmount); |
|
|
cardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
cardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
cardInfo.setUpdateDate(curDate); |
|
|
cardInfo.setUpdateDate(curDate); |
|
|
// 消费后,修改卡转赠状态 |
|
|
|
|
|
|
|
|
// 7.1 消费后,修改卡转赠状态 |
|
|
if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
} |
|
|
} |
|
|
@@ -673,19 +671,18 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() + real_payment; |
|
|
Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() + real_payment; |
|
|
Integer remaingAmount = cardInfo.getRemainingAmount()+record.getDeductionAmount(); |
|
|
Integer remaingAmount = cardInfo.getRemainingAmount()+record.getDeductionAmount(); |
|
|
|
|
|
|
|
|
// 5.、如果还是原价更改卡转赠状态 |
|
|
|
|
|
|
|
|
// 5.、update card info |
|
|
WxCardInfo updateCardInfo = new WxCardInfo(); |
|
|
WxCardInfo updateCardInfo = new WxCardInfo(); |
|
|
updateCardInfo.setId(record.getCardId()); |
|
|
updateCardInfo.setId(record.getCardId()); |
|
|
|
|
|
updateCardInfo.setRemainingAmount(remaingAmount); |
|
|
|
|
|
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
|
|
|
updateCardInfo.setUpdateDate(curDate); |
|
|
|
|
|
// 5.1 如果还是原价更改卡转赠状态 |
|
|
if (cardInfo.getAmount().equals(remaingAmount) && |
|
|
if (cardInfo.getAmount().equals(remaingAmount) && |
|
|
cardInfo.getSupportTransfer().equals(EnumCouponTransfer.NO.getCode()) && |
|
|
cardInfo.getSupportTransfer().equals(EnumCouponTransfer.NO.getCode()) && |
|
|
coupon.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
coupon.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
updateCardInfo.setSupportTransfer(EnumCouponTransfer.YES.getCode()); |
|
|
updateCardInfo.setSupportTransfer(EnumCouponTransfer.YES.getCode()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 6. update card info |
|
|
|
|
|
updateCardInfo.setRemainingAmount(remaingAmount); |
|
|
|
|
|
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
|
|
|
updateCardInfo.setUpdateDate(curDate); |
|
|
|
|
|
try { |
|
|
try { |
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(updateCardInfo); |
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(updateCardInfo); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
@@ -707,4 +704,194 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
return updateCardInfo; |
|
|
return updateCardInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
|
|
public WxCardSpend cardSpendForPosPay(WxCardSpend record) throws MallinkException { |
|
|
|
|
|
Date curDate = new Date(); |
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
// 1. get card info |
|
|
|
|
|
WxCardInfo cardInfo = wxCardInfoMapper.selectByPrimaryKey(record.getCardId()); |
|
|
|
|
|
if (cardInfo == null) { |
|
|
|
|
|
logger.error("card not found: " + record.getCardId()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
// 2. coupon |
|
|
|
|
|
Integer subsidyRate = 0; |
|
|
|
|
|
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(cardInfo.getCouponId()); |
|
|
|
|
|
if (coupon == null) { |
|
|
|
|
|
logger.error("card's coupon not found: " + cardInfo.getCouponId()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
if (coupon.getSubsidyNum() == null) { |
|
|
|
|
|
logger.error("卡补贴额未填写: " + cardInfo.getCouponId()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.CARD_SUBSIDY_NOT_SET); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. get pay account |
|
|
|
|
|
WxPayAccount payAccount = null; |
|
|
|
|
|
WxPayAccount payAccountQ = new WxPayAccount(); |
|
|
|
|
|
payAccountQ.setTenantId(record.getTenantId()); |
|
|
|
|
|
try { |
|
|
|
|
|
payAccount = payAccountMapper.selectOne(payAccountQ); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("获取payAccount error: " + record.getTenantId()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_MCH_NOT_FOUND); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 扣减计算 |
|
|
|
|
|
Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); |
|
|
|
|
|
Integer payment = paymentD.intValue(); |
|
|
|
|
|
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate()); |
|
|
|
|
|
Integer real_payment = payment - iChargeFee; |
|
|
|
|
|
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 = cardInfo.getRemainingShareFeeAmount() - real_payment; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 5. card_spend |
|
|
|
|
|
record.setTenantId(cardInfo.getTenantId()); |
|
|
|
|
|
record.setPayment(payment); |
|
|
|
|
|
record.setRealPayment(real_payment); |
|
|
|
|
|
record.setCardBeforeAmount(cardInfo.getRemainingAmount()); |
|
|
|
|
|
record.setCardRemainAmount(remaingAmount); |
|
|
|
|
|
record.setCardBeforeRealAmount(cardInfo.getRemainingShareFeeAmount()); |
|
|
|
|
|
record.setCardRemainRealAmount(remain_real_pament); |
|
|
|
|
|
record.setPayStatus(EnumCardSpendStatus.NOT_PAY.getCode()); |
|
|
|
|
|
record.setCreateDate(curDate); |
|
|
|
|
|
record.setUpdateDate(curDate); |
|
|
|
|
|
if (record.getId() == null) { |
|
|
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
|
|
try { |
|
|
|
|
|
wxCardSpendMapper.insertSelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("card spend insert error"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "卡消费插入出错"); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
try { |
|
|
|
|
|
wxCardSpendMapper.updateByPrimaryKeySelective(record); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("card spend update error"); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "卡消费更新出错"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 7. update card info |
|
|
|
|
|
WxCardInfo updateCardInfo = new WxCardInfo(); |
|
|
|
|
|
updateCardInfo.setId(cardInfo.getId()); |
|
|
|
|
|
updateCardInfo.setRemainingAmount(remaingAmount); |
|
|
|
|
|
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); |
|
|
|
|
|
updateCardInfo.setUpdateDate(curDate); |
|
|
|
|
|
// 7.1 消费后,修改卡转赠状态 |
|
|
|
|
|
if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { |
|
|
|
|
|
updateCardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
wxCardInfoMapper.updateByPrimaryKeySelective(updateCardInfo); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errMessage = "消费卡信息更新出错: " + cardInfo.getId(); |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
// 7.2 update coupon card status |
|
|
|
|
|
if(cardInfo.getRemainingAmount().equals(0)) { |
|
|
|
|
|
if (cardFinished(curDate, cardInfo)) { |
|
|
|
|
|
String errMessage = "消费卡信息更新出错: " + cardInfo.getId(); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
// 8. 补贴 |
|
|
|
|
|
// 补贴额 = 商城补贴总额/卡券面额 * 抵扣额(本次支付额) |
|
|
|
|
|
Double subsidyFeeD = 1.0 * record.getDeductionAmount() * coupon.getSubsidyNum() / cardInfo.getAmount(); |
|
|
|
|
|
Integer subsidyFee = subsidyFeeD.intValue(); |
|
|
|
|
|
logger.info("补贴额: " + subsidyFee); |
|
|
|
|
|
if(subsidyFee > 0) { |
|
|
|
|
|
// 有补贴时入库 |
|
|
|
|
|
int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRate()); |
|
|
|
|
|
Integer realSubsidyFee = subsidyFee - iSubChargeFee; |
|
|
|
|
|
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); |
|
|
|
|
|
merchantSubsidy.setId(idWorker.nextId()); |
|
|
|
|
|
merchantSubsidy.setTenantId(record.getTenantId()); |
|
|
|
|
|
/// merchantSubsidy.setOrderId(order.getId()); TODO |
|
|
|
|
|
merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); |
|
|
|
|
|
merchantSubsidy.setMerchantId(record.getMerchantId()); |
|
|
|
|
|
merchantSubsidy.setCouponOrderId(cardInfo.getId()); |
|
|
|
|
|
merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); |
|
|
|
|
|
merchantSubsidy.setOrderPayment(record.getDeductionAmount()); |
|
|
|
|
|
merchantSubsidy.setReceiverPayment(payment); |
|
|
|
|
|
merchantSubsidy.setRealPayment(real_payment); |
|
|
|
|
|
merchantSubsidy.setSubsidy(subsidyFee); |
|
|
|
|
|
merchantSubsidy.setRealSubsidy(realSubsidyFee); |
|
|
|
|
|
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { |
|
|
|
|
|
// 立减领券 |
|
|
|
|
|
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode()); |
|
|
|
|
|
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) { |
|
|
|
|
|
// 转账倒现金 |
|
|
|
|
|
} else { |
|
|
|
|
|
// 未补贴 |
|
|
|
|
|
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
merchantSubsidy.setCreateDate(curDate); |
|
|
|
|
|
merchantSubsidy.setUpdateDate(curDate); |
|
|
|
|
|
try { |
|
|
|
|
|
wxMerchantSubsidyMapper.insertSelective(merchantSubsidy); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errMessage = "商户补贴信息插入出错!"; |
|
|
|
|
|
logger.error(errMessage); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
// 9. 分账 |
|
|
|
|
|
try { |
|
|
|
|
|
shareForCardPay(record.getTenantId(), record.getCardId(), record.getOrderId(), record.getId()); |
|
|
|
|
|
} catch (MallinkException e) { |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
if(ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode()) { |
|
|
|
|
|
// 分账已到20次限制,后面只记录,无法分账 |
|
|
|
|
|
logger.error("分账已到20次限制,后面只记录,无法分账"); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new MallinkException(e.getErrorCode(), e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
// 成长值 |
|
|
|
|
|
try { |
|
|
|
|
|
orderUpdate.setPayment(real_payment); |
|
|
|
|
|
wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, orderUpdate, coupon.getBusiness()); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("成长值:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
// 积分 |
|
|
|
|
|
try { |
|
|
|
|
|
//-------此处为【现金支付】记录增加积分操作------- |
|
|
|
|
|
WxCreditHistory creditHistory = new WxCreditHistory(); |
|
|
|
|
|
creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); |
|
|
|
|
|
creditHistory.setOperatorId(record.getOwnerId()); |
|
|
|
|
|
creditHistory.setCUserId(record.getOwnerId()); |
|
|
|
|
|
creditHistory.setCreateDate(new Date()); |
|
|
|
|
|
creditHistory.setTenantId(record.getTenantId()); |
|
|
|
|
|
creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); |
|
|
|
|
|
creditHistory.setCouponId(coupon.getId()); |
|
|
|
|
|
creditHistory.setBusinessId(Long.valueOf(coupon.getBusiness())); |
|
|
|
|
|
creditHistory.setSpend(real_payment); |
|
|
|
|
|
//如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 |
|
|
|
|
|
creditHistory.setMerchantId(record.getMerchantId()); |
|
|
|
|
|
wxCreditHistoryService.saveOrUpdate(creditHistory); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("积分值:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
return record; |
|
|
|
|
|
} |
|
|
} |
|
|
} |