From 723f9351384094c716f12655b0e455010c28debd Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Tue, 29 Oct 2024 11:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=88=E6=9D=83=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bweb/src/main/resources/prod/application.yml | 10 +- .../com/hfkj/controller/ClientController.java | 47 +++- .../com/hfkj/controller/UserController.java | 61 ++++- cweb/src/main/resources/prod/application.yml | 12 +- .../src/main/resources/prod/application.yml | 12 +- .../main/java/com/hfkj/dao/BsUserMapper.java | 37 +-- .../java/com/hfkj/dao/BsUserSqlProvider.java | 42 ++++ .../src/main/java/com/hfkj/entity/BsUser.java | 48 ++++ .../java/com/hfkj/entity/BsUserExample.java | 210 ++++++++++++++++++ .../partner/Impl/PartnerServiceImpl.java | 2 +- .../hfkj/service/user/BsUserGradeService.java | 4 +- .../com/hfkj/service/user/BsUserService.java | 20 +- .../user/impl/BsUserGradeServiceImpl.java | 14 +- .../service/user/impl/BsUserServiceImpl.java | 81 +++++-- .../com/hfkj/sysenum/user/UserLoginType.java | 2 +- 15 files changed, 518 insertions(+), 84 deletions(-) diff --git a/bweb/src/main/resources/prod/application.yml b/bweb/src/main/resources/prod/application.yml index 18a5cc0..8d5c08d 100644 --- a/bweb/src/main/resources/prod/application.yml +++ b/bweb/src/main/resources/prod/application.yml @@ -1,5 +1,5 @@ server: - port: 9302 + port: 9102 servlet: context-path: /brest @@ -9,9 +9,9 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 - username: root - password: HF123456. + url: jdbc:mysql://127.0.0.1:3306/youtao?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: yqyt + password: yqyt123!@#Mysql type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat @@ -31,7 +31,7 @@ spring: database: 0 host: 127.0.0.1 port: 36379 - password: HF123456.Redis + password: yqyt123!@#Redis timeout: 1000 jedis: pool: diff --git a/cweb/src/main/java/com/hfkj/controller/ClientController.java b/cweb/src/main/java/com/hfkj/controller/ClientController.java index 4238cd1..fbf3b6a 100644 --- a/cweb/src/main/java/com/hfkj/controller/ClientController.java +++ b/cweb/src/main/java/com/hfkj/controller/ClientController.java @@ -5,9 +5,11 @@ import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.HttpsUtils; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsUser; import com.hfkj.model.ResponseData; import com.hfkj.model.SecUserSessionObject; import com.hfkj.service.user.BsUserService; @@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; +import java.util.Map; /** * @className: ClientController @@ -78,22 +81,42 @@ public class ClientController { } } - - @RequestMapping(value = "/smsLogin", method = RequestMethod.GET) + @RequestMapping(value = "/weChat", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "登录并注册") - public ResponseData smsLogin(@RequestParam(value = "phone" , required = true) String phone) { + @ApiOperation(value = "微信授权登录") + public ResponseData weChat(@RequestBody JSONObject body) { try { - - - // 校验手机号格式 - if (!MemberValidateUtil.validatePhone(phone)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); + if (body == null || StringUtils.isBlank(body.getString("code"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + // 邀请人id + Long inviteUseId = body.getLong("inviteUseId"); - - return ResponseMsgUtil.success(userService.login(phone, UserLoginType.SMS, new HashMap<>(), null)); - + Map params = new HashMap<>(); + params.put("appid", "wxa075e8509802f826"); + params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5"); + params.put("code", body.getString("code")); + params.put("grant_type", "authorization_code"); + JSONObject accessToken = HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params); + if (accessToken == null || StringUtils.isBlank(accessToken.getString("openid"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "授权失败"); + } + params.clear(); + params.put("access_token", accessToken.getString("access_token")); + params.put("openid", accessToken.getString("openid")); + params.put("lang", "zh_CN"); + JSONObject userinfo = HttpsUtils.doGet("https://api.weixin.qq.com/sns/userinfo", params); + if (userinfo == null || StringUtils.isBlank(userinfo.getString("openid"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取用户信息失败"); + } + BsUser user = new BsUser(); + user.setHeadImg(userinfo.getString("headimgurl")); + user.setName(userinfo.getString("nickname")); + user.setWechatOpenId(userinfo.getString("openid")); + user.setWechatUnionid(userinfo.getString("unionid")); + userService.weChatAuth(user, new HashMap<>(), inviteUseId); + + return ResponseMsgUtil.success(userinfo); } catch (Exception e) { return ResponseMsgUtil.exception(e); } diff --git a/cweb/src/main/java/com/hfkj/controller/UserController.java b/cweb/src/main/java/com/hfkj/controller/UserController.java index 6703bb9..540047f 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserController.java @@ -6,10 +6,7 @@ import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; -import com.hfkj.common.utils.DateUtil; -import com.hfkj.common.utils.MemberValidateUtil; -import com.hfkj.common.utils.RedisUtil; -import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.common.utils.*; import com.hfkj.config.CommonSysConst; import com.hfkj.config.SysConfig; import com.hfkj.entity.BsUser; @@ -205,8 +202,12 @@ public class UserController { if (StringUtils.isBlank(body.getString("smsCode"))) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); } - if (userService.getUser(phone) != null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); + // 手机号用户 + BsUser user = userService.getUser(phone); + if (user != null) { + if (StringUtils.isNotBlank(user.getWechatOpenId())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); + } } // 手机号的验证码 Object phoneCodeObject = redisUtil.get("SMS_BIND_PHONE_CODE:" + phone); @@ -294,8 +295,12 @@ public class UserController { if (userSession.getUser().getPhone().equals(phone)) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "新手机号与现绑定手机号相同"); } - if (userService.getUser(phone) != null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); + // 手机号用户 + BsUser user = userService.getUser(phone); + if (user != null) { + if (StringUtils.isNotBlank(user.getWechatOpenId())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); + } } // 校验手机号格式 if (!MemberValidateUtil.validatePhone(phone)) { @@ -324,6 +329,46 @@ public class UserController { } } + @RequestMapping(value = "/bindWeChat", method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "绑定微信") + public ResponseData bindWeChat(@RequestBody JSONObject body) { + try { + if (body == null || StringUtils.isBlank(body.getString("code"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (StringUtils.isNotBlank(userSession.getUser().getWechatOpenId())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已绑定过微信"); + } + Map params = new HashMap<>(); + params.put("appid", "wxa075e8509802f826"); + params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5"); + params.put("code", body.getString("code")); + params.put("grant_type", "authorization_code"); + JSONObject accessToken = HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params); + if (accessToken == null || StringUtils.isBlank(accessToken.getString("openid"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "授权失败"); + } + params.clear(); + params.put("access_token", accessToken.getString("access_token")); + params.put("openid", accessToken.getString("openid")); + params.put("lang", "zh_CN"); + JSONObject userinfo = HttpsUtils.doGet("https://api.weixin.qq.com/sns/userinfo", params); + if (userinfo == null || StringUtils.isBlank(userinfo.getString("openid"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取用户信息失败"); + } + BsUser user = userSession.getUser(); + user.setWechatOpenId(userinfo.getString("openid")); + user.setWechatUnionid(userinfo.getString("unionid")); + userService.updateInfo(user); + + return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class)); + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/delete", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "注销账户") diff --git a/cweb/src/main/resources/prod/application.yml b/cweb/src/main/resources/prod/application.yml index 18a5cc0..1d0831a 100644 --- a/cweb/src/main/resources/prod/application.yml +++ b/cweb/src/main/resources/prod/application.yml @@ -1,7 +1,7 @@ server: - port: 9302 + port: 9101 servlet: - context-path: /brest + context-path: /crest #配置是否为debug模式,debug模式下,不开启权限校验 debug: false @@ -9,9 +9,9 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 - username: root - password: HF123456. + url: jdbc:mysql://127.0.0.1:3306/youtao?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: yqyt + password: yqyt123!@#Mysql type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat @@ -31,7 +31,7 @@ spring: database: 0 host: 127.0.0.1 port: 36379 - password: HF123456.Redis + password: yqyt123!@#Redis timeout: 1000 jedis: pool: diff --git a/schedule/src/main/resources/prod/application.yml b/schedule/src/main/resources/prod/application.yml index 18a5cc0..6f67edf 100644 --- a/schedule/src/main/resources/prod/application.yml +++ b/schedule/src/main/resources/prod/application.yml @@ -1,7 +1,7 @@ server: - port: 9302 + port: 9103 servlet: - context-path: /brest + context-path: /schedule #配置是否为debug模式,debug模式下,不开启权限校验 debug: false @@ -9,9 +9,9 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 - username: root - password: HF123456. + url: jdbc:mysql://127.0.0.1:3306/youtao?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: yqyt + password: yqyt123!@#Mysql type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat @@ -31,7 +31,7 @@ spring: database: 0 host: 127.0.0.1 port: 36379 - password: HF123456.Redis + password: yqyt123!@#Redis timeout: 1000 jedis: pool: diff --git a/service/src/main/java/com/hfkj/dao/BsUserMapper.java b/service/src/main/java/com/hfkj/dao/BsUserMapper.java index 42dc362..8ccedd5 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsUserMapper.java @@ -41,18 +41,20 @@ public interface BsUserMapper extends BsUserMapperExt { @Insert({ "insert into bs_user (head_img, `name`, ", "phone, grade, wechat_num, ", - "invite_user_id, invite_time, ", - "partner_level, partner_income_per, ", - "`status`, create_time, ", - "update_time, ext_1, ", - "ext_2, ext_3)", + "wechat_open_id, wechat_unionid, ", + "elm_pid, invite_user_id, ", + "invite_time, partner_level, ", + "partner_income_per, `status`, ", + "create_time, update_time, ", + "ext_1, ext_2, ext_3)", "values (#{headImg,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ", "#{phone,jdbcType=VARCHAR}, #{grade,jdbcType=INTEGER}, #{wechatNum,jdbcType=VARCHAR}, ", - "#{inviteUserId,jdbcType=BIGINT}, #{inviteTime,jdbcType=TIMESTAMP}, ", - "#{partnerLevel,jdbcType=INTEGER}, #{partnerIncomePer,jdbcType=DECIMAL}, ", - "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{updateTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{wechatOpenId,jdbcType=VARCHAR}, #{wechatUnionid,jdbcType=VARCHAR}, ", + "#{elmPid,jdbcType=VARCHAR}, #{inviteUserId,jdbcType=BIGINT}, ", + "#{inviteTime,jdbcType=TIMESTAMP}, #{partnerLevel,jdbcType=INTEGER}, ", + "#{partnerIncomePer,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(BsUser record); @@ -69,6 +71,9 @@ public interface BsUserMapper extends BsUserMapperExt { @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR), @Result(column="grade", property="grade", jdbcType=JdbcType.INTEGER), @Result(column="wechat_num", property="wechatNum", jdbcType=JdbcType.VARCHAR), + @Result(column="wechat_open_id", property="wechatOpenId", jdbcType=JdbcType.VARCHAR), + @Result(column="wechat_unionid", property="wechatUnionid", jdbcType=JdbcType.VARCHAR), + @Result(column="elm_pid", property="elmPid", jdbcType=JdbcType.VARCHAR), @Result(column="invite_user_id", property="inviteUserId", jdbcType=JdbcType.BIGINT), @Result(column="invite_time", property="inviteTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="partner_level", property="partnerLevel", jdbcType=JdbcType.INTEGER), @@ -84,9 +89,9 @@ public interface BsUserMapper extends BsUserMapperExt { @Select({ "select", - "id, head_img, `name`, phone, grade, wechat_num, invite_user_id, invite_time, ", - "partner_level, partner_income_per, `status`, create_time, update_time, ext_1, ", - "ext_2, ext_3", + "id, head_img, `name`, phone, grade, wechat_num, wechat_open_id, wechat_unionid, ", + "elm_pid, invite_user_id, invite_time, partner_level, partner_income_per, `status`, ", + "create_time, update_time, ext_1, ext_2, ext_3", "from bs_user", "where id = #{id,jdbcType=BIGINT}" }) @@ -97,6 +102,9 @@ public interface BsUserMapper extends BsUserMapperExt { @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR), @Result(column="grade", property="grade", jdbcType=JdbcType.INTEGER), @Result(column="wechat_num", property="wechatNum", jdbcType=JdbcType.VARCHAR), + @Result(column="wechat_open_id", property="wechatOpenId", jdbcType=JdbcType.VARCHAR), + @Result(column="wechat_unionid", property="wechatUnionid", jdbcType=JdbcType.VARCHAR), + @Result(column="elm_pid", property="elmPid", jdbcType=JdbcType.VARCHAR), @Result(column="invite_user_id", property="inviteUserId", jdbcType=JdbcType.BIGINT), @Result(column="invite_time", property="inviteTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="partner_level", property="partnerLevel", jdbcType=JdbcType.INTEGER), @@ -126,6 +134,9 @@ public interface BsUserMapper extends BsUserMapperExt { "phone = #{phone,jdbcType=VARCHAR},", "grade = #{grade,jdbcType=INTEGER},", "wechat_num = #{wechatNum,jdbcType=VARCHAR},", + "wechat_open_id = #{wechatOpenId,jdbcType=VARCHAR},", + "wechat_unionid = #{wechatUnionid,jdbcType=VARCHAR},", + "elm_pid = #{elmPid,jdbcType=VARCHAR},", "invite_user_id = #{inviteUserId,jdbcType=BIGINT},", "invite_time = #{inviteTime,jdbcType=TIMESTAMP},", "partner_level = #{partnerLevel,jdbcType=INTEGER},", diff --git a/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java index 107aec7..c09e00d 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java @@ -48,6 +48,18 @@ public class BsUserSqlProvider { sql.VALUES("wechat_num", "#{wechatNum,jdbcType=VARCHAR}"); } + if (record.getWechatOpenId() != null) { + sql.VALUES("wechat_open_id", "#{wechatOpenId,jdbcType=VARCHAR}"); + } + + if (record.getWechatUnionid() != null) { + sql.VALUES("wechat_unionid", "#{wechatUnionid,jdbcType=VARCHAR}"); + } + + if (record.getElmPid() != null) { + sql.VALUES("elm_pid", "#{elmPid,jdbcType=VARCHAR}"); + } + if (record.getInviteUserId() != null) { sql.VALUES("invite_user_id", "#{inviteUserId,jdbcType=BIGINT}"); } @@ -103,6 +115,9 @@ public class BsUserSqlProvider { sql.SELECT("phone"); sql.SELECT("grade"); sql.SELECT("wechat_num"); + sql.SELECT("wechat_open_id"); + sql.SELECT("wechat_unionid"); + sql.SELECT("elm_pid"); sql.SELECT("invite_user_id"); sql.SELECT("invite_time"); sql.SELECT("partner_level"); @@ -154,6 +169,18 @@ public class BsUserSqlProvider { sql.SET("wechat_num = #{record.wechatNum,jdbcType=VARCHAR}"); } + if (record.getWechatOpenId() != null) { + sql.SET("wechat_open_id = #{record.wechatOpenId,jdbcType=VARCHAR}"); + } + + if (record.getWechatUnionid() != null) { + sql.SET("wechat_unionid = #{record.wechatUnionid,jdbcType=VARCHAR}"); + } + + if (record.getElmPid() != null) { + sql.SET("elm_pid = #{record.elmPid,jdbcType=VARCHAR}"); + } + if (record.getInviteUserId() != null) { sql.SET("invite_user_id = #{record.inviteUserId,jdbcType=BIGINT}"); } @@ -208,6 +235,9 @@ public class BsUserSqlProvider { sql.SET("phone = #{record.phone,jdbcType=VARCHAR}"); sql.SET("grade = #{record.grade,jdbcType=INTEGER}"); sql.SET("wechat_num = #{record.wechatNum,jdbcType=VARCHAR}"); + sql.SET("wechat_open_id = #{record.wechatOpenId,jdbcType=VARCHAR}"); + sql.SET("wechat_unionid = #{record.wechatUnionid,jdbcType=VARCHAR}"); + sql.SET("elm_pid = #{record.elmPid,jdbcType=VARCHAR}"); sql.SET("invite_user_id = #{record.inviteUserId,jdbcType=BIGINT}"); sql.SET("invite_time = #{record.inviteTime,jdbcType=TIMESTAMP}"); sql.SET("partner_level = #{record.partnerLevel,jdbcType=INTEGER}"); @@ -248,6 +278,18 @@ public class BsUserSqlProvider { sql.SET("wechat_num = #{wechatNum,jdbcType=VARCHAR}"); } + if (record.getWechatOpenId() != null) { + sql.SET("wechat_open_id = #{wechatOpenId,jdbcType=VARCHAR}"); + } + + if (record.getWechatUnionid() != null) { + sql.SET("wechat_unionid = #{wechatUnionid,jdbcType=VARCHAR}"); + } + + if (record.getElmPid() != null) { + sql.SET("elm_pid = #{elmPid,jdbcType=VARCHAR}"); + } + if (record.getInviteUserId() != null) { sql.SET("invite_user_id = #{inviteUserId,jdbcType=BIGINT}"); } diff --git a/service/src/main/java/com/hfkj/entity/BsUser.java b/service/src/main/java/com/hfkj/entity/BsUser.java index 7447507..43e658d 100644 --- a/service/src/main/java/com/hfkj/entity/BsUser.java +++ b/service/src/main/java/com/hfkj/entity/BsUser.java @@ -44,6 +44,21 @@ public class BsUser implements Serializable { */ private String wechatNum; + /** + * 微信openid + */ + private String wechatOpenId; + + /** + * 微信unionid + */ + private String wechatUnionid; + + /** + * 饿了么推广位编码 + */ + private String elmPid; + /** * 邀请人id */ @@ -135,6 +150,30 @@ public class BsUser implements Serializable { this.wechatNum = wechatNum; } + public String getWechatOpenId() { + return wechatOpenId; + } + + public void setWechatOpenId(String wechatOpenId) { + this.wechatOpenId = wechatOpenId; + } + + public String getWechatUnionid() { + return wechatUnionid; + } + + public void setWechatUnionid(String wechatUnionid) { + this.wechatUnionid = wechatUnionid; + } + + public String getElmPid() { + return elmPid; + } + + public void setElmPid(String elmPid) { + this.elmPid = elmPid; + } + public Long getInviteUserId() { return inviteUserId; } @@ -233,6 +272,9 @@ public class BsUser implements Serializable { && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) && (this.getGrade() == null ? other.getGrade() == null : this.getGrade().equals(other.getGrade())) && (this.getWechatNum() == null ? other.getWechatNum() == null : this.getWechatNum().equals(other.getWechatNum())) + && (this.getWechatOpenId() == null ? other.getWechatOpenId() == null : this.getWechatOpenId().equals(other.getWechatOpenId())) + && (this.getWechatUnionid() == null ? other.getWechatUnionid() == null : this.getWechatUnionid().equals(other.getWechatUnionid())) + && (this.getElmPid() == null ? other.getElmPid() == null : this.getElmPid().equals(other.getElmPid())) && (this.getInviteUserId() == null ? other.getInviteUserId() == null : this.getInviteUserId().equals(other.getInviteUserId())) && (this.getInviteTime() == null ? other.getInviteTime() == null : this.getInviteTime().equals(other.getInviteTime())) && (this.getPartnerLevel() == null ? other.getPartnerLevel() == null : this.getPartnerLevel().equals(other.getPartnerLevel())) @@ -255,6 +297,9 @@ public class BsUser implements Serializable { result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); result = prime * result + ((getGrade() == null) ? 0 : getGrade().hashCode()); result = prime * result + ((getWechatNum() == null) ? 0 : getWechatNum().hashCode()); + result = prime * result + ((getWechatOpenId() == null) ? 0 : getWechatOpenId().hashCode()); + result = prime * result + ((getWechatUnionid() == null) ? 0 : getWechatUnionid().hashCode()); + result = prime * result + ((getElmPid() == null) ? 0 : getElmPid().hashCode()); result = prime * result + ((getInviteUserId() == null) ? 0 : getInviteUserId().hashCode()); result = prime * result + ((getInviteTime() == null) ? 0 : getInviteTime().hashCode()); result = prime * result + ((getPartnerLevel() == null) ? 0 : getPartnerLevel().hashCode()); @@ -280,6 +325,9 @@ public class BsUser implements Serializable { sb.append(", phone=").append(phone); sb.append(", grade=").append(grade); sb.append(", wechatNum=").append(wechatNum); + sb.append(", wechatOpenId=").append(wechatOpenId); + sb.append(", wechatUnionid=").append(wechatUnionid); + sb.append(", elmPid=").append(elmPid); sb.append(", inviteUserId=").append(inviteUserId); sb.append(", inviteTime=").append(inviteTime); sb.append(", partnerLevel=").append(partnerLevel); diff --git a/service/src/main/java/com/hfkj/entity/BsUserExample.java b/service/src/main/java/com/hfkj/entity/BsUserExample.java index f305789..fdd2cef 100644 --- a/service/src/main/java/com/hfkj/entity/BsUserExample.java +++ b/service/src/main/java/com/hfkj/entity/BsUserExample.java @@ -526,6 +526,216 @@ public class BsUserExample { return (Criteria) this; } + public Criteria andWechatOpenIdIsNull() { + addCriterion("wechat_open_id is null"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdIsNotNull() { + addCriterion("wechat_open_id is not null"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdEqualTo(String value) { + addCriterion("wechat_open_id =", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdNotEqualTo(String value) { + addCriterion("wechat_open_id <>", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdGreaterThan(String value) { + addCriterion("wechat_open_id >", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdGreaterThanOrEqualTo(String value) { + addCriterion("wechat_open_id >=", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdLessThan(String value) { + addCriterion("wechat_open_id <", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdLessThanOrEqualTo(String value) { + addCriterion("wechat_open_id <=", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdLike(String value) { + addCriterion("wechat_open_id like", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdNotLike(String value) { + addCriterion("wechat_open_id not like", value, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdIn(List values) { + addCriterion("wechat_open_id in", values, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdNotIn(List values) { + addCriterion("wechat_open_id not in", values, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdBetween(String value1, String value2) { + addCriterion("wechat_open_id between", value1, value2, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatOpenIdNotBetween(String value1, String value2) { + addCriterion("wechat_open_id not between", value1, value2, "wechatOpenId"); + return (Criteria) this; + } + + public Criteria andWechatUnionidIsNull() { + addCriterion("wechat_unionid is null"); + return (Criteria) this; + } + + public Criteria andWechatUnionidIsNotNull() { + addCriterion("wechat_unionid is not null"); + return (Criteria) this; + } + + public Criteria andWechatUnionidEqualTo(String value) { + addCriterion("wechat_unionid =", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidNotEqualTo(String value) { + addCriterion("wechat_unionid <>", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidGreaterThan(String value) { + addCriterion("wechat_unionid >", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidGreaterThanOrEqualTo(String value) { + addCriterion("wechat_unionid >=", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidLessThan(String value) { + addCriterion("wechat_unionid <", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidLessThanOrEqualTo(String value) { + addCriterion("wechat_unionid <=", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidLike(String value) { + addCriterion("wechat_unionid like", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidNotLike(String value) { + addCriterion("wechat_unionid not like", value, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidIn(List values) { + addCriterion("wechat_unionid in", values, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidNotIn(List values) { + addCriterion("wechat_unionid not in", values, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidBetween(String value1, String value2) { + addCriterion("wechat_unionid between", value1, value2, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andWechatUnionidNotBetween(String value1, String value2) { + addCriterion("wechat_unionid not between", value1, value2, "wechatUnionid"); + return (Criteria) this; + } + + public Criteria andElmPidIsNull() { + addCriterion("elm_pid is null"); + return (Criteria) this; + } + + public Criteria andElmPidIsNotNull() { + addCriterion("elm_pid is not null"); + return (Criteria) this; + } + + public Criteria andElmPidEqualTo(String value) { + addCriterion("elm_pid =", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidNotEqualTo(String value) { + addCriterion("elm_pid <>", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidGreaterThan(String value) { + addCriterion("elm_pid >", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidGreaterThanOrEqualTo(String value) { + addCriterion("elm_pid >=", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidLessThan(String value) { + addCriterion("elm_pid <", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidLessThanOrEqualTo(String value) { + addCriterion("elm_pid <=", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidLike(String value) { + addCriterion("elm_pid like", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidNotLike(String value) { + addCriterion("elm_pid not like", value, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidIn(List values) { + addCriterion("elm_pid in", values, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidNotIn(List values) { + addCriterion("elm_pid not in", values, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidBetween(String value1, String value2) { + addCriterion("elm_pid between", value1, value2, "elmPid"); + return (Criteria) this; + } + + public Criteria andElmPidNotBetween(String value1, String value2) { + addCriterion("elm_pid not between", value1, value2, "elmPid"); + return (Criteria) this; + } + public Criteria andInviteUserIdIsNull() { addCriterion("invite_user_id is null"); return (Criteria) this; diff --git a/service/src/main/java/com/hfkj/service/partner/Impl/PartnerServiceImpl.java b/service/src/main/java/com/hfkj/service/partner/Impl/PartnerServiceImpl.java index 665dd39..8255d57 100644 --- a/service/src/main/java/com/hfkj/service/partner/Impl/PartnerServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/partner/Impl/PartnerServiceImpl.java @@ -589,7 +589,7 @@ public class PartnerServiceImpl implements PartnerService { // 设置用户合伙人等级 bsUser.setPartnerLevel(level.getLevel()); // 编辑用户数据 - bsUserService.editData(bsUser); + bsUserService.updateInfo(bsUser); } // 收益记录 diff --git a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java index 04aa6d1..225531f 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java @@ -16,13 +16,13 @@ public interface BsUserGradeService { * @param userId * @param userGrade */ - void gradeAdjust(Long userId, UserGradeEnum userGrade); + void gradeAdjust(Long userId, UserGradeEnum userGrade) throws Exception; /** * 等级晋升 * @param userId */ - void promote(Long userId); + void promote(Long userId) throws Exception; /** * 购买优淘会员 diff --git a/service/src/main/java/com/hfkj/service/user/BsUserService.java b/service/src/main/java/com/hfkj/service/user/BsUserService.java index 9e4881d..60a0b6e 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserService.java @@ -72,18 +72,36 @@ public interface BsUserService { BsUser getUser(Long userId); /** - * 查询详情SmsController + * 查询详情 * @param userPhone * @return */ BsUser getUser(String userPhone); + /** + * 查询详情 + * @param wechatOpenId + * @return + */ + BsUser getUserByWechatOpenId(String wechatOpenId); + /** * 查询列表 * @param param * @return */ List getList(Map param); + + /** + * 微信授权 + * @param user 用户 + * @param other 其他参数 + * @param inviteUseId 邀请人id + * @return + * @throws Exception + */ + SessionObject weChatAuth(BsUser user, Map other, Long inviteUseId) throws Exception; + /** * 用户注册 * @param phone 手机号 diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java index 3969910..0a992fc 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java @@ -37,14 +37,14 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { @Override @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) - public void gradeAdjust(Long userId, UserGradeEnum userGrade) { + public void gradeAdjust(Long userId, UserGradeEnum userGrade) throws Exception { // 查询详情 BsUser user = userService.getUser(userId); if (user == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); } user.setGrade(userGrade.getCode()); - userService.editData(user); + userService.updateInfo(user); // 修改上下级关系等级 userParentRelService.updateParentGrade(user.getId(), userGrade); @@ -52,7 +52,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { @Override @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) - public void promote(Long userId) { + public void promote(Long userId) throws Exception { // 查询详情 BsUser user = userService.getUser(userId); if (user == null) { @@ -62,7 +62,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { // 晋升优淘会员 if (promoteGrade2(user)) { user.setGrade(UserGradeEnum.grade2.getCode()); - userService.editData(user); + userService.updateInfo(user); // 修改上下级关系等级 userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade2); @@ -71,7 +71,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { // 晋升团长 if (promoteGrade3(user)) { user.setGrade(UserGradeEnum.grade3.getCode()); - userService.editData(user); + userService.updateInfo(user); // 修改上下级关系等级 userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade3); @@ -80,7 +80,7 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { // 晋升渠道 if (promoteGrade4(user)) { user.setGrade(UserGradeEnum.grade4.getCode()); - userService.editData(user); + userService.updateInfo(user); // 修改上下级关系等级 userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade4); diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index 3085fba..f4f02f0 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -92,13 +92,8 @@ public class BsUserServiceImpl implements BsUserService { } String oldPhone = user.getPhone(); user.setPhone(newPhone); - editData(user); + updateInfo(user); - // 更新session - UserSessionObject session = new UserSessionObject(); - session.setUser(user); - SessionObject sessionObject = new SessionObject(userToken(user.getId()), session); - userCenter.save(sessionObject); // 删除缓存 redisUtil.hdel(CACHE_KEY, oldPhone); } @@ -123,13 +118,7 @@ public class BsUserServiceImpl implements BsUserService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); } user.setWechatNum(wechatNum); - editData(user); - - // 更新session - UserSessionObject session = new UserSessionObject(); - session.setUser(user); - SessionObject sessionObject = new SessionObject(userToken(user.getId()), session); - userCenter.save(sessionObject); + updateInfo(user); } @Override @@ -145,21 +134,15 @@ public class BsUserServiceImpl implements BsUserService { if (getUser(inviteUseId) == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的邀请人Id"); } - user.setInviteUserId(inviteUseId); - user.setInviteTime(new Date()); - editData(user); - BsUserParentRel userParentRel = new BsUserParentRel(); userParentRel.setParentUserId(userParentRel.getParentUserId()); userParentRel.setParentUserGrade(userParentRel.getParentUserGrade()); userParentRel.setUserId(userId); userParentRelService.editData(userParentRel); - // 更新session - UserSessionObject session = new UserSessionObject(); - session.setUser(user); - SessionObject sessionObject = new SessionObject(userToken(user.getId()), session); - userCenter.save(sessionObject); + user.setInviteUserId(inviteUseId); + user.setInviteTime(new Date()); + updateInfo(user); } @Override @@ -250,6 +233,17 @@ public class BsUserServiceImpl implements BsUserService { return null; } + @Override + public BsUser getUserByWechatOpenId(String wechatOpenId) { + BsUserExample example = new BsUserExample(); + example.createCriteria().andStatusNotEqualTo(0).andWechatOpenIdEqualTo(wechatOpenId); + List list = userMapper.selectByExample(example); + if (!list.isEmpty()) { + return list.get(0); + } + return null; + } + @Override public List getList(Map param) { BsUserExample example = new BsUserExample(); @@ -279,6 +273,49 @@ public class BsUserServiceImpl implements BsUserService { return userMapper.selectByExample(example); } + @Override + @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) + public SessionObject weChatAuth(BsUser user, Map other, Long inviteUseId) throws Exception { + if (inviteUseId != null) { + // 校验邀请码 + BsUserInviteCode userInviteCode = userInviteCodeService.getDetail(inviteUseId); + if (userInviteCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的邀请码"); + } + user.setInviteUserId(userInviteCode.getUserId()); + } + + // 查询用户 + BsUser bsUser = getUserByWechatOpenId(user.getWechatOpenId()); + if (bsUser == null) { + bsUser = new BsUser(); + bsUser.setHeadImg(user.getHeadImg()); + bsUser.setName(user.getName()); + bsUser.setWechatOpenId(user.getWechatOpenId()); + bsUser.setWechatUnionid(user.getWechatUnionid()); + bsUser.setGrade(UserGradeEnum.grade1.getCode()); + bsUser.setStatus(UserStatusEnum.status1.getCode()); + editData(user); + // 创建账户余额 + userAccountService.create(user.getId()); + } else { + bsUser.setHeadImg(user.getHeadImg()); + bsUser.setName(user.getName()); + user.setInviteUserId(inviteUseId); + user.setInviteTime(new Date()); + updateInfo(user); + } + // 缓存 + UserSessionObject session = new UserSessionObject(); + session.setUser(user); + SessionObject sessionObject = new SessionObject(userToken(user.getId()), session); + userCenter.save(sessionObject); + + // 异步记录登录信息 + userLoginLogService.asyncCreateLog(UserLoginType.WECHAT_AUTH, user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); + return sessionObject; + } + @Override @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) public BsUser register(String phone, Map other, Long inviteUseId) { diff --git a/service/src/main/java/com/hfkj/sysenum/user/UserLoginType.java b/service/src/main/java/com/hfkj/sysenum/user/UserLoginType.java index 2e6e833..ddc6594 100644 --- a/service/src/main/java/com/hfkj/sysenum/user/UserLoginType.java +++ b/service/src/main/java/com/hfkj/sysenum/user/UserLoginType.java @@ -19,7 +19,7 @@ public enum UserLoginType { /** * 微信授权 */ - WECHAT_EMPOWER("WECHAT_EMPOWER", "微信授权"), + WECHAT_AUTH("WECHAT_AUTH", "微信授权"), ; private String code;