Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

176 строки
6.6 KiB

  1. package com.simple.controller;
  2. import com.simple.annotation.AuthIgnore;
  3. import com.simple.common.ErrorCode;
  4. import com.simple.common.Result;
  5. import com.simple.common.ResultData;
  6. import com.simple.domain.po.WxMall;
  7. import com.simple.domain.po.WxMerchant;
  8. import com.simple.domain.po.WxMerchantBUser;
  9. import com.simple.service.WxMallService;
  10. import com.simple.service.WxMerchantBUserService;
  11. import com.simple.service.WxMerchantService;
  12. import com.simple.utils.IPUtil;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.apache.log4j.Logger;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import org.springframework.web.context.request.RequestContextHolder;
  20. import org.springframework.web.context.request.ServletRequestAttributes;
  21. import javax.servlet.http.HttpServletRequest;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. @RestController
  26. @Api(description="B端用户相关接口")
  27. @RequestMapping("/api/user")
  28. public class WxMerchantBUserController extends BaseController
  29. {
  30. private Logger logger = Logger.getLogger(WxMerchantBUserController.class);
  31. @Autowired
  32. private WxMerchantBUserService wxMerchantBUserService;
  33. @Autowired
  34. private WxMerchantService wxMerchantService;
  35. @Autowired
  36. private WxMallService wxMallService;
  37. @ApiOperation("查寻当bUser详情接口")
  38. @GetMapping("/detail")
  39. public ResultData detail() {
  40. Map resultMap = new HashMap();
  41. WxMerchantBUser user = wxMerchantBUserService.getById(getUser().getId());
  42. if (user==null)
  43. return new ResultData(ErrorCode.USER_IS_EMPTY);
  44. WxMerchant merchant = wxMerchantService.getById(user.getMerchantId());
  45. if (merchant==null)
  46. return new ResultData(ErrorCode.MCH_INFO_NOT_FOUND);
  47. WxMall mall = wxMallService.getByTenantId(merchant.getTenantId());
  48. if (mall==null)
  49. return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND);
  50. resultMap.put("phone",user.getPhone());
  51. resultMap.put("name",user.getName());
  52. resultMap.put("merchant_name",merchant.getName());
  53. resultMap.put("merchant_img_url",merchant.getImgUrl());
  54. resultMap.put("mall_name",mall.getName());
  55. resultMap.put("service_phone",mall.getServicePhone());
  56. return new ResultData(resultMap);
  57. }
  58. /**
  59. * 用户登录
  60. * @param map
  61. * @return
  62. */
  63. @AuthIgnore
  64. @PostMapping("/login")
  65. @ApiOperation(value="用户登录", notes="{" +
  66. "\"appId\":\"string\"," +
  67. "\"phone\":\"string\",\"password\":\"string\"," +
  68. "\"latitude\":\"string\",\"longitude\":\"string\"}")
  69. public ResultData userLogin(@RequestBody Map<String, String> map) {
  70. logger.debug(map.toString());
  71. Map resultMap = new HashMap();
  72. String appId = map.get("appId");
  73. String phone = map.get("phone");
  74. String password = map.get("password");
  75. String latitude = map.get("latitude");
  76. String longitude = map.get("longitude");
  77. //登录凭证不能为空
  78. if (StringUtils.isBlank(phone)) {
  79. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "手机号不能为空");
  80. }
  81. if (StringUtils.isBlank(password)) {
  82. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "密码不能为空");
  83. }
  84. String token = null;
  85. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
  86. String ipaddress = IPUtil.getIpAddr(request);
  87. if (!StringUtils.isBlank(latitude)&&!StringUtils.isBlank(longitude)) {
  88. //return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "经纬度未获取");
  89. logger.info("B端用户: " + phone + " 登录 IP" + ipaddress + ", 经纬度(" + longitude + "," + latitude + ")");
  90. }
  91. WxMerchantBUser user = new WxMerchantBUser();
  92. user.setAppId(appId);
  93. user.setPhone(phone);
  94. Date currentDate = new Date();
  95. try {
  96. WxMerchantBUser user1 = wxMerchantBUserService.getBUserByAppId(user);
  97. if (user1 != null) {
  98. // check merchant 状态
  99. WxMerchant merchant = wxMerchantService.getById(user1.getMerchantId());
  100. if (merchant == null) {
  101. logger.error(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage( ) + ": " + user1.getMerchantId());
  102. return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND);
  103. }
  104. if (!merchant.isValid()) {
  105. logger.error(ErrorCode.MERCHANT_INFO_NOT_VALID.getMessage( ) + ": " + user1.getMerchantId());
  106. return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID);
  107. }
  108. // check password
  109. if (user1.getBUserPwd().equalsIgnoreCase(password)) {
  110. user1.createToken(currentDate);
  111. token = user1.getToken();
  112. wxMerchantBUserService.saveOrUpdate(user1);
  113. resultMap.put("token", token);
  114. } else {
  115. return new ResultData(ErrorCode.PASSWORD_ERROR);
  116. }
  117. } else {
  118. logger.error("B端用户不存在, phone: " + phone);
  119. return new ResultData(ErrorCode.USER_IS_EMPTY);
  120. }
  121. } catch (Exception e) {
  122. logger.error(e.getMessage());
  123. return new ResultData(ErrorCode.DB_FAIL.getCode(), "B端用户数据库更新出错", resultMap);
  124. }
  125. return new ResultData(resultMap);
  126. }
  127. @AuthIgnore
  128. @ApiOperation("修改密码")
  129. @PostMapping("/updatepwd")
  130. public ResultData updatepwd(@RequestBody Map<String,String> params) {
  131. // String phone,String code,String pwd
  132. String phone=params.get("phone");
  133. String code=params.get("code");
  134. String pwd=params.get("pwd");
  135. boolean blank = StringUtils.isBlank(phone);
  136. if(blank){
  137. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"手机号不能为空");
  138. }
  139. blank = StringUtils.isBlank(code);
  140. if(blank){
  141. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"验证码不能为空");
  142. }
  143. blank = StringUtils.isBlank(pwd);
  144. if(blank){
  145. return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"密码不能为空");
  146. }
  147. return wxMerchantBUserService.updatepwd(phone,code,pwd);
  148. }
  149. }