|
@@ -1,20 +1,28 @@
|
|
|
package cn.newfeifan.mall.module.distri.service.integral;
|
|
|
|
|
|
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.consumptionchangelog.vo.ConsumptionChangeLogSaveReqVO;
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.integral.vo.IntegralSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.ptprofitlog.vo.PtProfitLogSaveReqVO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPercentageDO;
|
|
|
-import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofitlog.PtProfitLogDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.integral.IntegralMapper;
|
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.ptprofit.PtProfitMapper;
|
|
|
import cn.newfeifan.mall.module.distri.enums.CaclEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.enums.ConsumptionEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.service.consumptionchangelog.ConsumptionChangeLogService;
|
|
|
import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
|
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.newfeifan.mall.module.distri.enums.ErrorCodeConstants.INTEGRAL_NOT_EXISTS;
|
|
|
+
|
|
|
/**
|
|
|
* 推荐用户积分 Service 实现类
|
|
|
*
|
|
@@ -33,6 +41,9 @@ public class IntegralServiceImpl implements IntegralService {
|
|
|
@Resource
|
|
|
private OrderPercentageService orderPercentageService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ConsumptionChangeLogService consumptionChangeLogService;
|
|
|
+
|
|
|
/**
|
|
|
* add by Ben
|
|
|
* 修改用户积分
|
|
@@ -43,58 +54,50 @@ public class IntegralServiceImpl implements IntegralService {
|
|
|
* @param freezeAmount 用户冻结积分变化金额,可为负数
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateUserIntegral(Long generateUserId,//导致产生积分变动的用户ID
|
|
|
+ public Boolean updateUserIntegral(Long generateUserId,//导致产生积分变动的用户ID
|
|
|
Long userId, CaclEnum caclEnum, Long amount, Long freezeAmount,
|
|
|
Long tradeOrderId,
|
|
|
String orderNum
|
|
|
) {
|
|
|
- //修改用户积分钱包的积分
|
|
|
- IntegralDO integralDO = integralMapper.selectOne(IntegralDO::getUserId, userId);
|
|
|
-
|
|
|
- // 退款返回 为 +
|
|
|
- integralDO.setCurrentQuota(integralDO.getCurrentQuota() + amount);
|
|
|
+ Boolean success = null;
|
|
|
|
|
|
- // 直推奖超出额度
|
|
|
- Long ancestorQuotaAmount = 0L;
|
|
|
- // 如果是推荐人
|
|
|
- if (caclEnum.getType().equals(CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER.getType())) {
|
|
|
+ //修改用户积分钱包的积分
|
|
|
+ int effectRowNum = ptProfitMapper.updateUserIntegral(amount,amount,freezeAmount,freezeAmount,userId);
|
|
|
|
|
|
- PtProfitLogDO profitLog = ptProfitLogService.selectProfitLogByUserIdWithProfitStatus(userId, CaclEnum.RECOMMENDED_PERSON_QUOTA.getType(), orderNum);
|
|
|
+ if (effectRowNum==1) {//如果成功修改积分记录
|
|
|
+ success = true;
|
|
|
|
|
|
- if(profitLog.getAncestorQuotaAmount() != null && profitLog.getAncestorQuotaAmount() != 0){
|
|
|
- ancestorQuotaAmount = profitLog.getAncestorQuotaAmount();
|
|
|
- }
|
|
|
- integralDO.setCurrentQuota(integralDO.getCurrentQuota() + ancestorQuotaAmount);
|
|
|
- // 退回扣减的最大可用额度,和累加获得的直推奖额度
|
|
|
- integralDO.setHighQuota(integralDO.getHighQuota() - amount - ancestorQuotaAmount);
|
|
|
- integralDO.setAncestorQuota(integralDO.getAncestorQuota() + amount + ancestorQuotaAmount);
|
|
|
- }
|
|
|
+ //用户修改后的当前可用的钱包余额
|
|
|
+ Long afterAmount = null;
|
|
|
+ //用户修改后的冻结积分钱包余额
|
|
|
+ Long afterFreezeAmount = null;
|
|
|
|
|
|
- integralMapper.updateById(integralDO);
|
|
|
+ //查询用户修改后的积分
|
|
|
+ Map<String, Object> map = ptProfitMapper.selectUserIntegral(userId);
|
|
|
+ Object currentQuotaObj = map.get("current_quota");
|
|
|
+ Object freezeQuotaObj = map.get("freeze_quota");
|
|
|
|
|
|
- //用户修改后的当前可用的钱包余额
|
|
|
- Long afterAmount = null;
|
|
|
- //用户修改后的冻结积分钱包余额
|
|
|
- Long afterFreezeAmount = null;
|
|
|
+ afterAmount = (Long)currentQuotaObj;
|
|
|
+ afterFreezeAmount = (Long)freezeQuotaObj;
|
|
|
|
|
|
- //查询用户修改后的积分
|
|
|
- Map<String, Object> map = ptProfitMapper.selectUserIntegral(userId);
|
|
|
- Object currentQuotaObj = map.get("current_quota");
|
|
|
- Object freezeQuotaObj = map.get("freeze_quota");
|
|
|
+ if(afterAmount<0||afterFreezeAmount<0){
|
|
|
+ throw new RuntimeException("用户钱包为负数:用户IO为"+userId+"的用户可用钱包为"+afterAmount+",冻结钱包为"+afterFreezeAmount);
|
|
|
+ }
|
|
|
|
|
|
- afterAmount = (Long) currentQuotaObj;
|
|
|
- afterFreezeAmount = (Long) freezeQuotaObj;
|
|
|
+ //记录用户的积分变动日志
|
|
|
+ ptProfitLogService.addMessage(generateUserId,//导致产生积分变动的用户ID
|
|
|
+ userId, caclEnum, amount, afterAmount,
|
|
|
+ freezeAmount, afterFreezeAmount,null,tradeOrderId,orderNum);
|
|
|
|
|
|
- //记录用户的积分变动日志
|
|
|
- if (caclEnum.getType().equals(CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER.getType())) {
|
|
|
- OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
|
|
|
- ptProfitLogService.addMessage(generateUserId, userId, caclEnum, amount + ancestorQuotaAmount, afterAmount,
|
|
|
- freezeAmount, afterFreezeAmount, null, tradeOrderId, orderNum, -amount - ancestorQuotaAmount, integralDO.getHighQuota() + Long.parseLong(orderPercentageDO.getBaseMaxQuota()));
|
|
|
- } else {
|
|
|
- ptProfitLogService.addMessage(generateUserId, userId, caclEnum, amount, afterAmount,
|
|
|
- freezeAmount, afterFreezeAmount, null, tradeOrderId, orderNum, null, null);
|
|
|
+ }else if(effectRowNum<1){//如果钱包积分不足,不够抵扣
|
|
|
+ success = false;
|
|
|
+ } else if (effectRowNum>1) {
|
|
|
+// success = false;
|
|
|
+ throw new RuntimeException("用户IO为"+userId+"的用户钱包不只一个!");
|
|
|
}
|
|
|
|
|
|
+ return success;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -122,6 +125,43 @@ public class IntegralServiceImpl implements IntegralService {
|
|
|
ptProfitLogService.createPtProfitLog(profitLogSaveReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void updateUserConsumptionPoints(Long generateUserId, Long userId, Long payConsumptionPoints, Long tradeOrderId, String tradeOrderNum) {
|
|
|
+ // 获取用户钱包,然后退回消费分
|
|
|
+ IntegralDO integralDO = integralMapper.selectOne(IntegralDO::getUserId, userId);
|
|
|
+ integralDO.setConsumptionPoints(integralDO.getConsumptionPoints() + payConsumptionPoints);
|
|
|
+ integralMapper.updateById(integralDO);
|
|
|
+
|
|
|
+ // 记录消费分变动日志
|
|
|
+ consumptionChangeLogService.createConsumptionChangeLog(ConsumptionChangeLogSaveReqVO.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .generateUserId(generateUserId)
|
|
|
+ .consumptionPoints(payConsumptionPoints)
|
|
|
+ .afterConsumptionPoints(integralDO.getConsumptionPoints())
|
|
|
+ .consumptionStatus(ConsumptionEnum.REFUND_ORDER.getType())
|
|
|
+ .build());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IntegralDO selectByUser(Long descendant) {
|
|
|
+ return integralMapper.selectOne(new LambdaQueryWrapper<IntegralDO>().eq(IntegralDO::getUserId, descendant));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateIntegral(IntegralSaveReqVO updateReqVO) {
|
|
|
+ // 校验存在
|
|
|
+ validateIntegralExists(updateReqVO.getId());
|
|
|
+ // 更新
|
|
|
+ IntegralDO updateObj = BeanUtils.toBean(updateReqVO, IntegralDO.class);
|
|
|
+ integralMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+ private void validateIntegralExists(Long id) {
|
|
|
+ if (integralMapper.selectById(id) == null) {
|
|
|
+ throw exception(INTEGRAL_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//
|
|
|
// /**
|
|
|
// * 修改用户身价
|