developrelease_toaliyun_real
| @@ -78,6 +78,7 @@ public class WxCreditHistoryController extends BaseController { | |||||
| wxCreditHistory.setTenantId(user.getTenantId()); | wxCreditHistory.setTenantId(user.getTenantId()); | ||||
| wxCreditHistory.setOperatorId(user.getId()); | wxCreditHistory.setOperatorId(user.getId()); | ||||
| try { | try { | ||||
| wxCreditHistoryService.creditUsercheck(wxCreditHistory.getCUserId()) ; | |||||
| WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | ||||
| return new ResultData(Result.SUCCESS, "操作成功", credit); | return new ResultData(Result.SUCCESS, "操作成功", credit); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| @@ -0,0 +1,24 @@ | |||||
| DROP TABLE IF EXISTS `mall_sale_type` ; | |||||
| CREATE TABLE `mall_sale_type` ( | |||||
| `id` bigint(64) NOT NULL, | |||||
| `name` varchar(32) DEFAULT NULL COMMENT '销售类型', | |||||
| `type` tinyint(2) DEFAULT NULL COMMENT '资源类型1:尊享全能版 2:尊享营销版 3.速享版', | |||||
| `period` tinyint(2) DEFAULT NULL COMMENT '有效期(单位月)', | |||||
| `menus` json DEFAULT NULL COMMENT '菜单列表', | |||||
| PRIMARY KEY (`id`), | |||||
| UNIQUE `id_UNIQUE` USING BTREE (`id`) comment '' | |||||
| ) ENGINE=`InnoDB` ROW_FORMAT=DYNAMIC COMMENT='系统销售表' CHECKSUM=0 DELAY_KEY_WRITE=0; | |||||
| INSERT INTO `mall_sale_type` | |||||
| (`id`,`name`, `type`, `period`, `menus`) | |||||
| VALUES | |||||
| (1, '尊享全能版', 1, 12, | |||||
| '[1,2,3,4,5,6,7,8,9,10,50,101,102,103,104,105,106,107,108,201,202,203,204,205,206,211,212,221,222,251,299,300,301,302,303,304,305,306,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,501,502,503,504,505,506,507,508,509,511,512,513,521,522,523,531,532,533,591,592,595,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,627,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932,951,952,961,962,965,966,967,968]' | |||||
| ), | |||||
| (2, '尊享营销版', 2, 12, | |||||
| '[1,2,4,5,6,7,8,9,10,50,101,102,103,104,105,106,107,201,202,203,204,205,211,212,221,222,251,409,410,411,416,501,502,503,504,505,506,507,508,509,511,512,513,521,522,523,531,532,533,591,592,595,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,627,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932,951,961]' | |||||
| ), | |||||
| (3, '速享版', 3, 1, | |||||
| '[2,4,5,6,7,10,50,201,202,205,211,212,221,222,251,409,410,411,416,501,502,503,504,505,506,507,508,511,512,513,521,522,523,531,532,533,591,592,601,602,603,604,605,606,607,608,609,610,611,612,621,622,623,624,625,626,641,642,643,644,645,651,661,662,663,671,672,673,674,681,682,683,684,685,691,692,693,694,695,701,702,711,712,713,901,902,903,931,932]' | |||||
| ) | |||||
| ; | |||||
| @@ -92,6 +92,7 @@ public class WxCUserController extends BaseController { | |||||
| wxCUser.setOpenId(wxCUserFromBDto.getOpenid()); | wxCUser.setOpenId(wxCUserFromBDto.getOpenid()); | ||||
| wxCUser = wxCUserService.getByOpenId(wxCUser); | wxCUser = wxCUserService.getByOpenId(wxCUser); | ||||
| if (wxCUserFromB == null) { | if (wxCUserFromB == null) { | ||||
| //TODO phone可能为空 | |||||
| String phone = wxCUser.getPhone(); | String phone = wxCUser.getPhone(); | ||||
| String tenantId = wxCUser.getTenantId(); | String tenantId = wxCUser.getTenantId(); | ||||
| //查询会员信息 | //查询会员信息 | ||||
| @@ -15,6 +15,7 @@ import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCreditHistoryService; | import com.iformall.service.WxCreditHistoryService; | ||||
| import com.iformall.service.WxMerchantService; | import com.iformall.service.WxMerchantService; | ||||
| import com.iformall.utils.UserUtil; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -25,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| import java.util.Objects; | import java.util.Objects; | ||||
| @RestController | @RestController | ||||
| @@ -61,7 +63,14 @@ public class WxCreditHistoryController extends BaseController { | |||||
| if(Objects.isNull(merchantId)|| StringUtils.isEmpty(spendStr)||Objects.isNull(userId)) { | if(Objects.isNull(merchantId)|| StringUtils.isEmpty(spendStr)||Objects.isNull(userId)) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL) ; | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL) ; | ||||
| } | } | ||||
| return new ResultData(wxCreditHistoryService.findByMerchantIdAndSpend(merchantId,spendStr,userId,getTenantId())); | |||||
| try { | |||||
| Map<String, Integer> result = wxCreditHistoryService.findByMerchantIdAndSpend(merchantId, spendStr, userId, getTenantId()); | |||||
| return new ResultData(result); | |||||
| } catch (MallinkException e) { | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR, e.getMessage()); | |||||
| } | |||||
| } | } | ||||
| @ApiOperation("根据手机号查询接口") | @ApiOperation("根据手机号查询接口") | ||||
| @@ -104,7 +113,7 @@ public class WxCreditHistoryController extends BaseController { | |||||
| //B端操作用户 | //B端操作用户 | ||||
| wxCreditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | wxCreditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | ||||
| try { | try { | ||||
| wxCreditHistoryService.check(wxCreditHistory.getCUserId()); | |||||
| wxCreditHistoryService.creditUsercheck(wxCreditHistory.getCUserId()); | |||||
| WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | ||||
| return new ResultData(Result.SUCCESS, "操作成功", credit); | return new ResultData(Result.SUCCESS, "操作成功", credit); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| @@ -25,21 +25,6 @@ public class WxCreditHistoryController extends BaseController{ | |||||
| @Autowired | @Autowired | ||||
| private WxCreditHistoryService wxCreditHistoryService; | private WxCreditHistoryService wxCreditHistoryService; | ||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("/add") | |||||
| public ResultData add(@RequestBody WxCreditHistory wxCreditHistory) { | |||||
| log.debug("[" + getIpAddr() + "] WxCreditHistoryController::add"); | |||||
| wxCreditHistory.setTenantId(getTenantId()); | |||||
| wxCreditHistory.setOperatorId(getUser().getId()); | |||||
| try { | |||||
| WxCreditHistory credit = wxCreditHistoryService.saveOrUpdate(wxCreditHistory); | |||||
| return new ResultData(Result.SUCCESS, "操作成功", credit); | |||||
| } catch (MallinkException e) { | |||||
| log.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("用户积分列表") | @ApiOperation("用户积分列表") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -129,7 +129,7 @@ public class WxShop extends BaseEntity { | |||||
| private String rent; | private String rent; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "预置业态", name = "businessId") | @io.swagger.annotations.ApiModelProperty(value = "预置业态", name = "businessId") | ||||
| private Long businessId; | |||||
| private Integer businessId; | |||||
| @io.swagger.annotations.ApiModelProperty(value = "租金单位", name = "rentUnit") | @io.swagger.annotations.ApiModelProperty(value = "租金单位", name = "rentUnit") | ||||
| private Integer rentUnit; | private Integer rentUnit; | ||||
| @@ -5,6 +5,7 @@ import com.iformall.domain.po.WxCreditHistory; | |||||
| import com.iformall.domain.vo.WxCreditHistoryNewIdVo; | import com.iformall.domain.vo.WxCreditHistoryNewIdVo; | ||||
| import com.iformall.domain.vo.WxCreditHistoryVo; | import com.iformall.domain.vo.WxCreditHistoryVo; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Long> { | public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Long> { | ||||
| @@ -29,7 +30,5 @@ public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Lon | |||||
| long getPeopleCount(WxCreditHistory wxCreditHistory); | long getPeopleCount(WxCreditHistory wxCreditHistory); | ||||
| List<WxCreditHistory> findListAfter(Integer creditType, String dateTime); | |||||
| } | } | ||||
| @@ -40,11 +40,12 @@ public interface WxCreditHistoryService { | |||||
| WxCreditHistory getById(Long id); | WxCreditHistory getById(Long id); | ||||
| /** | /** | ||||
| * 校验用户是否存在 | |||||
| * 添加积分时,需要校验用户以及手机号是否存在 | |||||
| * 规则:有手机号增加积分,无手机号提示授权手机号 | |||||
| * @param cUserId | * @param cUserId | ||||
| */ | */ | ||||
| void check(Long cUserId) ; | |||||
| void creditUsercheck(Long cUserId); | |||||
| /** | /** | ||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| * | * | ||||
| @@ -311,7 +311,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||||
| @Override | @Override | ||||
| public void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll) { | public void exportBill(HttpServletRequest request, HttpServletResponse response, WxBillAll wxBillAll) { | ||||
| Map<Long, List<WxBillAllVo>> collect = wxBillAllMapper.list(wxBillAll).parallelStream() | |||||
| Map<Long, List<WxBillAllVo>> collect = wxBillAllMapper.list(wxBillAll) | |||||
| .stream().filter(b -> null != b.getMerchantId()) | |||||
| .collect(Collectors.groupingBy(WxBillAllVo::getMerchantId)); | .collect(Collectors.groupingBy(WxBillAllVo::getMerchantId)); | ||||
| Set<Map.Entry<Long, List<WxBillAllVo>>> entries = collect.entrySet(); | Set<Map.Entry<Long, List<WxBillAllVo>>> entries = collect.entrySet(); | ||||
| List<WxBillAllVo> datalist = new ArrayList<>(); | List<WxBillAllVo> datalist = new ArrayList<>(); | ||||
| @@ -2632,7 +2632,7 @@ public class WxChartServiceImpl implements WxChartDataService { | |||||
| query.setFloor(Long.valueOf(floor)); | query.setFloor(Long.valueOf(floor)); | ||||
| } | } | ||||
| if (StringUtils.isNotEmpty(business)) { | if (StringUtils.isNotEmpty(business)) { | ||||
| query.setBusinessId(Long.valueOf(business)); | |||||
| query.setBusinessId(Integer.valueOf(business)); | |||||
| } | } | ||||
| query.setType(null); | query.setType(null); | ||||
| Long total = wxShopMapper.getCountByWxShop(query); | Long total = wxShopMapper.getCountByWxShop(query); | ||||
| @@ -19,6 +19,7 @@ import com.iformall.service.WxCreditHistoryService; | |||||
| import com.iformall.service.WxScoreRulesService; | import com.iformall.service.WxScoreRulesService; | ||||
| import com.iformall.utils.CreditUtil; | import com.iformall.utils.CreditUtil; | ||||
| import com.iformall.utils.RedisLock; | import com.iformall.utils.RedisLock; | ||||
| import com.iformall.utils.UserUtil; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -195,11 +196,10 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void check(Long cUserId) { | |||||
| public void creditUsercheck(Long cUserId) { | |||||
| WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(cUserId); | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(cUserId); | WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(cUserId); | ||||
| if (wxCUserBasicInfo == null) { | |||||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||||
| } | |||||
| UserUtil.creditUserCheck(wxCUser, wxCUserBasicInfo); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -224,9 +224,6 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||||
| if (record.getCreditAmount() == null) { | if (record.getCreditAmount() == null) { | ||||
| record.setCreditAmount(currentCreditAmount); | record.setCreditAmount(currentCreditAmount); | ||||
| } | } | ||||
| if (record.getCreditNum() == null) { | |||||
| record.setCreditNum(0); | |||||
| } | |||||
| int creditChangeNumOrigin = creditIncrement(record); | int creditChangeNumOrigin = creditIncrement(record); | ||||
| int creditChangeNum = creditChangeNumOrigin ; | int creditChangeNum = creditChangeNumOrigin ; | ||||
| @@ -234,12 +231,13 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||||
| boolean hasBirthDateCredit = false; | boolean hasBirthDateCredit = false; | ||||
| if (record.getCreditType().equals(EnumScoreType.CONSUMPTION.getCode()) || record.getCreditType().equals(EnumScoreType.SPEND_CREDIT.getCode())) { | if (record.getCreditType().equals(EnumScoreType.CONSUMPTION.getCode()) || record.getCreditType().equals(EnumScoreType.SPEND_CREDIT.getCode())) { | ||||
| //等级积分配置 | //等级积分配置 | ||||
| Integer levelScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()); | |||||
| try { | try { | ||||
| creditChangeNum = CreditUtil.calUserCredit(creditChangeNumOrigin, wxCUser, levelScale, wxCUserBasicInfo, wxScoreRulesService); | |||||
| creditChangeNum = CreditUtil.calUserCredit(creditChangeNumOrigin, wxCUser, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||||
| if (Objects.nonNull(CreditUtil.getIsBirthDayScale())) { | if (Objects.nonNull(CreditUtil.getIsBirthDayScale())) { | ||||
| hasBirthDateCredit = true; | hasBirthDateCredit = true; | ||||
| } | } | ||||
| } catch (Exception e) { | |||||
| logger.error("积分倍率计算异常",e); | |||||
| } finally { | } finally { | ||||
| CreditUtil.clear(); | CreditUtil.clear(); | ||||
| } | } | ||||
| @@ -350,8 +348,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||||
| if (Objects.nonNull(userId)) { | if (Objects.nonNull(userId)) { | ||||
| WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(userId); | WxCUser wxCUser = wxCUserMapper.selectByPrimaryKey(userId); | ||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(userId); | WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoMapper.selectByPrimaryKey(userId); | ||||
| Integer birthdayScale = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()); | |||||
| creditNew = CreditUtil.calUserCredit(credit, wxCUser, birthdayScale, wxCUserBasicInfo, wxScoreRulesService); | |||||
| creditNew = CreditUtil.calUserCredit(credit, wxCUser, wxCUserBasicInfo, wxScoreRulesService,wxLevelConfigMapper); | |||||
| } else { | } else { | ||||
| creditNew = credit; | creditNew = credit; | ||||
| } | } | ||||
| @@ -493,7 +490,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||||
| for (int i = 0; i < busRules.size(); i++) { | for (int i = 0; i < busRules.size(); i++) { | ||||
| JSONObject bus = (JSONObject) busRules.get(i); | JSONObject bus = (JSONObject) busRules.get(i); | ||||
| Integer businessId1 = bus.getInteger("businessId"); | Integer businessId1 = bus.getInteger("businessId"); | ||||
| if (record.getBusinessId().equals(Long.valueOf(businessId1))) { | |||||
| if (record.getBusinessId().equals(businessId1)) { | |||||
| busRule = bus; | busRule = bus; | ||||
| } | } | ||||
| if (businessId1.equals(EnumBusiness.BUSINESS_ID6.getCode())) { | if (businessId1.equals(EnumBusiness.BUSINESS_ID6.getCode())) { | ||||
| @@ -1,8 +1,10 @@ | |||||
| package com.iformall.utils; | package com.iformall.utils; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.mapper.WxLevelConfigMapper; | |||||
| import com.iformall.service.WxScoreRulesService; | import com.iformall.service.WxScoreRulesService; | ||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.util.Objects; | import java.util.Objects; | ||||
| @@ -17,17 +19,35 @@ public class CreditUtil { | |||||
| * | * | ||||
| * @param creditOrigin 原始积分 | * @param creditOrigin 原始积分 | ||||
| * @param wxCUser C端用户信息 | * @param wxCUser C端用户信息 | ||||
| * @param levelScaleConfig 等级倍率配置 | |||||
| * @param wxCUserBasicInfo C端用户信息 | * @param wxCUserBasicInfo C端用户信息 | ||||
| * @param wxScoreRulesService | * @param wxScoreRulesService | ||||
| * @param wxLevelConfigMapper | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| public static int calUserCredit(int creditOrigin, WxCUser wxCUser, Integer levelScaleConfig, WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) { | |||||
| if (Objects.isNull(wxCUser) || Objects.isNull(wxCUserBasicInfo)) { | |||||
| return 0; | |||||
| public static int calUserCredit(int creditOrigin, WxCUser wxCUser, WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService, WxLevelConfigMapper wxLevelConfigMapper) { | |||||
| Long userId = null; | |||||
| Integer score = null; | |||||
| String tenantId = null; | |||||
| Integer levelScaleConfig = WxLevelConfig.DEFAULT_SCALE ; | |||||
| if (Objects.nonNull(wxCUser)) { | |||||
| userId = wxCUser.getId(); | |||||
| score = wxCUser.getScore(); | |||||
| tenantId = wxCUser.getTenantId(); | |||||
| } | |||||
| if (Objects.isNull(userId)) { | |||||
| userId = wxCUserBasicInfo.getId(); | |||||
| } | |||||
| if (Objects.isNull(score)) { | |||||
| score = wxCUserBasicInfo.getPoins(); | |||||
| } | |||||
| if (StringUtils.isBlank(tenantId)) { | |||||
| tenantId = wxCUserBasicInfo.getTenantId(); | |||||
| } | } | ||||
| levelScaleConfig = wxLevelConfigMapper.getScale(tenantId, score) ; | |||||
| // 获取等级积分倍率, | // 获取等级积分倍率, | ||||
| int levelScale = getLevelScale(wxCUser, levelScaleConfig); | |||||
| int levelScale = getLevelScale(score, levelScaleConfig); | |||||
| // 获取生日积分倍率: | // 获取生日积分倍率: | ||||
| int birthdayScale = getBirthdayScale(wxCUserBasicInfo, wxScoreRulesService); | int birthdayScale = getBirthdayScale(wxCUserBasicInfo, wxScoreRulesService); | ||||
| @@ -38,20 +58,20 @@ public class CreditUtil { | |||||
| .divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)) | .divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)) | ||||
| .divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE) | .divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE) | ||||
| , BigDecimal.ROUND_HALF_UP).intValue(); | , BigDecimal.ROUND_HALF_UP).intValue(); | ||||
| log.info("积分倍率计算, 用户:{},成长值:{},等级积分倍率:{},生日积分倍率:{},原积分:{},新积分:{}", wxCUser.getId(), wxCUser.getScore(), levelScale, birthdayScale, creditOrigin, creditNew); | |||||
| log.info("积分倍率计算, 用户:{},成长值:{},等级积分倍率:{},生日积分倍率:{},原积分:{},新积分:{}", userId, score, levelScale, birthdayScale, creditOrigin, creditNew); | |||||
| return creditNew; | return creditNew; | ||||
| } | } | ||||
| /** | /** | ||||
| * 根据会员信息获取等级积分倍率 | * 根据会员信息获取等级积分倍率 | ||||
| * | * | ||||
| * @param wxCUser | |||||
| * @param levelScaleConfig | * @param levelScaleConfig | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| private static int getLevelScale(WxCUser wxCUser, Integer levelScaleConfig) { | |||||
| private static int getLevelScale(Integer score, Integer levelScaleConfig) { | |||||
| int levelScale = WxLevelConfig.DEFAULT_SCALE; | int levelScale = WxLevelConfig.DEFAULT_SCALE; | ||||
| Integer score = wxCUser.getScore(); | |||||
| //积分不为空时进行计算 | //积分不为空时进行计算 | ||||
| if (Objects.nonNull(score)) { | if (Objects.nonNull(score)) { | ||||
| //等级积分配置存在时进行计算 | //等级积分配置存在时进行计算 | ||||
| @@ -74,6 +94,9 @@ public class CreditUtil { | |||||
| */ | */ | ||||
| private static int getBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) { | private static int getBirthdayScale(WxCUserBasicInfo wxCUserBasicInfo, WxScoreRulesService wxScoreRulesService) { | ||||
| int birthdayScale = WxScoreRules.DEFAULT_SCALE; | int birthdayScale = WxScoreRules.DEFAULT_SCALE; | ||||
| if (Objects.isNull(wxCUserBasicInfo) || StringUtils.isBlank(wxCUserBasicInfo.getPhone())) { | |||||
| return 0; | |||||
| } | |||||
| //判断是否生日当天,一年一天有效 | //判断是否生日当天,一年一天有效 | ||||
| //没有发过生日券的用户或者没有享受过生日积分倍率的用户 | //没有发过生日券的用户或者没有享受过生日积分倍率的用户 | ||||
| if(Objects.isNull(wxCUserBasicInfo.getScoreDate())) { | if(Objects.isNull(wxCUserBasicInfo.getScoreDate())) { | ||||
| @@ -0,0 +1,38 @@ | |||||
| package com.iformall.utils; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import java.util.Objects; | |||||
| /** | |||||
| * 用户校验工具类 | |||||
| */ | |||||
| public class UserUtil { | |||||
| /** | |||||
| * 增加积分:校验用户信息 | |||||
| * 规则:有手机号增加积分,无手机号提示授权手机号 | |||||
| * @param wxCUser | |||||
| * @param wxCUserBasicInfo | |||||
| */ | |||||
| public static void creditUserCheck(WxCUser wxCUser, WxCUserBasicInfo wxCUserBasicInfo) { | |||||
| if (Objects.isNull(wxCUser) && Objects.isNull(wxCUserBasicInfo)) { | |||||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||||
| } | |||||
| if (Objects.isNull(wxCUserBasicInfo)|| StringUtils.isBlank(wxCUserBasicInfo.getPhone())) { | |||||
| throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||||
| } | |||||
| // 根据当前业务,wxCUserBasicInfo存在手机号,wxCUser肯定存在,除非人为删除手机号 | |||||
| //if (Objects.isNull(wxCUser)|| StringUtils.isBlank(wxCUser.getPhone())) { | |||||
| // throw new MallinkException(ErrorCode.USER_NOT_AUTH_PHONE); | |||||
| //} | |||||
| } | |||||
| } | |||||
| @@ -795,7 +795,9 @@ | |||||
| select <include refid="allCouponOrderColumns" /> | select <include refid="allCouponOrderColumns" /> | ||||
| from wx_coupon_order co, wx_merchant_b_user mbu | from wx_coupon_order co, wx_merchant_b_user mbu | ||||
| where mbu.id = co.b_user_id | where mbu.id = co.b_user_id | ||||
| and mbu.merchant_id = #{merchantId} | |||||
| <if test="merchantId != null"> | |||||
| and mbu.merchant_id = #{merchantId} | |||||
| </if> | |||||
| <if test="startDate != null"> | <if test="startDate != null"> | ||||
| AND co.update_date > #{startDate,jdbcType=TIMESTAMP} | AND co.update_date > #{startDate,jdbcType=TIMESTAMP} | ||||
| </if> | </if> | ||||
| @@ -249,4 +249,8 @@ | |||||
| ) credit | ) credit | ||||
| </select> | </select> | ||||
| <select id="findListAfter" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_credit_history where create_date > #{dateTime} and credit_type = #{creditType} | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||
| @@ -3,23 +3,23 @@ package com.iformall.controller.sys; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMall; | |||||
| import com.iformall.domain.po.WxMsgSignature; | |||||
| import com.iformall.domain.po.WxMsgValidationcodeModel; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumMsgModel; | import com.iformall.enums.EnumMsgModel; | ||||
| import com.iformall.mapper.WxMallMapper; | |||||
| import com.iformall.mapper.WxMsgSignatureMapper; | |||||
| import com.iformall.mapper.WxMsgValidationcodeModelMapper; | |||||
| import com.iformall.enums.EnumScoreType; | |||||
| import com.iformall.enums.EnumUserType; | |||||
| import com.iformall.mapper.*; | |||||
| import com.iformall.service.WxCreditHistoryService; | |||||
| import com.iformall.utils.DateUtils; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | 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 javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import java.util.*; | |||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| /** | /** | ||||
| @@ -28,7 +28,7 @@ import java.util.stream.Collectors; | |||||
| @Slf4j | @Slf4j | ||||
| @RestController | @RestController | ||||
| @RequestMapping("sys") | @RequestMapping("sys") | ||||
| public class DataInitController { | |||||
| public class DataInitController extends BaseController { | |||||
| @Resource | @Resource | ||||
| @@ -37,11 +37,35 @@ public class DataInitController { | |||||
| private WxMsgSignatureMapper signatureMapper; | private WxMsgSignatureMapper signatureMapper; | ||||
| @Resource | @Resource | ||||
| private WxMsgValidationcodeModelMapper modelMapper; | private WxMsgValidationcodeModelMapper modelMapper; | ||||
| @Resource | |||||
| private WxCreditHistoryMapper creditHistoryMapper; | |||||
| @Resource | |||||
| private WxCreditHistoryService creditHistoryService; | |||||
| @Resource | |||||
| private WxCUserMapper cUserMapper; | |||||
| @Resource | |||||
| private WxCUserBasicInfoMapper cUserBasicInfoMapper; | |||||
| @Resource | |||||
| private WxCouponMapper couponMapper; | |||||
| @Resource | |||||
| private WxCouponOrderMapper couponOrderMapper; | |||||
| @Resource | |||||
| private WxMerchantBUserMapper merchantBUserMapper; | |||||
| @GetMapping("/init") | @GetMapping("/init") | ||||
| public ResultData init() { | public ResultData init() { | ||||
| try { | try { | ||||
| addBirthDayMsgModel(); | |||||
| MallUserInfo userInfo = getUser(); | |||||
| if (userInfo.isFmSuperAdmin()) { | |||||
| addBirthDayMsgModel(); | |||||
| return new ResultData(); | |||||
| } | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| log.error("DataInitController::init error ", e); | log.error("DataInitController::init error ", e); | ||||
| return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); | return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); | ||||
| @@ -50,6 +74,150 @@ public class DataInitController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| /** | |||||
| * 积分数据修复 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @GetMapping("/fixCredit") | |||||
| public ResultData fixCredit() { | |||||
| try { | |||||
| MallUserInfo userInfo = getUser(); | |||||
| if(userInfo.isFmSuperAdmin()) { | |||||
| doFixCredit(); | |||||
| return new ResultData(); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("DataInitController::fixCredit error ", e); | |||||
| return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| /** | |||||
| * 核销积分数据修复 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @GetMapping("/fixVerifyCredit") | |||||
| public ResultData fixVerifyCredit() { | |||||
| try { | |||||
| MallUserInfo userInfo = getUser(); | |||||
| if(userInfo.isFmSuperAdmin()) { | |||||
| doFixVerifyCredit(); | |||||
| return new ResultData(); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("DataInitController::fixCredit error ", e); | |||||
| return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @Transactional(rollbackFor = Exception.class) | |||||
| public void doFixCredit() { | |||||
| // 1 获取积分记录 | |||||
| List<WxCreditHistory> creditList = creditHistoryMapper.findListAfter(10, "2019-09-16 22:00:00"); | |||||
| // 2 重新计算积分,比较是否需要修复 | |||||
| creditList.forEach(wxCreditHistory -> { | |||||
| WxCUser cUser = cUserMapper.selectByPrimaryKey(wxCreditHistory.getCUserId()); | |||||
| WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(wxCreditHistory.getCUserId()); | |||||
| //排查不存在的用户 | |||||
| if (Objects.isNull(cUser) && Objects.isNull(userBasicInfo)) { | |||||
| log.debug("用户不存在 id: {}", wxCreditHistory.getId()); | |||||
| return; | |||||
| } | |||||
| Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(wxCreditHistory.getSpend()), wxCreditHistory.getCUserId(), wxCreditHistory.getTenantId()); | |||||
| Integer creditDB = wxCreditHistory.getCreditNum(); | |||||
| Integer credit = result.get("credit"); | |||||
| if (Objects.equals(credit, creditDB)) { | |||||
| log.debug("本次积分计算:正确, id: {},原积分: {},重新计算积分: {}, 积分时间: {}", wxCreditHistory.getId(), creditDB, credit, DateUtils.format(wxCreditHistory.getCreateDate())); | |||||
| } else { | |||||
| log.debug("本次积分计算:错误, id: {},原积分: {},重新计算积分: {}, 积分时间: {}", wxCreditHistory.getId(), creditDB, credit, DateUtils.format(wxCreditHistory.getCreateDate())); | |||||
| // 3 重新计算积分 | |||||
| //用户新积分 | |||||
| Integer newCredit = wxCreditHistory.getCreditAmount() - creditDB + credit; | |||||
| // 4 更新积分 | |||||
| WxCUser toUpdateCUser = new WxCUser(); | |||||
| toUpdateCUser.setId(wxCreditHistory.getCUserId()); | |||||
| toUpdateCUser.setCredit(newCredit); | |||||
| toUpdateCUser.setUpdateDate(new Date()); | |||||
| cUserMapper.updateByPrimaryKeySelective(toUpdateCUser); | |||||
| WxCUserBasicInfo toUpdateBasicInfo = new WxCUserBasicInfo(); | |||||
| toUpdateBasicInfo.setId(wxCreditHistory.getCUserId()); | |||||
| toUpdateBasicInfo.setCredit(newCredit); | |||||
| toUpdateBasicInfo.setUpdateDate(new Date()); | |||||
| cUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdateBasicInfo); | |||||
| WxCreditHistory toUpdateCreditHistory = new WxCreditHistory(); | |||||
| toUpdateCreditHistory.setId(wxCreditHistory.getId()); | |||||
| toUpdateCreditHistory.setCreditNum(credit); | |||||
| toUpdateCreditHistory.setCreditAmount(newCredit); | |||||
| creditHistoryMapper.updateByPrimaryKeySelective(toUpdateCreditHistory); | |||||
| } | |||||
| }); | |||||
| } | |||||
| @Transactional(rollbackFor = Exception.class) | |||||
| public void doFixVerifyCredit() { | |||||
| // 1 获取券码 | |||||
| Map dateMap = new HashMap(); | |||||
| dateMap.put("startDate", "2019-09-16 22:00:00"); | |||||
| List<WxCouponOrder> coList = couponOrderMapper.findListOfVerifiedByDate(dateMap); | |||||
| // 2 重新计算积分,比较是否需要修复 | |||||
| coList.forEach(co -> { | |||||
| WxCUser cuUser = cUserMapper.selectByPrimaryKey(co.getcUserId()); | |||||
| WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(co.getcUserId()); | |||||
| //排查不存在的用户 | |||||
| if (Objects.isNull(cuUser) && Objects.isNull(userBasicInfo)) { | |||||
| log.debug("用户不存在 id: {}", co.getId()); | |||||
| return; | |||||
| } | |||||
| WxCoupon coupon = couponMapper.selectByPrimaryKey(co.getCouponId()); | |||||
| WxMerchantBUser buUser = merchantBUserMapper.selectByPrimaryKey(co.getBUserId()); | |||||
| Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(buUser.getMerchantId(), String.valueOf(co.getCouponPriceStr()), co.getCUserId(), co.getTenantId()); | |||||
| Integer credit = result.get("credit"); | |||||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||||
| creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | |||||
| creditHistory.setOperatorId(buUser.getId()); | |||||
| creditHistory.setCUserId(co.getcUserId()); | |||||
| creditHistory.setCreateDate(co.getUpdateDate()); | |||||
| creditHistory.setTenantId(co.getTenantId()); | |||||
| creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); | |||||
| creditHistory.setCouponId(coupon.getId()); | |||||
| creditHistory.setBusinessId(coupon.getBusiness()); | |||||
| creditHistory.setSpend(co.getCouponPrice()); | |||||
| //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | |||||
| creditHistory.setMerchantId(buUser.getMerchantId()); | |||||
| creditHistoryService.saveOrUpdate(creditHistory); | |||||
| //用户新积分 | |||||
| Integer newCredit = cuUser.getCredit() + credit; | |||||
| // 4 更新积分 | |||||
| WxCUser toUpdateCUser = new WxCUser(); | |||||
| toUpdateCUser.setId(co.getCUserId()); | |||||
| toUpdateCUser.setCredit(newCredit); | |||||
| toUpdateCUser.setUpdateDate(new Date()); | |||||
| cUserMapper.updateByPrimaryKeySelective(toUpdateCUser); | |||||
| WxCUserBasicInfo toUpdateBasicInfo = new WxCUserBasicInfo(); | |||||
| toUpdateBasicInfo.setId(co.getCUserId()); | |||||
| toUpdateBasicInfo.setCredit(newCredit); | |||||
| toUpdateBasicInfo.setUpdateDate(new Date()); | |||||
| cUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdateBasicInfo); | |||||
| }); | |||||
| } | |||||
| /** | /** | ||||
| * 增加会员生日短信模板 | * 增加会员生日短信模板 | ||||
| */ | */ | ||||