|
@@ -2,9 +2,12 @@ package cn.newfeifan.mall.module.distri.service.integral;
|
|
|
|
|
|
import cn.newfeifan.mall.module.distri.controller.admin.ptprofitlog.vo.PtProfitLogSaveReqVO;
|
|
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.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.integral.IntegralMapper;
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.ptprofit.PtProfitMapper;
|
|
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.CaclEnum;
|
|
|
|
+import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -21,133 +24,95 @@ import java.util.Map;
|
|
@Validated
|
|
@Validated
|
|
public class IntegralServiceImpl implements IntegralService {
|
|
public class IntegralServiceImpl implements IntegralService {
|
|
|
|
|
|
-// @Resource
|
|
|
|
-// private DuserMapper duserMapper;
|
|
|
|
-
|
|
|
|
-// @Resource
|
|
|
|
-// private IntegralMapper integralMapper;
|
|
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private PtProfitMapper ptProfitMapper;
|
|
private PtProfitMapper ptProfitMapper;
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private IntegralMapper integralMapper;
|
|
private IntegralMapper integralMapper;
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private PtProfitLogService ptProfitLogService;
|
|
private PtProfitLogService ptProfitLogService;
|
|
-
|
|
|
|
-// @Override
|
|
|
|
-// public Long createIntegral(IntegralSaveReqVO createReqVO) {
|
|
|
|
-// // 插入
|
|
|
|
-// IntegralDO integral = BeanUtils.toBean(createReqVO, IntegralDO.class);
|
|
|
|
-// integralMapper.insert(integral);
|
|
|
|
-// // 返回
|
|
|
|
-// return integral.getId();
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public void updateIntegral(IntegralSaveReqVO updateReqVO) {
|
|
|
|
-// // 校验存在
|
|
|
|
-// validateIntegralExists(updateReqVO.getId());
|
|
|
|
-// // 更新
|
|
|
|
-// IntegralDO updateObj = BeanUtils.toBean(updateReqVO, IntegralDO.class);
|
|
|
|
-// integralMapper.updateById(updateObj);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public void deleteIntegral(Long id) {
|
|
|
|
-// // 校验存在
|
|
|
|
-// validateIntegralExists(id);
|
|
|
|
-// // 删除
|
|
|
|
-// integralMapper.deleteById(id);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// private void validateIntegralExists(Long id) {
|
|
|
|
-// if (integralMapper.selectById(id) == null) {
|
|
|
|
-// throw exception(INTEGRAL_NOT_EXISTS);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public IntegralDO getIntegral(Long id) {
|
|
|
|
-// return integralMapper.selectOne(new LambdaQueryWrapperX<IntegralDO>().eq(IntegralDO::getUserId,id));
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public PageResult<IntegralDO> getIntegralPage(IntegralPageReqVO pageReqVO) {
|
|
|
|
-// return integralMapper.selectPage(pageReqVO);
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// @Override
|
|
|
|
-// public IntegralDO selectByUser(Long descendant) {
|
|
|
|
-// return integralMapper.selectOne(new LambdaQueryWrapper<IntegralDO>().eq(IntegralDO::getUserId, descendant));
|
|
|
|
-// }
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private OrderPercentageService orderPercentageService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* add by Ben
|
|
* add by Ben
|
|
* 修改用户积分
|
|
* 修改用户积分
|
|
*
|
|
*
|
|
- * @param userId 要修改积分的用户
|
|
|
|
- * @param caclEnum 导致积分变化的事件类型枚举
|
|
|
|
- * @param amount 用户可用积分变化金额,可为负数
|
|
|
|
|
|
+ * @param userId 要修改积分的用户
|
|
|
|
+ * @param caclEnum 导致积分变化的事件类型枚举
|
|
|
|
+ * @param amount 用户可用积分变化金额,可为负数
|
|
* @param freezeAmount 用户冻结积分变化金额,可为负数
|
|
* @param freezeAmount 用户冻结积分变化金额,可为负数
|
|
- * @return 返回是否执行成功。执行失败,通常是就是用户积分不足,没积分抵扣
|
|
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Boolean updateUserIntegral(Long generateUserId,//导致产生积分变动的用户ID
|
|
|
|
- Long userId, CaclEnum caclEnum, Long amount, Long freezeAmount,
|
|
|
|
- Long tradeOrderId,
|
|
|
|
- String OrderNum
|
|
|
|
- ) {
|
|
|
|
- Boolean success = null;
|
|
|
|
-
|
|
|
|
|
|
+ public void updateUserIntegral(Long generateUserId,//导致产生积分变动的用户ID
|
|
|
|
+ Long userId, CaclEnum caclEnum, Long amount, Long freezeAmount,
|
|
|
|
+ Long tradeOrderId,
|
|
|
|
+ String orderNum
|
|
|
|
+ ) {
|
|
//修改用户积分钱包的积分
|
|
//修改用户积分钱包的积分
|
|
- int effectRowNum = ptProfitMapper.updateUserIntegral(amount,amount,freezeAmount,freezeAmount,userId);
|
|
|
|
-
|
|
|
|
- if (effectRowNum==1) {//如果成功修改积分记录
|
|
|
|
- success = true;
|
|
|
|
|
|
+ IntegralDO integralDO = integralMapper.selectOne(IntegralDO::getUserId, userId);
|
|
|
|
|
|
- //用户修改后的当前可用的钱包余额
|
|
|
|
- Long afterAmount = null;
|
|
|
|
- //用户修改后的冻结积分钱包余额
|
|
|
|
- Long afterFreezeAmount = null;
|
|
|
|
|
|
+ // 退款返回 为 +
|
|
|
|
+ integralDO.setCurrentQuota(integralDO.getCurrentQuota() + amount);
|
|
|
|
|
|
- //查询用户修改后的积分
|
|
|
|
- Map<String, Object> map = ptProfitMapper.selectUserIntegral(userId);
|
|
|
|
- Object currentQuotaObj = map.get("current_quota");
|
|
|
|
- Object freezeQuotaObj = map.get("freeze_quota");
|
|
|
|
|
|
+ // 直推奖超出额度
|
|
|
|
+ Long ancestorQuotaAmount = 0L;
|
|
|
|
+ // 如果是推荐人
|
|
|
|
+ if (caclEnum.getType().equals(CaclEnum.ORDER_REFUND_INTEGRAL_ANCESTER.getType())) {
|
|
|
|
|
|
- afterAmount = (Long)currentQuotaObj;
|
|
|
|
- afterFreezeAmount = (Long)freezeQuotaObj;
|
|
|
|
|
|
+ PtProfitLogDO profitLog = ptProfitLogService.selectProfitLogByUserIdWithProfitStatus(userId, CaclEnum.RECOMMENDED_PERSON_QUOTA.getType(), orderNum);
|
|
|
|
|
|
- if(afterAmount<0||afterFreezeAmount<0){
|
|
|
|
- throw new RuntimeException("用户钱包为负数:用户IO为"+userId+"的用户可用钱包为"+afterAmount+",冻结钱包为"+afterFreezeAmount);
|
|
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ integralMapper.updateById(integralDO);
|
|
|
|
+
|
|
|
|
+ //用户修改后的当前可用的钱包余额
|
|
|
|
+ Long afterAmount = null;
|
|
|
|
+ //用户修改后的冻结积分钱包余额
|
|
|
|
+ Long afterFreezeAmount = null;
|
|
|
|
|
|
- //记录用户的积分变动日志
|
|
|
|
- ptProfitLogService.addMessage(generateUserId,userId, caclEnum, amount, afterAmount,
|
|
|
|
- freezeAmount, afterFreezeAmount,null,tradeOrderId,OrderNum);
|
|
|
|
|
|
+ //查询用户修改后的积分
|
|
|
|
+ Map<String, Object> map = ptProfitMapper.selectUserIntegral(userId);
|
|
|
|
+ Object currentQuotaObj = map.get("current_quota");
|
|
|
|
+ Object freezeQuotaObj = map.get("freeze_quota");
|
|
|
|
|
|
- }else if(effectRowNum<1){//如果钱包积分不足,不够抵扣
|
|
|
|
- success = false;
|
|
|
|
- } else if (effectRowNum>1) {
|
|
|
|
-// success = false;
|
|
|
|
- throw new RuntimeException("用户IO为"+userId+"的用户钱包不只一个!");
|
|
|
|
|
|
+ afterAmount = (Long) currentQuotaObj;
|
|
|
|
+ afterFreezeAmount = (Long) freezeQuotaObj;
|
|
|
|
+
|
|
|
|
+ //记录用户的积分变动日志
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
|
|
|
|
- return success;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void updateIntegralFreezeHighQuota(Long generateUserId, Long userId, CaclEnum caclEnum, Long totalFreezeHighQuota, Long tradeOrderId, String orderNum) {
|
|
public void updateIntegralFreezeHighQuota(Long generateUserId, Long userId, CaclEnum caclEnum, Long totalFreezeHighQuota, Long tradeOrderId, String orderNum) {
|
|
- IntegralDO integralDO = integralMapper.selectOne(IntegralDO::getUserId,userId);
|
|
|
|
- integralDO.setFreezeHighQuota(integralDO.getFreezeHighQuota() - totalFreezeHighQuota);
|
|
|
|
|
|
+ IntegralDO integralDO = integralMapper.selectOne(IntegralDO::getUserId, userId);
|
|
|
|
+// integralDO.setFreezeHighQuota(integralDO.getFreezeHighQuota() - totalFreezeHighQuota);
|
|
|
|
+ integralDO.setHighQuota(integralDO.getHighQuota() - totalFreezeHighQuota);
|
|
|
|
+ integralDO.setHighQuotaTotal(integralDO.getHighQuotaTotal() - totalFreezeHighQuota);
|
|
integralMapper.updateById(integralDO);
|
|
integralMapper.updateById(integralDO);
|
|
|
|
|
|
|
|
+ OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
|
|
|
|
+
|
|
//记录用户的积分变动日志
|
|
//记录用户的积分变动日志
|
|
PtProfitLogSaveReqVO profitLogSaveReqVO = PtProfitLogSaveReqVO.builder()
|
|
PtProfitLogSaveReqVO profitLogSaveReqVO = PtProfitLogSaveReqVO.builder()
|
|
- .freezeHighQuota(-totalFreezeHighQuota)
|
|
|
|
- .afterFreezeHighQuota(integralDO.getFreezeHighQuota())
|
|
|
|
|
|
+// .freezeHighQuota(-totalFreezeHighQuota)
|
|
|
|
+// .afterFreezeHighQuota(integralDO.getFreezeHighQuota())
|
|
|
|
+ .maxAvailablePointsAmount(-totalFreezeHighQuota)
|
|
|
|
+ .afterMaxAvailablePointsAmount(integralDO.getHighQuota() + Long.parseLong(orderPercentageDO.getBaseMaxQuota())) // 系统设置的最大可用积分
|
|
.userId(userId)
|
|
.userId(userId)
|
|
.generateUserId(generateUserId)
|
|
.generateUserId(generateUserId)
|
|
.profitStatus(caclEnum.getType())
|
|
.profitStatus(caclEnum.getType())
|