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