|
|
|
@@ -32,6 +32,7 @@ import java.math.BigDecimal; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@@ -69,6 +70,9 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { |
|
|
|
@Autowired |
|
|
|
ExcelService excelService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxLevelConfigMapper wxLevelConfigMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void clearCreditByYear() { |
|
|
|
WxScoreRules wxScoreRules = new WxScoreRules(); |
|
|
|
@@ -193,8 +197,20 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { |
|
|
|
currentCreditAmount = wxCUserBasicInfo.getCredit(); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取当前用户成长值:默认为1.0, |
|
|
|
int scale = 10; |
|
|
|
Integer score = wxCUser.getScore(); |
|
|
|
if (Objects.nonNull(score)) { |
|
|
|
Integer scaleFromDb = wxLevelConfigMapper.getScale(wxCUser.getTenantId(), wxCUser.getScore()); |
|
|
|
if (Objects.nonNull(scaleFromDb)) { |
|
|
|
scale = scaleFromDb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//计算出需要新增或减少的积分 |
|
|
|
int creditChangeNum = creditIncrement(record); |
|
|
|
int creditChangeNumOrigin = creditIncrement(record); |
|
|
|
int creditChangeNum = new BigDecimal(creditChangeNumOrigin).multiply(new BigDecimal(scale)).divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE),BigDecimal.ROUND_HALF_UP).intValue(); |
|
|
|
|
|
|
|
if (creditChangeNum != 0) { |
|
|
|
Long total = Long.valueOf(currentCreditAmount) + Long.valueOf(creditChangeNum); |
|
|
|
if (total > Integer.MAX_VALUE) { |
|
|
|
@@ -260,14 +276,14 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { |
|
|
|
if (wxCUser != null) { |
|
|
|
WxCUser wxCUserNew = new WxCUser(); |
|
|
|
wxCUserNew.setId(wxCUser.getId()); |
|
|
|
wxCUserNew.setCredit(wxCUser.getCredit()-wxCreditHistory.getCreditNum()); |
|
|
|
wxCUserNew.setCredit(wxCUser.getCredit() - wxCreditHistory.getCreditNum()); |
|
|
|
wxCUserNew.setUpdateDate(new Date()); |
|
|
|
wxCUserMapper.updateByPrimaryKeySelective(wxCUserNew); |
|
|
|
} |
|
|
|
if (wxCUserBasicInfo != null) { |
|
|
|
WxCUserBasicInfo wxCUserBasicInfoNew = new WxCUserBasicInfo(); |
|
|
|
wxCUserBasicInfoNew.setId(wxCUserBasicInfo.getId()); |
|
|
|
wxCUserBasicInfoNew.setCredit(wxCUserBasicInfo.getCredit()-wxCreditHistory.getCreditNum()); |
|
|
|
wxCUserBasicInfoNew.setCredit(wxCUserBasicInfo.getCredit() - wxCreditHistory.getCreditNum()); |
|
|
|
wxCUserBasicInfoNew.setUpdateDate(new Date()); |
|
|
|
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(wxCUserBasicInfoNew); |
|
|
|
} |
|
|
|
@@ -300,6 +316,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { |
|
|
|
|
|
|
|
//根据积分类型计算"增加积分" |
|
|
|
private int creditIncrement(WxCreditHistory record) { |
|
|
|
//查找C端用户的成长值 |
|
|
|
if (record.getCreditType() == EnumScoreType.LOGIN.getCode()) { |
|
|
|
return loginAddCredit(record); |
|
|
|
} |
|
|
|
@@ -446,7 +463,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { |
|
|
|
int baseScore = busRule.getInteger(WxScoreRules.SCORE); // 消费增长积分 |
|
|
|
|
|
|
|
// 4. 计算积分 |
|
|
|
if(record.getSpend() >= priceCondition.intValue()) { |
|
|
|
if (record.getSpend() >= priceCondition.intValue()) { |
|
|
|
Double dScoreT = Math.floor(record.getSpend() * 1.0D / priceCondition * baseScore); |
|
|
|
addCreditNumber = dScoreT.intValue(); |
|
|
|
log.info("CREDIT:" + busRule.toJSONString() + "\nAddCredit: " + addCreditNumber); |
|
|
|
|