jyy
2021-03-12 baa79615425b71521e67ec8a9344b88ce53fc5de
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.matrix.system.fenxiao.service;
 
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.biz.service.BizUserService;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.StringUtils;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.interceptor.HostInterceptor;
import com.matrix.system.fenxiao.constant.FenxiaoSettingConstant;
import com.matrix.system.fenxiao.dao.ShopSalesmanApplyDao;
import com.matrix.system.fenxiao.dao.ShopSalesmanGradeDao;
import com.matrix.system.fenxiao.dto.ShopSalesmanAppliingDto;
import com.matrix.system.fenxiao.dto.ShopSalesmanApplyDto;
import com.matrix.system.fenxiao.entity.ShopSalesmanApply;
import com.matrix.system.fenxiao.entity.ShopSalesmanGrade;
import com.matrix.system.fenxiao.vo.ShopSalesmanAppliingVo;
import com.matrix.system.fenxiao.vo.ShopSalesmanApplyVo;
import com.matrix.system.fenxiao.vo.ShopSalesmanGradeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Date;
import java.util.List;
 
/**
 * @description 推广员申请记录
 * @author jyy
 * @date 2021-03-10 15:22
 */
@Service
public class ShopSalesmanApplyService  extends ServiceImpl<ShopSalesmanApplyDao, ShopSalesmanApply>{
 
 
    @Autowired
    BusParameterSettingsDao busParameterSettingsDao;
 
    @Autowired
    ShopSalesmanApplyDao salesmanApplyDao;
    
    @Autowired
    ShopSalesmanGradeDao shopSalesmanGradeDao;
 
    @Autowired
    private BizUserDao bizUserDao;
 
    @Autowired
    BizUserService bizUserService;
 
    /**
     * 申请成为推广员
     * @param openId
     * @param invitationId
     * @return
     */
    public ShopSalesmanApply applyToBeAnSalesman(String openId,String gradeId,String invitationId) {
 
        BizUser loginUser=bizUserDao.findByOpenId(openId);
        //校验审核状态,和是否重复发起
        QueryWrapper<ShopSalesmanApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",loginUser.getOpenId());
        ShopSalesmanApply checkApply = salesmanApplyDao.selectOne(queryWrapper);
        if(checkApply==null||
                checkApply.getApplyStatus()==ShopSalesmanApply.APPLY_STATUS_WTG){
 
            ShopSalesmanApply shopSalesmanApply=new ShopSalesmanApply();
            shopSalesmanApply.setUserId(openId);
            
            shopSalesmanApply.setCreateBy(loginUser.getNickName());
            shopSalesmanApply.setApplyWay(ShopSalesmanApply.APPLY_WAY_SELF);
 
            shopSalesmanApply.setCompanyId(loginUser.getCompanyId());
            shopSalesmanApply.setUpdateBy(loginUser.getNickName());
            Date date = new Date();
            shopSalesmanApply.setCreateTime(date);
            shopSalesmanApply.setUpdateTime(date);
 
            if(StringUtils.isNotBlank(invitationId)){
                shopSalesmanApply.setParentUserId(invitationId);
            }else if(StringUtils.isNotBlank(loginUser.getParentOpenId())){
                //如果曾经是被邀请进来的则自动绑定为之前邀请人的下级
                shopSalesmanApply.setParentUserId(loginUser.getParentOpenId());
            }
            if(StringUtils.isNotBlank(gradeId)){
                shopSalesmanApply.setGradeId(Long.parseLong(gradeId));
            }else{
                //获取初始等级ID(公司id,是否为初始等级)
                Wrapper<ShopSalesmanGrade> queryWrapperOrepool = new QueryWrapper<>();
                ((QueryWrapper<ShopSalesmanGrade>) queryWrapperOrepool).eq("company_id", loginUser.getCompanyId());
                ((QueryWrapper<ShopSalesmanGrade>) queryWrapperOrepool).eq("is_default", 1);
                ShopSalesmanGrade shopSalesmanGrade = shopSalesmanGradeDao.selectOne(queryWrapperOrepool);
                shopSalesmanApply.setGradeId(shopSalesmanGrade.getId());
            }
 
            BusParameterSettings busParameterSettings = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_AUDIT_METHOD, HostInterceptor.getCompanyId());
            if(busParameterSettings!=null
                    &&busParameterSettings.getParamValue().equals("1")){
                //自动审核
                shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_TG);
                bizUserService.setToBeAnSalesman(loginUser.getOpenId(),invitationId);
 
            }else{
                shopSalesmanApply.setApplyStatus(ShopSalesmanApply.APPLY_STATUS_DSH);
            }
            salesmanApplyDao.insert(shopSalesmanApply);
            return  shopSalesmanApply;
        }else{
            throw  new GlobleException("不能重复申请");
        }
 
    }
 
    public IPage<ShopSalesmanApplyVo> findShopSalesmanApplyList(Page<ShopSalesmanApplyVo> page, ShopSalesmanApplyDto shopSalesmanApplyDto) {
        return salesmanApplyDao.findShopSalesmanApplyList(page,shopSalesmanApplyDto);
    }
 
    public IPage<ShopSalesmanAppliingVo> findShopSalesmanAppliingList(Page<ShopSalesmanAppliingVo> page,
            ShopSalesmanAppliingDto shopSalesmanAppliingDto) {
        return salesmanApplyDao.findShopSalesmanAppliingList(page,shopSalesmanAppliingDto);
    }
 
    public IPage<ShopSalesmanAppliingVo> selectBizUserApplyList(Page<ShopSalesmanAppliingVo> page, ShopSalesmanAppliingDto shopSalesmanAppliingDto) {
        return salesmanApplyDao.selectBizUserApplyList(page,shopSalesmanAppliingDto);
    }
 
    public List<ShopSalesmanGradeVo> getShopSalesmanGradeVo(Long companyId) {
        return shopSalesmanGradeDao.getShopSalesmanGradeVo(companyId);
    }
 
    public void addSaleManApply(String userId,String gradeId) {
        BizUser user = bizUserDao.selectById(userId);
        
        applyToBeAnSalesman(user.getOpenId(),gradeId, "");
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}