diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index 468ca5ed6..55a1fa18d 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -138,6 +138,13 @@ public class WxCoupon implements Serializable { /*是否支持转送(0:不支持,1支持)**/ @io.swagger.annotations.ApiModelProperty(value="是否支持转送(0:不支持,1支持)",name="supportTransfer") private Integer supportTransfer; + /**补贴类型(0:不支持, 1:微信支付立减与折扣, 2:线下结算, 3:微信付款到银行卡 )**/ + @io.swagger.annotations.ApiModelProperty(value="补贴类型(0:不支持, 1:微信支付立减与折扣, 2:线下结算, 3:微信付款到银行卡)",name="subsidyType") + private Integer subsidyType; + /**补贴额**/ + @io.swagger.annotations.ApiModelProperty(value="补贴额",name="subsidyNum") + private Integer subsidyNum; + public String getTenantId() { return tenantId; } @@ -350,6 +357,21 @@ public class WxCoupon implements Serializable { this.merchantParams = merchantParams; } + public Integer getSubsidyType() { + return subsidyType; + } + + public void setSubsidyType(Integer subsidyType) { + this.subsidyType = subsidyType; + } + + public Integer getSubsidyNum() { + return subsidyNum; + } + + public void setSubsidyNum(Integer subsidyNum) { + this.subsidyNum = subsidyNum; + } public static enum Field { @@ -380,6 +402,8 @@ public class WxCoupon implements Serializable { ,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC") ,Business_ASC("`business` ASC"),Business_DESC("`business` DESC") ,SupportTransfer_ASC("`support_transfer` ASC"),SupportTransfer_DESC("`support_transfer` DESC") + ,SubsidyType_ASC("`subsidy_type` ASC"),SubsidyType_DESC("`subsidy_type` DESC") + ,SubsidyNum_ASC("`subsidy_num` ASC"),SubsidyNum_DESC("`subsidy_num` DESC") ; private String value; Field(String value){ diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponSubsidyType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponSubsidyType.java new file mode 100644 index 000000000..871f2163e --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponSubsidyType.java @@ -0,0 +1,39 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumCouponSubsidyType { + + // 0: 无补贴 1:微信支付立减与折扣, 2:线下结算, 3:微信付款到银行卡 + NO_SUBSIDY(0, "无补贴"), + WECHAT_COUPON(1,"微信支付立减与折扣"), + OFFLINE_SUBSIDY(2, "线下结算"), + WECHAT_MCHPAY(3, "微信付款到银行卡") + ; + + public static EnumCouponSubsidyType getEnum(Integer code) { + for (EnumCouponSubsidyType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumCouponSubsidyType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index f636ee83a..9e1dd2a17 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -84,15 +84,12 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { logger.error("card not found: " + record.getCardId()); return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); } - // 2. coupon 补贴 rate + // 2. coupon Integer subsidyRate = 0; - if(couponMerchant.getParameter() != null) { - try { - subsidyRate = Integer.valueOf(couponMerchant.getParameter()); - } catch (Exception e) { - logger.error("couponmerchant subidy rate not found: " + cardInfo.getCouponId()); - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } + WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(cardInfo.getCouponId()); + if (coupon == null) { + logger.error("card's coupon not found: " + cardInfo.getCouponId()); + return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); } // 3. get pay account @@ -106,7 +103,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { return new ResultData(ErrorCode.DB_FAIL.getCode(), "获取payAccount失败"); } - // 5. 扣减计算 + // 5. 扣减计算 Integer payment = cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); Double dChargeFee = Math.ceil(payment * 1.0D * payAccount.getRate() / 10000); Integer real_payment = payment - dChargeFee.intValue(); @@ -162,7 +159,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } // 8. 补贴 - Integer subsidyFee = (record.getDeductionAmount() - payment)* subsidyRate / 10000; + // 补贴额 = 商城补贴总额/卡券面额 * 抵扣额(本次支付额) + Integer subsidyFee = record.getDeductionAmount() * coupon.getSubsidyNum() / cardInfo.getAmount(); if(subsidyFee > 0) { // 有补贴时入库 Double dSubChargeFee = Math.ceil(subsidyFee * 1.0D * payAccount.getRate() / 10000); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index 7e1b38ad8..9c70a43ef 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -420,19 +420,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); } - // coupon 补贴 rate - Integer subsidyRate = 0; - if(couponMerchant.getParameter() != null) { - try { - subsidyRate = Integer.valueOf(couponMerchant.getParameter()); - } catch (Exception e) { - logger.error("补贴比例计算不合法:" + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId); - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); - } - } else { - logger.info("无补贴参数:" + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId); - } - + // coupon WxCoupon coupon; try { coupon = wxCouponMapper.selectByPrimaryKey(couponOrder.getCouponId()); @@ -444,7 +432,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { WxAppinfo wxAppinfo = wxAppinfoService.getCAppInfo(couponOrder.getTenantId()); WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(wxAppinfo.getPayId()); - Integer subsidyFee = (coupon.getPrice() - coupon.getSalePrice()) * subsidyRate / 10000; + + // 本张券的补贴额 + Integer subsidyFee = coupon.getSubsidyNum(); if (subsidyFee > 0) { // 有补贴时入库 Double dSubChargeFee = Math.ceil(subsidyFee * 1.0D * payAccount.getRate() / 10000); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 61b64066b..3820a4384 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -101,14 +101,28 @@ public class WxCouponServiceImpl implements WxCouponService { record.setValidDays(null); } } + if(record.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { + // 微信 立减 + if(record.getSubsidyNum() > record.getSalePrice()) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); + } + } else if(record.getSubsidyType().equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) { + // 线下补贴 + int subsidy_num = record.getPrice() - record.getSalePrice(); + if(record.getSubsidyNum() > subsidy_num) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); + } + } else if(record.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) { + // TODO 微信转账到银行卡 + + } final IdWorker idWorker = IdWorker.get(); if (record.getId() == null) { record.setId(idWorker.nextId()); - if (record.getMerchantParams() != null) - { + if (record.getMerchantParams() != null) { List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); List businessList= new ArrayList<>(); merchantParamList.forEach(merchantParam -> {