|
|
@@ -18,9 +18,12 @@ import com.iformall.mapper.*; |
|
|
import com.iformall.service.*; |
|
|
import com.iformall.service.*; |
|
|
import com.iformall.utils.Constant; |
|
|
import com.iformall.utils.Constant; |
|
|
import com.iformall.utils.PayUtils; |
|
|
import com.iformall.utils.PayUtils; |
|
|
|
|
|
import com.iformall.utils.RedisLock; |
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@@ -54,9 +57,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponMerchantMapper wxCouponMerchantMapper; |
|
|
WxCouponMerchantMapper wxCouponMerchantMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxAppinfoService wxAppinfoService; |
|
|
WxAppinfoService wxAppinfoService; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxPayAccountService wxPayAccountService; |
|
|
WxPayAccountService wxPayAccountService; |
|
|
|
|
|
|
|
|
@@ -66,23 +71,34 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponOrderMapper wxCouponOrderMapper; |
|
|
WxCouponOrderMapper wxCouponOrderMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxProfitSharingOrderService profitSharingOrderService; |
|
|
WxProfitSharingOrderService profitSharingOrderService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
ExcelService excelService; |
|
|
ExcelService excelService; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCreditHistoryService wxCreditHistoryService; |
|
|
WxCreditHistoryService wxCreditHistoryService; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxScoreRulesService wxScoreRulesService; |
|
|
WxScoreRulesService wxScoreRulesService; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCashOutService wxCashOutService; |
|
|
WxCashOutService wxCashOutService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
WxCouponChannelMapper wxCouponChannelMapper; |
|
|
WxCouponChannelMapper wxCouponChannelMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
|
|
|
@Autowired |
|
|
|
|
|
WxCouponService wxCouponService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
RedisLock redisLock; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) { |
|
|
public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) { |
|
|
@@ -102,7 +118,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,EnumPayWay payWay) { |
|
|
|
|
|
|
|
|
public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant,Integer reduceCouponNumber,EnumPayWay payWay) { |
|
|
Date curDate = new Date(); |
|
|
Date curDate = new Date(); |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
// 1. get card info |
|
|
// 1. get card info |
|
|
@@ -132,6 +148,15 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { |
|
|
if(payAccount == null){ |
|
|
if(payAccount == null){ |
|
|
return new ResultData(ErrorCode.API_KEY_NOT_FOUND); |
|
|
return new ResultData(ErrorCode.API_KEY_NOT_FOUND); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//扣减库存 |
|
|
|
|
|
if (null != reduceCouponNumber && reduceCouponNumber > 0) { |
|
|
|
|
|
wxCouponService.reduceRemainInventory(coupon,coupon.getId(),reduceCouponNumber); |
|
|
|
|
|
long stock = redisLock.decrease(EnumCacheKey.COUPON_STOCK.getMessage()+coupon.getId(), reduceCouponNumber); |
|
|
|
|
|
if (stock < 0 ) { |
|
|
|
|
|
return new ResultData(ErrorCode.API_KEY_NOT_FOUND.getCode(),"库存不足"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 4. 扣减计算 |
|
|
// 4. 扣减计算 |
|
|
Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); |
|
|
Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); |
|
|
|