| | |
| | | package com.yeshi.fanli.util.rocketmq.consumer.user;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Action;
|
| | | import com.aliyun.openservices.ons.api.ConsumeContext;
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.MessageListener;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.ThreeSaleSeparateMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.user.body.UserLevelChangedMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteValidNumService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | /**
|
| | | * 用户超级会员
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Component
|
| | | public class UserVIPMessageListener implements MessageListener {
|
| | |
|
| | | @Resource
|
| | | private UserVIPPreInfoService userVIPPreInfoService;
|
| | |
|
| | | @Resource
|
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | | |
| | | @Resource
|
| | | private UserInviteValidNumService userInviteValidNumService;
|
| | |
|
| | | @Override
|
| | | public Action consume(Message message, ConsumeContext context) {
|
| | |
|
| | | LogHelper.mqInfo("consumer-UserVIPMessageListener", message.getMsgID(), message.getTopic(), message.getTag(),
|
| | | new String(message.getBody()));
|
| | | String tag = message.getTag();
|
| | | if (tag == null)
|
| | | tag = "";
|
| | |
|
| | | // 邀请相关
|
| | | if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.userLevelChanged.name())) {// 用户等级发生变化
|
| | | UserLevelChangedMQMsg msg = new Gson().fromJson(new String(message.getBody()),
|
| | | UserLevelChangedMQMsg.class);
|
| | | // 更新上2级的邀请统计
|
| | | teamUserLevelStatisticService.updateUserLevel(msg.getUid());
|
| | | UserInfo boss = threeSaleSerivce.getBoss(msg.getUid());
|
| | | if (boss != null) {
|
| | | teamUserLevelStatisticService.initData(boss.getId());
|
| | | boss = threeSaleSerivce.getBoss(boss.getId());
|
| | | if (boss != null) {
|
| | | teamUserLevelStatisticService.initData(boss.getId());
|
| | | }
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | } else if (tag.equalsIgnoreCase(UserTopicTagEnum.threeSaleSeparate.name())) {// 邀请关系脱离
|
| | | ThreeSaleSeparateMQMsg msg = new Gson().fromJson(new String(message.getBody()),
|
| | | ThreeSaleSeparateMQMsg.class);
|
| | | // 更新上两级邀请统计
|
| | | teamUserLevelStatisticService.initData(msg.getBossUid());
|
| | | UserInfo boss = threeSaleSerivce.getBoss(msg.getBossUid());
|
| | | if (boss != null) {
|
| | | teamUserLevelStatisticService.initData(boss.getId());
|
| | | }
|
| | | return Action.CommitMessage;
|
| | | }
|
| | |
|
| | | } else if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) {
|
| | | // 订单到账相关
|
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) {
|
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()),
|
| | | OrderMoneyRecievedMQMsg.class);
|
| | | if (dto != null) {
|
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {// 自购到账
|
| | | // 会员升级-自购订单数量验证
|
| | | userVIPPreInfoService.upgradeVipByFanLiOrder(dto.getUid());
|
| | | } else if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) {// 分享到账
|
| | | // 会员升级-分享订单数量验证
|
| | | userVIPPreInfoService.upgradeVipByShareOrder(dto.getUid());
|
| | | }
|
| | | }
|
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderConfirm.name())) {
|
| | | OrderConfirmMQMsg dto = new Gson().fromJson(new String(message.getBody()),OrderConfirmMQMsg.class);
|
| | | if (dto != null) {
|
| | | // 会员等级升级-粉丝数量验证
|
| | | userVIPPreInfoService.upgradeVipByTeamNum(dto.getSourceUid());
|
| | | userInviteValidNumService.addValidTeamNum(dto.getSourceUid(), dto.getSettleMent(), dto.getPlaceOrderTime());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | return Action.CommitMessage;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.util.rocketmq.consumer.user; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemFunction; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPUpgradeException; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.util.SystemInfoUtil; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.aliyun.openservices.ons.api.Action; |
| | | import com.aliyun.openservices.ons.api.ConsumeContext; |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.MessageListener; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.user.body.ThreeSaleSeparateMQMsg; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserLevelChangedMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; |
| | | import com.yeshi.fanli.service.inter.user.invite.UserInviteValidNumService; |
| | | import com.yeshi.fanli.service.inter.user.vip.TeamUserLevelStatisticService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.VersionUtil; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | |
| | | /** |
| | | * 用户超级会员 |
| | | * |
| | | * @author Administrator |
| | | */ |
| | | @Component |
| | | public class UserVIPMessageListener implements MessageListener { |
| | | |
| | | @Resource |
| | | private UserVIPPreInfoService userVIPPreInfoService; |
| | | |
| | | @Resource |
| | | private TeamUserLevelStatisticService teamUserLevelStatisticService; |
| | | |
| | | @Resource |
| | | private ThreeSaleSerivce threeSaleSerivce; |
| | | |
| | | @Resource |
| | | private UserInviteValidNumService userInviteValidNumService; |
| | | |
| | | @Resource |
| | | private UserActiveLogService userActiveLogService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | |
| | | @Override |
| | | public Action consume(Message message, ConsumeContext context) { |
| | | |
| | | LogHelper.mqInfo("consumer-UserVIPMessageListener", message.getMsgID(), message.getTopic(), message.getTag(), |
| | | new String(message.getBody())); |
| | | String tag = message.getTag(); |
| | | if (tag == null) |
| | | tag = ""; |
| | | |
| | | if (java.lang.System.currentTimeMillis() <= Constant.NEW_ORDER_FANLI_RULE_TIME) { |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | // 邀请相关 |
| | | if (MQTopicName.TOPIC_USER.name().equalsIgnoreCase(message.getTopic())) { |
| | | if (tag.equalsIgnoreCase(UserTopicTagEnum.userLevelChanged.name())) {// 用户等级发生变化 |
| | | UserLevelChangedMQMsg msg = new Gson().fromJson(new String(message.getBody()), |
| | | UserLevelChangedMQMsg.class); |
| | | |
| | | //判断系统是否有三级分销功能 |
| | | Long sourceUid = msg.getUid(); |
| | | SystemEnum system = userInfoService.getUserSystem(sourceUid); |
| | | if (!SystemInfoUtil.hasFunctions(system, SystemFunction.threeSale, SystemFunction.vip)) |
| | | return Action.CommitMessage; |
| | | |
| | | for (Long fuid : Constant.NO_UPGRADE_UIDS) {// 禁止不能升级的用户升级 |
| | | if (msg.getUid().longValue() == fuid) |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | |
| | | // 更新上2级的邀请统计 |
| | | teamUserLevelStatisticService.updateUserLevel(msg.getUid()); |
| | | UserInfo boss = threeSaleSerivce.getBoss(msg.getUid()); |
| | | if (boss != null) { |
| | | teamUserLevelStatisticService.initData(boss.getId()); |
| | | boss = threeSaleSerivce.getBoss(boss.getId()); |
| | | if (boss != null) { |
| | | teamUserLevelStatisticService.initData(boss.getId()); |
| | | } |
| | | } |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | } else if (MQTopicName.TOPIC_ORDER.name().equalsIgnoreCase(message.getTopic())) { |
| | | // 订单到账相关 |
| | | if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderFanLiActual.name())) { |
| | | OrderMoneyRecievedMQMsg dto = new Gson().fromJson(new String(message.getBody()), |
| | | OrderMoneyRecievedMQMsg.class); |
| | | |
| | | if (dto != null) { |
| | | SystemEnum system = userInfoService.getUserSystem(dto.getUid()); |
| | | if (!SystemInfoUtil.hasFunctions(system, SystemFunction.vip)) |
| | | return Action.CommitMessage; |
| | | for (Long fuid : Constant.NO_UPGRADE_UIDS) {// 禁止不能升级的用户升级 |
| | | if (dto.getUid().longValue() == fuid) |
| | | return Action.CommitMessage; |
| | | } |
| | | // 判断版本 |
| | | UserActiveLog log = userActiveLogService.getUserLatestActiveInfo(dto.getUid()); |
| | | if (log == null || !VersionUtil.greaterThan_2_1( |
| | | "appstore".equalsIgnoreCase(log.getChannel()) ? "ios" : "android", log.getVersionCode())) { |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_ZIGOU) {// 自购到账 |
| | | // 会员升级-自购订单数量验证 |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByMyOrder(dto.getUid()); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if (dto.getType() == OrderMoneyRecievedMQMsg.TYPE_SHARE) {// 分享到账 |
| | | // 会员升级-分享订单数量验证 |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByMyOrder(dto.getUid()); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else if (tag.equalsIgnoreCase(OrderTopicTagEnum.orderConfirm.name())) { |
| | | OrderConfirmMQMsg dto = new Gson().fromJson(new String(message.getBody()), OrderConfirmMQMsg.class); |
| | | if (dto != null) { |
| | | SystemEnum system = userInfoService.getUserSystem(dto.getSourceUid()); |
| | | if (!SystemInfoUtil.hasFunctions(system, SystemFunction.vip)) |
| | | return Action.CommitMessage; |
| | | for (Long fuid : Constant.NO_UPGRADE_UIDS) {// 禁止不能升级的用户升级 |
| | | if (dto.getSourceUid().longValue() == fuid) |
| | | return Action.CommitMessage; |
| | | } |
| | | |
| | | // 会员等级升级-粉丝数量验证 |
| | | try { |
| | | userVIPPreInfoService.upgradeVipByTeamNum(dto.getSourceUid()); |
| | | } catch (UserVIPUpgradeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | userInviteValidNumService.addValidTeamNum(dto.getSourceUid(), dto.getSettleMent(), |
| | | dto.getPlaceOrderTime()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return Action.CommitMessage; |
| | | } |
| | | } |