| @@ -2,6 +2,7 @@ package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.GetPointDTO; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxLevelConfig; | |||
| @@ -112,6 +113,44 @@ public class UserBasicInfoController extends BaseController { | |||
| return new ResultData(basicInfo); | |||
| } | |||
| @PostMapping("/pointChange") | |||
| @ApiOperation(value = "变更积分", notes = "") | |||
| public ResultData pointChange(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBasicInfoController >>>>>>>>>>>> pointChange >>>>>>>>>>>>>"+map.toString()); | |||
| String phone = map.get("phone")==null?"":map.get("phone").toString(); | |||
| String changePoints = map.get("changePoints")==null?"":map.get("changePoints").toString(); | |||
| if(StringUtils.isBlank(phone)){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"手机号不能为空"); | |||
| } | |||
| if(!phone.matches("^1[0-9]{10}$")){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"手机号格式不正确"); | |||
| } | |||
| try { | |||
| Integer.parseInt(changePoints); | |||
| } catch (NumberFormatException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"changePoints为整数"); | |||
| } | |||
| wxCUserBasicInfoService.updatePointsByPhone(getTenantInfo(), Integer.parseInt(changePoints), phone); | |||
| return new ResultData(); | |||
| } | |||
| @PostMapping("/getPoint") | |||
| @ApiOperation(value = "查询积分", notes = "") | |||
| public ResultData getPoint(@RequestBody Map<String,Object> map) { | |||
| logger.info("UserBasicInfoController >>>>>>>>>>>> getPoint >>>>>>>>>>>>>"+map.toString()); | |||
| String phone = map.get("phone")==null?"":map.get("phone").toString(); | |||
| if(StringUtils.isBlank(phone)){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"手机号不能为空"); | |||
| } | |||
| if(!phone.matches("^1[0-9]{10}$")){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"手机号格式不正确"); | |||
| } | |||
| WxCUserBasicInfo result = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone); | |||
| GetPointDTO getPointDTO = WxCUserBasicInfo.mappingDTO(result); | |||
| return new ResultData(getPointDTO); | |||
| } | |||
| private void setLevel(WxCUserBasicInfo basicInfo,TenantEntity tenantEntity){ | |||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantInfo(tenantEntity); | |||
| basicInfo.setLevelList(levelList); | |||
| @@ -124,5 +163,4 @@ public class UserBasicInfoController extends BaseController { | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,78 @@ | |||
| package com.iformall.utils; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.utils.sign.SignUtils; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| public class CallTest { | |||
| private static final String BASIC_URL = "https://openapitest.malls.iformall.com"; | |||
| public static void main(String[] args) { | |||
| String appId = "CP6nwHvZ"; | |||
| String appKey = "b257eb97bb9380714306a077a66086e8b1f10639"; | |||
| String signKey = "C61842C8570524AA81756C53B8096978A06AE00D"; | |||
| // 会员注册 | |||
| // userRegister(appId, appKey, signKey); | |||
| // 会员查询 | |||
| getUserInfo(appId, appKey, signKey); | |||
| // 查询积分 | |||
| // getPoint(appId, appKey, signKey); | |||
| } | |||
| public static void userRegister(String appId, String appKey, String signKey) { | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| String timeStamp = Long.toString(new Date().getTime()); | |||
| paramMap.put("timeStamp",timeStamp); | |||
| paramMap.put("phone","17600000000"); | |||
| paramMap.put("nickName","昵称"); | |||
| paramMap.put("sex","1"); | |||
| paramMap.put("avatarUrl","xxx"); | |||
| String path = "/api/userInfo/register"; | |||
| String result = getResult(appId, appKey, signKey, paramMap, path); | |||
| System.out.println(result); | |||
| } | |||
| private static String getResult(String appId, String appKey, String signKey, Map<String, Object> paramMap, String path) { | |||
| //签名 | |||
| String sign = SignUtils.getSign(signKey, paramMap, "MD5"); | |||
| System.out.println("sign="+sign); | |||
| String url = BASIC_URL + path; | |||
| String headAppKey = appId+"&"+appKey; | |||
| String headSign = sign; | |||
| String paramJson = JSON.toJSONString(paramMap); | |||
| Map<String, String> headMap = new HashMap<>(); | |||
| headMap.put("appKey", headAppKey); | |||
| headMap.put("sign", headSign); | |||
| return HttpUtil.doPost(url, headMap, paramJson); | |||
| } | |||
| public static void getUserInfo(String appId, String appKey, String signKey) { | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| String timeStamp = Long.toString(new Date().getTime()); | |||
| paramMap.put("timeStamp",timeStamp); | |||
| paramMap.put("phone","17600000000"); | |||
| String path = "/api/userInfo/get"; | |||
| String result = getResult(appId, appKey, signKey, paramMap, path); | |||
| System.out.println(result); | |||
| } | |||
| public static void getPoint(String appId, String appKey, String signKey) { | |||
| Map<String,Object> paramMap = new HashMap<>(); | |||
| String timeStamp = Long.toString(new Date().getTime()); | |||
| paramMap.put("timeStamp",timeStamp); | |||
| paramMap.put("phone","17600000000"); | |||
| String path = "/api/userInfo/getPoint"; | |||
| String result = getResult(appId, appKey, signKey, paramMap, path); | |||
| System.out.println(result); | |||
| } | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| package com.iformall.domain.dto; | |||
| import lombok.Data; | |||
| /** | |||
| * 获取积分DTO | |||
| * | |||
| * @author xmzhao71 | |||
| * @date 2023-08-31 | |||
| */ | |||
| @Data | |||
| public class GetPointDTO { | |||
| private String phone; | |||
| private Integer points; | |||
| } | |||
| @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.fasterxml.jackson.annotation.JsonIgnore; | |||
| import com.iformall.domain.dto.GetPointDTO; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.base.TenantEntityWithoutFinalTenantId; | |||
| @@ -251,4 +252,11 @@ public class WxCUserBasicInfo extends TenantEntityWithoutFinalTenantId { | |||
| } | |||
| } | |||
| public static GetPointDTO mappingDTO(WxCUserBasicInfo result) { | |||
| GetPointDTO dto = new GetPointDTO(); | |||
| dto.setPhone(result.getPhone()); | |||
| dto.setPoints(result.getCredit()); | |||
| return dto; | |||
| } | |||
| } | |||
| @@ -183,5 +183,13 @@ public interface WxCUserBasicInfoService { | |||
| void phoneFirstMsg(TenantEntity tenantEntity, Long id, boolean isFirst); | |||
| void completeInfoMsg(TenantEntity tenantEntity, Long id); | |||
| /** | |||
| * 通过手机号更新积分 | |||
| * @param tenantEntity 租户实体 | |||
| * @param changePoints 变更积分 | |||
| * @param phone 电话 | |||
| */ | |||
| void updatePointsByPhone(TenantEntity tenantEntity, Integer changePoints, String phone); | |||
| } | |||
| @@ -2,6 +2,9 @@ package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |||
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| @@ -1381,5 +1384,16 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc | |||
| } | |||
| } | |||
| @Override | |||
| public void updatePointsByPhone(TenantEntity tenantEntity, Integer changePoints, String phone) { | |||
| WxCUserBasicInfo wxCUserBasicInfo = this.findInfoByPhone(tenantEntity, phone); | |||
| wxCUserBasicInfo.setCredit(wxCUserBasicInfo.getCredit() + changePoints); | |||
| wxCUserBasicInfoMapper.update(wxCUserBasicInfo, | |||
| new LambdaUpdateWrapper<WxCUserBasicInfo>() | |||
| .eq(WxCUserBasicInfo::getFinalTenantId, wxCUserBasicInfo.getFinalTenantId()) | |||
| .eq(WxCUserBasicInfo::getPhone, phone)); | |||
| } | |||
| } | |||