From 7ed4e1fac319129dfb37071d457e40efeae8c5c0 Mon Sep 17 00:00:00 2001 From: xhxu Date: Tue, 19 Jan 2021 12:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mem/WxScoreRulesController.java | 42 ++++++++++++++++--- .../com/iformall/enums/EnumScoreRules.java | 3 +- .../iformall/service/WxScoreRulesService.java | 1 + .../service/impl/WxScoreRulesServiceImpl.java | 26 ++++++++++++ .../java/com/iformall/utils/Constant.java | 2 + 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java b/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java index a0be99868..d08859336 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java @@ -4,9 +4,13 @@ import com.iformall.annotation.SystemControllerLog; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; +import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxScoreRules; import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.EnumCreditLockedStatus; +import com.iformall.enums.EnumGroupSupport; +import com.iformall.enums.EnumScoreRules; +import com.iformall.service.WxMallService; import com.iformall.service.WxScoreRulesService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -25,6 +29,9 @@ public class WxScoreRulesController extends BaseController { @Autowired private WxScoreRulesService wxScoreRulesService; + @Autowired + private WxMallService wxMallService; + @ApiOperation("成长值配置") @GetMapping("setting") @SystemControllerLog(description = "成长值-配置") @@ -42,11 +49,27 @@ public class WxScoreRulesController extends BaseController { @SystemControllerLog(description = "成长值-积分-配置-新增") public ResultData add(@RequestBody WxScoreRules wxScoreRules) { logger.debug("[" + getIpAddr() + "] WxScoreRulesController::add"); - TenantEntity tenantEntity = ifParentUpdateTenantInfo(); - if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { - return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "广场用户无此权限"); + if(wxScoreRules.getType() != null){ + if(wxScoreRules.getType().equals(EnumScoreRules.SCORE.getCode()) || wxScoreRules.getType().equals(EnumScoreRules.CREDIT.getCode())){ + TenantEntity tenantEntity = ifParentUpdateTenantInfo(); + if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { + return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "广场用户无此权限"); + } + wxScoreRules.updateTenantInfo(tenantEntity); + }else if(wxScoreRules.getType().equals(EnumScoreRules.CREDIT_DOUBLE.getCode())){ + TenantEntity tenantEntity = getTenantInfo(); + WxMall mall = wxMallService.getByTenantId(getUser().getTenantId()); + if((mall.getGroupSupport().equals(EnumGroupSupport.SUPPORT.getCode()) && StringUtils.isBlank(getUser().getParentTenantId())) || + StringUtils.isBlank(tenantEntity.getTenantId())){ + return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "集团用户无此权限"); + } + wxScoreRules.updateTenantInfo(tenantEntity); + }else{ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"type"); + } + }else{ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"type"); } - wxScoreRules.updateTenantInfo(tenantEntity); wxScoreRulesService.saveOrUpdate(wxScoreRules); return new ResultData(); } @@ -55,11 +78,20 @@ public class WxScoreRulesController extends BaseController { @GetMapping("/credit_rules") @SystemControllerLog(description = "积分-配置") public ResultData creditRulesList() { - logger.debug("[" + getIpAddr() + "] WxScoreRulesController::list"); + logger.debug("[" + getIpAddr() + "] creditRulesList::list"); WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(getTenantInfo().getFinalTenantId()); return new ResultData(scoreRules); } + @ApiOperation("积分倍率") + @GetMapping("/credit_double") + @SystemControllerLog(description = "积分-配置") + public ResultData creditDoubleRulesList() { + logger.debug("[" + getIpAddr() + "] creditDoubleRulesList::list"); + WxScoreRules scoreRules = wxScoreRulesService.getCreditDoubleRules(getTenantInfo().getTenantId()); + return new ResultData(scoreRules); + } + @ApiOperation("更新积分开关状态") @PostMapping("updateCreditLocked") @SystemControllerLog(description = "更新积分开关状态") diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumScoreRules.java b/mallinkService/src/main/java/com/iformall/enums/EnumScoreRules.java index 8c1167f68..3d2cdf373 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumScoreRules.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumScoreRules.java @@ -3,7 +3,8 @@ package com.iformall.enums; public enum EnumScoreRules { SCORE(1, "成长值"), - CREDIT(2, "积分") + CREDIT(2, "积分"), + CREDIT_DOUBLE(4, "积分倍率") ; public static EnumScoreRules getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java index b8fcb6ac5..801db890a 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java @@ -62,4 +62,5 @@ public interface WxScoreRulesService { void updateCreditLocked(WxScoreRules wxScoreRules); + WxScoreRules getCreditDoubleRules(String tenantId); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java index 376b599bc..eb10f2e1c 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java @@ -679,6 +679,32 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { updateMerchantCreditLocked(wxScoreRules); } + @Override + public WxScoreRules getCreditDoubleRules(String tenantId) { + String key = Constant.CREDIT_DOUBLE_RULES_KEY_PREV + tenantId; + + // 缓存存在 + if (scoreRulesRedisTemplate.hasKey(key)) { + WxScoreRules wScoreRules = scoreRulesRedisTemplate.opsForValue().get(key); + logger.info("WxScoreRulesServiceImpl.getScoreRules() : 从缓存中获取了积分倍率设置 >> " + wScoreRules.toString()); + return wScoreRules; + } + + WxScoreRules scoreRules = new WxScoreRules(); + scoreRules.setTenantId(tenantId); + scoreRules.setType(EnumScoreRules.CREDIT_DOUBLE.getCode()); + List list = wxScoreRulesMapper.findList(scoreRules); + if (list.size() > 0) { + scoreRules = list.get(0); + // 插入缓存 + scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); + logger.info("WxScoreRulesServiceImpl.getScoreRules() : 积分设置插入缓存 >> " + scoreRules.toString()); + } else{ + return null; + } + return scoreRules; + } + public void updateMerchantCreditLocked(WxScoreRules wxScoreRules) { WxMerchant wxMerchant = new WxMerchant(); wxMerchant.updateTenantInfo(wxScoreRules); diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index 0a0df0e23..a6612c247 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -65,6 +65,8 @@ public class Constant { public static final String SCORE_RULES_KEY_PREV = "setting:scorerules:"; // 积分规则 key prev public static final String CREDIT_RULES_KEY_PREV = "setting:creditrules:"; + // 倍率规则 key prev + public static final String CREDIT_DOUBLE_RULES_KEY_PREV = "setting:creditdoublerules:"; // 导入会员 public static final String importMemPrev = "importmem:";