| | |
| | | package com.yeshi.fanli.controller.wxmp.v1;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpSession;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.entity.wx.WXMPSessionInfo;
|
| | | import org.yeshi.utils.wx.WXXCXUtil;
|
| | |
|
| | | import com.yeshi.fanli.dto.WXMPAcceptData;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
|
| | | import com.yeshi.fanli.exception.user.UserInfoException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.service.inter.user.MaskKeyService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller("WXMPUserController")
|
| | | @RequestMapping("/wxmp/api/v1/user")
|
| | | public class UserController {
|
| | |
|
| | | public final static String WXMP_SESSION_INFO_KEY = "WXMP-SESSION-INFO";
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | | |
| | | @Resource
|
| | | private MaskKeyService maskKeyService;
|
| | | |
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | | |
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | | |
| | | @Resource
|
| | | private UserVIPInfoService userVIPInfoService;
|
| | |
|
| | | /**
|
| | | * 获取openId
|
| | | * |
| | | * @param acceptData
|
| | | * @param code
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping("getOpenId")
|
| | | public void getOpenId(WXMPAcceptData acceptData, String code, HttpSession session, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(code)) {
|
| | | out.print(JsonUtil.loadFalseResult("code为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | WXMPSessionInfo info = WXXCXUtil.getSessionInfo(Constant.WXMP_APP_INFO, code);
|
| | | if (info != null) {
|
| | | session.setAttribute(WXMP_SESSION_INFO_KEY, info);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("openId", info.getOpenId());
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("openId获取失败"));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | @RequestMapping(value = "saveInfo")
|
| | | public void saveInfo(AcceptData acceptData, String nickName, String weiXin, Integer sex, Long uid,
|
| | | String inviteCode, MultipartFile qrCodeFile, HttpServletRequest request, PrintWriter out) {
|
| | | try {
|
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 修改昵称
|
| | | if (!StringUtil.isNullOrEmpty(nickName)) {
|
| | | if (nickName.length() > 200) {
|
| | | out.print(JsonUtil.loadFalseResult("昵称过长"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (maskKeyService.examineContent(nickName)) {
|
| | | out.print(JsonUtil.loadFalseResult("不能包含敏感词汇"));
|
| | | return;
|
| | | }
|
| | | userInfoService.saveUserInfo(nickName, uid);
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.nickName, nickName);
|
| | | }
|
| | |
|
| | | // 修改微信号
|
| | | if (!StringUtil.isNullOrEmpty(weiXin)) {
|
| | | if (weiXin.length() > 32) {
|
| | | out.print(JsonUtil.loadFalseResult("微信号过长"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra != null) {
|
| | | UserInfoExtra extra = new UserInfoExtra();
|
| | | extra.setId(userInfoExtra.getId());
|
| | | extra.setWeiXin(weiXin);
|
| | | userInfoExtraService.saveUserInfoExtra(extra);
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.setWeiXinNum, weiXin);
|
| | | }
|
| | | }
|
| | |
|
| | | // 修改性别
|
| | | if (sex != null && sex > 0 && sex < 3) {
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra != null) {
|
| | | UserInfoExtra extra = new UserInfoExtra();
|
| | | extra.setId(userInfoExtra.getId());
|
| | | extra.setSex(sex);
|
| | | userInfoExtraService.saveUserInfoExtra(extra);
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.gender, sex + "");
|
| | | }
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {// 邀请码不为空
|
| | | inviteCode = inviteCode.trim();
|
| | | if (inviteCode.length() >= 4 && inviteCode.length() <= 12) {
|
| | |
|
| | | if (!userVIPInfoService.isVIP(uid)) {
|
| | | out.print(JsonUtil.loadFalseResult(20, "只有超级会员才能修改"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | userInfoExtraService.updateInviteCodeVip(inviteCode, uid);
|
| | | out.print(JsonUtil.loadTrueResult("保存成功"));
|
| | | return;
|
| | | } catch (UserInfoExtraException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
|
| | | }
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(1, "邀请码必须为4到12位"));
|
| | | return;
|
| | | }
|
| | | }
|
| | | |
| | | // 二维码
|
| | | if (qrCodeFile != null) {
|
| | | userInfoExtraService.uploadERCode(qrCodeFile, uid);
|
| | | }
|
| | | |
| | | |
| | | |
| | | out.print(JsonUtil.loadTrueResult("保存成功"));
|
| | | } catch (UserInfoException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getMsg()));
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("保存失败"));
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.wxmp.v1; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.entity.wx.WXMPSessionInfo; |
| | | import org.yeshi.utils.wx.WXXCXUtil; |
| | | |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.fanli.dto.WXMPAcceptData; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum; |
| | | import com.yeshi.fanli.entity.system.BusinessSystem; |
| | | import com.yeshi.fanli.exception.user.UserInfoException; |
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException; |
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.user.MaskKeyService; |
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService; |
| | | import com.yeshi.fanli.service.inter.user.UserCustomSettingsService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService; |
| | | import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.ThreadUtil; |
| | | import com.yeshi.fanli.util.VersionUtil; |
| | | import com.yeshi.fanli.util.annotation.UserActive; |
| | | import com.yeshi.fanli.vo.user.UserInfoExtraVO; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller("WXMPUserController") |
| | | @RequestMapping("/wxmp/api/v1/user") |
| | | public class UserController { |
| | | |
| | | public final static String WXMP_SESSION_INFO_KEY = "WXMP-SESSION-INFO"; |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | @Resource |
| | | private MaskKeyService maskKeyService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserInfoModifyRecordService userInfoModifyRecordService; |
| | | |
| | | @Resource |
| | | private UserVIPInfoService userVIPInfoService; |
| | | |
| | | @Resource |
| | | private UserActiveLogService userActiveLogService; |
| | | |
| | | @Resource |
| | | private BusinessSystemService businessSystemService; |
| | | |
| | | @Resource |
| | | private UserCustomSettingsService userCustomSettingsService; |
| | | |
| | | @Resource |
| | | private ThreeSaleSerivce threeSaleSerivce; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private UserVipConfigService userVipConfigService; |
| | | |
| | | /** |
| | | * 获取openId |
| | | * |
| | | * @param acceptData |
| | | * @param code |
| | | * @param out |
| | | */ |
| | | @RequestMapping("getOpenId") |
| | | public void getOpenId(WXMPAcceptData acceptData, String code, HttpSession session, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(code)) { |
| | | out.print(JsonUtil.loadFalseResult("code为空")); |
| | | return; |
| | | } |
| | | |
| | | WXMPSessionInfo info = WXXCXUtil.getSessionInfo(Constant.WXMP_APP_INFO, code); |
| | | if (info != null) { |
| | | session.setAttribute(WXMP_SESSION_INFO_KEY, info); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("openId", info.getOpenId()); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult("openId获取失败")); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "saveInfo") |
| | | public void saveInfo(AcceptData acceptData, String nickName, String weiXin, Integer sex, Long uid, |
| | | String inviteCode, MultipartFile qrCodeFile, HttpServletRequest request, PrintWriter out) { |
| | | try { |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | // 修改昵称 |
| | | if (!StringUtil.isNullOrEmpty(nickName)) { |
| | | if (nickName.length() > 200) { |
| | | out.print(JsonUtil.loadFalseResult("昵称过长")); |
| | | return; |
| | | } |
| | | |
| | | if (maskKeyService.examineContent(nickName)) { |
| | | out.print(JsonUtil.loadFalseResult("不能包含敏感词汇")); |
| | | return; |
| | | } |
| | | userInfoService.saveUserInfo(nickName, uid); |
| | | |
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.nickName, nickName); |
| | | } |
| | | |
| | | // 修改微信号 |
| | | if (!StringUtil.isNullOrEmpty(weiXin)) { |
| | | if (weiXin.length() > 32) { |
| | | out.print(JsonUtil.loadFalseResult("微信号过长")); |
| | | return; |
| | | } |
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (userInfoExtra != null) { |
| | | UserInfoExtra extra = new UserInfoExtra(); |
| | | extra.setId(userInfoExtra.getId()); |
| | | extra.setWeiXin(weiXin); |
| | | userInfoExtraService.saveUserInfoExtra(extra); |
| | | |
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.setWeiXinNum, weiXin); |
| | | } |
| | | } |
| | | |
| | | // 修改性别 |
| | | if (sex != null && sex > 0 && sex < 3) { |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (userInfoExtra != null) { |
| | | UserInfoExtra extra = new UserInfoExtra(); |
| | | extra.setId(userInfoExtra.getId()); |
| | | extra.setSex(sex); |
| | | userInfoExtraService.saveUserInfoExtra(extra); |
| | | |
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.gender, sex + ""); |
| | | } |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {// 邀请码不为空 |
| | | inviteCode = inviteCode.trim(); |
| | | if (inviteCode.length() >= 4 && inviteCode.length() <= 12) { |
| | | |
| | | if (!userVIPInfoService.isVIP(uid)) { |
| | | out.print(JsonUtil.loadFalseResult(20, "只有超级会员才能修改")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | userInfoExtraService.updateInviteCodeVip(inviteCode, uid); |
| | | out.print(JsonUtil.loadTrueResult("保存成功")); |
| | | return; |
| | | } catch (UserInfoExtraException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); |
| | | } |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult(1, "邀请码必须为4到12位")); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 二维码 |
| | | if (qrCodeFile != null) { |
| | | userInfoExtraService.uploadERCode(qrCodeFile, uid); |
| | | } |
| | | |
| | | out.print(JsonUtil.loadTrueResult("保存成功")); |
| | | } catch (UserInfoException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | e.printStackTrace(); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("保存失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | private void outUserInfoHandle(UserInfo user) { |
| | | |
| | | // 红包处理 |
| | | user.setTotalHongBao(new BigDecimal(0)); |
| | | user.setNoOpenHongBao(new BigDecimal(0)); |
| | | user.setCanOpenHongBao(new BigDecimal(0)); |
| | | |
| | | // 电话号码处理 |
| | | if (!StringUtil.isNullOrEmpty(user.getPhone())) { |
| | | if (user.getPhone().length() > 5) { |
| | | String phone = user.getPhone().substring(0, 3); |
| | | phone += "******"; |
| | | phone += user.getPhone().substring(user.getPhone().length() - 2, user.getPhone().length()); |
| | | user.setPhone(phone); |
| | | } |
| | | } |
| | | |
| | | UserInfoExtraVO userInfoExtra = userInfoExtraService.getInfoExtraVOByUid(user.getId()); |
| | | if (userInfoExtra != null && userInfoExtra.getUserRank() != null) { |
| | | String picture = userInfoExtra.getUserRank().getPicture(); |
| | | String icon = userInfoExtra.getUserRank().getIcon(); |
| | | user.setRankNamePicture(picture); |
| | | user.setRankIcon(icon); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | | * @param acceptData |
| | | * @param form |
| | | * @param requst |
| | | * @param out |
| | | */ |
| | | @UserActive(uid = "#uid") |
| | | @RequestMapping(value = "getUserInfo") |
| | | public void getuserinfoNew(WXMPAcceptData acceptData, Long uid, HttpServletRequest requst, PrintWriter out) { |
| | | try { |
| | | BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), |
| | | acceptData.getAppId(),acceptData.getSystem()); |
| | | if (system == null) { |
| | | out.print(JsonUtil.loadFalseResult("系统不存在")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("请求参数为空")); |
| | | return; |
| | | } |
| | | |
| | | UserInfo userInfo = userInfoService.getUserInfo(uid); |
| | | |
| | | // 添加用户活跃记录 |
| | | UserActiveLog userActiveLog = new UserActiveLog(); |
| | | userActiveLog.setChannel("wxmp"); |
| | | userActiveLog.setIp(requst.getRemoteHost()); |
| | | userActiveLog.setUid(userInfo.getId()); |
| | | userActiveLog.setVersionCode(acceptData.getVersion()); |
| | | userActiveLog.setOsVersion(acceptData.getWxVersion()); |
| | | userActiveLog.setDeviceType("wxmp"); |
| | | userActiveLog.setDevice(acceptData.getDevice()); |
| | | userActiveLogService.addUserActiveLog(userActiveLog); |
| | | |
| | | |
| | | // 处理用户信息 |
| | | outUserInfoHandle(userInfo); |
| | | userInfo.setVip(userVIPInfoService.isVIP(uid)); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | JSONObject data = new JSONObject(); |
| | | |
| | | boolean tailor = false; |
| | | int welfareCenterNews = 0; |
| | | String invitCode = null; |
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (userInfoExtra != null) { |
| | | if (userInfoExtra.getCouponNews() != null) { |
| | | welfareCenterNews = userInfoExtra.getCouponNews(); |
| | | } |
| | | // vip邀请码优先 |
| | | if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) { |
| | | invitCode = userInfoExtra.getInviteCodeVip(); |
| | | } else if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) { |
| | | tailor = true; |
| | | invitCode = userInfoExtra.getInviteCode(); |
| | | } |
| | | |
| | | if (userInfoExtra.getUserRank() != null) { |
| | | String picture = userInfoExtra.getUserRank().getPicture(); |
| | | String icon = userInfoExtra.getUserRank().getIcon(); |
| | | userInfo.setRankNamePicture(picture); |
| | | userInfo.setRankIcon(icon); |
| | | } else { |
| | | userInfo.setRankNamePicture(null); |
| | | userInfo.setRankIcon(null); |
| | | } |
| | | |
| | | if (userInfoExtra.getSex() != null) |
| | | userInfo.setSex(userInfoExtra.getSex()); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(userInfoExtra.getWeiXin())) |
| | | userInfo.setWeiXin(userInfoExtra.getWeiXin()); |
| | | |
| | | // 二维码 |
| | | userInfo.setErCode(userInfoExtra.getErCode()); |
| | | } |
| | | // 显示邀请码特制入口 |
| | | data.put("tailor", tailor); |
| | | |
| | | userInfo.setWeiXinTip("添加微信号后,你的邀请人和直接粉丝可以通过微信与你建立联系。"); |
| | | |
| | | data.put("user", JsonUtil.getConvertBigDecimalToStringBuilder(gsonBuilder).create().toJson(userInfo)); |
| | | data.put("invitCode", invitCode); // 邀请码 |
| | | if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) |
| | | data.put("invitCodeUpdated", true);// 邀请码是否已经修改过 |
| | | else |
| | | data.put("invitCodeUpdated", false); |
| | | data.put("vipLink", userVipConfigService.getValueByKey("vip_link"));// 超级会员升级链接 |
| | | |
| | | if (!StringUtil.isNullOrEmpty(invitCode)) { |
| | | String bossName = ""; |
| | | ThreeSale threeSale = threeSaleSerivce.getMyBoss(uid); |
| | | if (threeSale != null && threeSale.getBoss() != null) { |
| | | bossName = threeSale.getBoss().getNickName(); |
| | | } |
| | | data.put("bossName", bossName); |
| | | } |
| | | |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | |
| | | final UserInfo uuser = userInfo; |
| | | ThreadUtil.run(new Runnable() { |
| | | public void run() { |
| | | // 获取邀请码:若无邀请码且存在有效的队员关系 则自动生成邀请码 |
| | | userInfoExtraService.getInviteCodeByUid(uuser.getId()); |
| | | |
| | | // 更新用户附加信息,老用户不存在的需要添加 |
| | | try { |
| | | userInfoExtraService.updateUserRankByUid(uuser.getId()); |
| | | } catch (UserInfoExtraException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } catch (UserInfoException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("获取失败")); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |