| @@ -8,10 +8,12 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallRolePermission; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.MallUserRole; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.MallRolePermissionService; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import com.iformall.service.MallUserRoleService; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.shiro.UserSession; | |||
| import com.iformall.shiro.UseriFormallToken; | |||
| import com.iformall.utils.ShiroUtils; | |||
| @@ -56,6 +58,9 @@ public class HomeController extends BaseController { | |||
| @Autowired | |||
| private MallRolePermissionService mallRolePermissionService; | |||
| @Autowired | |||
| private WxAppinfoService appinfoService; | |||
| @GetMapping("/captcha.jpg") | |||
| public void captcha(HttpServletResponse response)throws ServletException, IOException { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::captcha"); | |||
| @@ -167,15 +172,25 @@ public class HomeController extends BaseController { | |||
| public ResultData bLogin(@RequestBody MallUserInfo user) { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::bHidLogin"); | |||
| ResultData data = new ResultData(); | |||
| // tenantId is appId | |||
| if(StringUtils.isBlank(user.getTenantId())) { | |||
| logger.error("appid信息未提供"); | |||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | |||
| } | |||
| WxAppinfo appinfo = appinfoService.getByAppId(user.getTenantId()); | |||
| if(appinfo == null) { | |||
| logger.error("appid未找到"); | |||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | |||
| } | |||
| if(StringUtils.isNotBlank(user.getPhone())) { | |||
| // 领导登录 | |||
| user = mallUserInfoService.getByPhone(user.getPhone()); | |||
| user = mallUserInfoService.getByPhone(user.getPhone(), appinfo.getTenantId()); | |||
| if(user == null || !isInMobileAdmin(user)) { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN); | |||
| } | |||
| } else if(StringUtils.isNotBlank(user.getOpenId())) { | |||
| // 领导登录 | |||
| user = mallUserInfoService.getByOpenId(user.getOpenId()); | |||
| user = mallUserInfoService.getByOpenId(user.getOpenId(), appinfo.getTenantId()); | |||
| if(user == null || !isInMobileAdmin(user)) { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN); | |||
| } | |||
| @@ -86,10 +86,12 @@ public class WxInfoController extends BaseController { | |||
| if (StringUtils.isBlank(code)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "code不能为空"); | |||
| } | |||
| WxAppinfo wxAppinfo = getAppInfo(appId); | |||
| try { | |||
| Map<String, String> retMap = getOpenIdInfo(appId, code); | |||
| String openId = retMap.get("openId"); | |||
| MallUserInfo user = mallUserInfoService.getByOpenId(openId); | |||
| MallUserInfo user = mallUserInfoService.getByOpenId(openId, wxAppinfo.getTenantId()); | |||
| if(user == null) { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION, retMap); | |||
| } | |||
| @@ -218,6 +220,8 @@ public class WxInfoController extends BaseController { | |||
| } | |||
| WxMaService wxMaService = getWeappService(appId); | |||
| WxAppinfo wxAppinfo = getAppInfo(appId); | |||
| try { | |||
| // 解密 | |||
| WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(session_key, encryptedData, iv); | |||
| @@ -226,7 +230,7 @@ public class WxInfoController extends BaseController { | |||
| String phone = phoneNoInfo.getPhoneNumber(); | |||
| resultMap.put("phone", phone); | |||
| MallUserInfo user = mallUserInfoService.getByPhone(phone); | |||
| MallUserInfo user = mallUserInfoService.getByPhone(phone, wxAppinfo.getTenantId()); | |||
| if(user == null) { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION, resultMap); | |||
| } | |||
| @@ -13,9 +13,9 @@ public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | |||
| MallUserInfo selectByUserName(@Param("username") String username); | |||
| MallUserInfo selectByOpenId(@Param("openId") String openId); | |||
| MallUserInfo selectByOpenId(@Param("openId") String openId, @Param("tenantId") String tenantId); | |||
| MallUserInfo selectByPhone(@Param("phone") String phone); | |||
| MallUserInfo selectByPhone(@Param("phone") String phone, @Param("tenantId") String tenantId); | |||
| Integer hasButtonPermission(@Param("userId") Long userId, @Param("permission") String permission); | |||
| @@ -3,6 +3,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import java.util.List; | |||
| @@ -87,14 +88,14 @@ public interface MallUserInfoService { | |||
| * @param phone | |||
| * @return | |||
| */ | |||
| MallUserInfo getByPhone(String phone); | |||
| MallUserInfo getByPhone(String phone, String tenantId); | |||
| /** | |||
| * 根据OpenId获得实体 | |||
| * | |||
| * @param openId | |||
| * @return | |||
| */ | |||
| MallUserInfo getByOpenId(String openId); | |||
| MallUserInfo getByOpenId(String openId, String tenantId); | |||
| /** | |||
| * 根据条件用户列表 | |||
| @@ -8,6 +8,7 @@ import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.MallUserRole; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxMsgValidationcode; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.MallUserInfoMapper; | |||
| @@ -57,13 +58,13 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||
| } | |||
| @Override | |||
| public MallUserInfo getByOpenId(String openId) { | |||
| return mallUserInfoMapper.selectByOpenId(openId); | |||
| public MallUserInfo getByOpenId(String openId, String tenantId) { | |||
| return mallUserInfoMapper.selectByOpenId(openId, tenantId); | |||
| } | |||
| @Override | |||
| public MallUserInfo getByPhone(String phone) { | |||
| return mallUserInfoMapper.selectByPhone(phone); | |||
| public MallUserInfo getByPhone(String phone, String tenantId) { | |||
| return mallUserInfoMapper.selectByPhone(phone, tenantId); | |||
| } | |||
| @Override | |||
| @@ -103,6 +103,9 @@ | |||
| <include refid="allColumns"/> | |||
| from mall_user_info | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id`=#{tenantId} | |||
| </if> | |||
| <if test=" null != openId "> | |||
| and `open_id`=#{openId} | |||
| </if> | |||
| @@ -113,6 +116,9 @@ | |||
| <include refid="allColumns"/> | |||
| from mall_user_info | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id`=#{tenantId} | |||
| </if> | |||
| <if test=" null != phone "> | |||
| and `phone`=#{phone} | |||
| </if> | |||