Browse Source

//商户积分倍率

release_toaliyun_real
xhxu 3 years ago
parent
commit
ec93ccb2c5
5 changed files with 53 additions and 11 deletions
  1. +5
    -3
      mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantScoreRulesController.java
  2. +3
    -5
      mallinkService/src/main/java/com/iformall/mapper/WxMerchantScoreRulesMapper.java
  3. +5
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java
  4. +33
    -2
      mallinkService/src/main/java/com/iformall/utils/CreditUtil.java
  5. +7
    -0
      mallinkService/src/main/resources/mapper/WxMerchantScoreRulesMapper.xml

+ 5
- 3
mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantScoreRulesController.java View File

@@ -56,9 +56,11 @@ public class WxMerchantScoreRulesController extends BaseController {
}
scoreRules.updateTenantInfo(getTenantInfo());
scoreRules.setType(EnumScoreRules.CREDIT.getCode());
WxMerchantScoreRules oldScoreRules = wxMerchantScoreRulesService.getScoreRules(scoreRules.getMerchantId(), EnumScoreRules.CREDIT.getCode());
if(oldScoreRules != null){
scoreRules.setId(oldScoreRules.getId());
if(scoreRules.getId() == null){
WxMerchantScoreRules oldScoreRules = wxMerchantScoreRulesService.getScoreRules(scoreRules.getMerchantId(), EnumScoreRules.CREDIT.getCode());
if(oldScoreRules != null){
scoreRules.setId(oldScoreRules.getId());
}
}
if(scoreRules.getScale() == null){
scoreRules.setScale(WxMerchantScoreRules.DEFAULT_SCALE);


+ 3
- 5
mallinkService/src/main/java/com/iformall/mapper/WxMerchantScoreRulesMapper.java View File

@@ -3,16 +3,14 @@ package com.iformall.mapper;
import com.iformall.common.CommonMapper;
import com.iformall.domain.po.WxMerchantScoreRules;
import com.iformall.domain.po.WxScoreRules;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface WxMerchantScoreRulesMapper extends CommonMapper<WxMerchantScoreRules, String> {

List<WxMerchantScoreRules> findList(WxMerchantScoreRules scoreRules);

WxMerchantScoreRules findMerchantScoreRules(@Param("merchantId") Long merchantId, @Param("type") Integer type);

}

+ 5
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java View File

@@ -92,6 +92,9 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService {
@Autowired
WxLevelConfigMapper wxLevelConfigMapper;

@Autowired
WxMerchantScoreRulesMapper wxMerchantScoreRulesMapper;

@Autowired
private WxMallService wxMallService;

@@ -1047,7 +1050,8 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService {
}
//积分倍率
try {
addCreditNumber = CreditUtil.calUserCredit(addCreditNumber, wxCUserBasicInfo, tenantEntity, wxScoreRulesService,wxLevelConfigMapper);
addCreditNumber = CreditUtil.calUserCredit(addCreditNumber, wxCUserBasicInfo, tenantEntity, record.getMerchantId(),
wxScoreRulesService,wxLevelConfigMapper,wxMerchantScoreRulesMapper);
if (Objects.nonNull(CreditUtil.getIsBirthDayScale())) {
hasBirthDateCredit = true;
}


+ 33
- 2
mallinkService/src/main/java/com/iformall/utils/CreditUtil.java View File

@@ -4,8 +4,11 @@ import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.DateUtil;
import com.iformall.domain.po.*;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.enums.EnumScoreRules;
import com.iformall.enums.EnumScoreScaleRules;
import com.iformall.enums.EnumYesOrNo;
import com.iformall.mapper.WxLevelConfigMapper;
import com.iformall.mapper.WxMerchantScoreRulesMapper;
import com.iformall.service.WxScoreRulesService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -29,7 +32,8 @@ public class CreditUtil {
* @param wxLevelConfigMapper
* @return
*/
public static int calUserCredit(int creditOrigin, WxCUserBasicInfo wxCUserBasicInfo, TenantEntity tenantEntity, WxScoreRulesService wxScoreRulesService, WxLevelConfigMapper wxLevelConfigMapper) {
public static int calUserCredit(int creditOrigin, WxCUserBasicInfo wxCUserBasicInfo, TenantEntity tenantEntity, Long merchantId,
WxScoreRulesService wxScoreRulesService, WxLevelConfigMapper wxLevelConfigMapper, WxMerchantScoreRulesMapper wxMerchantScoreRulesMapper) {
Long userId = wxCUserBasicInfo.getId();
Integer score = wxCUserBasicInfo.getPoins();
String finalTenantId = wxCUserBasicInfo.getFinalTenantId();
@@ -44,13 +48,18 @@ public class CreditUtil {
// 获取会员日倍率:
int memberDayScale = getMemberDayScale(tenantEntity, wxScoreRulesService);

//获取商户积分倍率:
int merchantScale = getMerchantScale(merchantId,wxMerchantScoreRulesMapper);

int creditNew = new BigDecimal(creditOrigin)
.multiply(new BigDecimal(levelScale))
.multiply(new BigDecimal(birthdayScale))
.multiply(new BigDecimal(memberDayScale))
.multiply(new BigDecimal(merchantScale))
.divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE))
.divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE))
.divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE)
.divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE))
.divide(new BigDecimal(WxMerchantScoreRules.DEFAULT_SCALE)
, BigDecimal.ROUND_HALF_UP).intValue();

log.info("积分倍率计算, 用户:{},成长值:{},等级积分倍率:{},生日积分倍率:{},原积分:{},新积分:{}", userId, score, levelScale, birthdayScale, creditOrigin, creditNew);
@@ -228,6 +237,28 @@ public class CreditUtil {
return memberDayScale;
}

/**
* 获取商户积分倍率
*
* @param
* @param wxMerchantScoreRulesMapper
* @return
*/
private static int getMerchantScale(Long merchantId, WxMerchantScoreRulesMapper wxMerchantScoreRulesMapper) {
int merchantScale = WxMerchantScoreRules.DEFAULT_SCALE;

WxMerchantScoreRules rules = wxMerchantScoreRulesMapper.findMerchantScoreRules(merchantId, EnumScoreRules.CREDIT.getCode());
if (Objects.nonNull(rules) && EnumYesOrNo.YES.getCode().equals(rules.getOpen())) {
merchantScale = rules.getScale();

} else {
//没有配置积分规则
//log.info("积分倍率计算:商户积分倍率配置=null");
}
log.info("商户积分倍率配置:{}", merchantScale);
return merchantScale;
}

public static Long getIsBirthDayScale() {
return isBirthDayScale.get();
}


+ 7
- 0
mallinkService/src/main/resources/mapper/WxMerchantScoreRulesMapper.xml View File

@@ -59,4 +59,11 @@
</select>


<select id="findMerchantScoreRules" parameterType="java.util.Map" resultMap="BaseResultMap">
select
<include refid="allColumns"/>
from wx_merchant_score_rules
where `merchant_id` = #{merchantId} and `type` = #{type}
</select>

</mapper>

Loading…
Cancel
Save