|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -19,7 +20,7 @@ import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
import com.cyksj.dto.UserSharedDto;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ChannelPopularizeMapper;
|
|
|
-import com.cyksj.mapper.claudecode.ClaudeCodeUserPopularizeTrialTicketRecordMapper;
|
|
|
+import com.cyksj.mapper.claudecode.PopularizeTrialTicketRecordMapper;
|
|
|
import com.cyksj.mapper.claudecode.ClaudeCodeUserTrialReceiveRecordMapper;
|
|
|
import com.cyksj.mapper.corp.*;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
@@ -29,6 +30,7 @@ import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
import com.cyksj.mapper.mirrorshop.UserMirrorShopMapper;
|
|
|
+import com.cyksj.mapper.nano.NanoUserTrialReceiveRecordMapper;
|
|
|
import com.cyksj.mapper.station.CollegeStudentStationUserRelateMapper;
|
|
|
import com.cyksj.mapper.vip.VipUserMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
@@ -150,12 +152,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
private final ClaudeCodeService claudeCodeService;
|
|
|
|
|
|
- private final ClaudeCodeUserPopularizeTrialTicketRecordMapper claudeCodeUserPopularizeTrialTicketRecordMapper;
|
|
|
+ private final PopularizeTrialTicketRecordMapper popularizeTrialTicketRecordMapper;
|
|
|
|
|
|
private final CouponRecommendMapper couponRecommendMapper;
|
|
|
|
|
|
private final ClaudeCodeUserTrialReceiveRecordMapper claudeCodeUserTrialReceiveRecordMapper;
|
|
|
|
|
|
+ private final NanoUserTrialReceiveRecordMapper nanoUserTrialReceiveRecordMapper;
|
|
|
+
|
|
|
+ private final NanoUserQuotaMapper nanoUserQuotaMapper;
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
@Override
|
|
|
@@ -167,6 +173,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
String callback = re.getCk();
|
|
|
String callbackType = re.getCt();
|
|
|
String customId = re.getCd();
|
|
|
+ Boolean isNano = re.getIsNano();
|
|
|
|
|
|
final String unionid = info.getUnionid();
|
|
|
if (StrUtil.isEmpty(unionid)) {
|
|
|
@@ -248,8 +255,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
if (sharedId != null && dsType != null && dsType == 2) {
|
|
|
equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
|
|
|
}
|
|
|
- //查找渠道是否有设置了对应的claude code优惠码
|
|
|
- setClaudeCodePopularize(sharedId, dsPopularizeId, user);
|
|
|
+ //处理特殊推广
|
|
|
+ handlerSpecialPopularize(sharedId, dsPopularizeId, user, isNewUser, isNano);
|
|
|
//每日活跃记录
|
|
|
userLoginRecordService.saveUserLoginDayRecord(user.getId());
|
|
|
//是否是大学生快递站进来的用户
|
|
|
@@ -262,8 +269,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param popularizeGoodsId 独立站推广商品id
|
|
|
+ */
|
|
|
@Override
|
|
|
- public UserWhoami whoami(long userId, Boolean ccCode) {
|
|
|
+ public UserWhoami whoami(long userId, Long popularizeGoodsId) {
|
|
|
User user = this.getById(userId);
|
|
|
Assert.notNull(user, "业务处理失败,请联系客服");
|
|
|
UserWhoami userWhoami = new UserWhoami();
|
|
|
@@ -316,21 +327,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
.in(OrderDon::getUserId, userIdList)
|
|
|
.notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
userWhoami.setIsPay(selectCount > 0);
|
|
|
- if (ccCode != null) {
|
|
|
- Number number = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getSkuId, Constant.DISTRIBUTE_CLAUDE_CODE_TRIAL_SKU_ID).field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID).build());
|
|
|
- userWhoami.setCcCode(number.intValue() > 0);
|
|
|
- Integer selectCount1 = claudeCodeUserPopularizeTrialTicketRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUserPopularizeTrialTicketRecord.class).in(ClaudeCodeUserPopularizeTrialTicketRecord::getUserId, userIdList));
|
|
|
- if (selectCount1 == 0) {
|
|
|
- ClaudeCodeUserPopularizeTrialTicketRecord record = new ClaudeCodeUserPopularizeTrialTicketRecord();
|
|
|
- record.setUserId(userId);
|
|
|
- claudeCodeUserPopularizeTrialTicketRecordMapper.insert(record);
|
|
|
- }
|
|
|
- userWhoami.setTc(selectCount1 == 0);
|
|
|
+ //推广信息
|
|
|
+ if (popularizeGoodsId != null) {
|
|
|
+ setPopularizeUserInfo(popularizeGoodsId, userIdList, userId, userWhoami);
|
|
|
}
|
|
|
return userWhoami;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public User getSyncUser(String openId, String unionId, WxSyncLog wxSyncLog) {
|
|
|
User user;
|
|
|
//迁移公众号之后同步授权后信息
|
|
|
@@ -603,7 +607,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
|
|
|
}
|
|
|
//查找渠道是否有设置了对应的claude code优惠码
|
|
|
- setClaudeCodePopularize(sharedId, dsPopularizeId, user);
|
|
|
+ handlerSpecialPopularize(sharedId, dsPopularizeId, user, isNewUser, loginReq.getIsNano());
|
|
|
|
|
|
//每日活跃记录
|
|
|
userLoginRecordService.saveUserLoginDayRecord(user.getId());
|
|
|
@@ -947,7 +951,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
/**
|
|
|
* 查找渠道是否有设置了对应的claude code优惠码
|
|
|
*/
|
|
|
- public void setClaudeCodePopularize(Long sharedId, Long dsPopularizeId, User user) {
|
|
|
+ public void handlerSpecialPopularize(Long sharedId, Long dsPopularizeId, User user, Boolean isNewUser, Boolean isNano) {
|
|
|
+ if (!isNewUser) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String email = user.getEmail();
|
|
|
+ if (StrUtil.isNotBlank(email)) {
|
|
|
+ Long count = email.chars().filter(c -> c == '.').count();
|
|
|
+ //邮箱超过3个'.'字符用户过滤
|
|
|
+ if (count > 3) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
//查找渠道是否有设置了对应的claude code优惠码
|
|
|
if (sharedId != null) {
|
|
|
UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, sharedId).eq(UserDistribute::getDeleted, Boolean.TRUE).last("limit 1"));
|
|
|
@@ -960,36 +975,61 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return;
|
|
|
}
|
|
|
//是否是cc推广
|
|
|
- if (StrUtil.isEmpty(userDistributePopularize.getOtherUrl()) || !"cc".equals(userDistributePopularize.getOtherUrl())) {
|
|
|
- return;
|
|
|
- }
|
|
|
- Integer selectCount = couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class).eq(CouponDistributePopularize::getDistributeId, userDistribute.getId()).eq(CouponDistributePopularize::getDeleted, Boolean.TRUE).eq(CouponDistributePopularize::getCouponId, Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID));
|
|
|
- //是否设置claude cod优惠券
|
|
|
- if (selectCount > 0) {
|
|
|
- //设置了 直接发送优惠券
|
|
|
- couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
|
|
|
- if (redisService.setNx(RedisService.key.CLAUDE_CODE_TY_DAY_CARD_KEY.getName() + user.getId(), user.getId(), RedisService.key.CLAUDE_CODE_TY_DAY_CARD_KEY.getTimeout())) {
|
|
|
- //存在Claude code车票不发送体验卡
|
|
|
- if (!claudeCodeService.checkClaudeCodeUser(user.getId())) {
|
|
|
- Integer receiveRecord = claudeCodeUserTrialReceiveRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUserTrialReceiveRecord.class).eq(ClaudeCodeUserTrialReceiveRecord::getUserId, user.getId()));
|
|
|
- if (receiveRecord > 0) {
|
|
|
- return;
|
|
|
+ if (Constant.CC_DISTRIBUTE_MARK.equals(userDistributePopularize.getOtherUrl())) {
|
|
|
+ Integer selectCount = couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class).eq(CouponDistributePopularize::getDistributeId, userDistribute.getId()).eq(CouponDistributePopularize::getDeleted, Boolean.TRUE).eq(CouponDistributePopularize::getCouponId, Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID));
|
|
|
+ //是否设置claude cod优惠券
|
|
|
+ if (selectCount > 0) {
|
|
|
+ //设置了 直接发送优惠券
|
|
|
+ Boolean b = couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
|
|
|
+ if (!b) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (redisService.setNx(RedisService.key.CLAUDE_CODE_TY_DAY_CARD_KEY.getName() + user.getId(), user.getId(), RedisService.key.CLAUDE_CODE_TY_DAY_CARD_KEY.getTimeout())) {
|
|
|
+ //存在Claude code车票不发送体验卡
|
|
|
+ if (!claudeCodeService.checkClaudeCodeUser(user.getId())) {
|
|
|
+ Integer receiveRecord = claudeCodeUserTrialReceiveRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUserTrialReceiveRecord.class).eq(ClaudeCodeUserTrialReceiveRecord::getUserId, user.getId()));
|
|
|
+ if (receiveRecord > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //发送claude code 体验卡
|
|
|
+ Long relationId = groupRelationFrontService.getTrialTicketByUserIdAndGoodsId(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_TRIAL_SKU_ID, 1);
|
|
|
+ recordReceiveClaudeCodeRecord(user.getId(), relationId);
|
|
|
}
|
|
|
- //发送claude code 体验卡
|
|
|
- Long relationId = groupRelationFrontService.getTrialTicketByUserIdAndGoodsId(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_TRIAL_SKU_ID, 1);
|
|
|
- recordReceiveClaudeCodeRecord(user.getId(), relationId);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //该优惠券是否处于推荐中
|
|
|
+ int isTj = couponRecommendMapper.checkPresentRecommendByCouponId(Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID);
|
|
|
+ if (isTj != 0) {
|
|
|
+ //发送无优惠码的 优惠券
|
|
|
+ couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- //该优惠券是否处于推荐中
|
|
|
- int isTj = couponRecommendMapper.checkPresentRecommendByCouponId(Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID);
|
|
|
- if (isTj != 0) {
|
|
|
- //发送无优惠码的 优惠券
|
|
|
- couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否是nano 推广
|
|
|
+ if (Constant.NANO_DISTRIBUTE_MARK.equals(userDistributePopularize.getOtherUrl())) {
|
|
|
+ Integer selectCount = couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class).eq(CouponDistributePopularize::getDistributeId, userDistribute.getId()).eq(CouponDistributePopularize::getDeleted, Boolean.TRUE).eq(CouponDistributePopularize::getCouponId, Constant.DISTRIBUTE_NANO_COUPON_ID));
|
|
|
+ if (selectCount > 0) {
|
|
|
+ //设置了 直接发送优惠券
|
|
|
+ couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_NANO_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //新用户都发
|
|
|
+ if (isNano != null && isNano) {
|
|
|
+ if (redisService.setNx(RedisService.key.NANO_TY_DAY_CARD_KEY.getName() + user.getId(), user.getId(), RedisService.key.NANO_TY_DAY_CARD_KEY.getTimeout())) {
|
|
|
+ Integer receiveRecord = nanoUserTrialReceiveRecordMapper.selectCount(Wrappers.lambdaQuery(NanoUserTrialReceiveRecord.class).eq(NanoUserTrialReceiveRecord::getUserId, user.getId()));
|
|
|
+ if (receiveRecord > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //发送nano 体验卡
|
|
|
+ Long relationId = groupRelationFrontService.getTrialTicketByUserIdAndGoodsId(user.getId(), Constant.DISTRIBUTE_NANO_TRIAL_SKU_ID, 2);
|
|
|
+ recordReceiveNanoRecord(user.getId(), relationId);
|
|
|
+ //创建nano user
|
|
|
+ createNanoUser(user.getId(), relationId, goodsDonSkuMapper.selectById(Constant.DISTRIBUTE_NANO_TRIAL_SKU_ID));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void recordReceiveClaudeCodeRecord(Long userId,Long relationId) {
|
|
|
@@ -1000,4 +1040,60 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
claudeCodeUserTrialReceiveRecordMapper.insert(record);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void recordReceiveNanoRecord(Long userId, Long relationId) {
|
|
|
+ if (relationId != null) {
|
|
|
+ NanoUserTrialReceiveRecord record = new NanoUserTrialReceiveRecord();
|
|
|
+ record.setUserId(userId);
|
|
|
+ record.setRelationId(relationId);
|
|
|
+ nanoUserTrialReceiveRecordMapper.insert(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 独立站渠道推广弹窗
|
|
|
+ */
|
|
|
+ private void setPopularizeUserInfo(Long popularizeGoodsId, List<Long> userIdList, Long userId, UserWhoami userWhoami) {
|
|
|
+ Long trialSkuId = null;
|
|
|
+ if (popularizeGoodsId == Constant.CLAUDE_CODE_GOODS_ID) {
|
|
|
+ trialSkuId = Constant.DISTRIBUTE_CLAUDE_CODE_TRIAL_SKU_ID;
|
|
|
+ }
|
|
|
+ if (popularizeGoodsId == Constant.NANO_GOODS_ID) {
|
|
|
+ trialSkuId = Constant.DISTRIBUTE_NANO_TRIAL_SKU_ID;
|
|
|
+ }
|
|
|
+ if (trialSkuId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Number number = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getUserId, userIdList).op(Operator.InList).field(GroupsRelationView::getSkuId, trialSkuId).field(GroupsRelationView::getGoodsId, popularizeGoodsId).build());
|
|
|
+ userWhoami.setCcCode(number.intValue() > 0);
|
|
|
+ Integer selectCount1 = popularizeTrialTicketRecordMapper.selectCount(Wrappers.lambdaQuery(PopularizeTrialTicketRecord.class).eq(PopularizeTrialTicketRecord::getGoodsId, popularizeGoodsId).in(PopularizeTrialTicketRecord::getUserId, userIdList));
|
|
|
+ if (selectCount1 == 0) {
|
|
|
+ PopularizeTrialTicketRecord record = new PopularizeTrialTicketRecord();
|
|
|
+ record.setGoodsId(popularizeGoodsId);
|
|
|
+ record.setUserId(userId);
|
|
|
+ popularizeTrialTicketRecordMapper.insert(record);
|
|
|
+ }
|
|
|
+ userWhoami.setTc(selectCount1 == 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createNanoUser(Long userId, Long relationId, GoodsDonSku sku) {
|
|
|
+ try {
|
|
|
+ if (relationId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ NanoUserQuota nanoUserQuota = new NanoUserQuota();
|
|
|
+ nanoUserQuota.setUid(userId);
|
|
|
+ nanoUserQuota.setRelationId(relationId);
|
|
|
+ nanoUserQuota.setUserToken(UUID.randomUUID().toString());
|
|
|
+ nanoUserQuota.setNickname(user.getNickname());
|
|
|
+ nanoUserQuota.setAvatar(user.getHeadimgurl());
|
|
|
+ nanoUserQuota.setPurchaseDate(DateTime.now());
|
|
|
+ nanoUserQuota.setTotalQuota(sku.getNanoQuota());
|
|
|
+ nanoUserQuota.setRemainingQuota(nanoUserQuota.getTotalQuota());
|
|
|
+ nanoUserQuotaMapper.insert(nanoUserQuota);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|