diff --git a/mallinkCApi/src/main/java/com/simple/controller/BaseController.java b/mallinkCApi/src/main/java/com/simple/controller/BaseController.java index 74687a3fc..03b24b0cb 100644 --- a/mallinkCApi/src/main/java/com/simple/controller/BaseController.java +++ b/mallinkCApi/src/main/java/com/simple/controller/BaseController.java @@ -1,22 +1,17 @@ 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.impl.WxMaServiceImpl; -import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; -import com.simple.annotation.AuthIgnore; import com.simple.common.ErrorCode; import com.simple.domain.po.WxAppinfo; import com.simple.domain.po.WxCUser; +import com.simple.domain.po.WxCUserBasicInfo; import com.simple.exception.MallinkException; import com.simple.interceptor.AuthorizationInterceptor; import com.simple.service.WxAppinfoService; +import com.simple.service.WxCUserBasicInfoService; import com.simple.service.WxCUserService; import com.simple.utils.MaUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.WebDataBinder; 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 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 public class BaseController { @@ -34,6 +34,9 @@ public class BaseController { @Autowired private WxAppinfoService wxAppinfoService; + @Autowired + private WxCUserBasicInfoService wxCUserBasicInfoService; + @InitBinder public void InitBinder(WebDataBinder dataBinder) { dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @@ -56,7 +59,7 @@ public class BaseController { }); } - public WxCUser getUser(){ + public WxCUser getUser() { Long cUserId = getUserId(); WxCUser user = wxCUserService.getById(cUserId); if (user == null) @@ -65,12 +68,12 @@ public class BaseController { } 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; } - public String getTenantId(){ + public String getTenantId() { Long cUserId = getUserId(); WxCUser user = wxCUserService.getById(cUserId); if (user == null) @@ -92,4 +95,43 @@ public class BaseController { WxMaService service = MaUtil.getWeappService(appinfo); return service; } + + + public void saveToBasicInfo(WxCUser user) { + String phone = user.getPhone(); + if (phone.contains("*")) { + phone = user.getVerifyCodePhone(); + if (StringUtils.isBlank(phone)) + return; + } + + List 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); + } + } } diff --git a/mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java b/mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java index 108ad066a..93c3c47eb 100644 --- a/mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java +++ b/mallinkCApi/src/main/java/com/simple/controller/WxMsgValidationcodeController.java @@ -1,8 +1,10 @@ package com.simple.controller; +import com.simple.common.Result; import com.simple.common.ResultData; import com.simple.domain.po.WxCUser; import com.simple.domain.po.WxMsgValidationcode; +import com.simple.service.WxCUserService; import com.simple.service.WxMerchantBUserService; import com.simple.service.WxMerchantService; 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.RestController; +import java.util.Date; + @RestController @RequestMapping("/api/wxMsgValidationcode") @Api(description = "短信验证相关接口") @@ -31,6 +35,9 @@ public class WxMsgValidationcodeController extends BaseController { @Autowired private WxMerchantService wxMerchantService; + @Autowired + private WxCUserService wxCUserService; + @GetMapping("sendvalidationcode") @ApiImplicitParams({ @@ -59,7 +66,17 @@ public class WxMsgValidationcodeController extends BaseController { wxMsgValidationcode.setType(type); wxMsgValidationcode.setCode(code); 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; } diff --git a/mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java b/mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java index c50f099b1..51f4ea58c 100755 --- a/mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java +++ b/mallinkCApi/src/main/java/com/simple/controller/WxUserGrantController.java @@ -53,9 +53,6 @@ public class WxUserGrantController extends BaseController { @Autowired private WxCUserService wxCUserService; - @Autowired - private WxCUserBasicInfoService wxCUserBasicInfoService; - @Autowired private WxCUserCarService wxCUserCarService; @@ -262,15 +259,9 @@ public class WxUserGrantController extends BaseController { return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap); } - // update wx_c_user_basic_info - List 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); diff --git a/mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java b/mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java index 616d50da8..443a8333a 100644 --- a/mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java +++ b/mallinkService/src/main/java/com/simple/service/WxCUserBasicInfoService.java @@ -52,9 +52,6 @@ public interface WxCUserBasicInfoService { */ void deleteById(Long id); - - PageInfo list(WxCUserBasicInfoDto record, Integer pageIndex, Integer pageSize); - List findByPhone(String tenantId, String phone); /** diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java index aaffd8b5e..81522ce3f 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/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)); } - - - @Override - public PageInfo list(WxCUserBasicInfoDto record, Integer pageIndex, Integer pageSize) { - return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.list(record)); - } - @Override public List findByPhone(String tenantId, String phone) { WxCUserBasicInfo basicQ = new WxCUserBasicInfo(); diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java index dfb2ea248..758613089 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java @@ -87,12 +87,15 @@ public class WxCUserServiceImpl implements WxCUserService { @Override public void scoreCalculate(String tenantId, Long cUserId) { - // login count - int login_count = 0; + 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 WxCouponOrder couponOrder = new WxCouponOrder(); couponOrder.setTenantId(tenantId); diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java index 4330c6920..851c47822 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxMsgValidationcodeServiceImpl.java @@ -183,9 +183,9 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic Date currentdate = new Date(); wxmsgvalidationcodelist = wxmsgvalidationcodelist.stream().filter(validationcode -> 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); } diff --git a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml index 81e153bff..d1694f2e3 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml @@ -21,7 +21,7 @@ `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