|
@@ -1,8 +1,7 @@
|
|
|
package com.management.platform.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.management.platform.entity.Custom;
|
|
|
-import com.management.platform.entity.User;
|
|
|
+import com.management.platform.entity.MiniBindUser;
|
|
|
import com.management.platform.entity.WechatQrcodeScan;
|
|
|
import com.management.platform.entity.WechatUserFollow;
|
|
|
import com.management.platform.mapper.WechatQrcodeScanMapper;
|
|
@@ -27,7 +26,7 @@ import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
@@ -171,30 +170,34 @@ public class WechatCallbackController {
|
|
|
followRecord.setSalesmanId(salesmanId);
|
|
|
followMapper.insert(followRecord);
|
|
|
|
|
|
- /*List<MiniBindUser> miniBindUserList = miniBindUserService.list(new QueryWrapper<MiniBindUser>()
|
|
|
- .eq("unionid", scanRecord.getUnionid())
|
|
|
- .orderByDesc("create_time")
|
|
|
- .last("limit 1"));*/
|
|
|
+ log.info("销售人员的id==>"+salesmanId);
|
|
|
+ log.info("用户的openid==>"+openId);
|
|
|
+ List<MiniBindUser> miniBindUserList = miniBindUserService.list(new QueryWrapper<MiniBindUser>()
|
|
|
+ .eq("openid", scanRecord.getOpenId()).eq("user_id",salesmanId));
|
|
|
+
|
|
|
+ if (miniBindUserList.isEmpty()){
|
|
|
+ /*int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
|
|
|
+ if(count==0) {
|
|
|
+ Custom custom = new Custom();
|
|
|
+ custom.setCustomName(openId);//用户的openId
|
|
|
+ custom.setIsDelete(0);
|
|
|
+ custom.setCreateTime(new Date());
|
|
|
+ if (StringUtils.isNotEmpty(salesmanId)) {
|
|
|
+ custom.setInchargerId(salesmanId);
|
|
|
+ User user = userService.getById(salesmanId);
|
|
|
+ custom.setCompanyId(user != null ? user.getCompanyId() : null);
|
|
|
+ customService.save(custom);
|
|
|
+ log.info("新增客户成功");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info("已存在custom_name为"+openId+"的客户");
|
|
|
+ }*/
|
|
|
+ MiniBindUser miniBindUser = new MiniBindUser();
|
|
|
+ miniBindUser.setUserId(salesmanId).setOpenid(openId).setCreateTime(LocalDateTime.now());
|
|
|
+ miniBindUserService.save(miniBindUser);
|
|
|
+ log.info("用户关注服务号销售人员的二维码,绑定销售人员和用户id成功");
|
|
|
|
|
|
-// if (!miniBindUserList.isEmpty()){
|
|
|
- int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
|
|
|
- if(count==0) {
|
|
|
- Custom custom = new Custom();
|
|
|
- custom.setCustomName(openId);//用户的openId
|
|
|
- custom.setIsDelete(0);
|
|
|
- custom.setCreateTime(new Date());
|
|
|
- if (StringUtils.isNotEmpty(salesmanId)) {
|
|
|
- custom.setInchargerId(salesmanId);
|
|
|
- User user = userService.getById(salesmanId);
|
|
|
- custom.setCompanyId(user != null ? user.getCompanyId() : null);
|
|
|
- customService.save(custom);
|
|
|
- log.info("新增客户成功");
|
|
|
- }
|
|
|
- }else {
|
|
|
- log.info("已存在custom_name为"+openId+"的客户");
|
|
|
}
|
|
|
-// }
|
|
|
- log.info("用户关注成功");
|
|
|
} else {
|
|
|
followRecord.setIsFollow(true);
|
|
|
followRecord.setFollowTime(LocalDateTime.now());
|
|
@@ -204,17 +207,15 @@ public class WechatCallbackController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //取消关注
|
|
|
private void handleUnsubscribe(String openId) {
|
|
|
- WechatUserFollow followRecord = followMapper.findByOpenId(openId);
|
|
|
- if (followRecord != null) {
|
|
|
- followRecord.setIsFollow(false);
|
|
|
- followRecord.setUnfollowTime(LocalDateTime.now());
|
|
|
- followMapper.update(followRecord);
|
|
|
|
|
|
- customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
|
|
|
- log.info("用户取消关注成功");
|
|
|
- }
|
|
|
+ followMapper.delete(new QueryWrapper<WechatUserFollow>().eq("open_id", openId));
|
|
|
+// customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
|
|
|
+ miniBindUserService.remove(new QueryWrapper<MiniBindUser>().eq("openid", openId));
|
|
|
+ log.info("用户取消绑定销售人员成功");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private String successResponse(Element root) {
|