Commit e33e7a1b e33e7a1b2ceab638524b3e5ae6919ff2c4fe2029 by xianghan

1.扫码关注功能修复,解决老用户先关注后绑定无法免费看的问题修订

1 parent fc3fe125
...@@ -61,6 +61,8 @@ public class UserOperationController { ...@@ -61,6 +61,8 @@ public class UserOperationController {
61 private MemberService memberService; 61 private MemberService memberService;
62 @Autowired 62 @Autowired
63 private RedisUtils redisUtils; 63 private RedisUtils redisUtils;
64 @Autowired
65 private UserOperationService userOperationService;
64 66
65 private static final String SUBSCRIBE = "subscribe"; 67 private static final String SUBSCRIBE = "subscribe";
66 private static final String UNSUBSCRIBE = "unsubscribe"; 68 private static final String UNSUBSCRIBE = "unsubscribe";
...@@ -170,7 +172,6 @@ public class UserOperationController { ...@@ -170,7 +172,6 @@ public class UserOperationController {
170 172
171 } 173 }
172 174
173
174 return ResultInfo.success(); 175 return ResultInfo.success();
175 } 176 }
176 177
...@@ -246,7 +247,6 @@ public class UserOperationController { ...@@ -246,7 +247,6 @@ public class UserOperationController {
246 @AnonymousAccess 247 @AnonymousAccess
247 public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException { 248 public ResultInfo subscribe(@Validated @RequestBody SubscribeBeanEvent data) throws IOException {
248 String content = data.getContent(); 249 String content = data.getContent();
249
250 log.info("subscribe ==> input ==> [{}]",content); 250 log.info("subscribe ==> input ==> [{}]",content);
251 251
252 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class); 252 SubscribeBean subscribeBean = JSONUtil.parseMsg2Object(content, SubscribeBean.class);
...@@ -255,7 +255,6 @@ public class UserOperationController { ...@@ -255,7 +255,6 @@ public class UserOperationController {
255 return ResultInfo.success(result); 255 return ResultInfo.success(result);
256 } 256 }
257 257
258
259 /** 258 /**
260 * 259 *
261 * @param subscribeBean 260 * @param subscribeBean
...@@ -297,9 +296,11 @@ public class UserOperationController { ...@@ -297,9 +296,11 @@ public class UserOperationController {
297 if (StringUtils.isNotBlank(content)) { 296 if (StringUtils.isNotBlank(content)) {
298 // 大屏信息 297 // 大屏信息
299 iptvUserInfo = JSONObject.parseObject(content); 298 iptvUserInfo = JSONObject.parseObject(content);
299
300 } else { 300 } else {
301 301
302 String eventKey = subscribeBean.getEventKey(); 302 String eventKey = subscribeBean.getEventKey();
303 log.info(" eventKey ==> [{}] ", eventKey);
303 304
304 if (StringUtils.isNotBlank(eventKey)) { 305 if (StringUtils.isNotBlank(eventKey)) {
305 // 用户扫描带参二维码关注。发消息 306 // 用户扫描带参二维码关注。发消息
...@@ -310,8 +311,9 @@ public class UserOperationController { ...@@ -310,8 +311,9 @@ public class UserOperationController {
310 311
311 } 312 }
312 313
313 // 用户自己搜索关注就没有大屏信息的话,否则表示扫码关注 314 // 用户自己搜索关注就没有大屏信息,否则表示扫码关注
314 if (Objects.nonNull(iptvUserInfo)) { 315 if (Objects.nonNull(iptvUserInfo)) {
316
315 subscribeBean.setIptvUserInfo(iptvUserInfo); 317 subscribeBean.setIptvUserInfo(iptvUserInfo);
316 318
317 String headimgurl = iptvUserInfo.get("headimgurl").toString(); 319 String headimgurl = iptvUserInfo.get("headimgurl").toString();
...@@ -383,96 +385,49 @@ public class UserOperationController { ...@@ -383,96 +385,49 @@ public class UserOperationController {
383 385
384 // 保存大小屏信息到redis同时返回小屏信息 386 // 保存大小屏信息到redis同时返回小屏信息
385 UserWeixinDTO userWeixinDTO = this.userTvOperationService.saveUserInfo(data); 387 UserWeixinDTO userWeixinDTO = this.userTvOperationService.saveUserInfo(data);
386 388 // 小屏用户不存在或者关注状态为未关注(0),返回未关注
387 if (Objects.isNull(userWeixinDTO) || Objects.isNull(userWeixinDTO.getId())) { 389 if (Objects.isNull(userWeixinDTO) || Objects.isNull(userWeixinDTO.getId()) || userWeixinDTO.getStatus() != SUBSCRIBE_STATUS) {
388 result = UNSUBSCRIBE;
389 }
390
391 Integer status = userWeixinDTO.getStatus();
392 log.info("saveUserInfo ==>> status ==>> [{}]",status);
393 if (status != SUBSCRIBE_STATUS) {
394 result = UNSUBSCRIBE; 390 result = UNSUBSCRIBE;
391 return ResultInfo.success(result);
395 } 392 }
396 393
394 /***************************************************************************************/
395 // 关注未绑定
397 if (result.equalsIgnoreCase(SUBSCRIBE)) { 396 if (result.equalsIgnoreCase(SUBSCRIBE)) {
398 397 // 小屏会员
399 // 考虑老用户先关注后扫码的情况,即使关注了也要进行绑定检查
400 SubscribeBean subscribeBean = new SubscribeBean();
401 subscribeBean.setUnionid(userWeixinDTO.getUnionid());
402 subscribeBean.setAppId(userWeixinDTO.getAppid());
403 subscribeBean.setAppid(userWeixinDTO.getAppid());
404 subscribeBean.setOpenId(userWeixinDTO.getOpenid());
405 subscribeBean.setNickname(userWeixinDTO.getNickname());
406 subscribeBean.setHeadimgurl(userWeixinDTO.getHeadimgurl());
407 try {
408 // 解析
409 this.parseSubscribe(subscribeBean);
410
411 log.info("saveUserInfo ==>> subscribeBean ==>> [{}]",subscribeBean);
412
413 JSONObject iptvUserInfo = subscribeBean.getIptvUserInfo();
414 String platformAccount = iptvUserInfo.getString("platformAccount");
415 MemberDTO memberDTO = this.memberService.findById(userWeixinDTO.getMemberId()); 398 MemberDTO memberDTO = this.memberService.findById(userWeixinDTO.getMemberId());
416 399
417 TempIptvUser tempIptvUser = new TempIptvUser(); 400 // redis中的大小屏信息
418 tempIptvUser.setPlatformAccount(platformAccount); 401 String content = (String) this.redisUtils.get(RedisKeyUtil.genSeSuSubscribeKey(unionid));
419 tempIptvUser.setMemberCode(memberDTO.getCode()); 402 JSONObject iptvUserInfo = JSONObject.parseObject(content);
420
421 this.unbindPriorityCode(memberDTO);
422
423 log.info("subscribe again start subscribeBean ==>> [{}]",subscribeBean);
424 this.userTvOperationService.subscribe(subscribeBean);
425 log.info("subscribe again end !!!!");
426 403
404 // 大屏账户
405 String platformAccount = iptvUserInfo.getString("platformAccount");
427 406
428 } catch (IOException e) { 407 try {
429 e.printStackTrace(); 408 String headimgurl = iptvUserInfo.get("headimgurl").toString();
430 } 409 String nickname = iptvUserInfo.get("nickname").toString();
410 if (StringUtils.isNotBlank(nickname)) {
411 String nicknameDecode = URLDecoder.decode(nickname, "UTF-8");
412 String nicknameEncode = Base64Util.encode(nicknameDecode);
413 memberDTO.setNickname(nicknameEncode);
431 } 414 }
432 415
433 return ResultInfo.success(result); 416 if (StringUtils.isNotBlank(headimgurl)) {
417 String headimgurlDecode = URLDecoder.decode(headimgurl, "UTF-8");
418 memberDTO.setAvatarUrl(headimgurlDecode);
434 } 419 }
435 420 }catch (Exception e) {
436 421 log.info("headimgurl , nickname ===>> encode error!");
437 /** 422 e.printStackTrace();
438 *
439 * @param memberDTO_0
440 */
441 private void unbindPriorityCode(MemberDTO memberDTO_0) {
442 String code1 = memberDTO_0.getCode();
443 UserTvDTO userTvDTO1 = this.userTvService.findByPriorityMemberCode(code1);
444 if (Objects.nonNull(userTvDTO1) && Objects.nonNull(userTvDTO1.getId())) {
445 userTvDTO1.setPriorityMemberCode(null);
446 UserTv userTv = new UserTv();
447 BeanUtils.copyProperties(userTvDTO1,userTv);
448 this.userTvService.update(userTv);
449 } 423 }
450 424
425 // 大小屏绑定
426 this.userOperationService.bind(memberDTO,platformAccount);
451 } 427 }
428 /****************************************************************************************/
452 429
453 430 return ResultInfo.success(result);
454 /**
455 * 检查是否绑定当前大屏账户
456 * @param subscribeBean
457 * @param userWeixinDTO
458 * @return
459 */
460 private boolean checkBind(SubscribeBean subscribeBean, UserWeixinDTO userWeixinDTO) {
461 boolean result = false;
462 JSONObject iptvUserInfo = subscribeBean.getIptvUserInfo();
463 if (Objects.nonNull(iptvUserInfo)) {
464 String platformAccount = iptvUserInfo.getString("platformAccount");
465 Long memberId = userWeixinDTO.getMemberId();
466 MemberDTO memberDTO = this.memberService.findById(memberId);
467 if (Objects.nonNull(memberDTO.getUserIptvId()) && StringUtils.isNotBlank(platformAccount)) {
468 UserTvDTO userTvDTO = this.userTvService.findById(memberDTO.getUserIptvId());
469 String platformAccount1 = userTvDTO.getPlatformAccount();
470 if (platformAccount.equalsIgnoreCase(platformAccount1)) {
471 result = true;
472 }
473 }
474 }
475 return result;
476 } 431 }
477 432
478 @PostMapping(value = "/saveUserWeixinPhone") 433 @PostMapping(value = "/saveUserWeixinPhone")
......
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
4 import com.topdraw.business.module.member.profile.domain.MemberProfile; 4 import com.topdraw.business.module.member.profile.domain.MemberProfile;
5 import com.topdraw.business.module.member.service.dto.MemberDTO; 5 import com.topdraw.business.module.member.service.dto.MemberDTO;
6 import com.topdraw.business.module.user.iptv.domain.UserTv; 6 import com.topdraw.business.module.user.iptv.domain.UserTv;
7 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
7 import com.topdraw.business.module.user.weixin.domain.UserWeixin; 8 import com.topdraw.business.module.user.weixin.domain.UserWeixin;
8 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO; 9 import com.topdraw.business.module.user.weixin.service.dto.UserWeixinDTO;
9 import com.topdraw.business.process.domian.weixin.BindBean; 10 import com.topdraw.business.process.domian.weixin.BindBean;
...@@ -140,4 +141,11 @@ public interface UserOperationService { ...@@ -140,4 +141,11 @@ public interface UserOperationService {
140 JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code); 141 JSONObject getUnionIdByAppIdAndOpenId(String appId,String secret,String code);
141 142
142 UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources); 143 UserWeixinDTO createWeixinUserAndCreateMember(UserWeixin resources);
144
145 void bind(String memberCode, String platformAccount);
146
147 void bind(MemberDTO memberDTO, UserTvDTO userTvDTO);
148
149 void bind(MemberDTO memberDTO, String platformAccount);
150
143 } 151 }
......
...@@ -182,27 +182,12 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -182,27 +182,12 @@ public class UserOperationServiceImpl implements UserOperationService {
182 if (Objects.nonNull(iptvUserInfo)) { 182 if (Objects.nonNull(iptvUserInfo)) {
183 183
184 // 小屏会员 184 // 小屏会员
185 MemberDTO memberDTO_0 = this.findMemberByAppIdAndOpenId(appId,openId); 185 MemberDTO memberDTO = this.findMemberByAppIdAndOpenId(appId,openId);
186 186
187 // 账户 187 // 账户
188 String platformAccount = iptvUserInfo.getString("platformAccount"); 188 String platformAccount = iptvUserInfo.getString("platformAccount");
189 189
190 // 大屏账户 190 this.bind(memberDTO,platformAccount);
191 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
192 if (Objects.isNull(userTvDTO)) {
193 throw new BadRequestException("大屏信息不存在!");
194 }
195
196 memberDTO_0.setPlatformAccount(platformAccount);
197
198 // 大屏是否绑定主账号
199 this.bondPriorityMember(userTvDTO,memberDTO_0,"auto");
200
201 // 小屏会员绑定大屏账户id
202 MemberDTO memberDTO_1 = this.bindIptvId(memberDTO_0,userTvDTO);
203
204 // 修改会员
205 this.doUpdateMemberByMemberDTO(memberDTO_1);
206 191
207 } 192 }
208 193
...@@ -393,7 +378,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -393,7 +378,7 @@ public class UserOperationServiceImpl implements UserOperationService {
393 * 修改会员vip状态 378 * 修改会员vip状态
394 */ 379 */
395 private void doUpdateMemberVip(MemberDTO memberDTO,Integer vip1) { 380 private void doUpdateMemberVip(MemberDTO memberDTO,Integer vip1) {
396 381 if (memberDTO != null) {
397 Integer vip = memberDTO.getVip(); 382 Integer vip = memberDTO.getVip();
398 vip = (vip == null ? 0 : vip); 383 vip = (vip == null ? 0 : vip);
399 // 未购买付费会员 384 // 未购买付费会员
...@@ -402,10 +387,11 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -402,10 +387,11 @@ public class UserOperationServiceImpl implements UserOperationService {
402 memberDTO.setVip(vip1); 387 memberDTO.setVip(vip1);
403 388
404 Member member = new Member(); 389 Member member = new Member();
405 BeanUtils.copyProperties(memberDTO,member); 390 BeanUtils.copyProperties(memberDTO, member);
406 this.memberService.update(member); 391 this.memberService.update(member);
407 } 392 }
408 } 393 }
394 }
409 395
410 /** 396 /**
411 * 获取小屏会员 397 * 获取小屏会员
...@@ -535,6 +521,12 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -535,6 +521,12 @@ public class UserOperationServiceImpl implements UserOperationService {
535 return memberId; 521 return memberId;
536 } 522 }
537 523
524 /**
525 *
526 * @param userWeixin
527 * @param vip
528 * @return
529 */
538 private Member doCreateMemberAndReturnMember(UserWeixin userWeixin,Integer vip) { 530 private Member doCreateMemberAndReturnMember(UserWeixin userWeixin,Integer vip) {
539 Member memberReturn = null; 531 Member memberReturn = null;
540 532
...@@ -874,7 +866,11 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -874,7 +866,11 @@ public class UserOperationServiceImpl implements UserOperationService {
874 this.changeMainAccount(userTv); 866 this.changeMainAccount(userTv);
875 } 867 }
876 868
877 869 /**
870 *
871 * @param memberCode
872 * @return
873 */
878 private UserTvDTO findByPriorityMemberCode(String memberCode) { 874 private UserTvDTO findByPriorityMemberCode(String memberCode) {
879 UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode); 875 UserTvDTO userTvDTO = this.userTvService.findByPriorityMemberCode(memberCode);
880 return userTvDTO; 876 return userTvDTO;
...@@ -1067,9 +1063,10 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1067,9 +1063,10 @@ public class UserOperationServiceImpl implements UserOperationService {
1067 1063
1068 /** 1064 /**
1069 * 绑定会员中的userIptvId字段 1065 * 绑定会员中的userIptvId字段
1070 * @param resources 1066 * @param memberDTO
1067 * @param userTvDTO
1071 */ 1068 */
1072 private MemberDTO bindIptvId(MemberDTO resources,UserTvDTO userTvDTO) { 1069 private MemberDTO bindIptvId(MemberDTO memberDTO,UserTvDTO userTvDTO) {
1073 String platform = userTvDTO.getPlatform(); 1070 String platform = userTvDTO.getPlatform();
1074 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通 1071 // 绑定IPTV平台 0:未知;1:电信;2:移动;3:联通
1075 Integer bindIptvPlatformType = 0; 1072 Integer bindIptvPlatformType = 0;
...@@ -1089,24 +1086,10 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1089,24 +1086,10 @@ public class UserOperationServiceImpl implements UserOperationService {
1089 bindIptvPlatformType = PLATFORM_LIST[1]; 1086 bindIptvPlatformType = PLATFORM_LIST[1];
1090 } 1087 }
1091 1088
1092 return this.bindIptvId(resources,userTvDTO.getId(),bindIptvPlatformType); 1089 memberDTO.setUserIptvId(userTvDTO.getId());
1093 }
1094
1095 /**
1096 * 绑定会员中的userIptvId字段
1097 * @param userIptvId
1098 * @param bindIptvPlatformType
1099 */
1100 private MemberDTO bindIptvId(MemberDTO memberDTO,Long userIptvId,Integer bindIptvPlatformType) {
1101
1102 if (memberDTO != null) {
1103 memberDTO.setUserIptvId(userIptvId);
1104 memberDTO.setBindIptvTime(LocalDateTime.now()); 1090 memberDTO.setBindIptvTime(LocalDateTime.now());
1105 memberDTO.setBindIptvPlatformType(bindIptvPlatformType); 1091 memberDTO.setBindIptvPlatformType(bindIptvPlatformType);
1106 1092
1107 this.doUpdateMemberByMemberDTO(memberDTO);
1108 }
1109
1110 return memberDTO; 1093 return memberDTO;
1111 } 1094 }
1112 1095
...@@ -1495,6 +1478,7 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1495,6 +1478,7 @@ public class UserOperationServiceImpl implements UserOperationService {
1495 // 会员绑定大屏 1478 // 会员绑定大屏
1496 this.bindIptvId(memberDTO,userTvDTO); 1479 this.bindIptvId(memberDTO,userTvDTO);
1497 1480
1481 this.doUpdateMemberByMemberDTO(memberDTO);
1498 return true; 1482 return true;
1499 } 1483 }
1500 1484
...@@ -1580,6 +1564,42 @@ public class UserOperationServiceImpl implements UserOperationService { ...@@ -1580,6 +1564,42 @@ public class UserOperationServiceImpl implements UserOperationService {
1580 return userWeixinDTO1; 1564 return userWeixinDTO1;
1581 } 1565 }
1582 1566
1567 @Override
1568 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
1569 public void bind(String memberCode, String platformAccount) {
1570 MemberDTO memberDTO = this.memberService.getByCode(memberCode);
1571 this.bind(memberDTO,platformAccount);
1572 }
1573
1574 @Override
1575 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
1576 public void bind(MemberDTO memberDTO, UserTvDTO userTvDTO) {
1577 String platformAccount = userTvDTO.getPlatformAccount();
1578 // 绑定
1579 this.bind(memberDTO,platformAccount);
1580 }
1581
1582 @Override
1583 public void bind(MemberDTO memberDTO, String platformAccount) {
1584 // 大屏账户
1585 UserTvDTO userTvDTO = this.userTvService.findByPlatformAccount(platformAccount);
1586 if (Objects.isNull(userTvDTO)) {
1587 throw new BadRequestException("大屏信息不存在!");
1588 }
1589
1590 // mq同步数据时使用
1591 memberDTO.setPlatformAccount(platformAccount);
1592
1593 // 大屏是否绑定主账号,如果绑定了主账户则不操作大屏账户表
1594 this.bondPriorityMember(userTvDTO,memberDTO,"auto");
1595
1596 // 构建小屏会员对象,绑定user_iptv_id字段
1597 MemberDTO memberDTO0 = this.bindIptvId(memberDTO,userTvDTO);
1598
1599 // 修改会员
1600 this.doUpdateMemberByMemberDTO(memberDTO0);
1601 }
1602
1583 /** 1603 /**
1584 * 1604 *
1585 * @param userWeixinDTO1 1605 * @param userWeixinDTO1
......