参加消费赠券
新客立减 50%
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import com.czg.market.dto.MkCouponGiftDTO;
|
||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||
import com.czg.market.entity.MkShopConsumerCoupon;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.MkShopConsumerCouponService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.service.market.mapper.MkShopConsumerCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
@@ -17,6 +21,9 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消费赠券表 服务层实现。
|
||||
*
|
||||
@@ -28,6 +35,8 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||
|
||||
@Resource
|
||||
private MkCouponGiftService couponGiftService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService recordService;
|
||||
|
||||
@Override
|
||||
public Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
|
||||
@@ -43,6 +52,56 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void receiveConsumerCoupon(Long shopId, Long orderId, BigDecimal orderAmount, Long userId, Long shopUserId) {
|
||||
MkShopConsumerCoupon consumerCoupon = this.getOne(new QueryWrapper()
|
||||
.eq(MkShopConsumerCoupon::getShopId, shopId)
|
||||
.eq(MkShopConsumerCoupon::getStatus, 1)
|
||||
.le(MkShopConsumerCoupon::getFullAmount, orderAmount)
|
||||
.orderBy(MkShopConsumerCoupon::getFullAmount).desc()
|
||||
.orderBy(MkShopConsumerCoupon::getCreateTime).desc());
|
||||
if (consumerCoupon == null) {
|
||||
return;
|
||||
}
|
||||
//判断是否已被领取
|
||||
if (consumerCoupon.getGiveNum() != -10086 && consumerCoupon.getGiveNum() <= consumerCoupon.getGiftNum()) {
|
||||
return;
|
||||
}
|
||||
List<MkCouponGiftDTO> giftCoupons = couponGiftService.getCouponGiftBySourceId(consumerCoupon.getId(), 3);
|
||||
if (CollUtil.isEmpty(giftCoupons)) {
|
||||
return;
|
||||
}
|
||||
MkCouponGiftDTO giftCoupon = giftCoupons.getFirst();
|
||||
if (consumerCoupon.getLeftNum() != -10086 && consumerCoupon.getLeftNum() >= consumerCoupon.getGiftNum()) {
|
||||
if (consumerCoupon.getGetLimit() != -10086 && consumerCoupon.getGetLimit() <= consumerCoupon.getGiveNum()) {
|
||||
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getShopId, shopId)
|
||||
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
|
||||
.eq(MkShopCouponRecord::getSourceId, consumerCoupon.getId()));
|
||||
if (consumerCoupon.getGetLimit() >= count + giftCoupon.getNum()) {
|
||||
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO();
|
||||
giftDTO.setShopId(shopId);
|
||||
giftDTO.setShopUserId(shopUserId);
|
||||
giftDTO.setCouponId(giftCoupon.getCouponId());
|
||||
giftDTO.setSourceId(consumerCoupon.getId());
|
||||
giftDTO.setSourceFlowId(orderId);
|
||||
giftDTO.setSource("消费赠券");
|
||||
//发放券
|
||||
recordService.receiveCoupon(giftDTO, giftCoupon.getNum(), false);
|
||||
//更新优惠券信息
|
||||
consumerCoupon.setGiftNum(consumerCoupon.getGiftNum() + giftCoupon.getNum());
|
||||
if (consumerCoupon.getLeftNum() != -10086) {
|
||||
consumerCoupon.setLeftNum(consumerCoupon.getLeftNum() - giftCoupon.getNum());
|
||||
}
|
||||
updateById(new MkShopConsumerCoupon()
|
||||
.setId(consumerCoupon.getId())
|
||||
.setLeftNum(consumerCoupon.getLeftNum())
|
||||
.setGiftNum(consumerCoupon.getGiftNum()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
|
||||
AssertUtil.isNull(id, "ID不能为空");
|
||||
@@ -55,6 +114,9 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||
@Override
|
||||
@Transactional
|
||||
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
||||
if (CollUtil.isEmpty(param.getCouponGiftList())) {
|
||||
throw new ValidateException("优惠券信息不能为空");
|
||||
}
|
||||
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
||||
save(bean);
|
||||
//新增优惠券信息/数量
|
||||
|
||||
Reference in New Issue
Block a user