| @@ -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(); | |||
| } | |||
| } | |||
| @@ -237,6 +237,7 @@ public enum ErrorCode{ | |||
| * 会员 | |||
| */ | |||
| MEM_IMPORT_ERR(13000, "模板导入失败"), | |||
| MEM_SCORE_NOT_ENOUGH(13001, "成长值不够扣减值"), | |||
| /** | |||
| * 标签 | |||
| @@ -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 | |||
| { | |||
| @@ -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()) { | |||
| @@ -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); | |||
| } | |||
| @@ -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; | |||
| @@ -12,10 +12,11 @@ | |||
| <result column="pay_type" jdbcType="INTEGER" property="payType"/> | |||
| <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/> | |||
| <result column="score_amount" jdbcType="INTEGER" property="scoreAmount"/> | |||
| <result column="reason" jdbcType="VARCHAR" property="reason"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `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` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -60,6 +61,9 @@ | |||
| <if test=" null != scoreAmount "> | |||
| and `score_amount` = #{scoreAmount} | |||
| </if> | |||
| <if test=" null != reason "> | |||
| and `reason` = #{reason} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||