更新10.9

This commit is contained in:
许允枞 2024-10-09 18:01:07 +08:00
parent 7fec6165b5
commit 7cce0cb66f
3 changed files with 116 additions and 0 deletions

View File

@ -92,4 +92,16 @@ public interface UserBalanceService extends IService<UserBalance> {
* @return
*/
int logOffBalance(Integer id);
/**
*
* @param userId 用户id
* @param chainStoreId 连锁店id
* @param storeId 店铺id
* @param consumptioType 消费类型 1-汽油消费 2-柴油消费 3-天然气消费 4-会员充值
* @param money 消费金额
* @param fromType 消费来源
* @param orderNo 订单号
*/
void growthValue(Integer userId, Integer chainStoreId,Integer storeId, String consumptioType, Double money,String fromType, String orderNo);
}

View File

@ -2,6 +2,7 @@ package com.fuint.business.userManager.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@ -19,13 +20,18 @@ import com.fuint.business.marketingActivity.cardGift.mapper.CardGiftMapper;
import com.fuint.business.marketingActivity.cardGiftActive.mapper.CardGiftActiveMapper;
import com.fuint.business.marketingActivity.cardValue.entity.CardValueRecord;
import com.fuint.business.marketingActivity.cardValue.mapper.CardValueRecordMapper;
import com.fuint.business.order.entity.AllOrderInfo;
import com.fuint.business.order.entity.GrowthValueChange;
import com.fuint.business.order.mapper.AllOrderInfoMapper;
import com.fuint.business.order.mapper.GrowthValueChangeMapper;
import com.fuint.business.store.mapper.MtStoreMapper;
import com.fuint.business.storeInformation.entity.LJStore;
import com.fuint.business.storeInformation.service.ILJStoreService;
import com.fuint.business.userManager.entity.ChainStoreConfig;
import com.fuint.business.userManager.entity.LJUserGrade;
import com.fuint.business.userManager.entity.MtUserFuel;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.mapper.ChainStoreConfigMapper;
import com.fuint.business.userManager.mapper.LJUserGradeMapper;
import com.fuint.business.userManager.mapper.MtUserFuelMapper;
import com.fuint.business.userManager.mapper.UserBalanceMapper;
@ -37,6 +43,8 @@ import com.fuint.business.userManager.vo.UserBlanceUniVo;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.RedisLock;
import com.fuint.common.util.TokenUtil;
import com.fuint.repository.mapper.MtUserGradeMapper;
import com.fuint.repository.model.MtUserGrade;
import com.fuint.system.dept.mapper.SysDeptMapper;
import org.json.JSONObject;
import org.slf4j.Logger;
@ -90,6 +98,12 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
@Autowired
MtUserFuelMapper mtUserFuelMapper;
@Autowired
private ChainStoreConfigMapper chainStoreConfigMapper;
@Autowired
private GrowthValueChangeMapper growthValueChangeMapper;
@Autowired
private MtUserGradeMapper mtUserGradeMapper;
@ -267,6 +281,93 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
return baseMapper.updateById(userBalance);
}
/**
*
* @param userId 用户id
* @param chainStoreId 连锁店id
* @param storeId 店铺id
* @param consumptioType 消费类型 1-汽油消费 2-柴油消费 3-天然气消费 4-会员充值
* @param money 消费金额
* @param fromType 消费来源
* @param orderNo 订单号
*/
@Override
public void growthValue(Integer userId, Integer chainStoreId,Integer storeId,String consumptioType, Double money, String fromType, String orderNo) {
//查询成长值规则
ChainStoreConfig chainStoreConfig = chainStoreConfigMapper.selectOne(new LambdaQueryWrapper<ChainStoreConfig>()
.eq(ChainStoreConfig::getChainStoreId, chainStoreId));
//消费满购金额
int consumeAmount = 0;
//成长值增加
int growthValue = 0;
switch (consumptioType) {
//汽油
case "1":
consumeAmount = Integer.parseInt(chainStoreConfig.getGasConsumeAmount());
growthValue = Integer.parseInt(chainStoreConfig.getGasGrowthValue());
break;
//柴油
case "2":
consumeAmount = Integer.parseInt(chainStoreConfig.getDieselConsumeAmount());
growthValue = Integer.parseInt(chainStoreConfig.getDieselGrowthValue());
break;
//天然气
case "3":
consumeAmount = Integer.parseInt(chainStoreConfig.getNaturalConsumeAmount());
growthValue = Integer.parseInt(chainStoreConfig.getNaturalGrowthValue());
break;
//会员充值
case "4":
consumeAmount = Integer.parseInt(chainStoreConfig.getRechargeConsumeAmount());
growthValue = Integer.parseInt(chainStoreConfig.getRechargeGrowthValue());
break;
}
if (consumeAmount != 0 && money >= consumeAmount) {
//金额除以消费金额取整
int growth = (int) (money / consumeAmount);
//计算成长值
growthValue = growth * growthValue;
//更新用户余额表成长值
UserBalance userBalance = baseMapper.selectOne(new LambdaQueryWrapper<UserBalance>()
.eq(UserBalance::getMtUserId, userId));
userBalance.setGrowthValue(userBalance.getGrowthValue() + growthValue);
//更新成长值记录变化表
GrowthValueChange growthValueChange = new GrowthValueChange();
growthValueChange.setUserId(userId);
growthValueChange.setChangeType("1");
growthValueChange.setFromType(fromType);
growthValueChange.setGrowthValue(growthValue);
growthValueChange.setOrderNo(orderNo);
growthValueChange.setAfterTheChange(userBalance.getGrowthValue());
growthValueChange.setChainStoreId(chainStoreId);
growthValueChange.setStoreId(storeId);
growthValueChange.setCreateTime(DateUtil.date());
growthValueChange.setCreateBy(TokenUtil.getNowAccountInfo().getId().toString());
growthValueChangeMapper.insert(growthValueChange);
List<MtUserGrade> mtUserGrades = mtUserGradeMapper.selectList(new LambdaQueryWrapper<MtUserGrade>()
.eq(MtUserGrade::getStoreId, storeId));
//判断当前用户等级
for (int i = 0; i < mtUserGrades.size(); i++) {
if (i < mtUserGrades.size() - 2) {
if (userBalance.getGrowthValue() >= mtUserGrades.get(i).getGrowthValue() && userBalance.getGrowthValue() < mtUserGrades.get(i + 1).getGrowthValue()){
userBalance.setGradeId(mtUserGrades.get(i).getId());
break;
}
}else {
userBalance.setGradeId(mtUserGrades.get(mtUserGrades.size() - 1).getId());
}
}
userBalance.setUpdateTime(DateUtil.date());
userBalance.setUpdateBy(TokenUtil.getNowAccountInfo().getId().toString());
//更新用户等级
baseMapper.updateById(userBalance);
}
}
@Resource
RedisLock redisLock;

View File

@ -28,6 +28,9 @@ public class MtUserGrade implements Serializable {
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
private Integer storeId;
private Integer chainStoreId;
private Integer growthValue;
// @ApiModelProperty("商户ID")
// private Integer merchantId;