消费赠券修改
This commit is contained in:
@@ -707,6 +707,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||
AssertUtil.isTrue(config.getIsEnable() != 1, "分销未开启");
|
||||
// 当前用户上级分销员
|
||||
ShopUser sourceShopUserInfo = shopUserService.getShopUserInfo(shopId, sourceUserId);
|
||||
if (sourceShopUserInfo == null) {
|
||||
return;
|
||||
}
|
||||
ShopUserInvite sourceInviteUser = shopUserInviteService.getOneByShopIdAndShopUserId(shopId, sourceShopUserInfo.getId());
|
||||
if (sourceInviteUser.getDistributionUserId() == null) {
|
||||
return;
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -31,6 +32,7 @@ import java.util.List;
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerCouponMapper, MkShopConsumerCoupon> implements MkShopConsumerCouponService {
|
||||
|
||||
@@ -75,30 +77,35 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
||||
}
|
||||
MkCouponGiftDTO giftCoupon = giftCoupons.getFirst();
|
||||
if (consumerCoupon.getLeftNum() == -10086 || consumerCoupon.getLeftNum() >= consumerCoupon.getGiftNum()) {
|
||||
if (consumerCoupon.getGetLimit() == -10086 || consumerCoupon.getGetLimit() <= consumerCoupon.getGiveNum()) {
|
||||
boolean canReceive = consumerCoupon.getGetLimit() == -10086;
|
||||
// 限量发放,校验用户已经发放数量
|
||||
if (consumerCoupon.getGetLimit() != -10086) {
|
||||
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()));
|
||||
log.info("用户: {}, 已经发放: {}, 限量: {}", shopUserId, count, consumerCoupon.getGetLimit());
|
||||
canReceive = consumerCoupon.getGetLimit() >= count + giftCoupon.getNum();
|
||||
}
|
||||
|
||||
if (canReceive) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user