Browse Source

[储值卡][修改]:卡花费

release_toaliyun_real
Stormeye Wu 7 years ago
parent
commit
85b5984f71
4 changed files with 46 additions and 25 deletions
  1. +21
    -3
      mallinkCApi/src/main/java/com/iformall/controller/WxCardPayController.java
  2. +3
    -0
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  3. +6
    -4
      mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java
  4. +16
    -18
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java

+ 21
- 3
mallinkCApi/src/main/java/com/iformall/controller/WxCardPayController.java View File

@@ -36,6 +36,9 @@ public class WxCardPayController extends BaseController {
@Autowired @Autowired
WxOrderService wxOrderService; WxOrderService wxOrderService;


@Autowired
WxCardInfoService wxCardInfoService;

@Autowired @Autowired
WxCardSpendService wxCardSpendService; WxCardSpendService wxCardSpendService;


@@ -76,13 +79,28 @@ public class WxCardPayController extends BaseController {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantCode转换失败"); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantCode转换失败");
} }


// TODO check if merchantId is in card support merchant

BigDecimal totalFee = new BigDecimal(totalFeeStr); BigDecimal totalFee = new BigDecimal(totalFeeStr);
totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入)


Integer payment = totalFee.multiply(new BigDecimal(100)).intValue(); 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(); WxCUser user = getUser();


WxMerchant merchant = wxMerchantService.getById(merchantId); WxMerchant merchant = wxMerchantService.getById(merchantId);
@@ -108,7 +126,7 @@ public class WxCardPayController extends BaseController {
record.setDeductionAmount(payment); record.setDeductionAmount(payment);


try { try {
return wxCardSpendService.createCardSpend(record, order, user);
return wxCardSpendService.createCardSpend(record, order, couponMerchant, user);
} catch (MallinkException e) { } catch (MallinkException e) {
logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage());
return new ResultData(e.getErrorCode(), e.getMessage()); return new ResultData(e.getErrorCode(), e.getMessage());


+ 3
- 0
mallinkService/src/main/java/com/iformall/common/ErrorCode.java View File

@@ -143,11 +143,14 @@ public enum ErrorCode{
COUPON_ORDER_IS_OVER_TIME(4002, "卡券已过期"), COUPON_ORDER_IS_OVER_TIME(4002, "卡券已过期"),
COUPON_ORDER_IS_INVALID(4003, "卡券已经作废"), COUPON_ORDER_IS_INVALID(4003, "卡券已经作废"),
COUPON_ORDER_BUSER_IS_NULL(4004, "卡券B端用户不存在"), COUPON_ORDER_BUSER_IS_NULL(4004, "卡券B端用户不存在"),
COUPON_ORDER_MERANT_IS_NULL(4005, "卡券商户不存在"),


/** /**
* 卡 * 卡
*/ */
CARD_IS_NOT_FOUND(9001, "优惠卡不存在"), CARD_IS_NOT_FOUND(9001, "优惠卡不存在"),
CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH(9002, "优惠卡余额不足"),





/** /**


+ 6
- 4
mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java View File

@@ -2,12 +2,14 @@ package com.iformall.service;


import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.iformall.common.ResultData; 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 { public interface WxCardSpendService {


/**
*
*/
WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId);
/** /**
* 创建卡花费 * 创建卡花费
* @param record * @param record
@@ -15,7 +17,7 @@ public interface WxCardSpendService {
* @param user * @param user
* @return * @return
*/ */
ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCUser user);
ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant, WxCUser user);


/** /**
* 根据实体查询分页列表 * 根据实体查询分页列表


+ 16
- 18
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java View File

@@ -53,35 +53,33 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
WxProfitSharingOrderService profitSharingOrderService; WxProfitSharingOrderService profitSharingOrderService;


@Override @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 couponMerchant = null;
WxCouponMerchant couponMerchantQ = new WxCouponMerchant(); WxCouponMerchant couponMerchantQ = new WxCouponMerchant();
couponMerchantQ.setTenantId(record.getTenantId());
couponMerchantQ.setTenantId(cardInfo.getTenantId());
couponMerchantQ.setProductId(cardInfo.getCouponId()); couponMerchantQ.setProductId(cardInfo.getCouponId());
couponMerchantQ.setMerchantId(record.getMerchantId());
couponMerchantQ.setMerchantId(merchantId);
couponMerchantQ.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); couponMerchantQ.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
try { try {
couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ); couponMerchant = wxCouponMerchantMapper.selectOne(couponMerchantQ);
} catch (Exception e) { } catch (Exception e) {
logger.error("couponmerchant not found: " + cardInfo.getCouponId()); 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; Integer subsidyRate = 0;
if(couponMerchant.getParameter() != null) { if(couponMerchant.getParameter() != null) {
try { try {


Loading…
Cancel
Save