Просмотр исходного кода

[用户信息更新][新增]:微信用户获取手机号后,在basic_info表里也记录下来

release_toaliyun_real
Stormeye.Wu 7 лет назад
Родитель
Сommit
1ecbcd7b51
8 измененных файлов: 85 добавлений и 42 удалений
  1. +54
    -12
      mallinkCApi/src/main/java/com/simple/controller/BaseController.java
  2. +18
    -1
      mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java
  3. +3
    -12
      mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java
  4. +0
    -3
      mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java
  5. +0
    -7
      mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java
  6. +7
    -4
      mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java
  7. +2
    -2
      mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java
  8. +1
    -1
      mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml

+ 54
- 12
mallinkCApi/src/main/java/com/simple/controller/BaseController.java Просмотреть файл

@@ -1,22 +1,17 @@
package com.simple.controller; package com.simple.controller;


import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import com.simple.annotation.AuthIgnore;
import com.simple.common.ErrorCode; import com.simple.common.ErrorCode;
import com.simple.domain.po.WxAppinfo; import com.simple.domain.po.WxAppinfo;
import com.simple.domain.po.WxCUser; import com.simple.domain.po.WxCUser;
import com.simple.domain.po.WxCUserBasicInfo;
import com.simple.exception.MallinkException; import com.simple.exception.MallinkException;
import com.simple.interceptor.AuthorizationInterceptor; import com.simple.interceptor.AuthorizationInterceptor;
import com.simple.service.WxAppinfoService; import com.simple.service.WxAppinfoService;
import com.simple.service.WxCUserBasicInfoService;
import com.simple.service.WxCUserService; import com.simple.service.WxCUserService;
import com.simple.utils.MaUtil; import com.simple.utils.MaUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.InitBinder;
@@ -25,6 +20,11 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@RestController @RestController
public class BaseController { public class BaseController {
@@ -34,6 +34,9 @@ public class BaseController {
@Autowired @Autowired
private WxAppinfoService wxAppinfoService; private WxAppinfoService wxAppinfoService;


@Autowired
private WxCUserBasicInfoService wxCUserBasicInfoService;

@InitBinder @InitBinder
public void InitBinder(WebDataBinder dataBinder) { public void InitBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
@@ -56,7 +59,7 @@ public class BaseController {
}); });
} }


public WxCUser getUser(){
public WxCUser getUser() {
Long cUserId = getUserId(); Long cUserId = getUserId();
WxCUser user = wxCUserService.getById(cUserId); WxCUser user = wxCUserService.getById(cUserId);
if (user == null) if (user == null)
@@ -65,12 +68,12 @@ public class BaseController {
} }


public Long getUserId() { public Long getUserId() {
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
Long cUserId = (Long)request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Long cUserId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
return cUserId; return cUserId;
} }


public String getTenantId(){
public String getTenantId() {
Long cUserId = getUserId(); Long cUserId = getUserId();
WxCUser user = wxCUserService.getById(cUserId); WxCUser user = wxCUserService.getById(cUserId);
if (user == null) if (user == null)
@@ -92,4 +95,43 @@ public class BaseController {
WxMaService service = MaUtil.getWeappService(appinfo); WxMaService service = MaUtil.getWeappService(appinfo);
return service; return service;
} }


public void saveToBasicInfo(WxCUser user) {
String phone = user.getPhone();
if (phone.contains("*")) {
phone = user.getVerifyCodePhone();
if (StringUtils.isBlank(phone))
return;
}

List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(user.getTenantId(), phone);
if (list.size() > 0) {
WxCUserBasicInfo basicInfo = list.get(0);
// 微信名称
if (basicInfo.getNickName() == null || basicInfo.getNickName().equals(user.getNickName())) {
basicInfo.setNickName(user.getNickName());
}
// 性别
if (basicInfo.getSex() == null) {
basicInfo.setSex(user.getGender());
}
// 成长值
if (basicInfo.getPoins() == null) {
basicInfo.setPoins(user.getScore());
}
wxCUserBasicInfoService.saveOrUpdate(basicInfo);
} else {
Date cur = new Date();
WxCUserBasicInfo basicInfo = new WxCUserBasicInfo();
basicInfo.setTenantId(user.getTenantId());
basicInfo.setPhone(phone);
basicInfo.setNickName(user.getNickName());
basicInfo.setSex(user.getGender());
basicInfo.setPoins(user.getScore());
basicInfo.setCreateDate(cur);
basicInfo.setUpdateDate(cur);
wxCUserBasicInfoService.saveOrUpdate(basicInfo);
}
}
} }

+ 18
- 1
mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java Просмотреть файл

@@ -1,8 +1,10 @@
package com.simple.controller; package com.simple.controller;


import com.simple.common.Result;
import com.simple.common.ResultData; import com.simple.common.ResultData;
import com.simple.domain.po.WxCUser; import com.simple.domain.po.WxCUser;
import com.simple.domain.po.WxMsgValidationcode; import com.simple.domain.po.WxMsgValidationcode;
import com.simple.service.WxCUserService;
import com.simple.service.WxMerchantBUserService; import com.simple.service.WxMerchantBUserService;
import com.simple.service.WxMerchantService; import com.simple.service.WxMerchantService;
import com.simple.service.WxMsgValidationcodeService; import com.simple.service.WxMsgValidationcodeService;
@@ -16,6 +18,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;


import java.util.Date;

