| @@ -36,6 +36,9 @@ public class WxCardPayController extends BaseController { | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxCardInfoService wxCardInfoService; | |||
| @Autowired | |||
| WxCardSpendService wxCardSpendService; | |||
| @@ -76,13 +79,28 @@ public class WxCardPayController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantCode转换失败"); | |||
| } | |||
| // TODO check if merchantId is in card support merchant | |||
| BigDecimal totalFee = new BigDecimal(totalFeeStr); | |||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||
| Integer payment = totalFee.multiply(new BigDecimal(100)).intValue(); | |||
| WxCardInfo cardInfo = wxCardInfoService.getById(cardId); | |||
| if(cardInfo == null) { | |||
| logger.error("卡不存在: " + cardIdStr); | |||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| if(payment>cardInfo.getRemainingAmount()) { | |||
| logger.error("卡余额不足: " + cardIdStr); | |||
| return new ResultData(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); | |||
| } | |||
| WxCouponMerchant couponMerchant = wxCardSpendService.checkMerchantInCoupon(cardInfo, merchantId); | |||
| if(couponMerchant == null) { | |||
| logger.error("商户不支持此卡 " + cardIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), "商户不支持此卡"); | |||
| } | |||
| WxCUser user = getUser(); | |||
| WxMerchant merchant = wxMerchantService.getById(merchantId); | |||
| @@ -108,7 +126,7 @@ public class WxCardPayController extends BaseController { | |||
| record.setDeductionAmount(payment); | |||
| try { | |||
| return wxCardSpendService.createCardSpend(record, order, user); | |||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant, user); | |||
| } catch (MallinkException e) { | |||
| logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -143,11 +143,14 @@ public enum ErrorCode{ | |||
| COUPON_ORDER_IS_OVER_TIME(4002, "卡券已过期"), | |||
| COUPON_ORDER_IS_INVALID(4003, "卡券已经作废"), | |||
| COUPON_ORDER_BUSER_IS_NULL(4004, "卡券B端用户不存在"), | |||
| COUPON_ORDER_MERANT_IS_NULL(4005, "卡券商户不存在"), | |||
| /** | |||
| * 卡 | |||
| */ | |||
| CARD_IS_NOT_FOUND(9001, "优惠卡不存在"), | |||
| CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH(9002, "优惠卡余额不足"), | |||
| /** | |||
| @@ -2,12 +2,14 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCardSpend; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.*; | |||
| public interface WxCardSpendService { | |||
| /** | |||
| * | |||
| */ | |||
| WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId); | |||
| /** | |||
| * 创建卡花费 | |||
| * @param record | |||
| @@ -15,7 +17,7 @@ public interface WxCardSpendService { | |||
| * @param user | |||
| * @return | |||
| */ | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCUser user); | |||
| ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant, WxCUser user); | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| @@ -53,35 +53,33 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||
| WxProfitSharingOrderService profitSharingOrderService; | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCUser user) { | |||
| 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()); | |||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| // 2. coupon 补贴 rate | |||
| public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) { | |||
| WxCouponMerchant couponMerchant = null; | |||
| WxCouponMerchant couponMerchantQ = new WxCouponMerchant(); | |||
| couponMerchantQ.setTenantId(record.getTenantId()); | |||
| couponMerchantQ.setTenantId(cardInfo.getTenantId()); | |||
| couponMerchantQ.setProductId(cardInfo.getCouponId()); | |||
| couponMerchantQ.setMerchantId(record.getMerchantId()); | |||
| couponMerchantQ.setMerchantId(merchantId); | |||
| couponMerchantQ.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| try { | |||
| couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ); | |||
| } catch (Exception e) { | |||
| logger.error("couponmerchant not found: " + cardInfo.getCouponId()); | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| return couponMerchant; | |||
| } | |||
| if (couponMerchant == null) { | |||
| logger.error("卡: card: " + cardInfo.getId() + " coupon-" + cardInfo.getCouponId() + "couponMerchantId-" + record.getMerchantId()); | |||
| return new ResultData(ErrorCode.COUPON_MERCHANT_NOT_FOUND); | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant, WxCUser user) { | |||
| 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()); | |||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); | |||
| } | |||
| // 2. coupon 补贴 rate | |||
| Integer subsidyRate = 0; | |||
| if(couponMerchant.getParameter() != null) { | |||
| try { | |||