AccountManager.java 2.6 KB
Newer Older
licc's avatar
licc committed
1
package cn.wisenergy.service.Manager;
licc's avatar
licc committed
2 3 4

import cn.wisenergy.mapper.AccountMapper;
import cn.wisenergy.mapper.OrderMapper;
licc's avatar
licc committed
5
import cn.wisenergy.mapper.TeamPerformanceMapper;
licc's avatar
licc committed
6
import cn.wisenergy.mapper.TradeRecordMapper;
licc's avatar
licc committed
7
import cn.wisenergy.model.app.*;
licc's avatar
licc committed
8 9 10 11 12 13
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
licc's avatar
licc committed
14
import java.util.List;
licc's avatar
licc committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

/**
 * @author 86187
 * @ Description: 账户管理公共类
 * @ Author     : 86187
 * @ Date       : 2021/2/23 10:43
 */
@Component
@Slf4j
public class AccountManager {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private AccountMapper accountMapper;

    @Autowired
    private TradeRecordMapper recordMapper;

licc's avatar
licc committed
35 36 37
    @Autowired
    private TeamPerformanceMapper teamPerformanceMapper;

licc's avatar
licc committed
38
    @Transactional(rollbackFor = Exception.class)
licc's avatar
licc committed
39
    public Boolean updateOrderAddMoney(OrderInfo orderInfo, AccountInfo accountInfo, MemberPercent memberpercent) {
licc's avatar
licc committed
40
        //1、计算返佣金额
licc's avatar
licc committed
41
        BigDecimal bigDecimal = orderInfo.getPayment().multiply(memberpercent.getPercent());
licc's avatar
licc committed
42 43 44
        BigDecimal extractMoney = accountInfo.getExtractMoney().add(bigDecimal);
        accountInfo.setExtractMoney(extractMoney);

licc's avatar
licc committed
45
        BigDecimal performanceMonth = accountInfo.getPerformanceMonth().add(bigDecimal);
licc's avatar
licc committed
46
        accountInfo.setPerformanceMonth(performanceMonth);
licc's avatar
licc committed
47 48 49

        BigDecimal performanceTotal = accountInfo.getPerformanceTotal().add(bigDecimal);
        accountInfo.setPerformanceMonth(performanceTotal);
licc's avatar
licc committed
50 51 52 53 54 55 56 57 58 59
        //2、修改订单返佣状态:已返佣 1
        orderInfo.setRebateStatus(1);

        int count = orderMapper.updateById(orderInfo);
        if (count == 0) {
            return false;
        }

        //3、增加账户可用金额
        int sum = accountMapper.updateById(accountInfo);
licc's avatar
licc committed
60 61 62
        if(sum ==0){
            return false;
        }
licc's avatar
licc committed
63 64 65 66 67 68 69 70 71 72 73 74 75

        //4、添加交易流水记录
        TradeRecord tradeRecord = new TradeRecord();
        tradeRecord.setUserId(orderInfo.getBuyerId());
        tradeRecord.setTradeType(2);
        tradeRecord.setTradeNo(orderInfo.getTid());
        int number = recordMapper.add(tradeRecord);
        if (number == 0) {
            return false;
        }

        return true;
    }
licc's avatar
licc committed
76 77 78 79 80 81 82

    @Transactional(rollbackFor = Exception.class)
    public void updateAccountPerformanceMonth(List<TeamPerformance> list) {
        for (TeamPerformance teamPerformance : list) {
            teamPerformanceMapper.updateById(teamPerformance);
        }
    }
licc's avatar
licc committed
83
}