|
|
@@ -83,6 +83,11 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxAppinfoService wxAppinfoService; |
|
|
WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxMerchantSubsidyMapper wxMerchantSubsidyMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxPayAccountMapper wxPayAccountMapper; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { |
|
|
public PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { |
|
|
@@ -390,6 +395,88 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 补贴 |
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
|
|
public void subsidyAfterVerify(WxCouponOrder couponOrder, Long merchantId) { |
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
|
|
|
|
|
|
WxCouponMerchant couponMerchantQ = new WxCouponMerchant(); |
|
|
|
|
|
|
|
|
|
|
|
couponMerchantQ.setProductId(couponOrder.getCouponId()); |
|
|
|
|
|
couponMerchantQ.setMerchantId(merchantId); |
|
|
|
|
|
WxCouponMerchant couponMerchant; |
|
|
|
|
|
try { |
|
|
|
|
|
couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ); |
|
|
|
|
|
}catch (Exception e) { |
|
|
|
|
|
logger.error("查找所属卡券商户错误: " + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId ); |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (couponMerchant == null) { |
|
|
|
|
|
logger.error("未找到所属卡券商户: " + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId); |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxCoupon coupon; |
|
|
|
|
|
try { |
|
|
|
|
|
coupon = wxCouponMapper.selectByPrimaryKey(couponOrder.getCouponId()); |
|
|
|
|
|
}catch (Exception e) { |
|
|
|
|
|
logger.error("查找卡券错误: " + "CouponId:" + couponMerchantQ.getProductId()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxAppinfo wxAppinfo = wxAppinfoService.getCAppInfo(couponOrder.getTenantId()); |
|
|
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(wxAppinfo.getPayId()); |
|
|
|
|
|
|
|
|
|
|
|
Integer subsidyFee = (coupon.getPrice() - coupon.getSalePrice()) * subsidyRate / 10000; |
|
|
|
|
|
if (subsidyFee > 0) { |
|
|
|
|
|
// 有补贴时入库 |
|
|
|
|
|
Double dSubChargeFee = Math.ceil(subsidyFee * 1.0D * payAccount.getRate() / 10000); |
|
|
|
|
|
Integer realSubsidyFee = subsidyFee - dSubChargeFee.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
Double priceChargeFee = Math.ceil(coupon.getSalePrice() * 1.0D * payAccount.getRate() / 10000); |
|
|
|
|
|
Integer realPayment = coupon.getSalePrice() - priceChargeFee.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); |
|
|
|
|
|
merchantSubsidy.setId(idWorker.nextId()); |
|
|
|
|
|
merchantSubsidy.setTenantId(couponOrder.getTenantId()); |
|
|
|
|
|
merchantSubsidy.setOrderId(couponOrder.getOrderId()); |
|
|
|
|
|
merchantSubsidy.setOrderType(EnumOrderType.COUPON.getCode()); |
|
|
|
|
|
merchantSubsidy.setMerchantId(merchantId); |
|
|
|
|
|
merchantSubsidy.setCouponOrderId(couponOrder.getId()); |
|
|
|
|
|
merchantSubsidy.setCouponType(EnumCouponType.COUPON_MULTIMCH.getCode()); |
|
|
|
|
|
merchantSubsidy.setOrderPayment(coupon.getPrice()); |
|
|
|
|
|
merchantSubsidy.setReceiverPayment(coupon.getSalePrice()); |
|
|
|
|
|
merchantSubsidy.setRealPayment(realPayment); |
|
|
|
|
|
merchantSubsidy.setSubsidy(subsidyFee); |
|
|
|
|
|
merchantSubsidy.setRealSubsidy(realSubsidyFee); |
|
|
|
|
|
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); |
|
|
|
|
|
merchantSubsidy.setCreateDate(new Date()); |
|
|
|
|
|
merchantSubsidy.setUpdateDate(new Date()); |
|
|
|
|
|
try { |
|
|
|
|
|
wxMerchantSubsidyMapper.insertSelective(merchantSubsidy); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("数据库插入错误:" + e.getMessage()); |
|
|
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean sendCouponAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser) { |
|
|
public boolean sendCouponAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser) { |
|
|
// 核销发券 |
|
|
// 核销发券 |
|
|
|