UserServiceImpl.java 20 KB

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