@RestController @RestController
@RequestMapping("/api/wxMsgValidationcode") @RequestMapping("/api/wxMsgValidationcode")
@Api(description = "短信验证相关接口") @Api(description = "短信验证相关接口")
@@ -31,6 +35,9 @@ public class WxMsgValidationcodeController extends BaseController {
@Autowired @Autowired
private WxMerchantService wxMerchantService; private WxMerchantService wxMerchantService;


@Autowired
private WxCUserService wxCUserService;



@GetMapping("sendvalidationcode") @GetMapping("sendvalidationcode")
@ApiImplicitParams({ @ApiImplicitParams({
@@ -59,7 +66,17 @@ public class WxMsgValidationcodeController extends BaseController {
wxMsgValidationcode.setType(type); wxMsgValidationcode.setType(type);
wxMsgValidationcode.setCode(code); wxMsgValidationcode.setCode(code);
wxMsgValidationcode.setAppid(user.getAppId()); wxMsgValidationcode.setAppid(user.getAppId());
return wxMsgValidationcodeService.hasvalidationcode(wxMsgValidationcode);
ResultData rd = wxMsgValidationcodeService.hasvalidationcode(wxMsgValidationcode);
if (rd.code == Result.SUCCESS) {
// 更新 WxCUser
user.setVerifyCodePhone(phone);
user.setUpdateDate(new Date());
wxCUserService.saveOrUpdate(user);

// 更新到basicinfo
saveToBasicInfo(user);
}
return rd;
} }






+ 3
- 12
mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java Просмотреть файл

@@ -53,9 +53,6 @@ public class WxUserGrantController extends BaseController {
@Autowired @Autowired
private WxCUserService wxCUserService; private WxCUserService wxCUserService;


@Autowired
private WxCUserBasicInfoService wxCUserBasicInfoService;

@Autowired @Autowired
private WxCUserCarService wxCUserCarService; private WxCUserCarService wxCUserCarService;


@@ -262,15 +259,9 @@ public class WxUserGrantController extends BaseController {
return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap); return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap);
} }


// update wx_c_user_basic_info
List<WxCUserBasicInfo> list = wxCUserBasicInfoService.findByPhone(user.getTenantId(), user.getPhone());
if (list.size() > 0) {
WxCUserBasicInfo basicInfo = list.get(0);
try {
wxCUserBasicInfoService.updateObj(basicInfo, user.getId());
} catch (Exception e) {

}
if (!user.getPhone().contains("*")) { // 用户手机非加密
// 更新到basicinfo
saveToBasicInfo(user);
} }


return new ResultData(resultMap); return new ResultData(resultMap);


+ 0
- 3
mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java Просмотреть файл

@@ -52,9 +52,6 @@ public interface WxCUserBasicInfoService {
*/ */
void deleteById(Long id); void deleteById(Long id);



PageInfo<WxCUserBasicInfo> list(WxCUserBasicInfoDto record, Integer pageIndex, Integer pageSize);

List<WxCUserBasicInfo> findByPhone(String tenantId, String phone); List<WxCUserBasicInfo> findByPhone(String tenantId, String phone);


/** /**


+ 0
- 7
mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java Просмотреть файл

@@ -48,13 +48,6 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findList(record)); return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findList(record));
} }

@Override
public PageInfo<WxCUserBasicInfo> list(WxCUserBasicInfoDto record, Integer pageIndex, Integer pageSize) {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.list(record));
}

@Override @Override
public List<WxCUserBasicInfo> findByPhone(String tenantId, String phone) { public List<WxCUserBasicInfo> findByPhone(String tenantId, String phone) {
WxCUserBasicInfo basicQ = new WxCUserBasicInfo(); WxCUserBasicInfo basicQ = new WxCUserBasicInfo();


+ 7
- 4
mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java Просмотреть файл

@@ -87,12 +87,15 @@ public class WxCUserServiceImpl implements WxCUserService {
@Override @Override
public void scoreCalculate(String tenantId, Long cUserId) { public void scoreCalculate(String tenantId, Long cUserId) {
// login count
int login_count = 0;

WxCUser user = wxCUserMapper.selectByPrimaryKey(cUserId); WxCUser user = wxCUserMapper.selectByPrimaryKey(cUserId);
if (user != null) {
login_count = user.getLoginCount();
if (user == null) {
return;
} }
// 登录次数
// login count
int login_count = user.getLoginCount();

// coupon order // coupon order
WxCouponOrder couponOrder = new WxCouponOrder(); WxCouponOrder couponOrder = new WxCouponOrder();
couponOrder.setTenantId(tenantId); couponOrder.setTenantId(tenantId);


+ 2
- 2
mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java Просмотреть файл

@@ -183,9 +183,9 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic
Date currentdate = new Date(); Date currentdate = new Date();
wxmsgvalidationcodelist = wxmsgvalidationcodelist.stream().filter(validationcode -> wxmsgvalidationcodelist = wxmsgvalidationcodelist.stream().filter(validationcode ->
validationcode.getExpiretime().after(currentdate)).collect(Collectors.toList()); validationcode.getExpiretime().after(currentdate)).collect(Collectors.toList());
if(wxmsgvalidationcodelist.size()>0) return new ResultData(200,"验证码存在",true);
if(wxmsgvalidationcodelist.size()>0) return new ResultData(Result.SUCCESS,"验证码存在",true);


return new ResultData(500,"验证码不存在或过期",false);
return new ResultData(Result.ERROR,"验证码不存在或过期",false);


} }




+ 1
- 1
mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml Просмотреть файл

@@ -21,7 +21,7 @@


<sql id="allColumns"> <sql id="allColumns">
`id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`, `id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`,
`create_date`,`update_date`,`tenant_id`,`name`,level,nick_name
`create_date`,`update_date`,`tenant_id`,`name`, level, nick_name
</sql> </sql>


<sql id="dynamicWhereConditions"> <sql id="dynamicWhereConditions">


Загрузка…
Отмена
Сохранить