浏览代码

扫描推广码后,用户已存在提示修改。

zhengqiang 5 年之前
父节点
当前提交
dd929db7d2

+ 21 - 7
picc-admin-server/src/main/java/com/jpsoft/picc/modules/admin/controller/JwtsUserController.java

@@ -1,7 +1,9 @@
 package com.jpsoft.picc.modules.admin.controller;
 
+import com.jpsoft.picc.modules.base.entity.Company;
 import com.jpsoft.picc.modules.base.entity.CompanyUser;
 import com.jpsoft.picc.modules.base.entity.ReplyMessage;
+import com.jpsoft.picc.modules.base.service.CompanyService;
 import com.jpsoft.picc.modules.base.service.CompanyUserService;
 import com.jpsoft.picc.modules.base.service.ReplyMessageService;
 import com.jpsoft.picc.modules.common.config.WeixinConfig;
@@ -63,6 +65,9 @@ public class JwtsUserController {
     @Autowired
     private CompanyUserService companyUserService;
 
+    @Autowired
+    private CompanyService companyService;
+
     @PostMapping("/login")
     @ApiOperation(value="登录获取token,在swagger ui中获取token时将写入session,调用其它接口时不用再设置header")
     @ApiImplicitParams({
@@ -279,13 +284,11 @@ public class JwtsUserController {
 
         try {
             CompanyUser companyUser = companyUserService.findByOpenId(openId);
+            String[] arr = eventKey.split(",");
+            String promoter = arr[1];
 
             if(companyUser==null) {
                 //未注册用户
-                String[] arr = eventKey.split(",");
-
-                String promoter = arr[1];
-
                 ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId,
                                             String.valueOf(WeixinEvent.PICC_ADMIN_SCAN_QRCODE_PROMOTION));
 
@@ -305,10 +308,21 @@ public class JwtsUserController {
                 }
             }
             else{
-                ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId,String.valueOf(WeixinEvent.PICC_ADMIN_SCAN_QRCODE_PROMOTION_EXIST));
-                //message = "您已注册!请在电脑端登录荆州人才超市联盟平台(http://picc.jzrccs.com)完成投保申请。";
+                //企业用户已注册,但推广人未填写时,企业用户扫描推广人的推广二维码后自动将关联推广人
+                if(StringUtils.isNotEmpty(companyUser.getCompanyId())){
+                    Company company = companyService.get(companyUser.getCompanyId());
+
+                    if (company!=null && StringUtils.isEmpty(company.getPromoter())){
+                        company.setPromoter(promoter);
+                        company.setUpdateTime(new Date());
+
+                        companyService.update(company);
+                    }
+                }
+
+                ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId, String.valueOf(WeixinEvent.PICC_ADMIN_SCAN_QRCODE_PROMOTION_EXIST));
 
-                if (replyMessage!=null){
+                if (replyMessage != null) {
                     message = replyMessage.getMessage();
                 }
             }

+ 7 - 1
picc-admin-server/src/main/java/com/jpsoft/picc/modules/base/controller/PromoterController.java

@@ -18,6 +18,8 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.util.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -57,7 +59,11 @@ public class PromoterController {
                 Company company = new Company();
                 company.setId(UUID.randomUUID().toString());
                 company.setName(companyName);
-                company.setPromoter(promoter);
+
+                if (!"0".equals(promoter)) {
+                    company.setPromoter(promoter);
+                }
+
                 company.setPromoterBindTime(new Date());
                 company.setCreateBy(userName);
                 company.setCreateTime(new Date());

+ 12 - 1
weixin-middleware/src/main/java/com/jpsoft/weixin/controller/WeixinController.java

@@ -8,6 +8,7 @@ import com.jpsoft.weixin.config.PICCEntScanConfig;
 import com.jpsoft.weixin.config.WeixinConfig;
 import com.jpsoft.weixin.entity.ReplyMessage;
 import com.jpsoft.weixin.service.ReplyMessageService;
+import com.jpsoft.weixin.utils.VelocityHelper;
 import com.jpsoft.weixin.utils.WeixinUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -222,7 +223,17 @@ public class WeixinController {
                     ReplyMessage replyMessage = replyMessageService.findByEvent(wechatId,event);
 
                     if(replyMessage!=null) {
-                        WeixinUtil.replyTextMessage(response, wechatId, openId, replyMessage.getMessage());
+                        //todo 自动回复新增了投保链接需要获取当前用户的openId
+                        StringBuilder urlBuilder = new StringBuilder();
+
+                        urlBuilder.append("openId=" + openId);
+                        urlBuilder.append("&promoter=0"); //自动回复带的推广人为0,这种情况就不保存到数据库
+
+                        Map<String, Object> vars = new HashMap<>();
+                        vars.put("params", urlBuilder.toString());
+
+                        String message = VelocityHelper.format(replyMessage.getMessage(), vars);
+                        WeixinUtil.replyTextMessage(response, wechatId, openId, message);
                     }
                     else{
                         log.warn(openId + ",事件:" + event + "未设置自动回复!");