1.优化
Showing
1 changed file
with
91 additions
and
4 deletions
... | @@ -170,13 +170,87 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -170,13 +170,87 @@ public class UserOperationServiceImpl implements UserOperationService { |
170 | String headimgurl = resources.getHeadimgurl(); | 170 | String headimgurl = resources.getHeadimgurl(); |
171 | Integer sex = resources.getSex(); | 171 | Integer sex = resources.getSex(); |
172 | 172 | ||
173 | // 检查小屏账户是否存在 | 173 | // 账户和会员都存在 |
174 | UserWeixinDTO userWeixinDTO = this.findFirstByUnionIdAndAppIdAndOpenId(unionId, appId, openId); | 174 | UserWeixinDTO userWeixinDTO = this.findFirstByAppIdAndOpenId(appId, openId); |
175 | if (Objects.nonNull(userWeixinDTO.getId())) { | 175 | if (Objects.nonNull(userWeixinDTO.getId()) && Objects.nonNull(userWeixinDTO.getMemberId())) { |
176 | log.error("createWeixinUserAndMember ==>> result ==>> [{}]", userWeixinDTO); | 176 | log.error("createWeixinUserAndMember ==>> result ==>> [{}]", userWeixinDTO); |
177 | throw new BadRequestException(GlobeExceptionMsg.OPERATION_FORBID + "==>> " + GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); | 177 | throw new BadRequestException(GlobeExceptionMsg.OPERATION_FORBID + "==>> " + GlobeExceptionMsg.ENTITY_ALREADY_EXISTS); |
178 | } | 178 | } |
179 | 179 | ||
180 | // 账号存在但无会员 | ||
181 | if (Objects.nonNull(userWeixinDTO.getId()) && Objects.isNull(userWeixinDTO.getMemberId())) { | ||
182 | |||
183 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 | ||
184 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); | ||
185 | if (Objects.nonNull(_userWeixinDTO.getId())) { | ||
186 | |||
187 | if (Objects.nonNull(_userWeixinDTO.getMemberId())) { | ||
188 | |||
189 | // 有其他账号的话,将此账号与对应的会员进行绑定 | ||
190 | MemberDTO memberDTO = this.findMemberById(_userWeixinDTO.getMemberId()); | ||
191 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
192 | userWeixinDTO.setMemberCode(memberDTO.getCode()); | ||
193 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
194 | userWeixinDTO.setUnionid(unionId); | ||
195 | } | ||
196 | UserWeixin userWeixin = new UserWeixin(); | ||
197 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
198 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
199 | return _userWeixinDTO1; | ||
200 | |||
201 | } else { | ||
202 | |||
203 | // 有其他账号但都无会员,新建会员并将此账号绑定新建的这个会员 | ||
204 | Member _member = | ||
205 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
206 | headimgurl, nickname, 0, sex); | ||
207 | |||
208 | MemberDTO memberDTO = this.createMember(_member); | ||
209 | |||
210 | if (Objects.nonNull(memberDTO)) { | ||
211 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
212 | userWeixinDTO.setMemberCode(memberDTO.getCode()); | ||
213 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
214 | userWeixinDTO.setUnionid(unionId); | ||
215 | } | ||
216 | UserWeixin userWeixin = new UserWeixin(); | ||
217 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
218 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
219 | return _userWeixinDTO1; | ||
220 | |||
221 | } | ||
222 | |||
223 | } | ||
224 | |||
225 | } else { | ||
226 | |||
227 | // 该账号存在但无其他账号,新建会员 | ||
228 | Member _member = | ||
229 | MemberBuilder.build(LocalConstants.MEMBER_PLATFORM_TYPE_WEIXIN, | ||
230 | headimgurl, nickname, 0, sex); | ||
231 | |||
232 | MemberDTO memberDTO = this.createMember(_member); | ||
233 | |||
234 | if (Objects.nonNull(memberDTO)) { | ||
235 | userWeixinDTO.setMemberId(memberDTO.getId()); | ||
236 | userWeixinDTO.setMemberCode(memberDTO.getCode()); | ||
237 | if (StringUtils.isBlank(userWeixinDTO.getUnionid())) { | ||
238 | userWeixinDTO.setUnionid(unionId); | ||
239 | } | ||
240 | UserWeixin userWeixin = new UserWeixin(); | ||
241 | BeanUtils.copyProperties(userWeixinDTO, userWeixin); | ||
242 | UserWeixinDTO _userWeixinDTO1 = this.updateWeixin(userWeixin); | ||
243 | return _userWeixinDTO1; | ||
244 | |||
245 | } | ||
246 | |||
247 | } | ||
248 | |||
249 | } | ||
250 | |||
251 | // 无账号 | ||
252 | if (Objects.isNull(userWeixinDTO.getId())) { | ||
253 | |||
180 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 | 254 | // 当前用户的任意微信app,因为同一unionId的会员是唯一的 |
181 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); | 255 | UserWeixinDTO _userWeixinDTO = this.findFirstByUnionId(unionId); |
182 | if (Objects.nonNull(_userWeixinDTO.getId())) { | 256 | if (Objects.nonNull(_userWeixinDTO.getId())) { |
... | @@ -227,6 +301,9 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -227,6 +301,9 @@ public class UserOperationServiceImpl implements UserOperationService { |
227 | 301 | ||
228 | } | 302 | } |
229 | 303 | ||
304 | return userWeixinDTO; | ||
305 | } | ||
306 | |||
230 | 307 | ||
231 | /** | 308 | /** |
232 | * 服务号登录 | 309 | * 服务号登录 |
... | @@ -1114,11 +1191,21 @@ public class UserOperationServiceImpl implements UserOperationService { | ... | @@ -1114,11 +1191,21 @@ public class UserOperationServiceImpl implements UserOperationService { |
1114 | * @param openId | 1191 | * @param openId |
1115 | * @return | 1192 | * @return |
1116 | */ | 1193 | */ |
1117 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId( String unionId,String appId, String openId) { | 1194 | private UserWeixinDTO findFirstByUnionIdAndAppIdAndOpenId(String unionId, String appId, String openId) { |
1118 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); | 1195 | return this.userWeixinService.findFirstByUnionIdAndAppIdAndOpenId(unionId,appId,openId); |
1119 | } | 1196 | } |
1120 | 1197 | ||
1121 | /** | 1198 | /** |
1199 | * 获取小屏账户 | ||
1200 | * @param appId | ||
1201 | * @param openId | ||
1202 | * @return | ||
1203 | */ | ||
1204 | private UserWeixinDTO findFirstByAppIdAndOpenId(String appId, String openId) { | ||
1205 | return this.userWeixinService.findFirstByAppIdAndOpenId(appId, openId); | ||
1206 | } | ||
1207 | |||
1208 | /** | ||
1122 | * | 1209 | * |
1123 | * @param member | 1210 | * @param member |
1124 | * @return | 1211 | * @return | ... | ... |
-
Please register or sign in to post a comment