Helius
2021-08-04 04b04d8e0746f6bf6f83450caec52bc7f9ce8db9
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
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;
    }
}