|
@@ -1,30 +1,33 @@
|
|
|
package com.qs.mp.channel.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.qs.mp.admin.domain.Coupon;
|
|
|
import com.qs.mp.admin.service.ICouponService;
|
|
|
import com.qs.mp.channel.domain.ChannelCouponVerifyLog;
|
|
|
+import com.qs.mp.channel.domain.ChannelGoods;
|
|
|
import com.qs.mp.channel.domain.ChannelMoneyLog;
|
|
|
import com.qs.mp.channel.mapper.ChannelCouponVerifyLogMapper;
|
|
|
import com.qs.mp.channel.service.IChannelCouponVerifyLogService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qs.mp.channel.service.IChannelGoodsService;
|
|
|
import com.qs.mp.channel.service.IChannelMoneyLogService;
|
|
|
-import com.qs.mp.common.enums.ChannelMoneyEnum;
|
|
|
-import com.qs.mp.common.enums.CouponDiscountTypeEnum;
|
|
|
-import com.qs.mp.common.enums.CouponSettleStatusEnum;
|
|
|
-import com.qs.mp.common.enums.CouponStatusEnum;
|
|
|
-import com.qs.mp.common.enums.UserCouponStatusEnum;
|
|
|
+import com.qs.mp.common.enums.*;
|
|
|
+import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.LogUtil;
|
|
|
import com.qs.mp.user.domain.UserCoupon;
|
|
|
import com.qs.mp.user.service.IUserCouponService;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -48,6 +51,9 @@ public class ChannelCouponVerifyLogServiceImpl extends ServiceImpl<ChannelCoupon
|
|
|
@Autowired
|
|
|
private IChannelMoneyLogService channelMoneyLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IChannelGoodsService channelGoodsService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void verify(Long channelId, UserCoupon userCoupon) {
|
|
@@ -92,7 +98,27 @@ public class ChannelCouponVerifyLogServiceImpl extends ServiceImpl<ChannelCoupon
|
|
|
channelMoneyLogService.changeMoney(moneyLog);
|
|
|
}
|
|
|
} else if (CouponDiscountTypeEnum.EXCHANGE == coupon.getDiscountType()) {
|
|
|
-
|
|
|
+ LambdaQueryWrapper<ChannelGoods> queryWrapper = new LambdaQueryWrapper<ChannelGoods>()
|
|
|
+ .eq(ChannelGoods::getChannelId, channelId)
|
|
|
+ .eq(ChannelGoods::getRefId, coupon.getCouponId())
|
|
|
+ .eq(ChannelGoods::getStatus, ChannelGoodsSettleStatusTypeEnum.NO)
|
|
|
+ .ge(ChannelGoods::getRemainQty, 0)
|
|
|
+ .orderByAsc(ChannelGoods::getCreatedTime);
|
|
|
+ List<ChannelGoods> channelGoodsList = channelGoodsService.list(queryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(channelGoodsList)) {
|
|
|
+ LogUtil.error(logger, "门店下未进货绑定该优惠劵的商品,channelId:{0}, couponId:{1}", channelId, coupon.getCouponId());
|
|
|
+ throw new ServiceException("门店下未进货绑定该优惠劵的商品");
|
|
|
+ }
|
|
|
+ ChannelGoods channelGoods = channelGoodsList.get(0);
|
|
|
+ if (channelGoods.getRemainQty() == 0) {
|
|
|
+ LogUtil.error(logger, "商品库存不足,无法核销,channelId:{0}, channel_goods_id:{1}", channelId, channelGoods.getId());
|
|
|
+ throw new ServiceException("门店商品库存不足,无法核销,请前往采购商品");
|
|
|
+ }
|
|
|
+ boolean rst = channelGoodsService.update(new LambdaUpdateWrapper<ChannelGoods>()
|
|
|
+ .set(ChannelGoods::getRemainQty, channelGoods.getRemainQty() - 1)
|
|
|
+ .set(ChannelGoods::getVerifyQty, channelGoods.getVerifyQty() + 1)
|
|
|
+ .eq(ChannelGoods::getId, channelGoods.getId()));
|
|
|
+ Assert.isTrue(rst,"更新门店下铺设商品失败,channel_goods_id:" + channelGoods.getId());
|
|
|
} else {
|
|
|
LogUtil.warn(logger, "优惠券核销结算,类型非代金券,忽略。userCouponId:{0}", userCoupon.getId());
|
|
|
}
|