diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxUserStructureController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxUserStructureController.java index 652b75c73..04c72d3e0 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxUserStructureController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxUserStructureController.java @@ -1,12 +1,14 @@ package com.iformall.controller; import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.dto.WxCUserBasicInfoDto; import com.iformall.domain.po.*; import com.iformall.domain.vo.UserStructureVo; import com.iformall.enums.EnumAgeInfo; import com.iformall.enums.EnumCUserBaseInfoSex; +import com.iformall.enums.EnumScoreType; import com.iformall.enums.EnumTag; import com.iformall.service.*; import io.swagger.annotations.Api; @@ -17,10 +19,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; import java.text.NumberFormat; @@ -51,6 +50,9 @@ public class WxUserStructureController extends BaseController { @Autowired private WxUserChannelService wxUserChannelService; + @Autowired + private WxScoreRulesService wxScoreRulesService; + /***************************会员结构*****************************/ @ApiOperation("查询会员性别结构") @@ -542,5 +544,30 @@ public class WxUserStructureController extends BaseController { return vo; } + // 成长值扣除 + @ApiOperation("用户成长值扣减") + @PostMapping("/scoreReduce") + @ApiImplicitParams({ + @ApiImplicitParam(name = "reason", value = "扣减理由", dataType = "String", required = true), + @ApiImplicitParam(name = "score", value = "扣减分数", dataType = "int", required = true)}) + public ResultData scoreReduce(@ModelAttribute WxCUserBasicInfo basicInfo, String reason, Integer score) { + logger.debug("[" + getIpAddr() + "] WxUserStructureController::scoreReduce"); + + // 1. 检查用户积分 + WxCUserBasicInfo info = wxCUserBasicInfoService.getById(basicInfo.getId()); + if(info == null) { + logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); + return new ResultData(ErrorCode.USER_IS_EMPTY); + } + if(info.getPoins() < score) { + logger.error(ErrorCode.MEM_SCORE_NOT_ENOUGH.getMessage()); + return new ResultData(ErrorCode.MEM_SCORE_NOT_ENOUGH); + } + // 2. 扣减积分 + wxScoreRulesService.reduceScore(EnumScoreType.MEM_REDUCE, info, reason, score); + + return new ResultData(); + } + } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 8035d4984..eab0dc06b 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -237,6 +237,7 @@ public enum ErrorCode{ * 会员 */ MEM_IMPORT_ERR(13000, "模板导入失败"), + MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"), /** * 标签 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreHistory.java b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreHistory.java index f4dcd6bd7..83bb715a0 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxScoreHistory.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxScoreHistory.java @@ -68,6 +68,10 @@ public class WxScoreHistory implements Serializable { /**积分**/ @io.swagger.annotations.ApiModelProperty(value="积分",name="scoreAmount") private Integer scoreAmount; + /**扣减原因**/ + @io.swagger.annotations.ApiModelProperty(value="扣减原因",name="reason") + private String reason; + public String getTenantId() { return tenantId; } @@ -126,7 +130,13 @@ public class WxScoreHistory implements Serializable { scoreAmount = _scoreAmount; } + public String getReason() { + return reason; + } + public void setReason(String reason) { + this.reason = reason; + } public static enum Field { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java b/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java index c75463afe..bd99dfa10 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumScoreType.java @@ -12,7 +12,8 @@ public enum EnumScoreType { WECHAT_PERSION(5, "微信用户昵称授权"), WECHAT_PHONE(6, "微信用户手机授权"), COMPLETE_INFO(7, "完善个人信息"), - MEM_IMPORT(8, "会员导入"); + MEM_IMPORT(8, "会员导入"), + MEM_REDUCE(9, "会员成长值扣减"); public static EnumScoreType getEnum(Integer code) { for (EnumScoreType value : values()) { diff --git a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java index 3de2b470a..9d5777d87 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxScoreRulesService.java @@ -1,9 +1,5 @@ package com.iformall.service; -import com.github.pagehelper.PageInfo; -import com.iformall.domain.po.WxCUser; -import com.iformall.domain.po.WxCUserCar; -import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxScoreRules; import com.iformall.enums.EnumScoreType; @@ -32,4 +28,9 @@ public interface WxScoreRulesService { */ int addScore2(EnumScoreType scoreType, Object param1, Object param2); + /** + * 扣减成长值 + */ + int reduceScore(EnumScoreType scoreType, Object param1, Object param2, Object param3); + } 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 489309a34..2501dbd89 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxScoreRulesServiceImpl.java @@ -300,7 +300,7 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { return addScoreNumber; } - private int infoResetScore(WxCUserBasicInfo userInfo, Integer score) { + private int memResetScore(WxCUserBasicInfo userInfo, Integer score) { // 1. 导入成长值 resetBasicUserScore(userInfo.getId(), score); @@ -310,6 +310,27 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { return score; } + private int memReduceScore(WxCUserBasicInfo userInfo, String reason, Integer scoreNum) { + int score = userInfo.getPoins() - scoreNum; + + // 1. update score/ 修改basic表积分 + userInfo.setPoins(score); + wxCUserBasicInfoMapper.updateScore(userInfo); + + // 2. 修改 c_user表积分 score + if (userInfo.getPhone() != null) { + WxCUser wxCUser = new WxCUser(); + wxCUser.setTenantId(userInfo.getTenantId()); + wxCUser.setPhone(userInfo.getPhone()); + wxCUser.setScore(score); + wxCUserService.saveOrUpdate(wxCUser); + } + + // 2. 记录历史 + recordReduceScoreHistory(scoreNum, reason, userInfo.getTenantId(), userInfo.getId(), EnumScoreType.MEM_REDUCE); + return score; + } + private void recordScoreHistory(int addScoreNumber, String tenantId, Long id, EnumScoreType wechatPhone) { final IdWorker idWorker = IdWorker.get(); WxScoreHistory history = new WxScoreHistory(); @@ -339,6 +360,18 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { wxScoreHistoryMapper.insert(history); } + private void recordReduceScoreHistory(int reduceScore, String reason, String tenantId, Long id, EnumScoreType wechatPhone) { + final IdWorker idWorker = IdWorker.get(); + WxScoreHistory history = new WxScoreHistory(); + history.setId(idWorker.nextId()); + history.setTenantId(tenantId); + history.setCUserId(id); + history.setCreateDate(new Date()); + history.setScoreType(wechatPhone.getCode()); + history.setScoreAmount(reduceScore*-1); + history.setReason(reason); + wxScoreHistoryMapper.insert(history); + } @Override public int addScore(EnumScoreType scoreType, Object param) { @@ -386,7 +419,22 @@ public class WxScoreRulesServiceImpl implements WxScoreRulesService { case MEM_IMPORT: { WxCUserBasicInfo user = (WxCUserBasicInfo) param1; Integer score = Integer.valueOf((String)param2); - return infoResetScore(user, score); + return memResetScore(user, score); + } + default: + break; + } + return 0; + } + + @Override + public int reduceScore(EnumScoreType scoreType, Object param1, Object param2, Object param3) { + switch (scoreType){ + case MEM_REDUCE: { + WxCUserBasicInfo user = (WxCUserBasicInfo)param1; + String reason = (String)param2; + Integer scoreNum = (Integer)param3; + return memReduceScore(user, reason, scoreNum); } default: break; diff --git a/mallinkService/src/main/resources/mapper/WxScoreHistoryMapper.xml b/mallinkService/src/main/resources/mapper/WxScoreHistoryMapper.xml index defd6aa1e..0b2ee296f 100644 --- a/mallinkService/src/main/resources/mapper/WxScoreHistoryMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxScoreHistoryMapper.xml @@ -12,10 +12,11 @@ + - `id`,`tenant_id`,`c_user_id`,`create_date`,`score_type`,`valid_date`,`order_id`,`pay_type`,`pay_amount`,`score_amount` + `id`,`tenant_id`,`c_user_id`,`create_date`,`score_type`,`valid_date`,`order_id`,`pay_type`,`pay_amount`,`score_amount`,`reason` @@ -60,6 +61,9 @@ and `score_amount` = #{scoreAmount} + + and `reason` = #{reason} + and id in