Helius
2021-07-14 290ae8b3a86a4fb00cc6c45744c76065593d276d
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.entity.AccountInfo;
import com.xzx.gc.entity.SysMessage;
import com.xzx.gc.entity.UserHeadRelate;
import com.xzx.gc.entity.UserShareInfo;
import com.xzx.gc.user.dto.HeadProfitLitDto;
import com.xzx.gc.user.dto.HeadTeamDto;
import com.xzx.gc.user.mapper.*;
import com.xzx.gc.user.vo.HeadInfoVo;
import com.xzx.gc.user.vo.HeadProfitListVo;
import com.xzx.gc.user.vo.HeadTeamVo;
import com.xzx.gc.user.vo.ViewSettingVo;
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.Date;
import java.util.List;
 
@Service
@Transactional
public class DistribService {
 
    @Autowired
    private UserHeadRelateMapper userHeadRelateMapper;
    @Autowired
    private UserHeadDetailsMapper userHeadDetailsMapper;
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private UserShareInfoMapper userShareInfoMapper;
    @Autowired
    private SysMessageMapper sysMessageMapper;
 
    public ViewSettingVo viewSetting(Long id) {
        ViewSettingVo viewSettingVo = new ViewSettingVo();
        return viewSettingVo;
    }
 
 
    public void join(String headId, String userId) {
        AccountInfo headInfo = accountMapper.selectOneByUserId(headId);
        if (AccountInfo.IS_HEAD_N.equals(headInfo.getIsHead())) {
            throw new RestException(-3, "不是团长");
        }
 
        if (AccountInfo.IS_PROHIBIT_Y.equals(headInfo.getIsProhibit())) {
            throw new RestException(-3, "该用户被冻结");
        }
 
        UserHeadRelate existHeadRelate = userHeadRelateMapper.selectMemberByUserId(userId);
        if (existHeadRelate != null) {
            throw new RestException(-3, "已加入其他团队");
        }
 
        AccountInfo accountInfo = accountMapper.selectOneByUserId(userId);
        UserShareInfo userShareInfo = userShareInfoMapper.selectByRegistPhone(accountInfo.getAccountName());
        if (userShareInfo != null) {
            throw new RestException(-3, "您已与推广员绑定, 无法加入");
        }
 
        UserHeadRelate userHeadRelate = new UserHeadRelate();
        userHeadRelate.setHeadUserId(headId);
        userHeadRelate.setUserId(userId);
        userHeadRelate.setScore(BigDecimal.ZERO);
        userHeadRelate.setAmount(BigDecimal.ZERO);
        userHeadRelateMapper.insert(userHeadRelate);
 
        SysMessage sysMessage = new SysMessage();
        sysMessage.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        sysMessage.setCreateUserId(userId);
        sysMessage.setMobilePhone(accountInfo.getAccountName());
        sysMessage.setMessageType("4");
        sysMessage.setMessage("手机号:" + accountInfo.getAccountName() + "的用户, 成功加入您的团队");
        sysMessage.setFlag("2");
        sysMessageMapper.insert(sysMessage);
    }
 
    public HeadInfoVo findHeadInfo(String userId) {
        AccountInfo accountInfo = accountMapper.selectOneByUserId(userId);
 
        HeadInfoVo headInfoVo = userHeadRelateMapper.selectHeadStatisticsData(userId);
        if (headInfoVo == null) {
            headInfoVo = new HeadInfoVo();
        }
 
        headInfoVo.setIsHead(accountInfo.getIsHead());
        return headInfoVo;
    }
 
    public List<HeadProfitListVo> findHeadProfitListInPage(HeadProfitLitDto profitLitDto) {
        PageHelper.startPage(profitLitDto.getPage(), profitLitDto.getLimit());
        return userHeadDetailsMapper.selectHeadProfitListInPage(profitLitDto.getUserId());
    }
 
    public List<HeadTeamVo> findHeadTeamListInPage(HeadTeamDto teamDto) {
        PageHelper.startPage(teamDto.getPage(), teamDto.getLimit());
        return userHeadRelateMapper.selectHeadTeamListInPage(teamDto.getUserId());
    }
}