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 d7f8af041..5f02f9faa 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/WxScoreRulesController.java @@ -4,14 +4,12 @@ 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.SysConfig; import com.iformall.domain.po.WxMall; import com.iformall.domain.po.WxMallDispose; 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.EnumMallDispose; -import com.iformall.enums.EnumScoreRules; +import com.iformall.enums.*; import com.iformall.service.WxMallDisposeService; import com.iformall.service.WxMallService; import com.iformall.service.WxScoreRulesService; @@ -23,6 +21,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; +import java.util.Map; + @RestController @RequestMapping("wxScoreRules") @Api(description = "成长值积分规则相关接口") @@ -97,38 +98,60 @@ public class WxScoreRulesController extends BaseController { @ApiOperation("获取积分倍率设置") @GetMapping("/credit_double") - @SystemControllerLog(description = "积分-配置") + @SystemControllerLog(description = "积分-获取积分倍率设置") public ResultData creditDoubleRulesList() { logger.debug("[" + getIpAddr() + "] creditDoubleRulesList::list"); WxScoreRules scoreRules = wxScoreRulesService.getCreditDoubleRules(getTenantInfo()); + if(scoreRules == null){ + return new ResultData(); + } if(getUser().getTenantId().equals(scoreRules.getTenantId())){ scoreRules.setEditable(true); } return new ResultData(scoreRules); } - @ApiOperation("更新积分开关状态") + @ApiOperation("获取商户积分功能设置") + @GetMapping("/merchantCreditLocked") + @SystemControllerLog(description = "积分-获取商户积分功能设置") + public ResultData merchantCreditLocked() { + logger.debug("[" + getIpAddr() + "] creditDoubleRulesList::merchantCreditLocked"); + Map result = new HashMap<>(); + SysConfig creditLocked = wxScoreRulesService.merchantCreditLocked(getTenantInfo()); + if(creditLocked == null){ + return new ResultData(); + } + result.put("sysId",creditLocked.getId()); + result.put("creditLocked",creditLocked); + if(getUser().getTenantId().equals(getTenantInfo().getTenantId())){ + result.put("isEditable",true); + } + return new ResultData(result); + } + + @ApiOperation("更新商户积分功能设置") @PostMapping("updateCreditLocked") @SystemControllerLog(description = "更新积分开关状态") - public ResultData updateCreditLocked(@RequestBody WxScoreRules wxScoreRules) { + public ResultData updateCreditLocked(@RequestBody Map map) { logger.debug("[" + getIpAddr() + "] WxScoreRulesController::updateCreditLocked"); - if (null == wxScoreRules.getId()) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); + Long sysId = (Long) map.get("sysId"); + Integer creditLocked = (Integer) map.get("creditLocked"); + + if(sysId == null || creditLocked == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } - if (null == wxScoreRules.getCreditLocked()) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "creditLocked不能为空"); + EnumCreditLockedStatus lockedEnum = EnumCreditLockedStatus.getEnum(creditLocked); + if(lockedEnum == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); } - TenantEntity tenantEntity = getTenantInfo(); - if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { - return new ResultData(ErrorCode.USER_NO_PERMISSION.getCode(), "子广场用户无此权限"); + if(wxMallService.isgroupSupport(getUser())){ + return new ResultData(ErrorCode.SYS_AUTH_ERROR); } - wxScoreRules.updateTenantInfo(tenantEntity); - try { - wxScoreRulesService.updateCreditLocked(wxScoreRules); - } catch (Exception e) { - return new ResultData(ErrorCode.DB_FAIL.getCode(), "更新积分开关状态失败"); + if(!getUser().getTenantId().equals(getTenantInfo().getTenantId())){ + return new ResultData(ErrorCode.SYS_AUTH_ERROR); } + wxScoreRulesService.updateCreditLocked(getTenantInfo(),sysId,lockedEnum); return new ResultData(); } diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/sys/SysConfigController.java b/mallinkAdmin/src/main/java/com/iformall/controller/sys/SysConfigController.java index cdcbd29ba..9922636c4 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/sys/SysConfigController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/sys/SysConfigController.java @@ -9,6 +9,7 @@ import com.iformall.domain.po.MallRolePermission; import com.iformall.domain.po.SysConfig; import com.iformall.domain.po.SysConfigValue; import com.iformall.domain.po.base.BaseEntity; +import com.iformall.enums.EnumYesOrNo; import com.iformall.service.SysConfigService; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -39,6 +40,7 @@ public class SysConfigController extends BaseController { @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData list(MallRole sysRole, Integer pageNum, Integer pageSize) { SysConfig config = new SysConfig(); + config.setIsHide(EnumYesOrNo.NO.getCode()); config.setStatus(0); PageInfo page = sysConfigService.listAsPage(config, pageNum, pageSize, getTenantInfo()); return new ResultData(page); diff --git a/mallinkAdmin/src/main/resources/db/migration/V2023033000001_upd_merchant_credit_locked.sql b/mallinkAdmin/src/main/resources/db/migration/V2023033000001_upd_merchant_credit_locked.sql new file mode 100644 index 000000000..2c6f014fe --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V2023033000001_upd_merchant_credit_locked.sql @@ -0,0 +1,14 @@ +ALTER TABLE `mallink`.`sys_config` +ADD COLUMN `is_hide` smallint(2) NOT NULL DEFAULT 0 COMMENT '是否隐藏' AFTER `update_date`; + + +INSERT INTO `mallink`.`sys_config`(`id`, `config_item_key`, `config_item_remark`, `create_date`, `update_date`, `is_hide`, `status`) VALUES (10, 'merchantCreditLocked', '商户功能是否开启,0-正常,1-锁定', '2023-03-30 18:13:01', '2023-03-30 18:13:01', 1, 0); +--记录下生产需要关闭商户积分的广场(默认是打开的)wx_score_rules 中 type=2 and credit_locked=1 的广场 +--初始化数据 +--INSERT INTO `mallink`.`sys_config_value`(`id`, `config_item_id`, `config_item_value`, `tenant_id`, `parent_tenant_id`, `create_date`, `update_date`) VALUES (78910, 10, '1', '789', NULL, '2023-03-30 18:13:01', '2023-03-30 18:13:01'); + +ALTER TABLE `mallink`.`wx_score_rules` +DROP COLUMN `credit_locked`; + + + diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java index 7ae894955..d17e459f3 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantBUserController.java @@ -86,8 +86,8 @@ public class WxMerchantBUserController extends BaseController { } resultMap.put("creditLocked", merchant.getCreditLocked()); - WxScoreRules scoreRules = wxScoreRulesService.getCreditRules(user); - if (scoreRules.getCreditLocked().equals(EnumCreditLockedStatus.CLOSE.getCode())) { + SysConfig creditLocked = wxScoreRulesService.merchantCreditLocked(merchant); + if (EnumCreditLockedStatus.CLOSE.getCode().toString().equals(creditLocked.getConfigItemValue())) { resultMap.put("creditLocked", EnumCreditLockedStatus.CLOSE.getCode()); } resultMap.put("tenant_id",merchant.getTenantId()); diff --git a/mallinkService/src/main/java/com/iformall/common/SysConfigConstant.java b/mallinkService/src/main/java/com/iformall/common/SysConfigConstant.java index 309dca9c7..5326e197b 100644 --- a/mallinkService/src/main/java/com/iformall/common/SysConfigConstant.java +++ b/mallinkService/src/main/java/com/iformall/common/SysConfigConstant.java @@ -8,5 +8,6 @@ public class SysConfigConstant { public static final String coupon_detail_show_selled = "couponDetailShowSelled"; public static final String coupon_list_show_selled = "couponListShowSelled"; public static final String member_seconds_key="memberSeconds"; + public static final String merchant_credit_locked="merchantCreditLocked"; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/SysConfig.java b/mallinkService/src/main/java/com/iformall/domain/po/SysConfig.java index 3a15717c2..2dd27cd4e 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/SysConfig.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/SysConfig.java @@ -25,6 +25,8 @@ public class SysConfig extends BaseEntity { private Date createDate; @io.swagger.annotations.ApiModelProperty(value="",name="updateDate") private Date updateDate; + @io.swagger.annotations.ApiModelProperty(value="是否隐藏",name="isHide") + private Integer isHide; @io.swagger.annotations.ApiModelProperty(value="0-有效 1-无效",name="status") private Integer status; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java index 9a2f716bc..d58b46e87 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreRules.java @@ -108,9 +108,6 @@ public class WxScoreRules extends BaseTenantEntity { @io.swagger.annotations.ApiModelProperty(value="生日积分倍率",name="scale") private Integer scale; - @io.swagger.annotations.ApiModelProperty(value = "积分锁定0正常1锁定", name = "creditLocked") - private Integer creditLocked; - public static String getScoreDefaultRules() { return scoreDefaultRules; } diff --git a/mallinkService/src/main/java/com/iformall/service/SysConfigService.java b/mallinkService/src/main/java/com/iformall/service/SysConfigService.java index 073408ae5..5776fcd60 100644 --- a/mallinkService/src/main/java/com/iformall/service/SysConfigService.java +++ b/mallinkService/src/main/java/com/iformall/service/SysConfigService.java @@ -31,9 +31,10 @@ public interface SysConfigService { /** * 保存或更新实体 * - * @param record + * @param */ void saveConfigValue(Long id,TenantEntity tenantEntity,String value); - + + void saveOrUpdate(SysConfig record); } diff --git a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java index e0bc857e9..26f4e76d2 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java @@ -1,8 +1,10 @@ package com.iformall.service; +import com.iformall.domain.po.SysConfig; import com.iformall.domain.po.WxScoreHistory; import com.iformall.domain.po.WxScoreRules; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumCreditLockedStatus; import com.iformall.enums.EnumScoreType; import java.util.List; @@ -75,7 +77,7 @@ public interface WxScoreRulesService { List findList(WxScoreRules wxScoreRules); - void updateCreditLocked(WxScoreRules wxScoreRules); + void updateCreditLocked(TenantEntity tenantEntity,Long sysId, EnumCreditLockedStatus lockedEnum); WxScoreRules getCreditDoubleRules(String tenantId); @@ -83,4 +85,5 @@ public interface WxScoreRulesService { WxScoreRules getById(Long id); + SysConfig merchantCreditLocked(TenantEntity tenantInfo); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/SysConfigServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/SysConfigServiceImpl.java index c1a9aa21b..ccb7c42c9 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/SysConfigServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/SysConfigServiceImpl.java @@ -128,5 +128,20 @@ public class SysConfigServiceImpl implements SysConfigService { } RedisCacheUtils.removeCache(baseRedisTemplate, String.format(cache_prex, tenantEntity.getTenantId(),config.getConfigItemKey())); } - + + @Override + public void saveOrUpdate(SysConfig record) { + Date curr = new Date(); + if (record.getId() == null) { + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateDate(curr); + record.setUpdateDate(curr); + sysConfigMapper.insert(record); + } else { + record.setUpdateDate(curr); + sysConfigMapper.updateById(record); + } + } + } 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 c91e1ef64..8a8dd1c64 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; +import com.iformall.common.SysConfigConstant; import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; import com.iformall.enums.*; @@ -60,6 +61,9 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { @Autowired WxMallService wxMallService; + @Autowired + SysConfigService sysConfigService; + @Override public void wxScoreRulesInit(String tenantId) { @@ -69,7 +73,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { wxScoreRules.setCreateDate(new Date()); wxScoreRules.setUpdateDate(new Date()); wxScoreRules.setType(EnumScoreRules.CREDIT.getCode()); - wxScoreRules.setCreditLocked(EnumCreditLockedStatus.OPEN.getCode()); wxScoreRulesMapper.insert(wxScoreRules); wxScoreRules = new WxScoreRules(); wxScoreRules.setTenantId(tenantId); @@ -77,7 +80,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { wxScoreRules.setCreateDate(new Date()); wxScoreRules.setUpdateDate(new Date()); wxScoreRules.setType(EnumScoreRules.SCORE.getCode()); - wxScoreRules.setCreditLocked(EnumCreditLockedStatus.CLOSE.getCode()); wxScoreRulesMapper.insert(wxScoreRules); } @@ -109,7 +111,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { final IdWorker idWorker = IdWorker.get(); scoreRules.setId(idWorker.nextId()); scoreRules.setRules(getScoreRulesNew(baseTenantEntity,WxScoreRules.getScoreDefaultRules(),EnumScoreRules.SCORE)); - scoreRules.setCreditLocked(EnumCreditLockedStatus.OPEN.getCode()); wxScoreRulesMapper.insert(scoreRules); } // 插入缓存 @@ -207,8 +208,6 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { final IdWorker idWorker = IdWorker.get(); scoreRules.setId(idWorker.nextId()); scoreRules.setRules(getScoreRulesNew(baseTenantEntity,WxScoreRules.getCreditDefaultRules(),EnumScoreRules.CREDIT)); - scoreRules.setScale(WxScoreRules.DEFAULT_SCALE); - scoreRules.setCreditLocked(EnumCreditLockedStatus.OPEN.getCode()); wxScoreRulesMapper.insert(scoreRules); } @@ -688,15 +687,15 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { } @Override - public void updateCreditLocked(WxScoreRules wxScoreRules) { - wxScoreRulesMapper.updateById(wxScoreRules); - updateMerchantCreditLocked(wxScoreRules); + public void updateCreditLocked(TenantEntity tenantEntity,Long sysId, EnumCreditLockedStatus lockedEnum) { + sysConfigService.saveConfigValue(sysId,tenantEntity,lockedEnum.getCode().toString()); + updateMerchantCreditLocked(tenantEntity,lockedEnum); } - public void updateMerchantCreditLocked(WxScoreRules wxScoreRules) { + public void updateMerchantCreditLocked(TenantEntity tenantEntity, EnumCreditLockedStatus lockedEnum) { WxMerchant wxMerchant = new WxMerchant(); - wxMerchant.updateTenantInfo(wxScoreRules); - wxMerchant.setStatus(wxScoreRules.getCreditLocked()); + wxMerchant.updateTenantInfo(tenantEntity); + wxMerchant.setStatus(lockedEnum.getCode()); wxMerchant.setUpdateDate(new Date()); wxMerchantMapper.updateCreditLocked(wxMerchant); } @@ -718,12 +717,16 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { 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; + final IdWorker idWorker = IdWorker.get(); + scoreRules.setId(idWorker.nextId()); + scoreRules.setRules("[]"); + scoreRules.setScale(WxScoreRules.DEFAULT_SCALE); + wxScoreRulesMapper.insert(scoreRules); } + // 插入缓存 + scoreRulesRedisTemplate.opsForValue().set(key, scoreRules); + logger.info("WxScoreRulesServiceImpl.getScoreRules() : 积分设置插入缓存 >> " + scoreRules.toString()); return scoreRules; } @@ -741,4 +744,22 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { return wxScoreRulesMapper.selectById(id); } + @Override + public SysConfig merchantCreditLocked(TenantEntity tenantInfo) { + SysConfig creditLocked = sysConfigService.getByKey(SysConfigConstant.merchant_credit_locked,tenantInfo); + if(creditLocked == null){ + creditLocked = new SysConfig(); + final IdWorker idWorker = IdWorker.get(); + creditLocked.setId(idWorker.nextId()); + creditLocked.setConfigItemKey(SysConfigConstant.merchant_credit_locked); + creditLocked.setConfigItemRemark("商户功能是否开启,0-正常,1-锁定"); + creditLocked.setIsHide(EnumYesOrNo.YES.getCode()); + sysConfigService.saveOrUpdate(creditLocked); + } + if(creditLocked.getConfigItemValue() == null){ + creditLocked.setConfigItemValue(EnumCreditLockedStatus.OPEN.getCode().toString()); + } + return creditLocked; + } + } diff --git a/mallinkService/src/main/resources/mapper/SysConfigMapper.xml b/mallinkService/src/main/resources/mapper/SysConfigMapper.xml index 61034237c..abf5cef7e 100644 --- a/mallinkService/src/main/resources/mapper/SysConfigMapper.xml +++ b/mallinkService/src/main/resources/mapper/SysConfigMapper.xml @@ -7,11 +7,12 @@ + - `id`,`config_item_key`,`config_item_remark`,`create_date`,`update_date`,`status` + `id`,`config_item_key`,`config_item_remark`,`create_date`,`update_date`,`is_hide`,`status` @@ -22,9 +23,12 @@ and `config_item_key` = #{configItemKey} - - and `status` = #{status} - + + and `is_hide` = #{isHide} + + + and `status` = #{status} + and id in @@ -42,8 +46,5 @@ - - - - + diff --git a/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml b/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml index 3fad0962c..e86517d21 100644 --- a/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxScoreRulesMapper.xml @@ -10,12 +10,11 @@ - - `id`,`tenant_id`,`rules`,`create_date`,`update_date`,`type`,`clear_year`,`scale`,credit_locked + `id`,`tenant_id`,`rules`,`create_date`,`update_date`,`type`,`clear_year`,`scale` @@ -44,10 +43,7 @@ and `scale` = #{scale} - - - and `credit_locked` = #{creditLocked} - + and id in