package com.xzx.gc.order.service; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.NumberUtil; import cn.hutool.json.JSONUtil; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.constant.OrderEnum; import com.xzx.gc.common.constant.UserEnum; import com.xzx.gc.entity.PartnerAccountLog; import com.xzx.gc.entity.PlatformAccountLog; import com.xzx.gc.entity.RedPaperRule; import com.xzx.gc.model.comon.account.AllAcountParamDto; import com.xzx.gc.service.BaseAccountService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.math.RoundingMode; @Service @Transactional @Slf4j public class CommissionsService extends BaseAccountService { @Autowired private RedPaperRuleService redPaperRuleService; @Autowired private PartnerAccountService partnerAccountService; @Autowired private PlatformAccountInfoService platformAccountInfoService; @Autowired private PartnerAccountLogService partnerAccountLogService; @Autowired private PlatformAccountLogService platformAccountLogService; @Override public Object account(AllAcountParamDto allAcountParamDto) { RedPaperRule one = redPaperRuleService.getOne(UserEnum.提佣规则.getValue(), allAcountParamDto.getPartnerId()); if (one != null) { //提佣比例 如0.005就是5厘 城市合伙人每笔订单成交,总部收取每笔订单回收流水的0.5%做为平台服务费。 BigDecimal shareRatio = Convert.toBigDecimal(one.getShareRatio(), Constants.MONEY_INIT); if (shareRatio.compareTo(BigDecimal.ZERO) == 0) { return null; } BigDecimal mul = NumberUtil.mul(allAcountParamDto.getMoney(), shareRatio); mul = NumberUtil.round(mul, 2, RoundingMode.HALF_UP); if (mul.compareTo(BigDecimal.ZERO) == 0) { return null; } //账户及日志变动 allAcountParamDto.setMoney(mul); log.debug("准备进行提佣操作:{}", JSONUtil.toJsonPrettyStr(allAcountParamDto)); //提佣 合伙人账户扣钱,总部加钱 PartnerAccountLog partnerAccountLog = new PartnerAccountLog(); partnerAccountLog.setPartnerId(allAcountParamDto.getPartnerId()); partnerAccountLog.setFlowNo(allAcountParamDto.getFlowNo()); partnerAccountLog.setType(OrderEnum.提佣.getValue()); partnerAccountLog.setMoney("-" + allAcountParamDto.getMoney().toString()); partnerAccountLog.setRuleId(allAcountParamDto.getRuleId()); partnerAccountLogService.add(partnerAccountLog); partnerAccountService.updateReduceMoneyByPartnerId(allAcountParamDto.getPartnerId(), allAcountParamDto.getMoney()); PlatformAccountLog platformAccountLog = new PlatformAccountLog(); platformAccountLog.setType(Convert.toInt(CommonEnum.平台总部流水提佣.getValue())); platformAccountLog.setFlowNo(allAcountParamDto.getFlowNo()); platformAccountLog.setCreateUserId(allAcountParamDto.getPartnerId()); platformAccountLog.setHbb(allAcountParamDto.getMoney()); platformAccountLogService.add(platformAccountLog); platformAccountInfoService.updateHbb(allAcountParamDto.getMoney().toString()); log.debug("提佣操作已完成"); } return null; } }