diff --git a/cash-api/market-server/src/main/java/com/czg/controller/user/UCarouselController.java b/cash-api/market-server/src/main/java/com/czg/controller/user/UCarouselController.java index 6f3a65c28..ba27d78e1 100644 --- a/cash-api/market-server/src/main/java/com/czg/controller/user/UCarouselController.java +++ b/cash-api/market-server/src/main/java/com/czg/controller/user/UCarouselController.java @@ -1,15 +1,13 @@ package com.czg.controller.user; -import com.czg.annotation.SaAdminCheckPermission; import com.czg.market.dto.MkCarouselDTO; import com.czg.market.entity.MkCarousel; import com.czg.market.service.MkCarouselService; +import com.czg.market.service.MkShareBaseService; import com.czg.resp.CzgResult; import com.czg.sa.StpKit; import jakarta.annotation.Resource; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -20,19 +18,44 @@ import java.util.List; * @author ww */ @RestController -@RequestMapping("/user/carousel") +@RequestMapping("/user") public class UCarouselController { @Resource private MkCarouselService mkCarouselService; + @Resource + private MkShareBaseService mkShareBaseService; + + /** * 轮播图配置 */ - @GetMapping - @SaAdminCheckPermission(parentName = "轮播图配置", value = "carousel:config", name = "轮播图-列表") + @GetMapping("/carousel") public CzgResult> getCarousels(MkCarouselDTO carouselDTO) { carouselDTO.setShopId(StpKit.USER.getShopId()); return CzgResult.success(mkCarouselService.getCarousels(carouselDTO)); } + + /** + * 分享 领取触发 + * + * @param tagType + * @param shopId + * @param fromUserId 分享人的shopUserId + * @param toUserId 被分享人的shopUserId + */ + public record ShareClaim(String tagType, Long shopId, Long fromUserId, Long toUserId) { + } + + + /** + * 分享 领取触发 + * 会绑定上下级关系 + */ + @PostMapping("/shareClaim") + public CzgResult shareClaim(@RequestBody ShareClaim shareClaim) { + mkShareBaseService.shareClaim(shareClaim.tagType, shareClaim.shopId, shareClaim.fromUserId, shareClaim.toUserId); + return CzgResult.success(); + } } \ No newline at end of file diff --git a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java index 7d5b1c4c7..5c9d09df4 100644 --- a/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java +++ b/cash-api/market-server/src/main/java/com/czg/controller/user/UDistributionController.java @@ -19,7 +19,6 @@ import com.mybatisflex.core.paginate.Page; import io.seata.core.exception.TransactionException; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import org.springframework.core.NestedExceptionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -107,19 +106,6 @@ public class UDistributionController { return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId)); } - /** - * 分销员中心-获取邀请码 - */ - @GetMapping("/autoGetInviteCode") - public CzgResult autoGetInviteCode(@RequestParam Long shopId, @RequestParam Long shopUserId) { - try { - return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId)); - } catch (Exception e) { - String rootMsg = NestedExceptionUtils.getMostSpecificCause(e).getMessage(); - log.error("获取邀请码失败用户:{},:{}", shopUserId, rootMsg); - return CzgResult.success(""); - } - } /** * 分销员中心-实名认证 @@ -133,20 +119,6 @@ public class UDistributionController { return CzgResult.success(); } - /** - * 分销员中心-无感-绑定邀请人 - */ - @PostMapping("/autoBindInviteUser") - public CzgResult> autoBindInviteUser(@RequestBody MkDistributionUserDTO param) throws TransactionException { - try { - bindInviteUser(param); - } catch (Exception e) { - log.error("无感绑定邀请人失败:{}", param, e); - } - return CzgResult.success(); - } - - /** * 分销员中心-绑定邀请人 */ diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java index 6afc074f5..908fe49ec 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionUserService.java @@ -60,9 +60,18 @@ public interface MkDistributionUserService extends IService /** * 分销员中心-绑定邀请人 + * 通过邀请码 */ void bindInviteUser(MkDistributionUserDTO param) throws CzgException, ValidateException; + + /** + * 分销员中心-绑定邀请人 + * 通过邀请人id + * @param fromUserId shopUserId 邀请人 + * @param toUserId 被邀请人邀请人 + */ + void bindInviteUser(Long fromUserId, Long toUserId, Long shopId) throws CzgException, ValidateException; /** * 获取分销员分页列表 */ diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkShareBaseService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkShareBaseService.java index 36d0b8636..f214c51b0 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkShareBaseService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkShareBaseService.java @@ -12,4 +12,6 @@ import com.czg.market.entity.MkShareBase; public interface MkShareBaseService extends IService { MkShareBase getShareBase(Long shopId); + + void shareClaim(String tagType, Long shopId, Long fromUserId, Long toUserId); } diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java index 098617e46..7dfaef760 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java @@ -311,6 +311,92 @@ public class MkDistributionUserServiceImpl extends ServiceImpl= mkDistributionConfig.getInviteCount()) { + ShopUser parentShopUser1 = new ShopUser(); + parentShopUser1.setId(parentShopUser.getId()); + parentShopUser1.upDistributionShop(shopId, 1); + shopUserService.updateById(parentShopUser1); + } + } + if (mkDistributionConfig != null && !"not_upgrade".equals(mkDistributionConfig.getUpgradeType()) && parent.getIsAssignLevel() == 0) { + if ("invite".equals(mkDistributionConfig.getUpgradeType())) { + if (mkDistributionConfig.getInviteConsume() == 1) { + long count = orderInfoService.count(QueryWrapper.create() + .eq(OrderInfo::getUserId, shopUser.getUserId()) + .eq(OrderInfo::getShopId, parent.getShopId()) + .eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode())); + if (count < 1) { + throw new CzgException("绑定失败,被邀请人需要成功支付一笔订单"); + } + } + MkDistributionLevelConfig levelConfig = levelConfigService.getOne(QueryWrapper.create() + .eq(MkDistributionLevelConfig::getShopId, parent.getShopId()) + .le(MkDistributionLevelConfig::getInviteCount, newDistributionUser.getInviteCount()) + .orderBy(MkDistributionLevelConfig::getId).desc().limit(1)); + if (levelConfig != null) { + newDistributionUser.setDistributionLevelId(levelConfig.getId()); + newDistributionUser.setDistributionLevelName(levelConfig.getName()); + newDistributionUser.setStatus(1); + } + } else if ("cost".equals(mkDistributionConfig.getUpgradeType())) { + costUpgradeLevel(parent.getId(), parent.getShopId()); + } + } + update(newDistributionUser, QueryWrapper.create().eq(MkDistributionUser::getId, parent.getId()) + .eq(MkDistributionUser::getShopId, parent.getShopId())); + } + @Override public void costUpgradeLevelBefore(Long userId, Long shopId) { ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId); diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShareBaseServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShareBaseServiceImpl.java index e9230d092..f27b7f769 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShareBaseServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShareBaseServiceImpl.java @@ -1,7 +1,13 @@ package com.czg.service.market.service.impl; +import cn.hutool.core.util.StrUtil; +import com.czg.market.dto.MkShopCouponGiftDTO; import com.czg.market.dto.ShopCouponDTO; +import com.czg.market.entity.MkShopCouponRecord; +import com.czg.market.service.MkDistributionUserService; +import com.czg.market.service.MkShopCouponRecordService; import com.czg.market.service.ShopCouponService; +import com.czg.utils.FunUtils; import com.mybatisflex.spring.service.impl.ServiceImpl; import com.czg.market.entity.MkShareBase; import com.czg.market.service.MkShareBaseService; @@ -20,6 +26,10 @@ public class MkShareBaseServiceImpl extends ServiceImpl distributionUserService.bindInviteUser(fromUserId, toUserId, shopId)); + } + MkShareBase shareBase = getById(shopId); + if (shareBase == null || shareBase.getIsEnabled().equals(1) || StrUtil.isBlank(shareBase.getRewardSharePages())) { + return; + } + if (!shareBase.getRewardSharePages().contains(tagType)) { + return; + } + FunUtils.safeRun(() -> { + //发放分享人优惠券 + if (shareBase.getSharerCouponId() != null) { + boolean grant = true; + if (shareBase.getRewardTimesType().equals(1)) { + boolean exists = mkShopCouponRecordService.exists(query() + .eq(MkShopCouponRecord::getShopId, shopId) + .eq(MkShopCouponRecord::getShopUserId, fromUserId) + .eq(MkShopCouponRecord::getSource, "邀请获得")); + grant = !exists; + } + if (grant) { + MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO(); + giftDTO.setShopId(shopId) + .setSourceId(shareBase.getShopId()) + .setSourceFlowId(toUserId) + .setShopUserId(fromUserId) + .setCouponId(shareBase.getSharerCouponId()) + .setSource("邀请获得"); + int receiveNum = 1; + if (shareBase.getSharerCouponNum() != null && shareBase.getSharerCouponNum() > 0) { + receiveNum = shareBase.getSharerCouponNum(); + } + mkShopCouponRecordService.receiveCoupon(giftDTO, receiveNum, false); + } + } + return null; + }, "邀请人获取优惠券"); + FunUtils.safeRun(() -> { + //发放被分享人优惠券 + if (shareBase.getSharedUserCouponId() != null) { + boolean exists = mkShopCouponRecordService.exists(query() + .eq(MkShopCouponRecord::getShopId, shopId) + .eq(MkShopCouponRecord::getShopUserId, toUserId) + .eq(MkShopCouponRecord::getSourceFlowId, fromUserId) + .eq(MkShopCouponRecord::getSource, "参与分享获得")); + if (!exists) { + MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO(); + giftDTO.setShopId(shopId) + .setSourceId(shareBase.getShopId()) + .setShopUserId(toUserId) + .setSourceFlowId(fromUserId) + .setCouponId(shareBase.getSharedUserCouponId()) + .setSource("参与分享获得"); + int receiveNum = 1; + if (shareBase.getSharedUserCouponNum() != null && shareBase.getSharedUserCouponNum() > 0) { + receiveNum = shareBase.getSharedUserCouponNum(); + } + mkShopCouponRecordService.receiveCoupon(giftDTO, receiveNum, false); + } + } + return null; + }, "被分享人获取优惠券"); + } }