use of com.code.server.db.model.Recommend in project summer by foxsugar.
the class SubscribeHandler method handleSpecial.
/**
* 处理特殊请求,比如如果是扫码进来的,可以做相应处理
*/
private WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage, WxMpUser wxMpUser, WxMpService wxMpService) {
// 如果是扫码登录
String eventKey = wxMessage.getEventKey();
if (eventKey == null || "".equals(eventKey)) {
return null;
}
String[] s = eventKey.split("_");
logger.info("eventKey = " + eventKey);
if ("qrscene".equals(s[0])) {
String referrerUnionId = eventKey.split("qrscene_")[1];
// "|" 的分隔符要转义
String[] sp = referrerUnionId.split("\\|");
if (sp.length > 1) {
referrerUnionId = sp[1];
}
String unionId = wxMpUser.getUnionId();
// 这个人是否已经点过
// todo 自己不能推荐自己
Recommend recommend = recommendService.getRecommendDao().getByUnionId(unionId);
long agentId = userService.getUserDao().getIdByOpenId(referrerUnionId);
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean == null) {
return null;
}
boolean isSelf = referrerUnionId.equals(unionId);
StringBuilder sb = new StringBuilder(wxMpUser.getNickname() + "扫描您的专属二维码,");
if (recommend == null && !isSelf) {
recommend = new Recommend();
recommend.setUnionId(unionId).setAgentId(agentId);
// 保存
recommendService.getRecommendDao().save(recommend);
sb.append("成功绑定");
} else {
// 通知 代理 有人绑定他
// String name = wxMpUser.getNickname();
// 这个人如果已经是玩家 并且玩家没有上级 那么成为这个人的下级
User user = userService.getUserDao().getUserByOpenId(unionId);
if (user != null) {
long userId = user.getId();
boolean userIsAgnet = RedisManager.getAgentRedisService().isExit(userId);
// 点击者已经是代理
if (userIsAgnet) {
sb.append("但已成为代理");
} else {
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean != null) {
if (userBean.getReferee() == 0) {
userBean.setReferee((int) agentId);
RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (userBean.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
} else {
if (user.getReferee() == 0) {
user.setReferee((int) agentId);
userService.save(user);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (user.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
}
}
}
try {
wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(sb.toString()).build());
} catch (WxErrorException e) {
e.printStackTrace();
}
}
// TODO
return null;
}
return null;
}
use of com.code.server.db.model.Recommend in project summer by foxsugar.
the class LoginAction method login4sqlByOpenId.
private int login4sqlByOpenId(String openId, String unionId, String userName, String img, int sex, Map<String, Object> params) {
User user = userService.getUserByOpenId(openId);
// 查询数据库,没有新建玩家
if (user == null) {
// 新建玩家
user = createUser(openId, unionId, userName, img, sex);
// 代理推荐情况
Recommend recommend = recommendService.getRecommendDao().getByUnionId(openId);
if (recommend != null) {
// 玩家设置代理
user.setReferee((int) recommend.getAgentId());
}
// 保存
userService.save(user);
ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
if (!"".equals(serverConfig.getQrDir())) {
ZXingUtil.createQrCode(user.getId());
}
// reids 记录新增玩家
RedisManager.getLogRedisService().logRegisterUser();
if (recommend != null) {
// 代理多了一个玩家
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(recommend.getAgentId());
if (agentBean != null) {
if (!agentBean.getChildList().contains(user.getId())) {
agentBean.getChildList().add(user.getId());
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
}
// 通知
try {
wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(userName + " 下载并进入游戏,和您成功绑定").build());
} catch (WxErrorException e) {
e.printStackTrace();
}
}
}
}
String token = getToken(user.getId());
saveUser2Redis(user, token);
params.put("token", token);
params.put("userId", "" + user.getId());
return 0;
}
use of com.code.server.db.model.Recommend in project summer by foxsugar.
the class LoginAction method login4sqlByOpenIdAndIP.
private int login4sqlByOpenIdAndIP(String openId, String unionId, String userName, String img, int sex, Map<String, Object> params, String ip) {
User user = userService.getUserByOpenId(openId);
// 查询数据库,没有新建玩家
boolean addRebate = false;
if (user == null) {
// 新建玩家
user = createUser(openId, unionId, userName, img, sex);
// 代理推荐情况
Recommend recommend = recommendService.getRecommendDao().getByUnionId(ip);
if (recommend != null) {
// 玩家设置代理
user.setReferee((int) recommend.getAgentId());
}
// 保存
userService.save(user);
ServerConfig serverConfig = SpringUtil.getBean(ServerConfig.class);
if (!"".equals(serverConfig.getQrDir())) {
ZXingUtil.createQrCode(user.getId());
}
if (recommend != null) {
addRebate = true;
}
// reids 记录新增玩家
RedisManager.getLogRedisService().logRegisterUser();
}
String token = getToken(user.getId());
saveUser2Redis(user, token);
if (addRebate) {
CenterMsgService.addRebate(user.getId(), 0D);
}
params.put("token", token);
params.put("userId", "" + user.getId());
return 0;
}
use of com.code.server.db.model.Recommend in project summer by foxsugar.
the class PaysapiOrder method invite.
@RequestMapping(value = "/invite")
public String invite(long userId, RedirectAttributes attr, HttpServletRequest request) throws Exception {
String ip = Utils.getIpAddr(request);
Recommend recommend = new Recommend();
recommend.setUnionId(ip);
recommend.setAgentId(userId);
recommendService.getRecommendDao().save(recommend);
ModelAndView modelAndView = new ModelAndView();
return "/success";
// modelAndView.setViewName("redirect:https://pay.sxhhjc.cn/");
// return modelAndView;
}
use of com.code.server.db.model.Recommend in project summer by foxsugar.
the class WechatAction method clickLink.
/**
* 点击分享链接
*
* @param code
* @param state
* @param request
* @param response
* @throws IOException
*/
@GetMapping("/clickLink")
public void clickLink(@RequestParam("code") String code, @RequestParam("state") String state, HttpServletRequest request, HttpServletResponse response) throws IOException {
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = new WxMpOAuth2AccessToken();
try {
logger.info("------------- 点击分享链接-----------");
wxMpOAuth2AccessToken = wxMpService.oauth2getAccessToken(code);
WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
// state 是id
long agentId = Long.valueOf(state);
// 代理不存在 直接退出
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
if (agentBean == null)
return;
String unionId = wxMpUser.getUnionId();
boolean isSelf = agentBean.getUnionId().equals(unionId);
if (isSelf) {
// 处理跳转
handle_link_redirect(agentId, response);
return;
}
// 通知 代理 有人绑定他
String name = wxMpUser.getNickname();
StringBuilder sb = new StringBuilder();
sb.append(name).append(" 已点击您的专属链接,");
// 这个人是否已经点过
// 这个人如果已经是玩家 并且玩家没有上级 那么成为这个人的下级
User user = userService.getUserDao().getUserByOpenId(unionId);
if (user != null) {
long userId = user.getId();
boolean userIsAgnet = RedisManager.getAgentRedisService().isExit(userId);
// 点击者已经是代理
if (userIsAgnet) {
sb.append("但已成为代理");
} else {
UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
if (userBean != null) {
if (userBean.getReferee() == 0) {
userBean.setReferee((int) agentId);
RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (userBean.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
} else {
if (user.getReferee() == 0) {
user.setReferee((int) agentId);
userService.save(user);
agentBean.getChildList().add(userId);
RedisManager.getAgentRedisService().updateAgentBean(agentBean);
sb.append("已和您成功绑定");
} else {
if (user.getReferee() == agentId) {
sb.append("已经和您建立过绑定关系");
} else {
sb.append("但已绑定其他代理");
}
}
}
}
} else {
Recommend recommend = recommendService.getRecommendDao().getByUnionId(unionId);
if (recommend == null) {
recommend = new Recommend();
recommend.setUnionId(unionId).setAgentId(agentId);
// 保存
recommendService.getRecommendDao().save(recommend);
sb.append("已和您成功绑定");
}
}
try {
wxMpService.getKefuService().sendKefuMessage(WxMpKefuMessage.TEXT().toUser(agentBean.getOpenId()).content(sb.toString()).build());
} catch (WxErrorException e) {
logger.error("【clickLink】{}", e);
}
// 处理跳转
handle_link_redirect(agentId, response);
} catch (WxErrorException e) {
}
}
Aggregations