package com.xzx.gc.order.service; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; import cn.hutool.json.JSONUtil; import com.xzx.gc.common.constant.CommonEnum; import com.xzx.gc.common.constant.OrderEnum; import com.xzx.gc.common.constant.PayEnum; import com.xzx.gc.common.utils.BusinessUtil; import com.xzx.gc.common.utils.IdUtils; import com.xzx.gc.entity.AccountLog; import com.xzx.gc.entity.PartnerAccountLog; import com.xzx.gc.model.comon.account.AllAcountParamDto; import com.xzx.gc.order.mapper.PayInfoMapper; 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.util.HashMap; import java.util.Map; @Slf4j @Service @Transactional public class StairRebateService extends BaseAccountService { @Autowired private AccountService accountService; @Autowired private BusinessUtil businessUtil; @Autowired private PayInfoMapper payInfoMapper; @Autowired private PartnerAccountLogService partnerAccountLogService; @Autowired private PartnerAccountService partnerAccountService; @Autowired private IdUtils idUtils; @Autowired private AccountLogService accountLogService; @Override public Object account(AllAcountParamDto allAcountParamDto) { String now=DateUtil.now(); if(allAcountParamDto.getMoney()!=null&&allAcountParamDto.getMoney().compareTo(BigDecimal.ZERO)>0) { log.debug("准备进行阶梯返利支出操作:{}",JSONUtil.toJsonPrettyStr(allAcountParamDto)); //阶梯支出返利 合伙人扣钱,用户加钱 自助下单回收员需要帮合伙人垫付支出 Map payMap = new HashMap(); if(allAcountParamDto.getOrderType()==0) { /** * 用户 */ accountService.updateMoneyByUserId(allAcountParamDto.getUserId(), allAcountParamDto.getMoney()); //添加操作记录 我的环保金明细展示 String payOrderId = idUtils.generate("ZF", 0); payMap.put("payOrderId", payOrderId); payMap.put("orderId", allAcountParamDto.getFlowNo()); payMap.put("createUserId", allAcountParamDto.getUserId()); payMap.put("money", allAcountParamDto.getMoney()); payMap.put("accountId", allAcountParamDto.getAccountId()); payMap.put("payType", PayEnum.阶梯返利.getValue()); payMap.put("status", PayEnum.已支付.getValue()); payMap.put("createTime", now); payInfoMapper.payInfoAdd(payMap); AccountLog accountLog = new AccountLog(); accountLog.setAccountId(allAcountParamDto.getAccountId()); accountLog.setCreateUserId(allAcountParamDto.getUserId()); accountLog.setChannelType(Convert.toShort(CommonEnum.阶梯返利操作.getValue())); accountLog.setOldMoney(allAcountParamDto.getOldMoney().toString()); accountLog.setNewMoney(Convert.toStr(NumberUtil.add(Convert.toBigDecimal(accountLog.getOldMoney()), allAcountParamDto.getMoney()))); accountLog.setOrderId(payOrderId); accountLogService.add(accountLog); }else if(allAcountParamDto.getOrderType()==1){ /** * 回收员 */ String otherPayOrderId = idUtils.generate("ZF", 0); payMap.put("payOrderId", otherPayOrderId); payMap.put("orderId", allAcountParamDto.getFlowNo()); payMap.put("createUserId", allAcountParamDto.getOtherUserId()); payMap.put("money", Convert.toStr(allAcountParamDto.getMoney())); payMap.put("accountId", allAcountParamDto.getOtherAccountId()); payMap.put("payType", PayEnum.垫付合伙人.getValue()); payMap.put("status", PayEnum.已支付.getValue()); payMap.put("createTime", now); payInfoMapper.payInfoAdd(payMap); accountService.updateMoneyByUserId(allAcountParamDto.getOtherUserId(), allAcountParamDto.getMoney()); AccountLog log = new AccountLog(); log.setCreateTime(now); log.setAccountId(allAcountParamDto.getOtherAccountId()); log.setCreateUserId(allAcountParamDto.getOtherUserId()); log.setChannelType(Convert.toShort(CommonEnum.垫付合伙人.getValue())); log.setOldMoney(Convert.toStr(allAcountParamDto.getOtherOldMoney())); log.setNewMoney(Convert.toStr(NumberUtil.add(Convert.toBigDecimal(log.getOldMoney()), allAcountParamDto.getMoney()))); log.setOrderId(otherPayOrderId); accountLogService.add(log); } PartnerAccountLog partnerAccountLog = new PartnerAccountLog(); partnerAccountLog.setPartnerId(allAcountParamDto.getPartnerId()); partnerAccountLog.setFlowNo(allAcountParamDto.getFlowNo()); partnerAccountLog.setType(OrderEnum.阶梯返利.getValue()); partnerAccountLog.setMoney("-" + businessUtil.changeMoney(allAcountParamDto.getMoney())); partnerAccountLog.setRuleId(allAcountParamDto.getRuleId()); partnerAccountLogService.add(partnerAccountLog); //修改合伙人账户 partnerAccountService.updateReduceMoneyByPartnerId(allAcountParamDto.getPartnerId(), allAcountParamDto.getMoney()); log.debug("阶梯返利支出操作已完成"); } return null; } }