UserServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. package com.cyksj.service.user.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.RandomUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.exception.BusinessRuntimeException;
  12. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  13. import com.cyksj.common.util.Codec;
  14. import com.cyksj.common.util.Jsons;
  15. import com.cyksj.common.util.StringUtil;
  16. import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
  17. import com.cyksj.mapper.PhoneCodeMapper;
  18. import com.cyksj.mapper.UserMapper;
  19. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  20. import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
  21. import com.cyksj.mapper.market.task.UserBindDetailMapper;
  22. import com.cyksj.model.dto.*;
  23. import com.cyksj.model.entity.*;
  24. import com.cyksj.model.request.LoginReq;
  25. import com.cyksj.redis.RedisService;
  26. import com.cyksj.service.distribute.DistributeService;
  27. import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
  28. import com.cyksj.service.mange.coupon.CouponCommonService;
  29. import com.cyksj.service.market.task.BindTaskService;
  30. import com.cyksj.service.sys.SysConfigService;
  31. import com.cyksj.service.user.UserService;
  32. import com.cyksj.service.wechat.WeChatService;
  33. import lombok.RequiredArgsConstructor;
  34. import lombok.extern.slf4j.Slf4j;
  35. import org.springframework.dao.DuplicateKeyException;
  36. import org.springframework.stereotype.Service;
  37. import org.springframework.util.Assert;
  38. import java.util.ArrayList;
  39. import java.util.Date;
  40. import java.util.List;
  41. import java.util.Optional;
  42. /**
  43. * @author chan
  44. * @date 2021/10/10 下午3:27
  45. */
  46. @Slf4j
  47. @Service
  48. @RequiredArgsConstructor
  49. public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
  50. private final DistributeService distributeService;
  51. private final EquipmentDistributeService equipDistributeService;
  52. private final ChannelPopularizeMapper channelPopularizeMapper;
  53. private final CouponCommonService couponCommonService;
  54. private final RedisService redisService;
  55. private final SysConfigService sysConfigService;
  56. private final UserBindDetailMapper userBindDetailMapper;
  57. private final UserDistributePopularizeMapper distributePopularizeMapper;
  58. private final UserMapper userMapper;
  59. private final PhoneCodeMapper phoneCodeMapper;
  60. private final WeChatService weChatService;
  61. private final BindTaskService bindTaskService;
  62. private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
  63. private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
  64. @Override
  65. public User saveAuth(GzhOAuth2UserInfo info, Long sharedId, Integer dsType, Long pid, User.RegisterEnv registerEnv, String dsCode, String callback, String callbackType) throws Exception {
  66. final String unionid = info.getUnionid();
  67. if (StrUtil.isEmpty(unionid)) {
  68. throw BusinessRuntimeException.getInstance("授权操作异常,请刷新页面");
  69. }
  70. User user = getSyncUser(info.getOpenid(), info.getUnionid(), null);
  71. user = Optional.ofNullable(user).orElseGet(() -> new User()
  72. .setUnionid(unionid));
  73. user.setCountry(info.getCountry())
  74. .setProvince(info.getProvince())
  75. .setCity(info.getCity());
  76. if (user.getSex() == null) {
  77. user.setSex(info.getSex());
  78. }
  79. if (StrUtil.isEmpty(user.getHeadimgurl())) {
  80. user.setHeadimgurl(info.getHeadimgurl());
  81. }
  82. if (StrUtil.isEmpty(user.getNickname())) {
  83. user.setNickname(info.getNickname());
  84. }
  85. user.setUnionid(unionid);
  86. user.setOpenId(info.getOpenid());
  87. Boolean isNewUser = false;
  88. if (user.getId() == null) {
  89. isNewUser = true;
  90. user.setPopularizeId(pid);
  91. user.setRegisterEnv(registerEnv.name());
  92. if (!redisService.setNx(RedisService.key.REPEAT_USER_KEY.getNameFormat(user.getUnionid()), user.getUnionid(), RedisService.key.REPEAT_USER_KEY.getTimeout())) {
  93. return this.getOne(Wrappers.lambdaQuery(User.class)
  94. .eq(User::getUnionid, unionid).last("limit 1"));
  95. }
  96. this.save(user);
  97. //缓存用户注册 回传信息
  98. if (StrUtil.isNotBlank(callback)) {
  99. OrderDonPostDataDto orderDonPostDataDto = new OrderDonPostDataDto().setCallback(callback)
  100. .setCallbackType(callbackType);
  101. redisService.set(RedisService.key.ORDER_DON_POST_DATA_USER_KEY.getName() + user.getId(), Jsons.toJson(orderDonPostDataDto));
  102. }
  103. //发放新用户福利
  104. final Long fUid = user.getId();
  105. TASK_POOL.execute(() -> {
  106. try {
  107. sendNewUserWelfare(fUid);
  108. } catch (Exception e) {
  109. }
  110. });
  111. } else {
  112. if (StrUtil.isEmpty(user.getRegisterEnv())) {
  113. user.setRegisterEnv(registerEnv.name());
  114. }
  115. this.updateById(user);
  116. }
  117. Long dsPopularizeId = null;
  118. if (StrUtil.isNotBlank(dsCode)) {
  119. dsCode = dsCode.trim();
  120. User sharedUser = getOne(Wrappers.lambdaQuery(User.class)
  121. .eq(User::getShowId, dsCode).last("limit 1"));
  122. if (sharedUser != null) {
  123. sharedId = sharedUser.getId();
  124. } else {
  125. UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
  126. .eq(UserDistributePopularize::getCode, dsCode)
  127. .select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
  128. if (distributePopularize != null) {
  129. log.info("渠道sharedId:{}设置固定推广链接用户分销", distributePopularize.getUserId());
  130. sharedId = distributePopularize.getUserId();
  131. dsPopularizeId = distributePopularize.getId();
  132. }
  133. }
  134. }
  135. if (sharedId != null && isNewUser) {
  136. if (dsType == null || dsType == 1) {
  137. distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
  138. }
  139. }
  140. Long userId = user.getId();
  141. if (isNewUser && pid != null) {
  142. TASK_POOL.execute(() -> {
  143. sendFixedCustomerCoupon(pid, userId, unionid);
  144. });
  145. }
  146. //新旧用户都可实物分销
  147. if (sharedId != null && dsType != null && dsType == 2) {
  148. equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
  149. }
  150. return user;
  151. }
  152. @Override
  153. public UserWhoami whoami(long userId) {
  154. User user = this.getById(userId);
  155. Assert.notNull(user, "业务处理失败,请联系客服");
  156. UserWhoami userWhoami = new UserWhoami();
  157. if (StrUtil.isEmpty(user.getShowId())) {
  158. user.setShowId(getUserShowId(userId));
  159. }
  160. BeanUtil.copyProperties(user, userWhoami);
  161. UserBindDetail bindPhone = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  162. .eq(UserBindDetail::getUserId, userId).last("limit 1"));
  163. //手机号
  164. if (bindPhone != null) {
  165. userWhoami.setBindPhone(bindPhone.getPhone());
  166. userWhoami.setBindEmail(bindPhone.getEmail());
  167. }
  168. Integer type = 3;
  169. if (StrUtil.isNotBlank(user.getLoginPhone())) {
  170. type = 1;
  171. } else if (StrUtil.isNotBlank(user.getEmail())) {
  172. type = 2;
  173. }
  174. userWhoami.setType(type);
  175. return userWhoami;
  176. }
  177. @Override
  178. public User getSyncUser(String openId, String unionId, WxSyncLog wxSyncLog) {
  179. User user;
  180. //迁移公众号之后同步授权后信息
  181. //是否是迁移用户
  182. if (wxSyncLog != null) {
  183. user = this.getOne(Wrappers.lambdaQuery(User.class)
  184. .ne(User::getUnionid, unionId)
  185. .eq(User::getOpenId, wxSyncLog.getOriOpenid()).last("limit 1"));
  186. if (user != null) {
  187. user.setOpenId(wxSyncLog.getNewOpenid());
  188. } else {
  189. // 查询用户是否存在
  190. user = Optional.ofNullable(
  191. this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid, unionId)
  192. .orderByAsc(User::getId)
  193. .last("limit 1")))
  194. .orElseGet(() -> this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, openId)
  195. .orderByAsc(User::getId)
  196. .last("limit 1")));
  197. }
  198. } else {
  199. // 查询用户是否存在
  200. user = Optional.ofNullable(
  201. this.getOne(new LambdaQueryWrapper<User>().eq(User::getUnionid, unionId)
  202. .orderByAsc(User::getId)
  203. .last("limit 1")))
  204. .orElseGet(() -> this.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, openId)
  205. .orderByAsc(User::getId)
  206. .last("limit 1")));
  207. }
  208. return user;
  209. }
  210. @Override
  211. public void sendFixedCustomerCoupon(Long popularizeId, Long userId, String unionId) {
  212. //若是百度渠道 添加固定客服 注册后直接发放优惠券
  213. ChannelPopularize channelPopularize = channelPopularizeMapper.selectById(popularizeId);
  214. if (channelPopularize != null && channelPopularize.getChannelId() == 34) {
  215. // SysConfig corpConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  216. // .eq(SysConfig::getSysKey, Constant.CORP_FIXED_CUSTOMER)
  217. // .last("limit 1"));
  218. // if (corpConfig != null) {
  219. // Optional.ofNullable(corpConfig.getSysValue()).ifPresent(value -> {
  220. // try {
  221. // if (StrUtil.isNotBlank(value)) {
  222. // List<String> followIds = Jsons.parseList(value, String.class);
  223. // //添加固定客服发放优惠券
  224. // CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
  225. // .field(CorpUserFollowView::getUnionId, unionId)
  226. // .field(CorpUserFollowView::getFollowId, followIds).op(Operator.InList).build());
  227. // if (corpUserFollowView != null) {
  228. // Constant.FIXED_CUSTOMER_COUPON_IDS.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, 0l, 0l, 0l, CouponUser.Channel.wxCorp));
  229. // }
  230. // }
  231. // } catch (Exception e) {
  232. // }
  233. // });
  234. //
  235. // }
  236. SysConfig config = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  237. .eq(SysConfig::getSysKey, Constant.BAIDU_POPULARIZE_COUPON_IDS).last("limit 1"));
  238. if (config != null) {
  239. String sysValue = config.getSysValue();
  240. if (StrUtil.isNotBlank(sysValue)) {
  241. try {
  242. List<Long> couponIds = Jsons.parseList(sysValue, Long.class);
  243. couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, 0l, 0l, popularizeId, CouponUser.Channel.manual));
  244. } catch (Exception e) {
  245. log.error("百度渠道优惠券解析错误");
  246. }
  247. }
  248. }
  249. }
  250. }
  251. @Override
  252. public List<Long> getRelationUserIdList(Long userId, User selectUser) {
  253. List<Long> userIds = new ArrayList<>();
  254. userIds.add(userId);
  255. UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  256. .eq(UserBindDetail::getUserId, userId).last("limit 1"));
  257. if (userBindDetail == null) {
  258. User user = Optional.ofNullable(selectUser).orElse(this.getById(userId));
  259. if (StrUtil.isEmpty(user.getOpenId()) && StrUtil.isNotEmpty(user.getLoginPhone())) {
  260. userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  261. .eq(UserBindDetail::getPhone, user.getLoginPhone()).last("limit 1"));
  262. if (userBindDetail != null) {
  263. userIds.add(userBindDetail.getUserId());
  264. }
  265. }
  266. } else {
  267. if (StrUtil.isNotBlank(userBindDetail.getPhone())) {
  268. User otherUser = this.getOne(Wrappers.lambdaQuery(User.class)
  269. .eq(User::getLoginPhone, userBindDetail.getPhone()).last("limit 1"));
  270. if (otherUser != null) {
  271. userIds.add(otherUser.getId());
  272. }
  273. }
  274. }
  275. return userIds;
  276. }
  277. @Override
  278. public List<Long> getUserIdsByNickname(String nickname) {
  279. return userMapper.selectListByNickname(nickname);
  280. }
  281. @Override
  282. public String getUserShowId(Long userId) {
  283. Integer update = 0;
  284. String showId = null;
  285. while (update != 1) {
  286. showId = StringUtil.randomString(5);
  287. try {
  288. update = userMapper.update(null, Wrappers.lambdaUpdate(User.class)
  289. .set(User::getShowId, showId)
  290. .eq(User::getId, userId));
  291. } catch (DuplicateKeyException e) {
  292. update = 0;
  293. }
  294. }
  295. return showId;
  296. }
  297. @Override
  298. public Long getUserIdByShowId(String showId) {
  299. return userMapper.getUserIdByShowId(showId);
  300. }
  301. @Override
  302. public User webLogin(LoginReq loginReq) throws Exception {
  303. LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class).last("limit 1");
  304. if (loginReq.getType() == null || loginReq.getType() < 1 && loginReq.getType() > 2) {
  305. throw BusinessRuntimeException.getInstance("系统异常,请刷新页面重新操作");
  306. }
  307. if (loginReq.getType() == 1) {
  308. if (StrUtil.hasEmpty(loginReq.getPhone(), loginReq.getCode())) {
  309. throw BusinessRuntimeException.getInstance("请输入对应信息");
  310. }
  311. DateTime now = DateTime.now();
  312. PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, loginReq.getPhone()).last("limit 1"));
  313. if (phoneCode == null || StrUtil.isEmpty(phoneCode.getCode())) {
  314. throw BusinessRuntimeException.getInstance("请重新获取手机验证码");
  315. }
  316. //3分钟失效
  317. Date updateTime = phoneCode.getUpdateTime();
  318. DateTime afterFiveMinutes = DateUtil.offsetMinute(updateTime, 3);
  319. if (now.isAfter(afterFiveMinutes)) {
  320. throw BusinessRuntimeException.getInstance("手机验证码已失效,请重新获取");
  321. }
  322. if (!StrUtil.equals(loginReq.getCode(), phoneCode.getCode())) {
  323. throw BusinessRuntimeException.getInstance("手机验证码错误,请重新输入");
  324. }
  325. wrapper.eq(User::getLoginPhone, loginReq.getPhone());
  326. }
  327. if (loginReq.getType() == 2) {
  328. if (StrUtil.isEmpty(loginReq.getEmail())) {
  329. throw BusinessRuntimeException.getInstance("邮箱不能为空");
  330. }
  331. String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
  332. if (StrUtil.isEmpty(code)) {
  333. throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
  334. }
  335. if (!StrUtil.equals(loginReq.getCode(), code)) {
  336. throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
  337. }
  338. wrapper.eq(User::getEmail, loginReq.getEmail());
  339. redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(loginReq.getEmail()));
  340. }
  341. //保存用户信息
  342. User user = this.getOne(wrapper);
  343. String dsCode = loginReq.getDsCode();
  344. Long sharedId = loginReq.getSharedId();
  345. Long dsPopularizeId = null;
  346. Integer dsType = loginReq.getDsType();
  347. Boolean isNewUser = false;
  348. if (StrUtil.isNotBlank(dsCode)) {
  349. dsCode = dsCode.trim();
  350. User sharedUser = this.getOne(Wrappers.lambdaQuery(User.class)
  351. .eq(User::getShowId, dsCode).last("limit 1"));
  352. if (sharedUser != null) {
  353. sharedId = sharedUser.getId();
  354. } else {
  355. UserDistributePopularize distributePopularize = distributePopularizeMapper.selectOne(Wrappers.lambdaQuery(UserDistributePopularize.class)
  356. .eq(UserDistributePopularize::getCode, dsCode)
  357. .select(UserDistributePopularize::getUserId, UserDistributePopularize::getId).last("limit 1"));
  358. if (distributePopularize != null) {
  359. log.info("渠道sharedId:{}设置固定推广链接PC用户分销", distributePopularize.getUserId());
  360. sharedId = distributePopularize.getUserId();
  361. dsPopularizeId = distributePopularize.getId();
  362. }
  363. }
  364. }
  365. if (user == null) {
  366. user = new User();
  367. isNewUser = true;
  368. StringBuilder name = new StringBuilder();
  369. name.append(Constant.DEFAULT_NAME);
  370. if (loginReq.getPopularizeId() != null) {
  371. user.setPopularizeId(loginReq.getPopularizeId());
  372. }
  373. if (loginReq.getType() == 1) {
  374. user.setLoginPhone(loginReq.getPhone());
  375. }
  376. if (loginReq.getType() == 2) {
  377. user.setEmail(loginReq.getEmail());
  378. name.append("@");
  379. }
  380. user.setNickname(String.format("%s%s", name.toString(), RandomUtil.randomString(6)));
  381. //默认头像
  382. user.setHeadimgurl(Constant.DEFAULT_HEAD_IMG);
  383. String registerEnv = loginReq.getRegisterEnv();
  384. user.setRegisterEnv(StrUtil.isEmpty(registerEnv) ? User.RegisterEnv.pc.name() : registerEnv);
  385. this.save(user);
  386. //新用户分销
  387. if (sharedId != null) {
  388. distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
  389. }
  390. //缓存用户注册 回传信息
  391. String callback = loginReq.getCallback();
  392. String callbackType = loginReq.getCallbackType();
  393. if (StrUtil.isNotBlank(callback)) {
  394. OrderDonPostDataDto orderDonPostDataDto = new OrderDonPostDataDto().setCallback(callback)
  395. .setCallbackType(callbackType);
  396. redisService.set(RedisService.key.ORDER_DON_POST_DATA_USER_KEY.getName() + user.getId(), Jsons.toJson(orderDonPostDataDto));
  397. }
  398. //发放新用户福利
  399. final Long fUid = user.getId();
  400. TASK_POOL.execute(() -> {
  401. try {
  402. sendNewUserWelfare(fUid);
  403. } catch (Exception e) {
  404. }
  405. });
  406. final String login_email = user.getEmail();
  407. final String login_phone = user.getLoginPhone();
  408. UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
  409. .and(ub -> ub.eq(StrUtil.isNotBlank(login_email), UserBindDetail::getEmail, login_email)
  410. .or().eq(StrUtil.isNotBlank(login_phone), UserBindDetail::getPhone, login_phone))
  411. .last("limit 1"));
  412. if (bindDetail != null) {
  413. if (StrUtil.isNotBlank(login_phone)) {
  414. bindDetail.setPhoneUserId(user.getId());
  415. }
  416. if (StrUtil.isNotBlank(login_email)) {
  417. bindDetail.setEmailUserId(user.getId());
  418. }
  419. userBindDetailMapper.updateById(bindDetail);
  420. }
  421. }
  422. if (StrUtil.isEmpty(user.getShowId())) {
  423. user.setShowId(getUserShowId(user.getId()));
  424. }
  425. //新旧用户都可实物分销
  426. if (sharedId != null && dsType != null && dsType == 2) {
  427. equipDistributeService.saveDistributionInvitation(sharedId, isNewUser, user.getId());
  428. }
  429. return user;
  430. }
  431. @Override
  432. public String bindWxAccountRedirect(String code, String state) throws Exception {
  433. AuthToken token = weChatService.getAuthToken(code, wxOpenPlatYHLXLoginConfig.getAppId());
  434. //重定向
  435. // 根据openid 与 access_token 获取用户信息
  436. GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
  437. // 转跳参数
  438. String json = Codec.DoBase64.custom().setData(state).decodeAsText();
  439. AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
  440. //保存用户信息
  441. User user = saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), User.RegisterEnv.pc, re.getDsCode(), re.getCk(), re.getCt());
  442. if (user == null) {
  443. throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
  444. }
  445. String loginPhone = re.getLp();
  446. String loginEmail = re.getLe();
  447. if (StrUtil.isNotBlank(loginPhone)) {
  448. log.info("手机号phone:{}登录用户,微信扫描网页授权二维码进行用户信息绑定", loginPhone);
  449. try {
  450. bindTaskService.bindPhone(user, loginPhone, null);
  451. } catch (Exception e) {
  452. log.info(StringUtil.getErrorText(e));
  453. }
  454. }
  455. if (StrUtil.isNotBlank(loginEmail)) {
  456. log.info("邮箱email:{}登录用户,微信扫描网页授权二维码进行用户信息绑定", loginEmail);
  457. try {
  458. bindTaskService.bindEmail(user, loginEmail, null);
  459. } catch (Exception e) {
  460. log.info(StringUtil.getErrorText(e));
  461. }
  462. }
  463. return redisService.getStr(re.getMappingId().toString());
  464. }
  465. /**
  466. * 发放新用户福利
  467. */
  468. public void sendNewUserWelfare(Long userId) throws Exception {
  469. SysConfig newUserWelfareConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  470. .eq(SysConfig::getSysKey, Constant.NEW_USER_WELFARE_KEY).last("limit 1"));
  471. if (StrUtil.isEmpty(newUserWelfareConfig.getSysValue())) {
  472. return;
  473. }
  474. NewUserWelfareDto newUserWelfareDto = Jsons.parseObject(newUserWelfareConfig.getSysValue(), NewUserWelfareDto.class);
  475. if (newUserWelfareDto != null) {
  476. List<Long> couponIds = newUserWelfareDto.getCouponIds();
  477. couponIds.forEach(couponId -> couponCommonService.sendCouponToUser(userId, couponId, null, null, null, CouponUser.Channel.new_welfare));
  478. }
  479. }
  480. }