|
@@ -12,10 +12,21 @@ import cn.newfeifan.mall.framework.common.enums.UserTypeEnum;
|
|
|
import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
|
|
|
import cn.newfeifan.mall.framework.common.util.number.MoneyUtils;
|
|
|
import cn.newfeifan.mall.module.distri.constant.DistriConstants;
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.integral.vo.IntegralSaveReqVO;
|
|
|
+import cn.newfeifan.mall.module.distri.controller.admin.ptprofit.vo.PtProfitSaveReqVO;
|
|
|
+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.ptprofit.PtProfitDO;
|
|
|
+import cn.newfeifan.mall.module.distri.dal.dataobject.sharepath.SharePathDO;
|
|
|
import cn.newfeifan.mall.module.distri.dal.mysql.orderpercentage.OrderPercentageMapper;
|
|
|
import cn.newfeifan.mall.module.distri.enums.CaclEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.enums.SocialStatusEnum;
|
|
|
+import cn.newfeifan.mall.module.distri.service.duser.DuserService;
|
|
|
import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
|
|
|
+import cn.newfeifan.mall.module.distri.service.ptprofit.PtProfitService;
|
|
|
+import cn.newfeifan.mall.module.distri.service.ptprofitlog.PtProfitLogService;
|
|
|
+import cn.newfeifan.mall.module.distri.service.sharepath.SharePathService;
|
|
|
import cn.newfeifan.mall.module.member.api.address.MemberAddressApi;
|
|
|
import cn.newfeifan.mall.module.member.api.address.dto.MemberAddressRespDTO;
|
|
|
import cn.newfeifan.mall.module.member.service.user.MemberUserService;
|
|
@@ -74,11 +85,13 @@ import com.kuaidi100.sdk.request.SubscribeReq;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -151,6 +164,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
@Resource
|
|
|
private AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
+ private PtProfitService ptProfitService;
|
|
|
+ @Resource
|
|
|
+ private PtProfitLogService ptProfitLogService;
|
|
|
+ @Resource
|
|
|
+ @Lazy
|
|
|
+ private SharePathService sharePathService;
|
|
|
+ @Resource
|
|
|
+ @Lazy
|
|
|
+ private DuserService duserService;
|
|
|
|
|
|
|
|
|
|
|
@@ -1213,6 +1236,318 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
sentWcChatMessage(order);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ calc(TradeOrderDOList, orderPercentageDO, JsonUtils.toJsonString(orderPercentageDO));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 计算订单支付成功后,订单项的冻结积分转换
|
|
|
+ * @param tradeOrderDOList 订单列表
|
|
|
+ * @param orderPercentageDO 参数百分比
|
|
|
+ * @param percentTemplate 计算百分比模板
|
|
|
+ */
|
|
|
+ private void calc(List<TradeOrderDO> tradeOrderDOList, OrderPercentageDO orderPercentageDO, String percentTemplate) {
|
|
|
+
|
|
|
+ List<PtProfitLogSaveReqVO> ptProfitLogSaveReqVOS = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal oneHundred = new BigDecimal(BigInteger.ONE);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal otherOneHundred = oneHundred.subtract(new BigDecimal(orderPercentageDO.getGrossProfitUserQuotaPerc()))
|
|
|
+ .subtract(new BigDecimal(orderPercentageDO.getGrossProfitAncestorQuotaPerc()))
|
|
|
+ .subtract(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc()));
|
|
|
+
|
|
|
+
|
|
|
+ tradeOrderDOList.forEach(k -> {
|
|
|
+ PtProfitDO ptProfitDO = ptProfitService.getPtProfit();
|
|
|
+
|
|
|
+ List<PtProfitSaveReqVO> ptProfitSaveReqVOS = new ArrayList<>();
|
|
|
+
|
|
|
+ List<TradeOrderItemDO> tradeOrderItemDOS = tradeOrderItemMapper.selectListByOrderId(k.getId());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ final BigDecimal[] profit = {new BigDecimal("0"), new BigDecimal("0"), new BigDecimal("0"), new BigDecimal("0")};
|
|
|
+ tradeOrderItemDOS.forEach(j -> {
|
|
|
+ BigDecimal onePrice = new BigDecimal(j.getPrice());
|
|
|
+ BigDecimal oneCostPrice = new BigDecimal(j.getCostPrice());
|
|
|
+ BigDecimal productCount = new BigDecimal(j.getCount());
|
|
|
+ BigDecimal oneGrossProfit = onePrice.subtract(oneCostPrice).multiply(productCount);
|
|
|
+ profit[0] = profit[0].add(oneGrossProfit);
|
|
|
+ profit[1] = profit[1].add(new BigDecimal(j.getIncreaseIntegral()));
|
|
|
+ profit[2] = profit[2].add(new BigDecimal(j.getAncestorIncreaseIntegral()));
|
|
|
+ profit[3] = profit[3].add(new BigDecimal(j.getFreezeHighQuota()));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ TradeOrderItemDO item = new TradeOrderItemDO();
|
|
|
+ item.setId(j.getId());
|
|
|
+ item.setDistributeBenefit(true);
|
|
|
+ tradeOrderItemMapper.updateById(item);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal grossProfit = profit[0].multiply(new BigDecimal(orderPercentageDO.getGrossProfitPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal grossProfitAfterBonus = profit[0].multiply(oneHundred.subtract(new BigDecimal(orderPercentageDO.getGrossProfitPerc()))).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
+ if (otherOneHundred.compareTo(new BigDecimal(BigInteger.ZERO)) > 0) {
|
|
|
+ grossProfitAfterBonus = grossProfitAfterBonus.add(grossProfit.multiply(otherOneHundred).setScale(4, RoundingMode.DOWN));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal descendantQuota = profit[1];
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal ancestorQuota = profit[2];
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal platformQuota = grossProfit.multiply(new BigDecimal(orderPercentageDO.getGrossProfitPlatformQuotaPerc())).setScale(4, RoundingMode.DOWN);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal highQuota = profit[3];
|
|
|
+
|
|
|
+
|
|
|
+ Long ancestorQuotaInt = ancestorQuota.longValue();
|
|
|
+ Long descendantQuotaInt = descendantQuota.longValue();
|
|
|
+ Long highQuotaInt = highQuota.longValue();
|
|
|
+ Long grossProfitAfterBonusInt = grossProfitAfterBonus.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
+ Long platformQuotaInt = platformQuota.multiply(new BigDecimal("10000")).setScale(0, RoundingMode.DOWN).longValue();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ SharePathDO sharePath = sharePathService.getSharePathByDescendant(k.getUserId());
|
|
|
+
|
|
|
+ IntegralDO integralDOAncestor = integralService.selectByUser(sharePath.getAncestor());
|
|
|
+ IntegralDO integralDO = integralService.selectByUser(sharePath.getDescendant());
|
|
|
+ IntegralDO ptIntegral = integralService.selectByUser(1L);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ double orderAncestorSocialStatus = Double.parseDouble(orderPercentageDO.getOrderAncestorSocialStatus());
|
|
|
+ double ancestorSocial = k.getTotalPrice() * orderAncestorSocialStatus / 100;
|
|
|
+ duserService.updateDuserSocial(integralDOAncestor.getUserId(), (long) ancestorSocial, SocialStatusEnum.SHOPPING_ANCESTOR_SOCIAL.getStatus());
|
|
|
+
|
|
|
+
|
|
|
+ double orderUserSocialStatus = Double.parseDouble(orderPercentageDO.getOrderUserSocialStatus());
|
|
|
+ double descendantSocial = k.getTotalPrice() * orderUserSocialStatus / 100;
|
|
|
+ duserService.updateDuserSocial(integralDO.getUserId(), (long) descendantSocial, SocialStatusEnum.SHOPPING_SOCIAL.getStatus());
|
|
|
+
|
|
|
+
|
|
|
+ 原本这里有添加到distri_order_calc表的记录,但是现在要合赢奖和(直推奖、自得奖)分开,所以现在搬走了
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Long ancestorHighQuota = integralDOAncestor.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue();
|
|
|
+
|
|
|
+
|
|
|
+ Long amount = 0L;
|
|
|
+
|
|
|
+ Long ptReplenish = ancestorQuotaInt;
|
|
|
+
|
|
|
+
|
|
|
+ if (ancestorHighQuota.compareTo(0L) > 0) {
|
|
|
+ if (ancestorHighQuota.compareTo(ancestorQuotaInt) > 0) {
|
|
|
+
|
|
|
+ amount = ancestorQuotaInt;
|
|
|
+
|
|
|
+ ptReplenish = 0L;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ amount = ancestorHighQuota;
|
|
|
+
|
|
|
+ ptReplenish = ancestorQuotaInt - ancestorHighQuota;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ changeUserWallet(integralDO, integralDOAncestor, ptIntegral, amount,
|
|
|
+ descendantQuotaInt, highQuotaInt, grossProfitAfterBonusInt, platformQuotaInt, ptReplenish);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitSaveReqVO ptProfitSaveReqVO =
|
|
|
+ PtProfitSaveReqVO.builder()
|
|
|
+ .ptAdd(platformQuotaInt)
|
|
|
+ .ptGrossAdd(grossProfitAfterBonusInt)
|
|
|
+ .ptTotalAdd(platformQuotaInt + grossProfitAfterBonusInt).build();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (ptReplenish.compareTo(0L) > 0) {
|
|
|
+ calcIntegral(ptProfitSaveReqVOS, ptProfitSaveReqVO, ptReplenish,
|
|
|
+ k.getId(), k.getNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ ptProfitSaveReqVOS.add(ptProfitSaveReqVO);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptTotal = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.PLATFORM_TOTAL_ADD.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .amount(platformQuotaInt + grossProfitAfterBonusInt)
|
|
|
+ .afterAmount(ptProfitDO.getPtTotalAdd() + platformQuotaInt + grossProfitAfterBonusInt)
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptGrossAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.PLATFORM_REVENUE.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .amount(grossProfitAfterBonusInt)
|
|
|
+ .afterAmount(ptProfitDO.getPtGrossAdd() + ptProfitSaveReqVO.getPtGrossAdd())
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptAddLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.PLATFORM_SERVICE_FEE.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .amount(platformQuotaInt)
|
|
|
+ .afterAmount(ptProfitDO.getPtAdd() + ptProfitSaveReqVO.getPtAdd())
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO tjrLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.RECOMMENDED_PERSON_QUOTA.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .userId(sharePath.getAncestor())
|
|
|
+ .amount(amount)
|
|
|
+ .afterAmount(integralDOAncestor.getCurrentQuota())
|
|
|
+ .freezeAmount(-amount)
|
|
|
+ .afterFreezeAmount(integralDOAncestor.getFreezeQuota())
|
|
|
+ .ancestorQuotaAmount(ptReplenish)
|
|
|
+ .maxAvailablePointsAmount(-amount)
|
|
|
+ .afterMaxAvailablePointsAmount(ancestorHighQuota - amount)
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ztrLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(k.getId())
|
|
|
+ .profitStatus(CaclEnum.DIRECT_REFERRAL_QUOTA.getType())
|
|
|
+ .orderNo(k.getNo())
|
|
|
+ .userId(sharePath.getDescendant())
|
|
|
+ .amount(descendantQuotaInt)
|
|
|
+ .afterAmount(integralDO.getCurrentQuota())
|
|
|
+ .freezeAmount(-descendantQuotaInt)
|
|
|
+ .afterFreezeAmount(integralDO.getFreezeQuota())
|
|
|
+ .maxAvailablePointsAmount(highQuotaInt)
|
|
|
+ .afterMaxAvailablePointsAmount(integralDO.getHighQuota() + new BigDecimal(orderPercentageDO.getBaseMaxQuota()).longValue())
|
|
|
+ .freezeHighQuota(-highQuotaInt)
|
|
|
+ .afterFreezeHighQuota(integralDO.getFreezeHighQuota())
|
|
|
+ .percentTemplate(percentTemplate)
|
|
|
+ .generateUserId(integralDO.getUserId())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ ptProfitLogSaveReqVOS.add(ptTotal);
|
|
|
+ ptProfitLogSaveReqVOS.add(ptGrossAddLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(ptAddLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(tjrLog);
|
|
|
+ ptProfitLogSaveReqVOS.add(ztrLog);
|
|
|
+
|
|
|
+
|
|
|
+ PtProfitDO ptProfit = ptProfitService.getPtProfit();
|
|
|
+
|
|
|
+ Long total = ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtTotalAdd).sum();
|
|
|
+ Long add = ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtAdd).sum();
|
|
|
+ Long grossAdd = ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtGrossAdd).sum();
|
|
|
+ ptProfit.setPtAdd(ptProfit.getPtAdd() + add);
|
|
|
+ ptProfit.setPtTotalAdd(ptProfit.getPtTotalAdd() + total);
|
|
|
+ ptProfit.setPtGrossAdd(ptProfit.getPtGrossAdd() + grossAdd);
|
|
|
+ PtProfitSaveReqVO ptProfitSaveReqVO2 = PtProfitSaveReqVO.builder()
|
|
|
+ .id(ptProfitDO.getId())
|
|
|
+ .ptTotalAdd(ptProfit.getPtTotalAdd())
|
|
|
+ .ptAdd(ptProfit.getPtAdd())
|
|
|
+ .ptGrossAdd(ptProfit.getPtGrossAdd()).build();
|
|
|
+ ptProfitService.updatePtProfit(ptProfitSaveReqVO2);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ ptProfitLogService.saveBatch(ptProfitLogSaveReqVOS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 在用户获取直推奖的时候溢出的需要加入到平台,并记录log
|
|
|
+ */
|
|
|
+ private void calcIntegral(List<PtProfitSaveReqVO> ptProfitSaveReqVOS, PtProfitSaveReqVO ptProfitSaveReqVO
|
|
|
+ , Long ancestorQuotaInt, Long orderId, String orderNo) {
|
|
|
+ ptProfitSaveReqVO.setPtGrossAdd(ptProfitSaveReqVO.getPtGrossAdd() + ancestorQuotaInt);
|
|
|
+ ptProfitSaveReqVO.setPtTotalAdd(ptProfitSaveReqVO.getPtGrossAdd() + ptProfitSaveReqVO.getPtAdd());
|
|
|
+
|
|
|
+ PtProfitLogSaveReqVO ptProfitLog = PtProfitLogSaveReqVO.builder()
|
|
|
+ .orderId(orderId)
|
|
|
+ .profitStatus(CaclEnum.GROSS_PROFIT_ANCESTOR_QUOTA_PERC_EXCEED_MAXIMUM_LIMIT.getType())
|
|
|
+ .orderNo(orderNo)
|
|
|
+ .amount(ancestorQuotaInt)
|
|
|
+ .afterAmount(ptProfitSaveReqVOS.stream().mapToLong(PtProfitSaveReqVO::getPtGrossAdd).sum() + ancestorQuotaInt)
|
|
|
+ .build();
|
|
|
+ ptProfitLogService.createPtProfitLog(ptProfitLog);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 修改用户钱包
|
|
|
+ *
|
|
|
+ * @param integralDO 当前用户钱包
|
|
|
+ * @param integralDOAncestor 推荐人钱包
|
|
|
+ * @param pt pt钱包
|
|
|
+ * @param ancestorQuota 推荐人额度
|
|
|
+ * @param descendantQuota 直推人额度
|
|
|
+ * @param highQuota 最大可用额度
|
|
|
+ * @param ptA pt收益
|
|
|
+ * @param ptB pt服务费
|
|
|
+ * @param ptReplenish 超出没有获取到的积分
|
|
|
+ */
|
|
|
+ private void changeUserWallet(IntegralDO integralDO, IntegralDO integralDOAncestor, IntegralDO pt,
|
|
|
+ Long ancestorQuota, Long descendantQuota, Long highQuota, Long ptA, Long ptB, Long ptReplenish) {
|
|
|
+
|
|
|
+
|
|
|
+ integralDO.setHighQuota(integralDO.getHighQuota() + highQuota);
|
|
|
+
|
|
|
+ integralDO.setHighQuotaTotal(integralDO.getHighQuotaTotal() + highQuota);
|
|
|
+ integralDO.setFreezeHighQuota(integralDO.getFreezeHighQuota() - highQuota);
|
|
|
+
|
|
|
+
|
|
|
+ integralDO.setCurrentQuota(integralDO.getCurrentQuota() + descendantQuota);
|
|
|
+ integralDO.setFreezeQuota(integralDO.getFreezeQuota() - descendantQuota);
|
|
|
+
|
|
|
+ integralDOAncestor.setCurrentQuota(integralDOAncestor.getCurrentQuota() + ancestorQuota);
|
|
|
+
|
|
|
+ integralDOAncestor.setHighQuota(integralDOAncestor.getHighQuota() - ancestorQuota);
|
|
|
+ integralDOAncestor.setAncestorQuota(integralDOAncestor.getAncestorQuota() + ancestorQuota);
|
|
|
+ integralDOAncestor.setFreezeQuota(integralDOAncestor.getFreezeQuota() - ancestorQuota - ptReplenish);
|
|
|
+ integralService.updateIntegral(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(integralDOAncestor, IntegralSaveReqVO.class));
|
|
|
+
|
|
|
+
|
|
|
+ pt.setCurrentQuota(pt.getCurrentQuota() + ptA + ptB);
|
|
|
+
|
|
|
+ integralService.updateIntegral(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
|
|
|
+ integralService.updateIntegral(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(pt, IntegralSaveReqVO.class));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void sentWcChatMessage(TradeOrderDO order) {
|