935090232@qq.com
2021-03-11 dce21b3131e81663ccd0291b7e96542d3f1cec7e
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.matrix.system.shopXcx.api.action;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.matrix.biz.bean.BizUser;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.component.tools.WxacodeUtil;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.MD5Util;
import com.matrix.core.tools.PropertiesUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.constance.AppConstance;
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.entity.ShopSalesmanApply;
import com.matrix.system.fenxiao.service.ShopSalesmanApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2021-03-10
 **/
@Api(tags = "推广员接口类")
@RestController
@RequestMapping(value = "/wxapi/salesman")
public class WxSalesmanAction {
 
    @Autowired
    BusParameterSettingsDao busParameterSettingsDao;
 
    @Autowired
    ShopSalesmanApplyDao salesmanApplyDao;
 
    @Autowired
    ShopSalesmanApplyService shopSalesmanApplyService;
 
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
 
    @Autowired
    private BizUserDao bizUserDao;
 
 
    @ApiOperation(value = "查询推广计划", notes = "")
    @GetMapping(value = "/getTgPlan")
    public AjaxResult getTgPlan() {
        BusParameterSettings busParameterSettings = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_TG_PLAN, HostInterceptor.getCompanyId());
        AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("");
        ajaxResult.putInMap("data",busParameterSettings.getParamValue3());
        return ajaxResult;
    }
 
 
    @ApiOperation(value = "申请成为推广员", notes = "传入参数invitationId 邀请人openId ,非必填 例: {invitationId:openId}")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ShopSalesmanApply.class)
    })
    @PostMapping(value = "/applyToBeAnSalesman")
    @Transactional
    public AjaxResult applyToBeAnSalesman(@RequestBody Map<String,String> param) {
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        String invitationId = param.get("invitationId");
        ShopSalesmanApply shopSalesmanApply= shopSalesmanApplyService.applyToBeAnSalesman(loginUser.getOpenId(),invitationId);
        loginUser=bizUserDao.selectById(loginUser.getUserId());
        redisUserLoginUtils.updateUserInfo(loginUser);
        return AjaxResult.buildSuccessInstance(shopSalesmanApply);
    }
 
 
    @ApiOperation(value = "      ", notes = "")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ShopSalesmanApply.class)
    })
    @GetMapping(value = "/queryApplyProgress")
    public AjaxResult queryApplyProgress() {
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        QueryWrapper<ShopSalesmanApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",loginUser.getOpenId());
        ShopSalesmanApply shopSalesmanApply = salesmanApplyDao.selectOne(queryWrapper);
        return AjaxResult.buildSuccessInstance(shopSalesmanApply);
    }
 
 
    @ApiOperation(value = "绑定下级客户,当客户点击分销员分销的产品时调用", notes = "传入参数invitationId 必须 分销员openId 例: {invitationId:openId}")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = Map.class)
    })
    @PostMapping(value = "/bindingParentSalesman")
    public AjaxResult bindingParentSalesman(@RequestBody Map<String,String> param) {
        String invitationId = param.get("invitationId");
        if (StringUtils.isBlank(invitationId)) {
            return AjaxResult.buildFailInstance("请求参数错误");
        }
 
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        loginUser = bizUserDao.selectById(loginUser.getUserId());
        if (loginUser.getIsSales() == null || loginUser.getIsSales() == BizUser.NOT_SALES) {
            if (StringUtils.isBlank(loginUser.getParentOpenId())) {
 
                Map<String, Object> updateParam = new HashMap<>();
                updateParam.put("userId", loginUser.getUserId());
                updateParam.put("parentOpenId", invitationId);
                bizUserDao.updateByMap(updateParam);
                return AjaxResult.buildSuccessInstance("绑定成功");
            } else {
                return AjaxResult.buildSuccessInstance("已经存在上级");
            }
        } else {
            return AjaxResult.buildSuccessInstance("分销员不能被绑定");
        }
    }
 
 
    @ApiOperation(value = "生成邀请下级海报", notes = "")
    @PostMapping(value = "/getInvitationPoster")
    AjaxResult getInvitationPoster() {
        try {
            BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
            String qrcodeSavePath = WxacodeUtil.getWxacode(loginUser.getOpenId() + "", "pages/index/index", MD5Util.strToMD5(loginUser.getOpenId() + ""));
 
            //获取海报
            BusParameterSettings posterSetting = busParameterSettingsDao.selectCompanyParamByCode(FenxiaoSettingConstant.FX_TG_POSTER, HostInterceptor.getCompanyId());
 
            String posterSavePath = posterSetting.getParamValue1();
            BufferedImage productImgBuf = ImageIO.read(new File(qrcodeSavePath));
            BufferedImage qrcordImgBuf = ImageIO.read(new File(posterSavePath));
 
            BufferedImage backgroundImgBuf = new BufferedImage(750, 900, BufferedImage.TYPE_4BYTE_ABGR);
            //绘制背景+产品
            Graphics2D g = backgroundImgBuf.createGraphics();
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1));
 
 
 
 
            LogUtil.debug("qrcodeSavePath={}", qrcodeSavePath);
            // 图片保存目录路径
            String baseSavePath = PropertiesUtil.getString(AppConstance.FILES_TORAGE_PATH);
            // 图片访问URL
            String baseSaveUrl = PropertiesUtil.getString(AppConstance.NGINX_URL);
            String qrcodeImgUrl = qrcodeSavePath.replace(baseSavePath, baseSaveUrl);
 
            return AjaxResult.buildSuccessInstance(qrcodeImgUrl);
        } catch (Exception e) {
            LogUtil.error("门店生成二维码错误:{}", e, "");
        }
        return  AjaxResult.buildFailInstance("二维码生成失败");
    }
 
 
 
 
 
 
 
 
 
}