Helius
2021-06-28 cedf9aab0ee975b04c52c0a75749e1eba852db2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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<String,Object>  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;
    }
}