UserServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. package com.cyksj.service.user.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.date.DateTime;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.RandomUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.cyksj.common.constant.Constant;
  12. import com.cyksj.common.exception.BusinessRuntimeException;
  13. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  14. import com.cyksj.common.util.Codec;
  15. import com.cyksj.common.util.Jsons;
  16. import com.cyksj.common.util.StringUtil;
  17. import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
  18. import com.cyksj.dto.UserSharedDto;
  19. import com.cyksj.mapper.*;
  20. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  21. import com.cyksj.mapper.claudecode.ClaudeCodeUserPopularizeTrialTicketRecordMapper;
  22. import com.cyksj.mapper.corp.*;
  23. import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
  24. import com.cyksj.mapper.manage.coupon.CouponRecommendMapper;
  25. import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
  26. import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
  27. import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
  28. import com.cyksj.mapper.market.task.UserBindDetailMapper;
  29. import com.cyksj.mapper.mirrorshop.UserMirrorShopMapper;
  30. import com.cyksj.mapper.station.CollegeStudentStationUserRelateMapper;
  31. import com.cyksj.mapper.vip.VipUserMapper;
  32. import com.cyksj.model.dto.*;
  33. import com.cyksj.model.entity.*;
  34. import com.cyksj.model.manage.views.GroupsRelationView;
  35. import com.cyksj.model.request.LoginReq;
  36. import com.cyksj.model.views.*;
  37. import com.cyksj.redis.RedisService;
  38. import com.cyksj.service.claude.ClaudeCodeService;
  39. import com.cyksj.service.distribute.DistributeService;
  40. import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
  41. import com.cyksj.service.exchange.ExchangeCodeService;
  42. import com.cyksj.service.mange.coupon.CouponCommonService;
  43. import com.cyksj.service.market.task.BindTaskService;
  44. import com.cyksj.service.relation.GroupRelationFrontService;
  45. import com.cyksj.service.shop.YhShopDistributeService;
  46. import com.cyksj.service.sys.SysConfigService;
  47. import com.cyksj.service.user.*;
  48. import com.cyksj.service.wechat.WeChatService;
  49. import com.ejlchina.searcher.BeanSearcher;
  50. import com.ejlchina.searcher.param.Operator;
  51. import com.ejlchina.searcher.util.MapUtils;
  52. import lombok.RequiredArgsConstructor;
  53. import lombok.extern.slf4j.Slf4j;
  54. import org.springframework.dao.DuplicateKeyException;
  55. import org.springframework.stereotype.Service;
  56. import org.springframework.transaction.annotation.Transactional;
  57. import org.springframework.util.Assert;
  58. import javax.servlet.http.HttpServletRequest;
  59. import java.util.ArrayList;
  60. import java.util.Date;
  61. import java.util.List;
  62. import java.util.Optional;
  63. /**
  64. * @author chan
  65. * @date 2021/10/10 下午3:27
  66. */
  67. @Slf4j
  68. @Service
  69. @RequiredArgsConstructor
  70. public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
  71. private final DistributeService distributeService;
  72. private final EquipmentDistributeService equipDistributeService;
  73. private final ChannelPopularizeMapper channelPopularizeMapper;
  74. private final CouponCommonService couponCommonService;
  75. private final RedisService redisService;
  76. private final SysConfigService sysConfigService;
  77. private final UserBindDetailMapper userBindDetailMapper;
  78. private final UserDistributePopularizeMapper distributePopularizeMapper;
  79. private final UserMapper userMapper;
  80. private final PhoneCodeMapper phoneCodeMapper;
  81. private final WeChatService weChatService;
  82. private final BindTaskService bindTaskService;
  83. private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
  84. private final GiftCardUserRecordMapper giftCardUserRecordMapper;
  85. private final ExchangeCodeService exchangeCodeService;
  86. private final GoodsDonSkuMapper goodsDonSkuMapper;
  87. private final GroupsRelationMapper groupsRelationMapper;
  88. private final BeanSearcher beanSearcher;
  89. private final UserBindRelationService userBindRelationService;
  90. private final YhShopDistributeService yhShopDistributeService;
  91. private final CorpUserMapper corpUserMapper;
  92. private final CorpUserTagMapper corpUserTagMapper;
  93. private final CorpFollowActiveCodeMapper corpFollowActiveCodeMapper;
  94. private final CorpCustomerAcquisitionLinkMapper corpCustomerAcquisitionLinkMapper;
  95. private final CorpWelcomeTemplateMapper corpWelcomeTemplateMapper;
  96. private final UserLoginRecordService userLoginRecordService;
  97. private final UserDistributeSharedMapper userDistributeSharedMapper;
  98. private final BadIntentionOpService badIntentionOpService;
  99. private final CollegeStudentStationUserRelateMapper collegeStudentStationUserRelateMapper;
  100. private final GroupRelationFrontService groupRelationFrontService;
  101. private final UserMirrorShopMapper userMirrorShopMapper;
  102. private final UserCertRecordMapper userCertRecordMapper;
  103. private final UserStudentCertRecordMapper userStudentCertRecordMapper;
  104. private final OrderDonMapper orderDonMapper;
  105. private final UserCommonService userCommonService;
  106. private final VipUserMapper vipUserMapper;
  107. private final CouponDistributePopularizeMapper couponDistributePopularizeMapper;
  108. private final UserDistributeMapper userDistributeMapper;
  109. private final ClaudeCodeService claudeCodeService;
  110. private final ClaudeCodeUserPopularizeTrialTicketRecordMapper claudeCodeUserPopularizeTrialTicketRecordMapper;
  111. private final CouponRecommendMapper couponRecommendMapper;
  112. private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
  113. @Override
  114. public User saveAuth(GzhOAuth2UserInfo info, AuthRedirect re, User.RegisterEnv registerEnv) throws Exception {
  115. Long sharedId = re.getSharedId();
  116. Integer dsType = re.getDsType();
  117. Long pid = re.getPid();
  118. String dsCode = re.getDsCode();
  119. String callback = re.getCk();
  120. String callbackType = re.getCt();
  121. String customId = re.getCd();
  122. final String unionid = info.getUnionid();
  123. if (StrUtil.isEmpty(unionid)) {
  124. throw BusinessRuntimeException.getInstance("授权操作异常,请刷新页面");
  125. }
  126. User user = getSyncUser(info.getOpenid(), info.getUnionid(), null);
  127. user = Optional.ofNullable(user).orElseGet(() -> new User()
  128. .setUnionid(unionid));
  129. user.setCountry(info.getCountry())
  130. .setProvince(info.getProvince())
  131. .setCity(info.getCity());
  132. if (user.getSex() == null) {
  133. user.setSex(info.getSex());
  134. }
  135. if (StrUtil.isEmpty(user.getHeadimgurl())) {
  136. user.setHeadimgurl(info.getHeadimgurl());
  137. }
  138. if (StrUtil.isEmpty(user.getNickname())) {
  139. user.setNickname(info.getNickname());
  140. }
  141. user.setUnionid(unionid);
  142. user.setOpenId(info.getOpenid());
  143. Boolean isNewUser = false;
  144. if (user.getId() == null) {
  145. isNewUser = true;
  146. user.setPopularizeId(pid);
  147. user.setRegisterEnv(registerEnv.name());
  148. if (!redisService.setNx(RedisService.key.REPEAT_USER_KEY.getNameFormat(user.getUnionid()), user.getUnionid(), RedisService.key.REPEAT_USER_KEY.getTimeout())) {
  149. return this.getOne(Wrappers.lambdaQuery(User.class)
  150. .eq(User::getUnionid, unionid).last("limit 1"));
  151. }
  152. this.save(user);
  153. //缓存用户注册 回传信息
  154. if (StrUtil.isNotBlank(callback)) {
  155. OrderDonPostDataDto orderDonPostDataDto = new OrderDonPostDataDto().setCallback(callback)
  156. .setCallbackType(callbackType);
  157. redisService.set(RedisService.key.ORDER_DON_POST_DATA_USER_KEY.getName() + user.getId(), Jsons.toJson(orderDonPostDataDto));
  158. }
  159. //发放新用户福利
  160. final Long fUid = user.getId();
  161. TASK_POOL.execute(() -> {
  162. // try {
  163. // sendNewUserWelfare(fUid);
  164. // } catch (Exception e) {
  165. // }
  166. //去关联对应企业微信用户
  167. relateCorpUserAndSengWelfare(fUid, unionid);
  168. });
  169. } else {
  170. if (StrUtil.isEmpty(user.getRegisterEnv())) {
  171. user.setRegisterEnv(registerEnv.name());
  172. }
  173. this.updateById(user);
  174. }
  175. Long dsPopularizeId = null;
  176. if (StrUtil.isNotBlank(dsCode)) {
  177. UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
  178. sharedId = userSharedDto.getSharedId();
  179. dsPopularizeId = userSharedDto.getDsPopularizeId();
  180. }
  181. if (sharedId != null && isNewUser) {
  182. if (dsType == null || dsType == 1) {
  183. distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
  184. }
  185. }
  186. //店铺注册用户 关联
  187. if (isNewUser && StrUtil.isNotBlank(customId)) {
  188. yhShopDistributeService.saveDistributionInvitation(customId, user.getId(), re.getCmt());
  189. }
  190. Long userId = user.getId();
  191. if (isNewUser && pid != null) {
  192. TASK_POOL.execute(() -> {
  193. sendFixedCustomerCoupon(pid, userId, unionid);
  194. });
  195. }
  196. //新旧用户都可实物分销
  197. if (sharedId != null && dsType != null && dsType == 2) {
  198. equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
  199. }
  200. //查找渠道是否有设置了对应的claude code优惠码
  201. setClaudeCodePopularize(sharedId, dsPopularizeId, user);
  202. //每日活跃记录
  203. userLoginRecordService.saveUserLoginDayRecord(user.getId());
  204. //是否是大学生快递站进来的用户
  205. Integer cst = re.getCst();
  206. if (cst != null) {
  207. TASK_POOL.execute(() -> {
  208. handlerCollegeStudentUser(userId, cst);
  209. });
  210. }
  211. return user;
  212. }
  213. @Override
  214. public UserWhoami whoami(long userId, Boolean ccCode) {
  215. User user = this.getById(userId);
  216. Assert.notNull(user, "业务处理失败,请联系客服");
  217. UserWhoami userWhoami = new UserWhoami();
  218. if (StrUtil.isEmpty(user.getShowId())) {
  219. user.setShowId(userCommonService.getUserShowId(userId));
  220. }
  221. BeanUtil.copyProperties(user, userWhoami);
  222. UserBindDetail bindPhone = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  223. .eq(StrUtil.isNotEmpty(user.getUnionid()), UserBindDetail::getUserId, userId)
  224. .eq(StrUtil.isNotBlank(user.getLoginPhone()), UserBindDetail::getPhoneUserId, userId)
  225. .eq(StrUtil.isNotEmpty(user.getEmail()), UserBindDetail::getEmailUserId, userId).last("limit 1"));
  226. //手机号
  227. if (bindPhone != null) {
  228. userWhoami.setBindPhone(bindPhone.getPhone());
  229. userWhoami.setBindEmail(bindPhone.getEmail());
  230. }
  231. Integer type = 3;
  232. if (StrUtil.isNotBlank(user.getLoginPhone())) {
  233. type = 1;
  234. } else if (StrUtil.isNotBlank(user.getEmail())) {
  235. type = 2;
  236. }
  237. userWhoami.setType(type);
  238. //是否加过企业微信
  239. String unionId = user.getUnionid();
  240. if (StrUtil.isEmpty(unionId)) {
  241. //获取绑定的微信用户id
  242. UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  243. .and(qr -> qr.eq(UserBindDetail::getPhoneUserId, user.getId()).or().eq(UserBindDetail::getEmailUserId, user.getId()))
  244. .last("limit 1"));
  245. if (bindDetail != null && bindDetail.getUserId() != null) {
  246. User wxUser = userMapper.selectById(bindDetail.getUserId());
  247. if (wxUser != null) {
  248. unionId = wxUser.getUnionid();
  249. }
  250. }
  251. }
  252. if (StrUtil.isNotBlank(unionId)) {
  253. CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  254. .field(CorpUserFollowView::getUnionId, unionId)
  255. .field(CorpUserFollowView::getStatus, 1).build());
  256. if (corpUserFollowView != null) {
  257. userWhoami.setIsJoinWx(true);
  258. }
  259. }
  260. //是否下过单
  261. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, user);
  262. Integer selectCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  263. .in(OrderDon::getUserId, userIdList)
  264. .notIn(OrderDon::getStatus, Constant.noOrderStatus));
  265. userWhoami.setIsPay(selectCount > 0);
  266. if (ccCode != null) {
  267. 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());
  268. userWhoami.setCcCode(number.intValue() > 0);
  269. Integer selectCount1 = claudeCodeUserPopularizeTrialTicketRecordMapper.selectCount(Wrappers.lambdaQuery(ClaudeCodeUserPopularizeTrialTicketRecord.class).in(ClaudeCodeUserPopularizeTrialTicketRecord::getUserId, userIdList));
  270. if (selectCount1 == 0) {
  271. ClaudeCodeUserPopularizeTrialTicketRecord record = new ClaudeCodeUserPopularizeTrialTicketRecord();
  272. record.setUserId(userId);
  273. claudeCodeUserPopularizeTrialTicketRecordMapper.insert(record);
  274. }
  275. userWhoami.setTc(selectCount1 == 0);
  276. }
  277. return userWhoami;
  278. }
  279. @Override
  280. public User getSyncUser(String openId, String unionId, WxSyncLog wxSyncLog) {
  281. User user;
  282. //迁移公众号之后同步授权后信息
  283. //是否是迁移用户
  284. if (wxSyncLog != null) {
  285. user = this.getOne(Wrappers.lambdaQuery(User.class)
  286. .ne(User::getUnionid, unionId)
  287. .eq(User::getOpenId, wxSyncLog.getOriOpenid()).last("limit 1"));
  288. if (user != null) {
  289. user.setOpenId(wxSyncLog.getNewOpenid());
  290. } else {
  291. // 查询用户是否存在
  292. user = Optional.ofNullable(
  293. this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid, unionId)
  294. .orderByAsc(User::getId)
  295. .last("limit 1")))
  296. .orElseGet(() -> this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, openId)
  297. .orderByAsc(User::getId)
  298. .last("limit 1")));
  299. }
  300. } else {
  301. // 查询用户是否存在
  302. user = Optional.ofNullable(
  303. this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid, unionId)
  304. .orderByAsc(User::getId)
  305. .last("limit 1")))
  306. .orElseGet(() -> this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, openId)
  307. .orderByAsc(User::getId)
  308. .last("limit 1")));
  309. }
  310. return user;
  311. }
  312. @Override
  313. public void sendFixedCustomerCoupon(Long popularizeId, Long userId, String unionId) {
  314. //若是百度渠道 添加固定客服 注册后直接发放优惠券
  315. ChannelPopularize channelPopularize = channelPopularizeMapper.selectById(popularizeId);
  316. if (channelPopularize != null && channelPopularize.getChannelId() == 34) {
  317. // SysConfig corpConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  318. // .eq(SysConfig::getSysKey, Constant.CORP_FIXED_CUSTOMER)
  319. // .last("limit 1"));
  320. // if (corpConfig != null) {
  321. // Optional.ofNullable(corpConfig.getSysValue()).ifPresent(value -> {
  322. // try {
  323. // if (StrUtil.isNotBlank(value)) {
  324. // List<String> followIds = Jsons.parseList(value, String.class);
  325. // //添加固定客服发放优惠券
  326. // CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  327. // .field(CorpUserFollowView::getUnionId, unionId)
  328. // .field(CorpUserFollowView::getFollowId, followIds).op(Operator.InList).build());
  329. // if (corpUserFollowView != null) {
  330. // Constant.FIXED_CUSTOMER_COUPON_IDS.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, 0l, 0l, 0l, CouponUser.Channel.wxCorp));
  331. // }
  332. // }
  333. // } catch (Exception e) {
  334. // }
  335. // });
  336. //
  337. // }
  338. SysConfig config = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  339. .eq(SysConfig::getSysKey, Constant.BAIDU_POPULARIZE_COUPON_IDS).last("limit 1"));
  340. if (config != null) {
  341. String sysValue = config.getSysValue();
  342. if (StrUtil.isNotBlank(sysValue)) {
  343. try {
  344. List<Long> couponIds = Jsons.parseList(sysValue, Long.class);
  345. couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, 0l, 0l, popularizeId, CouponUser.Channel.manual));
  346. } catch (Exception e) {
  347. log.error("百度渠道优惠券解析错误");
  348. }
  349. }
  350. }
  351. }
  352. }
  353. @Override
  354. public List<Long> getRelationUserIdList(Long userId, User selectUser) {
  355. List<Long> userIds = new ArrayList<>();
  356. userIds.add(userId);
  357. UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  358. .eq(UserBindDetail::getUserId, userId).last("limit 1"));
  359. if (userBindDetail == null) {
  360. User user = Optional.ofNullable(selectUser).orElse(this.getById(userId));
  361. if (StrUtil.isEmpty(user.getOpenId()) && StrUtil.isNotEmpty(user.getLoginPhone())) {
  362. userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  363. .eq(UserBindDetail::getPhone, user.getLoginPhone()).last("limit 1"));
  364. if (userBindDetail != null) {
  365. userIds.add(userBindDetail.getUserId());
  366. }
  367. }
  368. } else {
  369. if (StrUtil.isNotBlank(userBindDetail.getPhone())) {
  370. User otherUser = this.getOne(Wrappers.lambdaQuery(User.class)
  371. .eq(User::getLoginPhone, userBindDetail.getPhone()).last("limit 1"));
  372. if (otherUser != null) {
  373. userIds.add(otherUser.getId());
  374. }
  375. }
  376. }
  377. return userIds;
  378. }
  379. @Override
  380. public List<Long> getUserIdsByNickname(String nickname) {
  381. return userMapper.selectListByNickname(nickname);
  382. }
  383. @Override
  384. public String getUserMirrorShopId(Long userId) {
  385. Integer update = 0;
  386. String showId = null;
  387. while (update != 1) {
  388. showId = StringUtil.randomString(5);
  389. try {
  390. update = userMirrorShopMapper.update(null, Wrappers.lambdaUpdate(UserMirrorShop.class)
  391. .set(UserMirrorShop::getCustomId, showId)
  392. .eq(UserMirrorShop::getUserId, userId));
  393. } catch (DuplicateKeyException e) {
  394. update = 0;
  395. }
  396. }
  397. return showId;
  398. }
  399. @Override
  400. public Long getUserIdByShowId(String showId) {
  401. return userMapper.getUserIdByShowId(showId);
  402. }
  403. @Override
  404. public User webLogin(LoginReq loginReq, HttpServletRequest request) throws Exception {
  405. LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class).last("limit 1");
  406. if (loginReq.getType() == null || loginReq.getType() < 1 || loginReq.getType() > 3) {
  407. throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
  408. }
  409. if (loginReq.getType() == 1) {
  410. if (StrUtil.hasEmpty(loginReq.getPhone(), loginReq.getCode())) {
  411. throw BusinessRuntimeException.getInstance("请输入对应信息");
  412. }
  413. DateTime now = DateTime.now();
  414. PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, loginReq.getPhone()).last("limit 1"));
  415. if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
  416. throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
  417. }
  418. //3分钟失效
  419. Date updateTime = phoneCode.getUpdateTime();
  420. DateTime afterFiveMinutes = DateUtil.offsetMinute(updateTime, 3);
  421. if (now.isAfter(afterFiveMinutes)) {
  422. throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
  423. }
  424. if (!StrUtil.equals(loginReq.getCode(), phoneCode.getCode())) {
  425. //是否是恶意用户
  426. badIntentionOpService.isBadOpLoginPhone(request, loginReq.getPhone());
  427. throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
  428. }
  429. wrapper.eq(User::getLoginPhone, loginReq.getPhone());
  430. }
  431. if (loginReq.getType() == 2) {
  432. if (StrUtil.isEmpty(loginReq.getEmail())) {
  433. throw BusinessRuntimeException.getInstance("邮箱不能为空");
  434. }
  435. String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
  436. if (StrUtil.isEmpty(code)) {
  437. throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
  438. }
  439. if (!StrUtil.equals(loginReq.getCode(), code)) {
  440. throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
  441. }
  442. redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
  443. wrapper.eq(User::getEmail, loginReq.getEmail());
  444. }
  445. if (loginReq.getType() == 3) {
  446. wrapper.eq(User::getEmail, loginReq.getEmail());
  447. }
  448. //保存用户信息
  449. User user = this.getOne(wrapper);
  450. String dsCode = loginReq.getDsCode();
  451. Long sharedId = loginReq.getSharedId();
  452. Long dsPopularizeId = null;
  453. Integer dsType = loginReq.getDsType();
  454. String customId = loginReq.getCustomId();
  455. Boolean isNewUser = false;
  456. if (StrUtil.isNotBlank(dsCode)) {
  457. UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
  458. sharedId = userSharedDto.getSharedId();
  459. dsPopularizeId = userSharedDto.getDsPopularizeId();
  460. }
  461. if (user != null && loginReq.getType() == 3 && !user.getIsGoogle()) {
  462. user.setIsGoogle(true);
  463. this.updateById(user);
  464. }
  465. if (user == null) {
  466. user = new User();
  467. isNewUser = true;
  468. StringBuilder name = new StringBuilder();
  469. if (loginReq.getCmt() == 2) {
  470. name.append(Constant.DEFAULT_MIRROR_SHOP_USER_NAME);
  471. }else {
  472. name.append(Constant.DEFAULT_NAME);
  473. }
  474. if (loginReq.getPopularizeId() != null) {
  475. user.setPopularizeId(loginReq.getPopularizeId());
  476. }
  477. if (loginReq.getType() == 1) {
  478. user.setLoginPhone(loginReq.getPhone());
  479. }
  480. if (loginReq.getType() == 2 || loginReq.getType() == 3) {
  481. user.setEmail(loginReq.getEmail());
  482. name.append("@");
  483. }
  484. if (loginReq.getType() == 3) {
  485. user.setIsGoogle(true);
  486. }
  487. user.setNickname(String.format("%s%s", name.toString(), RandomUtil.randomString(6)));
  488. if (loginReq.getCmt() == 2) {
  489. user.setHeadimgurl(Constant.USER_MIRROR_SHOP_USER_DEFAULT_IMG);
  490. } else {
  491. //默认头像
  492. user.setHeadimgurl(Constant.DEFAULT_HEAD_IMG);
  493. }
  494. String registerEnv = loginReq.getRegisterEnv();
  495. user.setRegisterEnv(StrUtil.isEmpty(registerEnv) ? User.RegisterEnv.pc.name() : registerEnv);
  496. this.save(user);
  497. //新用户分销
  498. if (sharedId != null) {
  499. distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
  500. }
  501. //店铺注册用户 关联
  502. if (StrUtil.isNotBlank(customId)) {
  503. yhShopDistributeService.saveDistributionInvitation(customId, user.getId(), loginReq.getCmt());
  504. }
  505. //缓存用户注册 回传信息
  506. String callback = loginReq.getCallback();
  507. String callbackType = loginReq.getCallbackType();
  508. if (StrUtil.isNotBlank(callback)) {
  509. OrderDonPostDataDto orderDonPostDataDto = new OrderDonPostDataDto().setCallback(callback)
  510. .setCallbackType(callbackType);
  511. redisService.set(RedisService.key.ORDER_DON_POST_DATA_USER_KEY.getName() + user.getId(), Jsons.toJson(orderDonPostDataDto));
  512. }
  513. //发放新用户福利
  514. final Long fUid = user.getId();
  515. // TASK_POOL.execute(() -> {
  516. // try {
  517. // sendNewUserWelfare(fUid);
  518. // } catch (Exception e) {
  519. // }
  520. // });
  521. final String login_email = user.getEmail();
  522. final String login_phone = user.getLoginPhone();
  523. UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  524. .and(ub -> ub.eq(StrUtil.isNotBlank(login_email), UserBindDetail::getEmail, login_email)
  525. .or().eq(StrUtil.isNotBlank(login_phone), UserBindDetail::getPhone, login_phone))
  526. .last("limit 1"));
  527. if (bindDetail != null) {
  528. if (StrUtil.isNotBlank(login_phone)) {
  529. bindDetail.setPhoneUserId(user.getId());
  530. }
  531. if (StrUtil.isNotBlank(login_email)) {
  532. bindDetail.setEmailUserId(user.getId());
  533. }
  534. userBindDetailMapper.updateById(bindDetail);
  535. }
  536. }
  537. if (StrUtil.isEmpty(user.getShowId())) {
  538. user.setShowId(userCommonService.getUserShowId(user.getId()));
  539. }
  540. //新旧用户都可实物分销
  541. if (sharedId != null && dsType != null && dsType == 2) {
  542. equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
  543. }
  544. //查找渠道是否有设置了对应的claude code优惠码
  545. setClaudeCodePopularize(sharedId, dsPopularizeId, user);
  546. //每日活跃记录
  547. userLoginRecordService.saveUserLoginDayRecord(user.getId());
  548. return user;
  549. }
  550. @Override
  551. public String bindWxAccountRedirect(String code, String state) throws Exception {
  552. AuthToken token = weChatService.getAuthToken(code, wxOpenPlatYHLXLoginConfig.getAppId());
  553. //重定向
  554. // 根据openid 与 access_token 获取用户信息
  555. GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
  556. // 转跳参数
  557. String json = Codec.DoBase64.custom().setData(state).decodeAsText();
  558. AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
  559. //保存用户信息
  560. User user = saveAuth(userinfo, re, User.RegisterEnv.pc);
  561. if (user == null) {
  562. throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
  563. }
  564. String loginPhone = re.getLp();
  565. String loginEmail = re.getLe();
  566. if (StrUtil.isNotBlank(loginPhone)) {
  567. log.info("手机号phone:{}登录用户,微信扫描网页授权二维码进行用户信息绑定", loginPhone);
  568. try {
  569. bindTaskService.bindPhone(user, loginPhone, null);
  570. } catch (Exception e) {
  571. log.info(StringUtil.getErrorText(e));
  572. }
  573. }
  574. if (StrUtil.isNotBlank(loginEmail)) {
  575. log.info("邮箱email:{}登录用户,微信扫描网页授权二维码进行用户信息绑定", loginEmail);
  576. try {
  577. bindTaskService.bindEmail(user, loginEmail, null);
  578. } catch (Exception e) {
  579. log.info(StringUtil.getErrorText(e));
  580. }
  581. }
  582. return redisService.getStr(re.getMappingId().toString());
  583. }
  584. @Override
  585. @Transactional(rollbackFor = Throwable.class)
  586. public void receiveGiftCardByRc(Long userId, String code, Long relationId) {
  587. GiftCardUserRecord giftCardUserRecord = giftCardUserRecordMapper.selectOne(Wrappers.lambdaQuery(GiftCardUserRecord.class)
  588. .eq(GiftCardUserRecord::getRc, code).last("limit 1"));
  589. if (giftCardUserRecord == null) {
  590. throw BusinessRuntimeException.getInstance("好友赠送礼品卡不存在");
  591. }
  592. if (!giftCardUserRecord.getIsPay()) {
  593. throw BusinessRuntimeException.getInstance("无效礼品卡,好友未购买");
  594. }
  595. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  596. if (relationUserIdList.contains(giftCardUserRecord.getUserId())) {
  597. throw BusinessRuntimeException.getInstance("无法领取自己购买的礼品卡");
  598. }
  599. if (giftCardUserRecord.getToUserId() != 0 && !giftCardUserRecord.getToUserId().equals(userId)) {
  600. throw BusinessRuntimeException.getInstance("好友赠送礼品卡已被领取");
  601. }
  602. if (giftCardUserRecord.getToUserId().equals(userId)) {
  603. throw BusinessRuntimeException.getInstance("您已领取该礼品卡");
  604. }
  605. giftCardUserRecord.setToUserId(userId);
  606. int update = giftCardUserRecordMapper.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
  607. .set(giftCardUserRecord.getGcType() != 1, GiftCardUserRecord::getIsUsed, true)
  608. .set(GiftCardUserRecord::getToUserId, userId)
  609. .set(GiftCardUserRecord::getIsSend, true)
  610. .set(GiftCardUserRecord::getReceivedTime, DateTime.now())
  611. .eq(GiftCardUserRecord::getId, giftCardUserRecord.getId())
  612. .eq(GiftCardUserRecord::getIsPay, true)
  613. .eq(GiftCardUserRecord::getToUserId, 0));
  614. if (update > 0) {
  615. //虚拟卡
  616. //直接发送 对应规格车票
  617. if (giftCardUserRecord.getGcType() != 1) {
  618. Long gcSkuId = giftCardUserRecord.getGcSkuId();
  619. log.info("用户userId:{}领取礼品卡id:{},开始发放虚拟车票skuId:{}", userId, giftCardUserRecord.getId(), gcSkuId);
  620. GoodsDonSku sku = goodsDonSkuMapper.selectById(gcSkuId);
  621. if (sku == null) {
  622. log.info("礼品卡id:{}虚拟车票skuId:{}不存在", giftCardUserRecord.getId(), gcSkuId);
  623. throw BusinessRuntimeException.getInstance("该礼品卡对应的虚拟卡不存在,请联系客服");
  624. }
  625. if (relationId != null) {
  626. GroupsRelation groupsRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
  627. .in(GroupsRelation::getUserId, relationUserIdList)
  628. .eq(GroupsRelation::getId, relationId)
  629. .in(GroupsRelation::getStatus, List.of(GroupsRelation.Status.validity, GroupsRelation.Status.outside)).last("limit 1"));
  630. if (groupsRelation == null) {
  631. throw BusinessRuntimeException.getInstance("您选择的车票不存在");
  632. }
  633. Date expiryTime = groupsRelation.getExpiryTime();
  634. if (expiryTime == null) {
  635. throw BusinessRuntimeException.getInstance("请等您该类型下的车票配置账号后再增加对应时长");
  636. }
  637. if (sku.getDays() != null && sku.getDays() > 0) {
  638. expiryTime = DateUtil.offsetDay(expiryTime, sku.getDays());
  639. } else {
  640. expiryTime = DateUtil.offsetMonth(expiryTime, sku.getMonths());
  641. }
  642. log.info("userId:{}领取虚拟卡skuId:{},增加车票时长至:{}", userId, sku.getId(), expiryTime.toString());
  643. groupsRelation.setExpiryTime(expiryTime);
  644. groupsRelationMapper.updateById(groupsRelation);
  645. return;
  646. }
  647. //是否存在对应车票
  648. List<UserTicketView> ticketViews = beanSearcher.searchAll(UserTicketView.class, MapUtils.builder()
  649. .field(UserTicketView::getUserId, relationUserIdList).op(Operator.InList)
  650. .field(UserTicketView::getSkuId, giftCardUserRecord.getGcSkuId())
  651. .field(RenewalView::getStatus, List.of("validity", "outside")).op(Operator.InList)
  652. .orderBy(UserTicketView::getRelationId).asc()
  653. .build());
  654. if (CollUtil.isEmpty(ticketViews)) {
  655. GroupsRelation relationNoOrder = exchangeCodeService.getRelationNoOrder(sku, userId, null);
  656. giftCardUserRecordMapper.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
  657. .set(GiftCardUserRecord::getRelationId, relationNoOrder.getId())
  658. .eq(GiftCardUserRecord::getId, giftCardUserRecord.getId()));
  659. log.info("用户未有该规格:{}车票,发送至用户userId:{}礼品卡虚拟车票结束", gcSkuId, userId);
  660. return;
  661. }
  662. if (ticketViews.size() > 1) {
  663. throw BusinessRuntimeException.getInstance("您有多张该类型的车票,请选择一张增加时长");
  664. }
  665. UserTicketView userTicketView = ticketViews.get(0);
  666. Date expiryTime = userTicketView.getExpiryTime();
  667. if (expiryTime == null) {
  668. throw BusinessRuntimeException.getInstance("请等您该类型下的车票配置账号后再增加对应时长");
  669. }
  670. if (sku.getDays() != null && sku.getDays() > 0) {
  671. expiryTime = DateUtil.offsetDay(expiryTime, sku.getDays());
  672. } else {
  673. expiryTime = DateUtil.offsetMonth(expiryTime, sku.getMonths());
  674. }
  675. groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
  676. .set(GroupsRelation::getExpiryTime, expiryTime)
  677. .eq(GroupsRelation::getId, userTicketView.getRelationId()));
  678. }
  679. }
  680. }
  681. /**
  682. * 发放新用户福利
  683. */
  684. public void sendNewUserWelfare(Long userId) throws Exception {
  685. SysConfig newUserWelfareConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  686. .eq(SysConfig::getSysKey, Constant.NEW_USER_WELFARE_KEY).last("limit 1"));
  687. if (StrUtil.isEmpty(newUserWelfareConfig.getSysValue())) {
  688. return;
  689. }
  690. NewUserWelfareDto newUserWelfareDto = Jsons.parseObject(newUserWelfareConfig.getSysValue(), NewUserWelfareDto.class);
  691. if (newUserWelfareDto != null) {
  692. List<Long> couponIds = newUserWelfareDto.getCouponIds();
  693. couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, null, null, null, CouponUser.Channel.new_welfare));
  694. }
  695. }
  696. /**
  697. * 关联企业微信用户 并发放福利
  698. */
  699. private void relateCorpUserAndSengWelfare(Long fUid, String unionid) {
  700. CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class)
  701. .eq(CorpUser::getUnionid, unionid).last("limit 1"));
  702. Long msgId = null;
  703. CouponUser.Channel channel = null;
  704. if (corpUser != null) {
  705. corpUser.setUserId(fUid);
  706. corpUserMapper.updateById(corpUser);
  707. //活码福利
  708. if (corpUser.getAcId() != null && corpUser.getAcId() > 0) {
  709. CorpFollowActiveCode corpFollowActiveCode = corpFollowActiveCodeMapper.selectById(corpUser.getAcId());
  710. if (corpFollowActiveCode != null) {
  711. msgId = corpFollowActiveCode.getMsgId();
  712. channel = CouponUser.Channel.corp_active_code;
  713. }
  714. }
  715. if (corpUser.getCustomerAcquisitionLinkId() != null && corpUser.getCustomerAcquisitionLinkId() > 0) {
  716. CorpCustomerAcquisitionLink corpCustomerAcquisitionLink = corpCustomerAcquisitionLinkMapper.selectById(corpUser.getCustomerAcquisitionLinkId());
  717. if (corpCustomerAcquisitionLink != null) {
  718. msgId = corpCustomerAcquisitionLink.getMsgId();
  719. channel = CouponUser.Channel.customer_link;
  720. }
  721. }
  722. if (msgId != null) {
  723. CorpWelcomeTemplate corpWelcomeTemplate = corpWelcomeTemplateMapper.selectById(msgId);
  724. if (corpWelcomeTemplate != null && StrUtil.isNotBlank(corpWelcomeTemplate.getCouponIds())) {
  725. final CouponUser.Channel fChannel = channel;
  726. try {
  727. List<Long> couponIds = Jsons.parseList(corpWelcomeTemplate.getCouponIds(), Long.class);
  728. couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(fUid, couponId, 0l, 0l, 0l, fChannel));
  729. } catch (Exception e) {
  730. }
  731. }
  732. }
  733. //是否有对应获客链接的标签
  734. List<Long> tagIds = corpUserTagMapper.getTagIdByCorpUserId(corpUser.getId());
  735. if (CollUtil.isNotEmpty(tagIds)) {
  736. List<String> couponIdsStrList = corpCustomerAcquisitionLinkMapper.selectAcLinkCorpTemplateCouponIdsByTagIds(tagIds);
  737. if (CollUtil.isNotEmpty(couponIdsStrList)) {
  738. log.info("用户userId:{}存在获客链接标记的标签:{}", fUid, tagIds);
  739. couponIdsStrList.forEach(couponIdsStr -> {
  740. try {
  741. Jsons.parseList(couponIdsStr, Long.class).forEach(couponId -> couponCommonService.sendCouponToUser(fUid, couponId, 0l, 0l, 0l, CouponUser.Channel.customer_link));
  742. } catch (Exception e) {
  743. }
  744. });
  745. }
  746. }
  747. }
  748. }
  749. @Override
  750. public UserSharedDto getUserShredDtoByDsCode(String dsCode) {
  751. Long sharedId = 0l;
  752. Long dsPopularizeId = 0l;
  753. dsCode = dsCode.trim();
  754. User sharedUser = getOne(Wrappers.lambdaQuery(User.class)
  755. .eq(User::getShowId, dsCode).last("limit 1"));
  756. if (sharedUser != null) {
  757. sharedId = sharedUser.getId();
  758. } else {
  759. UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
  760. .eq(UserDistributePopularize::getCode, dsCode)
  761. .select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
  762. if (distributePopularize != null) {
  763. log.info("渠道sharedId:{}设置固定推广链接用户分销", distributePopularize.getUserId());
  764. sharedId = distributePopularize.getUserId();
  765. dsPopularizeId = distributePopularize.getId();
  766. }
  767. }
  768. UserSharedDto sharedDto = new UserSharedDto();
  769. sharedDto.setSharedId(sharedId);
  770. sharedDto.setDsPopularizeId(dsPopularizeId);
  771. return sharedDto;
  772. }
  773. @Override
  774. public Long getSharedIdByUserId(Long userId) {
  775. UserDistributeShared distributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class)
  776. .eq(UserDistributeShared::getUserId, userId)
  777. .last("limit 1")
  778. .select(UserDistributeShared::getSharedId));
  779. if (distributeShared == null) {
  780. return 0l;
  781. }
  782. return distributeShared.getSharedId();
  783. }
  784. @Override
  785. public void bindUserDistributeShared(Long userId, String dsCode) {
  786. User user = userMapper.selectById(userId);
  787. if (StrUtil.equals(user.getShowId(), dsCode)) {
  788. return;
  789. }
  790. UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
  791. Long sharedId = userSharedDto.getSharedId();
  792. Long dsPopularizeId = userSharedDto.getDsPopularizeId();
  793. //建立绑定关系
  794. log.info("建立用户userId:{}与sharedId:{}绑定关系", userId, sharedId);
  795. distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
  796. }
  797. @Override
  798. public void saveEpDistributeShared(Long userId, String dsCode) {
  799. if (StrUtil.isEmpty(dsCode)) {
  800. log.info("设备好友邀请userId:{},code为空", userId);
  801. return;
  802. }
  803. User user = getById(userId);
  804. Date createdTime = user.getCreatedTime();
  805. String createDate = new DateTime(createdTime).toDateStr();
  806. Boolean isNewUser = false;
  807. if (StrUtil.equals(createDate, DateTime.now().toDateStr())) {
  808. isNewUser = true;
  809. }
  810. UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
  811. if (userSharedDto != null) {
  812. log.info("实物好友分销邀请sharedId:{},被邀请用户id:{}", userSharedDto.getSharedId(), userId);
  813. equipDistributeService.saveDistributionInvitation(userSharedDto.getSharedId(), isNewUser, user.getId());
  814. }
  815. }
  816. @Override
  817. public UserCertInfoView getCertOverView(long userId) {
  818. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  819. UserCertRecord record = userCertRecordMapper.selectOne(Wrappers.lambdaQuery(UserCertRecord.class)
  820. .in(UserCertRecord::getUserId, userIdList)
  821. .select(UserCertRecord::getName, UserCertRecord::getIdent)
  822. .last("limit 1"));
  823. if (record != null) {
  824. record.setIdent(StringUtil.enIndent(record.getIdent()));
  825. record.setName(StringUtil.enName(record.getName()));
  826. }
  827. UserStudentCertRecord userStudentCertRecord = userStudentCertRecordMapper.selectOne(Wrappers.lambdaQuery(UserStudentCertRecord.class)
  828. .in(UserStudentCertRecord::getUserId, userIdList)
  829. .select(UserStudentCertRecord::getSchool)
  830. .last("limit 1"));
  831. UserCertInfoView userCertInfoView = new UserCertInfoView();
  832. userCertInfoView.setIndent(record);
  833. userCertInfoView.setStudentCert(userStudentCertRecord);
  834. return userCertInfoView;
  835. }
  836. @Override
  837. public UserSyncInfoView getUserSyncInfo(long userId) {
  838. UserSyncInfoView syncInfoView = new UserSyncInfoView();
  839. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  840. //是否是会员
  841. VipUser vipUser = vipUserMapper.selectOne(Wrappers.lambdaQuery(VipUser.class)
  842. .in(VipUser::getUserId, userIdList)
  843. .gt(VipUser::getExpiryTime, DateTime.now())
  844. .last("limit 1"));
  845. if (vipUser != null) {
  846. syncInfoView.setIsVip(Boolean.TRUE);
  847. syncInfoView.setVipStartTime(vipUser.getStartTime());
  848. syncInfoView.setVipExpiryTime(vipUser.getExpiryTime());
  849. }
  850. User user = userMapper.selectById(userId);
  851. syncInfoView.setGalaxyCoin(user.getGalaxyCoin());
  852. return syncInfoView;
  853. }
  854. /**
  855. * 处理大学生快递站用户
  856. */
  857. public void handlerCollegeStudentUser(Long userId, Integer cst) {
  858. try {
  859. CollegeStudentStationUserRelate cstRelate = new CollegeStudentStationUserRelate();
  860. cstRelate.setType(cst);
  861. cstRelate.setUserId(userId);
  862. collegeStudentStationUserRelateMapper.insert(cstRelate);
  863. //赠送1天的GPT镜像车票
  864. groupRelationFrontService.getCollegeStudentUserGptTicket(userId);
  865. } catch (DuplicateKeyException e) {
  866. }
  867. }
  868. /**
  869. * 查找渠道是否有设置了对应的claude code优惠码
  870. */
  871. public void setClaudeCodePopularize(Long sharedId, Long dsPopularizeId, User user) {
  872. //查找渠道是否有设置了对应的claude code优惠码
  873. if (sharedId != null) {
  874. UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, sharedId).eq(UserDistribute::getDeleted, Boolean.TRUE).last("limit 1"));
  875. if (userDistribute != null) {
  876. if (dsPopularizeId == null) {
  877. return;
  878. }
  879. UserDistributePopularize userDistributePopularize = distributePopularizeMapper.selectById(dsPopularizeId);
  880. if (userDistributePopularize == null) {
  881. return;
  882. }
  883. //是否是cc推广
  884. if (StrUtil.isEmpty(userDistributePopularize.getOtherUrl()) || !"cc".equals(userDistributePopularize.getOtherUrl())) {
  885. return;
  886. }
  887. 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));
  888. //是否设置claude cod优惠券
  889. if (selectCount > 0) {
  890. //设置了 直接发送优惠券
  891. couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
  892. 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())) {
  893. //存在Claude code车票不发送体验卡
  894. if (!claudeCodeService.checkClaudeCodeUser(user.getId())) {
  895. //发送claude code 体验卡
  896. groupRelationFrontService.getTrialTicketByUserIdAndGoodsId(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_TRIAL_SKU_ID, 1);
  897. }
  898. }
  899. } else {
  900. //该优惠券是否处于推荐中
  901. int isTj = couponRecommendMapper.checkPresentRecommendByCouponId(Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID);
  902. if (isTj != 0) {
  903. //发送无优惠码的 优惠券
  904. couponCommonService.sendCouponToUser(user.getId(), Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID, 0l, 0l, dsPopularizeId, CouponUser.Channel.manual);
  905. }
  906. }
  907. }
  908. }
  909. }
  910. }