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.AccountLogMapper; import com.xzx.gc.order.mapper.PayInfoMapper; import com.xzx.gc.order.mapper.RedPaperMapper; 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; @Service @Transactional @Slf4j public class WeightRebateService extends BaseAccountService { @Autowired private PartnerAccountService partnerAccountService; @Autowired private AccountService accountService; @Autowired private PartnerAccountLogService partnerAccountLogService; @Autowired private AccountLogService accountLogService; @Autowired private PayInfoMapper payInfoMapper; @Autowired private IdUtils idUtils; @Autowired private BusinessUtil businessUtil; @Override public Object account(AllAcountParamDto allAcountParamDto) { String now=DateUtil.now(); //无返利 if (allAcountParamDto.getOtherMoney().compareTo(BigDecimal.ZERO) == 0&&allAcountParamDto.getMoney().compareTo(BigDecimal.ZERO)==0) { return null; } log.debug("准备进行重量返利支出操作:{}",JSONUtil.toJsonPrettyStr(allAcountParamDto)); //重量支出返利 回收员和合伙人扣钱,用户加钱 自助下单回收员需要帮合伙人垫付支出 Map payMap = new HashMap(); //正常下单 if(allAcountParamDto.getOrderType()==0) { /** * 回收员 * otherMoney 回收员返利 */ if (allAcountParamDto.getOtherMoney().compareTo(BigDecimal.ZERO) > 0) { String otherPayOrderId = idUtils.generate("ZF", 0); payMap.put("payOrderId", otherPayOrderId); payMap.put("orderId", allAcountParamDto.getFlowNo()); payMap.put("createUserId", allAcountParamDto.getOtherUserId()); payMap.put("money", allAcountParamDto.getOtherMoney()); payMap.put("accountId", allAcountParamDto.getOtherAccountId()); payMap.put("payType", PayEnum.按重量返利.getValue()); payMap.put("status", PayEnum.已支付.getValue()); payMap.put("createTime", now); payInfoMapper.payInfoAdd(payMap); AccountLog accountLog = new AccountLog(); accountLog.setAccountId(allAcountParamDto.getOtherAccountId()); accountLog.setCreateUserId(allAcountParamDto.getOtherUserId()); if (allAcountParamDto.getOtherMoneyType() == 1) { accountLog.setOldLimit(Convert.toStr(allAcountParamDto.getOtherOldMoney())); accountLog.setNewLimit(Convert.toStr(NumberUtil.sub(Convert.toBigDecimal(accountLog.getOldLimit()), allAcountParamDto.getOtherMoney()))); } else if(allAcountParamDto.getOtherMoneyType()==2){ accountLog.setOldMoney(Convert.toStr(allAcountParamDto.getOtherOldMoney())); accountLog.setNewMoney(Convert.toStr(NumberUtil.sub(Convert.toBigDecimal(accountLog.getOldMoney()), allAcountParamDto.getOtherMoney()))); } accountLog.setChannelType(Convert.toShort(CommonEnum.重量返利支出.getValue())); accountLog.setOrderId(otherPayOrderId); accountLogService.add(accountLog); } /** * 用户 * money 合伙人返利 * otherMoney 回收员返利 * oldmoney 用户增加了回收订单金额的金额 */ BigDecimal sub2 = NumberUtil.add(allAcountParamDto.getOtherMoney(), allAcountParamDto.getMoney()); if (sub2.compareTo(BigDecimal.ZERO) > 0) { payMap.clear(); String payOrderId = idUtils.generate("ZF", 0); payMap.put("payOrderId", payOrderId); payMap.put("orderId", allAcountParamDto.getFlowNo()); payMap.put("createUserId", allAcountParamDto.getUserId()); payMap.put("money", Convert.toStr(sub2)); 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(Convert.toStr(allAcountParamDto.getOldMoney())); accountLog.setNewMoney(Convert.toStr(NumberUtil.add(Convert.toBigDecimal(accountLog.getOldMoney()), sub2))); accountLog.setOrderId(payOrderId); accountLogService.add(accountLog); } //自助下单 }else if(allAcountParamDto.getOrderType()==1) { /** * 回收员 */ if (allAcountParamDto.getOtherMoney().compareTo(BigDecimal.ZERO) > 0) { payMap.clear(); String otherPayOrderId = idUtils.generate("ZF", 0); payMap.put("payOrderId", otherPayOrderId); payMap.put("orderId", allAcountParamDto.getFlowNo()); payMap.put("createUserId", allAcountParamDto.getOtherUserId()); payMap.put("money", allAcountParamDto.getOtherMoney()); payMap.put("accountId", allAcountParamDto.getOtherAccountId()); payMap.put("payType", PayEnum.按重量返利.getValue()); payMap.put("status", PayEnum.已支付.getValue()); payMap.put("createTime", now); payInfoMapper.payInfoAdd(payMap); } if (allAcountParamDto.getMoney().compareTo(BigDecimal.ZERO) > 0) { //发送环保金明细 payMap.clear(); 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); } } /** * 合伙人 */ if(allAcountParamDto.getMoney().compareTo(BigDecimal.ZERO) > 0) { 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; } }