| | |
| | | package com.yeshi.fanli.controller.wxmp.v1;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.lang.reflect.Type;
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | 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.yeshi.utils.IPUtil;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.entity.wx.WXMPSessionInfo;
|
| | | import org.yeshi.utils.entity.wx.WXMPUserInfo;
|
| | | import org.yeshi.utils.wx.WXXCXUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.JsonElement;
|
| | | import com.google.gson.JsonPrimitive;
|
| | | import com.google.gson.JsonSerializationContext;
|
| | | import com.google.gson.JsonSerializer;
|
| | | import com.yeshi.fanli.dto.WXMPAcceptData;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginData;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginResult;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.SMSHistory;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
|
| | | import com.yeshi.fanli.entity.shop.BanLiShopOrder;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
|
| | | import com.yeshi.fanli.service.inter.money.UserMoneyDetailService;
|
| | | import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.wx.WXMPUserLoginService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.ThreadUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.vo.user.UserVipRateVO;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller("WXMPUserAccountController")
|
| | | @RequestMapping("/wxmp/api/v1/useraccount")
|
| | | public class UserAccountController {
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserAccountService userAccountService;
|
| | |
|
| | | @Resource
|
| | | private WXMPUserLoginService wxMPUserLoginService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Resource
|
| | | private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailService userMoneyDetailService;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | | @Resource
|
| | | private UserVIPInfoService userVIPInfoService;
|
| | | |
| | | @Resource
|
| | | private UserVipConfigService userVipConfigService;
|
| | | |
| | | @Resource
|
| | | private BanLiShopOrderService banLiShopOrderService;
|
| | | |
| | | @Resource
|
| | | private HongBaoV2CountService hongBaoV2CountService;
|
| | |
|
| | | |
| | | /**
|
| | | * 通过邀请码获取用户信息
|
| | | * |
| | | * @param acceptData
|
| | | * @param inviteCode
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping("getInviteCodeInfo")
|
| | | public void getInviteCodeInfo(WXMPAcceptData acceptData, String inviteCode, PrintWriter out) {
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | out.print(JsonUtil.loadFalseResult("邀请码为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | UserInfo userInfo = userInfoExtraService.getUserByInviteCode(inviteCode);
|
| | | if (userInfo != null && userInfo.getState() == UserInfo.STATE_NORMAL) {
|
| | | JSONObject json = new JSONObject();
|
| | | json.put("id", userInfo.getId());
|
| | | json.put("nickName", userInfo.getNickName());
|
| | | json.put("portrait", userInfo.getPortrait());
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("user", json);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | return;
|
| | | }
|
| | | } catch (UserInfoExtraException e) {
|
| | |
|
| | | }
|
| | | out.print(JsonUtil.loadFalseResult("邀请码不存在"));
|
| | | }
|
| | |
|
| | | @RequestMapping("phoneLogin")
|
| | | public void phoneLogin(WXMPAcceptData acceptData, String code, String phoneEncryptedData, String phoneIv,
|
| | | String inviteCode, String userData, HttpServletRequest request, HttpSession session, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) {
|
| | | out.print(JsonUtil.loadFalseResult("openId为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(phoneEncryptedData) || StringUtil.isNullOrEmpty(phoneIv)) {
|
| | | out.print(JsonUtil.loadFalseResult("电话加密数据为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | String sessionKey = null;
|
| | | WXMPSessionInfo sessionInfo = (WXMPSessionInfo) session.getAttribute(UserController.WXMP_SESSION_INFO_KEY);
|
| | | if (sessionInfo == null) {
|
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | sessionKey = sessionInfo.getSessionKey();
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(sessionKey)) {
|
| | | out.print(JsonUtil.loadFalseResult("code无效"));
|
| | | return;
|
| | | }
|
| | | String phoneNumber = WXXCXUtil.getPhoneNumber(sessionKey, phoneEncryptedData, phoneIv);
|
| | | if (StringUtil.isNullOrEmpty(phoneNumber)) {
|
| | | out.print(JsonUtil.loadFalseResult("获取电话号码失败"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfo boss = null;
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | try {
|
| | | boss = userInfoExtraService.getUserByInviteCode(inviteCode);
|
| | | } catch (UserInfoExtraException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (boss != null && boss.getState() != UserInfo.STATE_NORMAL)
|
| | | boss = null;
|
| | | }
|
| | |
|
| | | UserInfo lastUserInfo = null;
|
| | | if (!StringUtil.isNullOrEmpty(userData)) {
|
| | | String redisKey = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, StringUtil.Md5(acceptData.getAppId() + "-" + acceptData.getOpenId()));
|
| | | String data = redisManager.getCommonString(redisKey);
|
| | | if (!StringUtil.isNullOrEmpty(data)) {
|
| | | lastUserInfo = new Gson().fromJson(data, UserInfo.class);
|
| | | }
|
| | | }
|
| | |
|
| | | try {
|
| | | WXMPLoginResult result = wxMPUserLoginService.wxmpLogin(new WXMPLoginData.Builder(Constant.APPID)
|
| | | .setBoss(boss).setLastUser(lastUserInfo).setPhone(phoneNumber).build());
|
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out);
|
| | | } catch (UserAccountException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @RequestMapping("wxLogin")
|
| | | public void wxLogin(WXMPAcceptData acceptData, String wxEncryptedData, String wxIv, String inviteCode,
|
| | | HttpServletRequest request, HttpSession session, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) {
|
| | | out.print(JsonUtil.loadFalseResult("openId为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(wxEncryptedData) || StringUtil.isNullOrEmpty(wxIv)) {
|
| | | out.print(JsonUtil.loadFalseResult("微信用户加密数据为空"));
|
| | | return;
|
| | | }
|
| | | WXMPSessionInfo sessionInfo = (WXMPSessionInfo) session.getAttribute(UserController.WXMP_SESSION_INFO_KEY);
|
| | | if (sessionInfo == null) {
|
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | String sessionKey = sessionInfo.getSessionKey();
|
| | | if (StringUtil.isNullOrEmpty(sessionKey)) {
|
| | | out.print(JsonUtil.loadFalseResult("code无效"));
|
| | | return;
|
| | | }
|
| | |
|
| | | WXMPUserInfo userInfo = WXXCXUtil.getUserInfo(sessionKey, wxEncryptedData, wxIv);
|
| | | if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUnionId())) {
|
| | | out.print(JsonUtil.loadFalseResult("获取微信信息失败"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | WXMPLoginResult result = wxMPUserLoginService
|
| | | .wxmpLogin(new WXMPLoginData.Builder(Constant.APPID).setWxUser(userInfo).build());
|
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out);
|
| | | } catch (UserAccountException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | @RequestMapping("bindInviteCode")
|
| | | public void bindInviteCode(WXMPAcceptData acceptData, String inviteCode, String userData,
|
| | | HttpServletRequest request, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) {
|
| | | out.print(JsonUtil.loadFalseResult("openId为空"));
|
| | | return;
|
| | | }
|
| | | if (StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | out.print(JsonUtil.loadFalseResult("邀请码为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, StringUtil.Md5(acceptData.getAppId() + "-" + acceptData.getOpenId()));
|
| | |
|
| | | UserInfo user = new Gson().fromJson(redisManager.getCommonString(key), UserInfo.class);
|
| | | if (user == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户数据为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfo boss = null;
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | try {
|
| | | boss = userInfoExtraService.getUserByInviteCode(inviteCode);
|
| | | } catch (UserInfoExtraException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (boss != null && boss.getState() != UserInfo.STATE_NORMAL)
|
| | | boss = null;
|
| | | }
|
| | |
|
| | | if (boss == null) {
|
| | | out.print(JsonUtil.loadFalseResult("邀请码有误"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | WXMPLoginResult result = wxMPUserLoginService
|
| | | .wxmpLogin(new WXMPLoginData.Builder(Constant.APPID).setLastUser(user).setBoss(boss).build());
|
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out);
|
| | | } catch (UserAccountException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | private void printWXMPLoginResult(String appId, String openId, WXMPLoginResult result, HttpServletRequest request,
|
| | | PrintWriter out) {
|
| | | JSONObject data = new JSONObject();
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, StringUtil.Md5(appId + "-" + openId));
|
| | |
|
| | | switch (result.getCode()) {
|
| | | case WXMPLoginResult.CODE_SUCCESS:
|
| | | UserInfo user = userInfoService.selectAvailableByPrimaryKey(result.getUser().getId());
|
| | | data.put("user", UserUtil.filterForClientUser(user));
|
| | | data.put("type", 0);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | final String ip = IPUtil.getRemotIP(request);
|
| | | final int port = request.getRemotePort();
|
| | | ThreadUtil.run(new Runnable() {
|
| | |
|
| | | @Override
|
| | | public void run() {// 登录成功
|
| | | UserInfo update = new UserInfo(user.getId());
|
| | | update.setLastLoginTime(System.currentTimeMillis());
|
| | | update.setLastLoginIp(ip + ":" + port);
|
| | | userAccountService.updateUserSelective(update);
|
| | | }
|
| | | });
|
| | | break;
|
| | | case WXMPLoginResult.CODE_BIND_PHONE:
|
| | | // 需要绑定电话号码
|
| | | redisManager.saveObj(result.getUser(), key, 60 * 5);// 只缓存5分钟
|
| | | data.put("userData", key);
|
| | | data.put("type", 2);
|
| | | break;
|
| | | case WXMPLoginResult.CODE_BIND_INVITE_CODE:
|
| | | redisManager.saveObj(result.getUser(), key, 60 * 5);// 只缓存5分钟
|
| | | data.put("userData", key);
|
| | | data.put("type", 1);
|
| | | break;
|
| | | }
|
| | |
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | @RequestMapping("bindWX")
|
| | | public void bindWX(WXMPAcceptData acceptData, Long uid, String wxEncryptedData, String wxIv,
|
| | | HttpServletRequest request, HttpSession session, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) {
|
| | | out.print(JsonUtil.loadFalseResult("openId为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | if(uid==null){
|
| | | out.print(JsonUtil.loadFalseResult("uid为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(wxEncryptedData) || StringUtil.isNullOrEmpty(wxIv)) {
|
| | | out.print(JsonUtil.loadFalseResult("微信信息为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | WXMPSessionInfo sessionInfo = (WXMPSessionInfo) session.getAttribute(UserController.WXMP_SESSION_INFO_KEY);
|
| | | if (sessionInfo == null) {
|
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | String sessionKey = sessionInfo.getSessionKey();
|
| | | if (StringUtil.isNullOrEmpty(sessionKey)) {
|
| | | out.print(JsonUtil.loadFalseResult("code无效"));
|
| | | return;
|
| | | }
|
| | |
|
| | | WXMPUserInfo userInfo = WXXCXUtil.getUserInfo(sessionKey, wxEncryptedData, wxIv);
|
| | | if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUnionId())) {
|
| | | out.print(JsonUtil.loadFalseResult("获取微信信息失败"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 绑定微信
|
| | |
|
| | | WeiXinUser wxUser = new WeiXinUser();
|
| | | wxUser.setHeadimgurl(userInfo.getAvatarUrl());
|
| | | wxUser.setCity(userInfo.getCity());
|
| | | wxUser.setCountry(userInfo.getCountry());
|
| | | wxUser.setNickname(userInfo.getNickName());
|
| | | wxUser.setOpenid("");
|
| | | wxUser.setProvince(userInfo.getProvince());
|
| | | wxUser.setSex(userInfo.getGender());
|
| | | wxUser.setUnionid(userInfo.getUnionId());
|
| | |
|
| | | try {
|
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
|
| | | // 判断taoBaoUid是否已经封禁
|
| | | ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
|
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, user.getWxUnionId());
|
| | | if (ic != null && ic.getEffective() != null && ic.getEffective()) {
|
| | | out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
|
| | | // 封禁用户
|
| | | // 封禁绑定的正常用户
|
| | | if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
|
| | | userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的微信号");
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | userAccountService.bindWeiXin(uid, wxUser);
|
| | | user = userInfoService.getUserByIdWithMybatis(uid);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("user", UserUtil.filterForClientUser(user));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (UserAccountException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 绑定电话号码 V1.5.3
|
| | | * |
| | | * @param acceptData
|
| | | * @param vcode
|
| | | * @param phone
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "bindPhone")
|
| | | public void bindPhone(WXMPAcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(vcode)) {
|
| | | out.print(JsonUtil.loadFalseResult("验证码不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(phone)) {
|
| | | out.print(JsonUtil.loadFalseResult("电话号码不能为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | phone = phone.replaceAll(" ", "");
|
| | |
|
| | | String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_BIND);
|
| | | if (Constant.IS_OUTNET) {
|
| | | if (!vcode.equalsIgnoreCase(oldVCode)) {
|
| | | out.print(JsonUtil.loadFalseResult(9001, "验证码错误,重新输入"));
|
| | | return;
|
| | | }
|
| | | redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_BIND);
|
| | | }
|
| | |
|
| | | try {
|
| | | // 绑定用户
|
| | | userAccountService.bindPhoneNew(uid, phone);
|
| | |
|
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
|
| | | // 判断电话号码是否已经封禁
|
| | | ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
|
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
|
| | | if (ic != null && ic.getEffective() != null && ic.getEffective()) {
|
| | | out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
|
| | | // 封禁用户
|
| | | // 封禁绑定的正常用户
|
| | | if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
|
| | | userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的电话号码");
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("user", UserUtil.filterForClientUser(user));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (UserAccountException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "绑定失败"));
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 获取vip信息
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getVIPInfo")
|
| | | public void getVIPInfo(String callback, WXMPAcceptData acceptData, Long uid, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfo userInfo = userInfoService.selectByPKey(uid);
|
| | | if (userInfo == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "该用户不存在"));
|
| | | return;
|
| | | }
|
| | | //
|
| | | String inviteCode = userInfoExtraService.getInviteCodeByUid(uid);
|
| | |
|
| | | UserVipRateVO vo = new UserVipRateVO();
|
| | | vo.setId(uid);
|
| | | vo.setInviteCode(inviteCode);
|
| | | vo.setNickName(userInfo.getNickName());
|
| | | vo.setPortrait(userInfo.getPortrait());
|
| | | vo.setHelpLink(userVipConfigService.getValueByKey("help_link_vip_h5"));
|
| | | vo.setCsdLink(configService.get(ConfigKeyEnum.customerServiceLink.getKey()));
|
| | |
|
| | | Date now = new Date();
|
| | | Date start = new Date(0);
|
| | |
|
| | | // 返利订单、奖励券提成
|
| | | List<UserMoneyDetailTypeEnum> typeFanli = new ArrayList<>();
|
| | | typeFanli.add(UserMoneyDetailTypeEnum.fanli);
|
| | | typeFanli.add(UserMoneyDetailTypeEnum.orderReward);
|
| | | BigDecimal finishMoney = userMoneyDetailService.statisticUserTypeMoneyWithDate(uid, typeFanli, start, now)
|
| | | .abs();
|
| | |
|
| | | // 邀请订单、分享订单、补贴
|
| | | List<UserMoneyDetailTypeEnum> typeList = new ArrayList<>();
|
| | | typeList.add(UserMoneyDetailTypeEnum.share);
|
| | | typeList.add(UserMoneyDetailTypeEnum.invite);
|
| | | typeList.add(UserMoneyDetailTypeEnum.inviteAndShare);
|
| | | typeList.add(UserMoneyDetailTypeEnum.systemEqualize);
|
| | | typeList.add(UserMoneyDetailTypeEnum.subsidy);
|
| | | BigDecimal rewardMoney = userMoneyDetailService.statisticUserTypeMoneyWithDate(uid, typeList, start, now).abs();
|
| | |
|
| | | UserVIPInfo userVIPInfo = userVIPInfoService.selectByUid(uid);
|
| | | vo.setVipInfo(userVIPInfo);
|
| | | String leftTime = "";
|
| | | if (userVIPInfo != null && userVIPInfo.getApplyTime() != null) {
|
| | | // TODO 计算时间
|
| | | long s = 48 * 60 * 60 - ((System.currentTimeMillis() - userVIPInfo.getApplyTime().getTime()) / 1000);
|
| | | if (s > 3600) {
|
| | | leftTime = s / 3600 + "小时";
|
| | | leftTime = "还剩" + leftTime;
|
| | | } else if (s >= 60) {
|
| | | leftTime = s / 60 + "分钟";
|
| | | leftTime = "还剩" + leftTime;
|
| | | } else if (s > 0) {
|
| | | leftTime = s + "秒";
|
| | | leftTime = "还剩" + leftTime;
|
| | | }
|
| | | }
|
| | | vo.setLeftTime(leftTime);
|
| | |
|
| | | if (userVIPInfo != null && userVIPInfo.getState() != null
|
| | | && userVIPInfo.getState() == UserVIPInfo.STATE_SUCCESS) { // VIP
|
| | | vo.setSuccessTime(TimeUtil.getGernalTime(userVIPInfo.getSuccessTime().getTime(), "yyyy.MM.dd"));
|
| | | vo.setConserveMoney(finishMoney);
|
| | | vo.setEarnMoney(rewardMoney);
|
| | | } else {
|
| | | BigDecimal rate = new BigDecimal("0.409");
|
| | | vo.setConserveMoney(MoneyBigDecimalUtil.mul2(finishMoney, rate));
|
| | | vo.setEarnMoney(MoneyBigDecimalUtil.mul2(rewardMoney, rate));
|
| | | }
|
| | | vo.setFinishMoney(hongBaoV2CountService.getRewardMoneyBySelf(uid));
|
| | |
|
| | | |
| | | List<Integer> list = new ArrayList<Integer>();
|
| | | list.add(BanLiShopOrder.STATE_SUCCESS);
|
| | | BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay"));
|
| | |
|
| | | vo.setFinishTeam(hongBaoV2CountService.countValidOrderTeamUserByUid(uid, TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney));
|
| | | vo.setFinishHongBao(banLiShopOrderService.countByUidAndState(uid, list));
|
| | |
|
| | | |
| | | // 区分老用户和新用户
|
| | | String limtDate = userVipConfigService.getValueByKey("vip_execute_time");
|
| | | Date executeDate = null;
|
| | | try {
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
|
| | | executeDate = format.parse(limtDate);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (extra != null
|
| | | && (extra.getFirstLoginTime() == null || extra.getFirstLoginTime().getTime() < executeDate.getTime())) {
|
| | | vo.setLimitTeam(Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_old_user")));
|
| | | } else {
|
| | | vo.setLimitTeam(Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_new_user")));
|
| | | }
|
| | | vo.setLimitHongBao(Long.parseLong(userVipConfigService.getValueByKey("require_shop_buy")));
|
| | | vo.setLimitMoney(new BigDecimal(userVipConfigService.getValueByKey("require_fan_money")));
|
| | | vo.setLimitgoldCoin(Long.parseLong(userVipConfigService.getValueByKey("require_gold_coin")));
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder();
|
| | | gsonBuilder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() {
|
| | | @Override
|
| | | public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) {
|
| | | if (value == null) {
|
| | | return new JsonPrimitive("");
|
| | | } else {
|
| | | // 保留2位小数
|
| | | value = value.setScale(2);
|
| | | return new JsonPrimitive(value.toString());
|
| | | }
|
| | | }
|
| | | });
|
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("info", gson.toJson(vo));
|
| | | data.put("welfare",JSONArray.fromObject( userVipConfigService.getValueByKey("vip_welfare")));
|
| | | if (!StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
|
| | | } else {
|
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(data)));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 开通VIP
|
| | | * |
| | | * @param callback
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "applyVip")
|
| | | public void applyVip(String callback, WXMPAcceptData acceptData, Long uid, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfo userInfo = userInfoService.selectByPKey(uid);
|
| | | if (userInfo == null) {
|
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "该用户不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 省钱 -自购产生返利
|
| | |
|
| | | List<Integer> list = new ArrayList<Integer>();
|
| | | list.add(BanLiShopOrder.STATE_SUCCESS);
|
| | | BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay"));
|
| | |
|
| | | long finishTeam = hongBaoV2CountService.countValidOrderTeamUserByUid(uid, TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney);
|
| | | long finishHongBao = banLiShopOrderService.countByUidAndState(uid, list);
|
| | | BigDecimal finishMoney = hongBaoV2CountService.getRewardMoneyBySelf(uid);
|
| | |
|
| | | long limitTeam = 0;
|
| | |
|
| | | // 区分老用户和新用户
|
| | | String limtDate = userVipConfigService.getValueByKey("vip_execute_time");
|
| | | Date executeDate = null;
|
| | | try {
|
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
|
| | | executeDate = format.parse(limtDate);
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (extra != null
|
| | | && (extra.getFirstLoginTime() == null || extra.getFirstLoginTime().getTime() < executeDate.getTime())) {
|
| | | limitTeam = (Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_old_user")));
|
| | | } else {
|
| | | limitTeam = (Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_new_user")));
|
| | | }
|
| | | long limitHongBao = (Long.parseLong(userVipConfigService.getValueByKey("require_shop_buy")));
|
| | | BigDecimal limitMoney = (new BigDecimal(userVipConfigService.getValueByKey("require_fan_money")));
|
| | |
|
| | | if (finishTeam >= limitTeam && finishHongBao >= limitHongBao && finishMoney.compareTo(limitMoney) >= 0) {
|
| | | // 条件符合
|
| | | } else {
|
| | | if (!StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("未达到开通条件")));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult("未达到开通条件"));
|
| | | }
|
| | | return;
|
| | | }
|
| | | // 开通
|
| | | try {
|
| | | userVIPInfoService.applyVIP(uid);
|
| | | } catch (UserVIPInfoException e) {
|
| | | if (!StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMsg())));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(e.getMsg()));
|
| | | }
|
| | | return;
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("已申请")));
|
| | | } else {
|
| | | out.print(JsonUtil.loadTrueResult("已申请"));
|
| | | }
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.controller.wxmp.v1; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | 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.yeshi.utils.IPUtil; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.entity.wx.WXMPSessionInfo; |
| | | import org.yeshi.utils.entity.wx.WXMPUserInfo; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | import org.yeshi.utils.wx.WXXCXUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.JsonElement; |
| | | import com.google.gson.JsonPrimitive; |
| | | import com.google.gson.JsonSerializationContext; |
| | | import com.google.gson.JsonSerializer; |
| | | import com.yeshi.fanli.dto.WXMPAcceptData; |
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginData; |
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginResult; |
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode; |
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum; |
| | | import com.yeshi.fanli.entity.bus.user.SMSHistory; |
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra; |
| | | import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo; |
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum; |
| | | import com.yeshi.fanli.entity.shop.BanLiShopOrder; |
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum; |
| | | import com.yeshi.fanli.exception.user.UserAccountException; |
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException; |
| | | import com.yeshi.fanli.exception.user.vip.UserVIPInfoException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; |
| | | import com.yeshi.fanli.service.inter.money.UserMoneyDetailService; |
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService; |
| | | import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService; |
| | | import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService; |
| | | import com.yeshi.fanli.service.inter.user.UserAccountService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | 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.service.inter.user.wx.WXMPUserLoginService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import com.yeshi.fanli.util.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.ThreadUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.account.UserUtil; |
| | | import com.yeshi.fanli.vo.user.UserVipRateVO; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller("WXMPUserAccountController") |
| | | @RequestMapping("/wxmp/api/v1/useraccount") |
| | | public class UserAccountController { |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserAccountService userAccountService; |
| | | |
| | | @Resource |
| | | private WXMPUserLoginService wxMPUserLoginService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; |
| | | |
| | | @Resource |
| | | private UserMoneyDetailService userMoneyDetailService; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private UserVIPInfoService userVIPInfoService; |
| | | |
| | | @Resource |
| | | private UserVipConfigService userVipConfigService; |
| | | |
| | | @Resource |
| | | private BanLiShopOrderService banLiShopOrderService; |
| | | |
| | | @Resource |
| | | private HongBaoV2CountService hongBaoV2CountService; |
| | | |
| | | @Resource |
| | | private ThreeSaleSerivce threeSaleSerivce; |
| | | |
| | | @Resource |
| | | private CommonOrderService commonOrderService; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 通过邀请码获取用户信息 |
| | | * |
| | | * @param acceptData |
| | | * @param inviteCode |
| | | * @param out |
| | | */ |
| | | @RequestMapping("getInviteCodeInfo") |
| | | public void getInviteCodeInfo(WXMPAcceptData acceptData, String inviteCode, PrintWriter out) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(inviteCode)) { |
| | | out.print(JsonUtil.loadFalseResult("邀请码为空")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | UserInfo userInfo = userInfoExtraService.getUserByInviteCode(inviteCode); |
| | | if (userInfo != null && userInfo.getState() == UserInfo.STATE_NORMAL) { |
| | | JSONObject json = new JSONObject(); |
| | | json.put("id", userInfo.getId()); |
| | | json.put("nickName", userInfo.getNickName()); |
| | | json.put("portrait", userInfo.getPortrait()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("user", json); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | return; |
| | | } |
| | | } catch (UserInfoExtraException e) { |
| | | |
| | | } |
| | | out.print(JsonUtil.loadFalseResult("邀请码不存在")); |
| | | } |
| | | |
| | | @RequestMapping("phoneLogin") |
| | | public void phoneLogin(WXMPAcceptData acceptData, String code, String phoneEncryptedData, String phoneIv, |
| | | String inviteCode, String userData, HttpServletRequest request, HttpSession session, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) { |
| | | out.print(JsonUtil.loadFalseResult("openId为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(phoneEncryptedData) || StringUtil.isNullOrEmpty(phoneIv)) { |
| | | out.print(JsonUtil.loadFalseResult("电话加密数据为空")); |
| | | return; |
| | | } |
| | | |
| | | String sessionKey = null; |
| | | WXMPSessionInfo sessionInfo = WXXCXUtil.getSessionInfo(Constant.WXMP_APP_INFO, code); |
| | | if (sessionInfo == null) { |
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录")); |
| | | return; |
| | | } else { |
| | | session.setAttribute(UserController.WXMP_SESSION_INFO_KEY, sessionInfo); |
| | | } |
| | | |
| | | sessionKey = sessionInfo.getSessionKey(); |
| | | |
| | | if (StringUtil.isNullOrEmpty(sessionKey)) { |
| | | out.print(JsonUtil.loadFalseResult("code无效")); |
| | | return; |
| | | } |
| | | String phoneNumber = WXXCXUtil.getPhoneNumber(sessionKey, phoneEncryptedData, phoneIv); |
| | | LogHelper.test("小程序获取到的电话号码为:"+phoneNumber); |
| | | |
| | | if (StringUtil.isNullOrEmpty(phoneNumber)) { |
| | | out.print(JsonUtil.loadFalseResult("获取电话号码失败")); |
| | | return; |
| | | } |
| | | |
| | | UserInfo boss = null; |
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) { |
| | | try { |
| | | boss = userInfoExtraService.getUserByInviteCode(inviteCode); |
| | | } catch (UserInfoExtraException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (boss != null && boss.getState() != UserInfo.STATE_NORMAL) |
| | | boss = null; |
| | | } |
| | | |
| | | UserInfo lastUserInfo = null; |
| | | if (!StringUtil.isNullOrEmpty(userData)) { |
| | | String redisKey = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, |
| | | StringUtil.Md5(acceptData.getAppId() + "-" + acceptData.getOpenId())); |
| | | String data = redisManager.getCommonString(redisKey); |
| | | if (!StringUtil.isNullOrEmpty(data)) { |
| | | lastUserInfo = new Gson().fromJson(data, UserInfo.class); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | WXMPLoginResult result = wxMPUserLoginService.wxmpLogin(new WXMPLoginData.Builder(Constant.APPID) |
| | | .setBoss(boss).setLastUser(lastUserInfo).setPhone(phoneNumber).build()); |
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | |
| | | } |
| | | |
| | | @RequestMapping("wxLogin") |
| | | public void wxLogin(WXMPAcceptData acceptData, String wxEncryptedData, String wxIv, String inviteCode, String code, |
| | | HttpServletRequest request, HttpSession session, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) { |
| | | out.print(JsonUtil.loadFalseResult("openId为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(wxEncryptedData) || StringUtil.isNullOrEmpty(wxIv)) { |
| | | out.print(JsonUtil.loadFalseResult("微信用户加密数据为空")); |
| | | return; |
| | | } |
| | | WXMPSessionInfo sessionInfo = WXXCXUtil.getSessionInfo(Constant.WXMP_APP_INFO, code); |
| | | |
| | | String sessionKey = sessionInfo.getSessionKey(); |
| | | if (StringUtil.isNullOrEmpty(sessionKey)) { |
| | | out.print(JsonUtil.loadFalseResult("code无效")); |
| | | return; |
| | | } |
| | | |
| | | WXMPUserInfo userInfo = WXXCXUtil.getUserInfo(sessionKey, wxEncryptedData, wxIv); |
| | | if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUnionId())) { |
| | | out.print(JsonUtil.loadFalseResult("获取微信信息失败")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | WXMPLoginResult result = wxMPUserLoginService |
| | | .wxmpLogin(new WXMPLoginData.Builder(Constant.APPID).setWxUser(userInfo).build()); |
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("bindInviteCode") |
| | | public void bindInviteCode(WXMPAcceptData acceptData, String inviteCode, String userData, |
| | | HttpServletRequest request, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) { |
| | | out.print(JsonUtil.loadFalseResult("openId为空")); |
| | | return; |
| | | } |
| | | if (StringUtil.isNullOrEmpty(inviteCode)) { |
| | | out.print(JsonUtil.loadFalseResult("邀请码为空")); |
| | | return; |
| | | } |
| | | |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, |
| | | StringUtil.Md5(acceptData.getAppId() + "-" + acceptData.getOpenId())); |
| | | |
| | | UserInfo user = new Gson().fromJson(redisManager.getCommonString(key), UserInfo.class); |
| | | if (user == null) { |
| | | out.print(JsonUtil.loadFalseResult("用户数据为空")); |
| | | return; |
| | | } |
| | | |
| | | UserInfo boss = null; |
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) { |
| | | try { |
| | | boss = userInfoExtraService.getUserByInviteCode(inviteCode); |
| | | } catch (UserInfoExtraException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (boss != null && boss.getState() != UserInfo.STATE_NORMAL) |
| | | boss = null; |
| | | } |
| | | |
| | | if (boss == null) { |
| | | out.print(JsonUtil.loadFalseResult("邀请码有误")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | WXMPLoginResult result = wxMPUserLoginService |
| | | .wxmpLogin(new WXMPLoginData.Builder(Constant.APPID).setLastUser(user).setBoss(boss).build()); |
| | | printWXMPLoginResult(acceptData.getAppId(), acceptData.getOpenId(), result, request, out); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | private void printWXMPLoginResult(String appId, String openId, WXMPLoginResult result, HttpServletRequest request, |
| | | PrintWriter out) { |
| | | JSONObject data = new JSONObject(); |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.wxmpUserLogin, StringUtil.Md5(appId + "-" + openId)); |
| | | |
| | | switch (result.getCode()) { |
| | | case WXMPLoginResult.CODE_SUCCESS: |
| | | UserInfo user = userInfoService.selectAvailableByPrimaryKey(result.getUser().getId()); |
| | | data.put("user", UserUtil.filterForClientUser(user)); |
| | | data.put("type", 0); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | final String ip = IPUtil.getRemotIP(request); |
| | | final int port = request.getRemotePort(); |
| | | ThreadUtil.run(new Runnable() { |
| | | |
| | | @Override |
| | | public void run() {// 登录成功 |
| | | UserInfo update = new UserInfo(user.getId()); |
| | | update.setLastLoginTime(System.currentTimeMillis()); |
| | | update.setLastLoginIp(ip + ":" + port); |
| | | userAccountService.updateUserSelective(update); |
| | | } |
| | | }); |
| | | return; |
| | | case WXMPLoginResult.CODE_BIND_PHONE: |
| | | // 需要绑定电话号码 |
| | | redisManager.saveObj(result.getUser(), key, 60 * 5);// 只缓存5分钟 |
| | | data.put("userData", key); |
| | | data.put("type", 2); |
| | | break; |
| | | case WXMPLoginResult.CODE_BIND_INVITE_CODE: |
| | | redisManager.saveObj(result.getUser(), key, 60 * 5);// 只缓存5分钟 |
| | | data.put("userData", key); |
| | | data.put("type", 1); |
| | | break; |
| | | } |
| | | |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | @RequestMapping("bindWX") |
| | | public void bindWX(WXMPAcceptData acceptData, Long uid, String wxEncryptedData, String wxIv, |
| | | HttpServletRequest request, HttpSession session, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) { |
| | | out.print(JsonUtil.loadFalseResult("openId为空")); |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("uid为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(wxEncryptedData) || StringUtil.isNullOrEmpty(wxIv)) { |
| | | out.print(JsonUtil.loadFalseResult("微信信息为空")); |
| | | return; |
| | | } |
| | | |
| | | WXMPSessionInfo sessionInfo = (WXMPSessionInfo) session.getAttribute(UserController.WXMP_SESSION_INFO_KEY); |
| | | if (sessionInfo == null) { |
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录")); |
| | | return; |
| | | } |
| | | |
| | | String sessionKey = sessionInfo.getSessionKey(); |
| | | if (StringUtil.isNullOrEmpty(sessionKey)) { |
| | | out.print(JsonUtil.loadFalseResult("code无效")); |
| | | return; |
| | | } |
| | | |
| | | WXMPUserInfo userInfo = WXXCXUtil.getUserInfo(sessionKey, wxEncryptedData, wxIv); |
| | | if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUnionId())) { |
| | | out.print(JsonUtil.loadFalseResult("获取微信信息失败")); |
| | | return; |
| | | } |
| | | |
| | | // 绑定微信 |
| | | |
| | | WeiXinUser wxUser = new WeiXinUser(); |
| | | wxUser.setHeadimgurl(userInfo.getAvatarUrl()); |
| | | wxUser.setCity(userInfo.getCity()); |
| | | wxUser.setCountry(userInfo.getCountry()); |
| | | wxUser.setNickname(userInfo.getNickName()); |
| | | wxUser.setOpenid(""); |
| | | wxUser.setProvince(userInfo.getProvince()); |
| | | wxUser.setSex(userInfo.getGender()); |
| | | wxUser.setUnionid(userInfo.getUnionId()); |
| | | |
| | | try { |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | // 判断taoBaoUid是否已经封禁 |
| | | ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService |
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, user.getWxUnionId()); |
| | | if (ic != null && ic.getEffective() != null && ic.getEffective()) { |
| | | out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); |
| | | // 封禁用户 |
| | | // 封禁绑定的正常用户 |
| | | if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) { |
| | | userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的微信号"); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | userAccountService.bindWeiXin(uid, wxUser); |
| | | user = userInfoService.getUserByIdWithMybatis(uid); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("user", UserUtil.filterForClientUser(user)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 绑定电话号码 V1.5.3 |
| | | * |
| | | * @param acceptData |
| | | * @param vcode |
| | | * @param phone |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "bindPhone") |
| | | public void bindPhone(WXMPAcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(vcode)) { |
| | | out.print(JsonUtil.loadFalseResult("验证码不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(phone)) { |
| | | out.print(JsonUtil.loadFalseResult("电话号码不能为空")); |
| | | return; |
| | | } |
| | | |
| | | phone = phone.replaceAll(" ", ""); |
| | | |
| | | String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_BIND); |
| | | if (Constant.IS_OUTNET) { |
| | | if (!vcode.equalsIgnoreCase(oldVCode)) { |
| | | out.print(JsonUtil.loadFalseResult(9001, "验证码错误,重新输入")); |
| | | return; |
| | | } |
| | | redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_BIND); |
| | | } |
| | | |
| | | try { |
| | | // 绑定用户 |
| | | userAccountService.bindPhoneNew(uid, phone); |
| | | |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | // 判断电话号码是否已经封禁 |
| | | ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService |
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone); |
| | | if (ic != null && ic.getEffective() != null && ic.getEffective()) { |
| | | out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); |
| | | // 封禁用户 |
| | | // 封禁绑定的正常用户 |
| | | if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) { |
| | | userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的电话号码"); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("user", UserUtil.filterForClientUser(user)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult(1, "绑定失败")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取vip信息 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getVIPInfo") |
| | | public void getVIPInfo(String callback, WXMPAcceptData acceptData, Long uid, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | UserInfo userInfo = userInfoService.selectByPKey(uid); |
| | | if (userInfo == null) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "该用户不存在")); |
| | | return; |
| | | } |
| | | // |
| | | String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); |
| | | |
| | | UserVipRateVO vo = new UserVipRateVO(); |
| | | vo.setId(uid); |
| | | vo.setInviteCode(inviteCode); |
| | | vo.setNickName(userInfo.getNickName()); |
| | | vo.setPortrait(userInfo.getPortrait()); |
| | | vo.setHelpLink(userVipConfigService.getValueByKey("help_link_vip_h5")); |
| | | vo.setCsdLink(configService.getValue(ConfigKeyEnum.customerServiceLink.getKey(),acceptData.getSystem())); |
| | | |
| | | Date now = new Date(); |
| | | Date start = new Date(0); |
| | | |
| | | // 返利订单、奖励券提成 |
| | | List<UserMoneyDetailTypeEnum> typeFanli = new ArrayList<>(); |
| | | typeFanli.add(UserMoneyDetailTypeEnum.fanli); |
| | | typeFanli.add(UserMoneyDetailTypeEnum.orderReward); |
| | | BigDecimal finishMoney = userMoneyDetailService.statisticUserTypeMoneyWithDate(uid, typeFanli, start, now) |
| | | .abs(); |
| | | |
| | | // 邀请订单、分享订单、补贴 |
| | | List<UserMoneyDetailTypeEnum> typeList = new ArrayList<>(); |
| | | typeList.add(UserMoneyDetailTypeEnum.share); |
| | | typeList.add(UserMoneyDetailTypeEnum.invite); |
| | | typeList.add(UserMoneyDetailTypeEnum.inviteAndShare); |
| | | typeList.add(UserMoneyDetailTypeEnum.systemEqualize); |
| | | typeList.add(UserMoneyDetailTypeEnum.subsidy); |
| | | BigDecimal rewardMoney = userMoneyDetailService.statisticUserTypeMoneyWithDate(uid, typeList, start, now).abs(); |
| | | |
| | | UserVIPInfo userVIPInfo = userVIPInfoService.selectByUid(uid); |
| | | vo.setVipInfo(userVIPInfo); |
| | | String leftTime = ""; |
| | | if (userVIPInfo != null && userVIPInfo.getApplyTime() != null) { |
| | | // TODO 计算时间 |
| | | long s = 48 * 60 * 60 - ((System.currentTimeMillis() - userVIPInfo.getApplyTime().getTime()) / 1000); |
| | | if (s > 3600) { |
| | | leftTime = s / 3600 + "小时"; |
| | | leftTime = "还剩" + leftTime; |
| | | } else if (s >= 60) { |
| | | leftTime = s / 60 + "分钟"; |
| | | leftTime = "还剩" + leftTime; |
| | | } else if (s > 0) { |
| | | leftTime = s + "秒"; |
| | | leftTime = "还剩" + leftTime; |
| | | } |
| | | } |
| | | vo.setLeftTime(leftTime); |
| | | |
| | | if (userVIPInfo != null && userVIPInfo.getState() != null |
| | | && userVIPInfo.getState() == UserVIPInfo.STATE_SUCCESS) { // VIP |
| | | vo.setSuccessTime(TimeUtil.getGernalTime(userVIPInfo.getSuccessTime().getTime(), "yyyy.MM.dd")); |
| | | vo.setConserveMoney(finishMoney); |
| | | vo.setEarnMoney(rewardMoney); |
| | | } else { |
| | | BigDecimal rate = new BigDecimal("0.409"); |
| | | vo.setConserveMoney(MoneyBigDecimalUtil.mul2(finishMoney, rate)); |
| | | vo.setEarnMoney(MoneyBigDecimalUtil.mul2(rewardMoney, rate)); |
| | | } |
| | | vo.setFinishMoney(hongBaoV2CountService.getRewardMoneyBySelf(uid)); |
| | | |
| | | List<Integer> list = new ArrayList<Integer>(); |
| | | list.add(BanLiShopOrder.STATE_SUCCESS); |
| | | BigDecimal payMoney = new BigDecimal(userVipConfigService.getValueByKey("require_order_pay")); |
| | | |
| | | // vo.setFinishTeam(hongBaoV2CountService.countValidOrderTeamUserByUid(uid, |
| | | // TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME), payMoney)); |
| | | |
| | | int finishTeam = 0; |
| | | long vipBegin = TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME); |
| | | List<ThreeSale> listThreeSale = threeSaleSerivce.getValidWorkerIdsByTime(uid, vipBegin); |
| | | if (listThreeSale != null && listThreeSale.size() > 0) { |
| | | for (ThreeSale three: listThreeSale) { |
| | | UserInfo worker = three.getWorker(); |
| | | if (worker == null || worker.getId() == null) { |
| | | continue; |
| | | } |
| | | // 1、邀请关系成功后;2、单(分享 + 自购)实付款大于1元 |
| | | long countValid = commonOrderService.countOrderByUidAndSettled(worker.getId(), payMoney); |
| | | if (countValid > 0) { |
| | | finishTeam ++; |
| | | } |
| | | } |
| | | } |
| | | vo.setFinishTeam(finishTeam); |
| | | |
| | | vo.setFinishHongBao(banLiShopOrderService.countByUidAndState(uid, list)); |
| | | |
| | | // 区分老用户和新用户 |
| | | String limtDate = userVipConfigService.getValueByKey("vip_execute_time"); |
| | | Date executeDate = null; |
| | | try { |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd"); |
| | | executeDate = format.parse(limtDate); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | UserInfoExtra extra = userInfoExtraService.getUserInfoExtra(uid); |
| | | if (extra != null |
| | | && (extra.getFirstLoginTime() == null || extra.getFirstLoginTime().getTime() < executeDate.getTime())) { |
| | | vo.setLimitTeam(Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_old_user"))); |
| | | } else { |
| | | vo.setLimitTeam(Long.parseLong(userVipConfigService.getValueByKey("require_invite_num_new_user"))); |
| | | } |
| | | vo.setLimitHongBao(Long.parseLong(userVipConfigService.getValueByKey("require_shop_buy"))); |
| | | vo.setLimitMoney(new BigDecimal(userVipConfigService.getValueByKey("require_fan_money"))); |
| | | vo.setLimitgoldCoin(Long.parseLong(userVipConfigService.getValueByKey("require_gold_coin"))); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder(); |
| | | gsonBuilder.registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() { |
| | | @Override |
| | | public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | // 保留2位小数 |
| | | value = value.setScale(2); |
| | | return new JsonPrimitive(value.toString()); |
| | | } |
| | | } |
| | | }); |
| | | Gson gson = gsonBuilder.create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("info", gson.toJson(vo)); |
| | | data.put("welfare", JSONArray.fromObject(userVipConfigService.getValueByKey("vip_welfare"))); |
| | | if (!StringUtil.isNullOrEmpty(callback)) { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); |
| | | } else { |
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(data))); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 开通VIP |
| | | * |
| | | * @param callback |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "applyVip") |
| | | public void applyVip(String callback, WXMPAcceptData acceptData, Long uid, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | userVIPInfoService.applyVIP(uid); |
| | | } catch (UserVIPInfoException e) { |
| | | if (!StringUtil.isNullOrEmpty(callback)) { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMsg()))); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(callback)) { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("申请成功,正在受理中"))); |
| | | } else { |
| | | out.print(JsonUtil.loadTrueResult("申请成功,正在受理中")); |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("logout") |
| | | public void logout(WXMPAcceptData acceptData, Long uid, PrintWriter out) { |
| | | if (uid == null) { |
| | | out.print(JsonUtil.loadFalseResult("uid为空")); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadTrueResult("")); |
| | | } |
| | | } |