| 
					
				 | 
			
			
				@@ -1,8 +1,11 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.gree.mall.contest.logic.user; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.binarywang.wx.miniapp.api.WxMaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.collection.CollectionUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.date.DateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.hutool.core.util.IdUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.json.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.json.JSONUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -10,23 +13,29 @@ import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.bean.ExcelData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.bean.admin.AdminUserCom; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.common.WechatOpenBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.bean.member.MemberBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.bean.member.MemberSortBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.gree.mall.contest.bean.user.UserApplyBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.gree.mall.contest.bean.user.UserWxBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.bean.user.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.commonmapper.CustomGoodsMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.commonmapper.CustomMemberMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.gree.mall.contest.commonmapper.CustomWebsitMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.commonmapper.OrderShareRankMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.constant.Constant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.enums.OrderShareStatusEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.enums.QrCodeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.enums.UserTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.exception.RemoteServiceException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.helper.ResponseHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.logic.activity.PromotionGroupLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.logic.common.CommonLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.logic.common.WechatLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.logic.coupon.CouponLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.logic.order.OrderShareLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.logic.order.ShoppingCartLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.plus.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.plus.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.utils.CommonUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.contest.utils.JwtUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.utils.RedisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.contest.utils.excel.ExcelUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.RequiredArgsConstructor; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -35,6 +44,7 @@ import org.apache.commons.collections4.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringEscapeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.integration.redis.util.RedisLockRegistry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,8 +52,11 @@ import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.servlet.http.HttpServletResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.locks.Lock; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.function.Function; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -57,20 +70,22 @@ public class UserLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final UserService userService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final UserAddressService userAddressService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private final GoodsFavoriteService goodsFavoriteService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final GoodsVisitService goodsVisitService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final CustomGoodsMapper customGoodsMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private final CustomWebsitMapper customWebsitMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final CustomMemberMapper customMemberMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final CouponLogic couponLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final OrderShareLogic orderShareLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private final RedisUtil redisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final WechatLogic wechatLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final PromotionGroupLogic promotionGroupLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final CommonLogic commonLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final UserServiceApplyService userServiceApplyService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final UserServiceWaitService userServiceWaitService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final AdminWebsitService adminWebsitService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final OrderShareRankMapper orderShareRankMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final RedisLockRegistry redisLockRegistry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final ShoppingCartLogic shoppingCartLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final OrderShareService orderShareService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final RedisUtil redisUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 会员列表 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -269,17 +284,17 @@ public class UserLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             AdminWebsit adminWebsit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminWebsit = adminWebsitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(AdminWebsit::getCompanyWechatId, companyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(AdminWebsit::getWebsitNumber, user.getWebsitId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.isNull(adminWebsit)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 adminWebsit = adminWebsitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         .eq(AdminWebsit::getCompanyWechatId, companyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        .eq(AdminWebsit::getWebsitNumber, user.getWebsitId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .orderByAsc(AdminWebsit::getCreateTime) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .last("limit 1") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (Objects.isNull(adminWebsit)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    adminWebsit = adminWebsitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            .eq(AdminWebsit::getCompanyWechatId, companyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            .orderByAsc(AdminWebsit::getCreateTime) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            .last("limit 1") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             user.setWebsitId(adminWebsit.getWebsitId() + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             user.setWebsitName(adminWebsit.getName()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -627,4 +642,469 @@ public class UserLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         IPage<UserApplyBean> page = customMemberMapper.queryServiceApplyList(new Page<>(pageNum, pageSize), companyWechatIds, keyword, status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 绑定业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void bind(String userId, String serviceId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User service = userService.getById(serviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //绑定业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user.getType().equals(UserTypeEnum.GENERAL.toString()) && service.getType().equals(UserTypeEnum.SERVICE.toString())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setServiceId(serviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setServiceTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //判断是否为团长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!user.getPromotionGroupLeader()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (service.getPromotionGroupLeader()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setPromotionGroupUserId(serviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String promotionGroupUserId = service.getPromotionGroupUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setPromotionGroupUserId(promotionGroupUserId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取绑定业务员小程序码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public String bindQrCode(HttpServletRequest request) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String userId = CommonUtils.getUserId(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getUserId, userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getStatus, true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("用户不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotEmpty(user.getBindQrcode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return user.getBindQrcode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String qrcode = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            qrcode = wechatLogic.getQrcode(QrCodeEnum.BIND.toString().toLowerCase(Locale.ROOT), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.getWorkUserId(), user.getUserId(), currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotEmpty(qrcode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setBindQrcode(qrcode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                userService.updateById(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.error("获取绑定业务员小程序码失败", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return qrcode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public RankBean rank(HttpServletRequest request) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String userId = CommonUtils.getUserId(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getUserId, userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getStatus, true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null || StringUtils.isEmpty(user.getWorkUserId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("业务员不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date endTime = DateUtil.beginOfMonth(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date startTime = DateUtil.beginOfMonth(DateUtil.lastMonth()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date endTimeDay = DateUtil.offsetDay(now, -1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RankBean rankBean = new RankBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<RankItemBean> rankItemBeans = orderShareRankMapper.queryRankList(null, endTime, endTimeDay, currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<RankItemBean> myRanks = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (rankItemBeans != null && rankItemBeans.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            rankBean.setRankList(rankItemBeans.size() > 10 ? rankItemBeans.subList(0, 10) : rankItemBeans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //此处的workUserId就是userId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myRanks = rankItemBeans.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .filter(o -> o.getWorkUserId() != null && o.getWorkUserId().equals(user.getUserId())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .limit(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RankItemBean myrank = myRanks != null && myRanks.size() > 0 ? myRanks.get(0) : orderShareRankMapper.queryWorkerInfo(user.getUserId(), currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rankBean.setMyRank(myrank); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal previousIncome = new BigDecimal("0.00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal currentIncome = new BigDecimal("0.00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<RankItemBean> previous = orderShareRankMapper.queryRankList(user.getUserId(), startTime, endTime, currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<RankItemBean> current = orderShareRankMapper.queryRankList(user.getUserId(), endTime, endTimeDay, currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (previous != null && previous.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            previousIncome = previous.get(0).getTotal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (current != null && current.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            currentIncome = current.get(0).getTotal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rankBean.setUpOrDown(currentIncome.compareTo(previousIncome) > 0 ? true : false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rankBean.setIncome(currentIncome); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Calendar date = Calendar.getInstance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        date.setTime(endTimeDay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //date.add(Calendar.SECOND, -1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rankBean.setStartPeriod(simpleDateFormat.format(endTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        rankBean.setEndPeriod(simpleDateFormat.format(date.getTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return rankBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 微信授权 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param serviceId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @throws RemoteServiceException 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @throws InterruptedException 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public UserWxBean addUser(String code, String serviceId, HttpServletRequest request) throws RemoteServiceException, InterruptedException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final WechatOpenBean wechatOpenBean = wechatLogic.authToken(code, currentCompanyWechat.getSubAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("【微信授权】:{}", JSONUtil.toJsonStr(wechatOpenBean)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String key = Constant.RedisPrefix.LOCK_AUTH + ":" + wechatOpenBean.getOpenid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Lock obtain = redisLockRegistry.obtain(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!obtain.tryLock(2, TimeUnit.SECONDS)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.error("请勿重复授权"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //如果用户不存在则新注册 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            User user = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(User::getOpenId, wechatOpenBean.getOpenid()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(User::getCompanyWechatId, currentCompanyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setLastLoginTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setNickName("微信用户_" + IdUtil.objectId().substring(16, 24)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setOpenId(wechatOpenBean.getOpenid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setSessionKey(wechatOpenBean.getSessionKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setServiceId(serviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setServiceTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setLastLoginTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setCompanyName(currentCompanyWechat.getCompanyName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                userService.save(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                log.info("【注册成为会员】:{}", user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return this.supplyUser(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //如果用户存在,则判断是否为业务员,并更新相关信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!user.getStatus()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException("用户已被冻结"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //判断该手机号是否为业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user = userToService(user, currentCompanyWechat); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setUnionId(wechatOpenBean.getUnionid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setSessionKey(wechatOpenBean.getSessionKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setLastLoginTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isEmpty(user.getServiceId()) && StringUtils.isNotEmpty(serviceId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setServiceId(serviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                user.setServiceTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setOpenId(wechatOpenBean.getOpenid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return this.supplyUser(user); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            obtain.unlock(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 返回小程序用户登录需要的信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param user 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private UserWxBean supplyUser(User user) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserWxBean userWxBean = new UserWxBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String token = JwtUtils.generateToken(user.getUserId(), user.getOpenId(), user.getNickName(), null, Constant.MINIAPP_API); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BeanUtils.copyProperties(user, userWxBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userWxBean.setToken(token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userWxBean.setShoppingCartNums(shoppingCartLogic.total(userWxBean.getUserId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //存放到redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(Constant.RedisPrefix.TOKEN_MP_WX + userWxBean.getToken(), user, 2 * 60 * 60 * 1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminWebsit adminWebsit = adminWebsitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminWebsit::getCompanyWechatId, user.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(AdminWebsit::getWebsitId, user.getWebsitId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (adminWebsit != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setWebsitNumber(adminWebsit.getWebsitNumber()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setWebsitName(adminWebsit.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotBlank(user.getServiceId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            final User serviceUser = userService.getById(user.getServiceId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ServiceWorkerBean bean = new ServiceWorkerBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotBlank(serviceUser.getWebsitId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bean.setWebsitId(Long.parseLong(serviceUser.getWebsitId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bean.setWebsit(serviceUser.getWebsitName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setServiceWorkerBean(bean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return userWxBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public User userToService(User user, CurrentCompanyWechat currentCompanyWechat) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //判断该手机号是否为业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotEmpty(user.getMobile())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            UserServiceWait waitUser = userServiceWaitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(UserServiceWait::getMobile, user.getMobile()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(UserServiceWait::getCompanyWechatId, user.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.nonNull(waitUser)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Long count = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getMobile, user.getMobile()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getType, UserTypeEnum.SERVICE.toString()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getCompanyWechatId, user.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (count < 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setType(UserTypeEnum.SERVICE.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkName(waitUser.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkUserId(waitUser.getWorkerId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setPosition(waitUser.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkPhone(waitUser.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWebsitId(waitUser.getWebsitId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWebsitName(waitUser.getWebsitName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setCompanyName(currentCompanyWechat.getCompanyName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    waitUser.setUserId(user.getUserId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setIsBind(true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setUpdateTime(new Date()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return user; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 新增用户访问记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void addVisit(HttpServletRequest request, String userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            UserVisit userVisit = new UserVisit(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userVisit.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userVisit.setVisitTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userVisit.setCompanyWechatId(currentCompanyWechat.getCurrentCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userVisit.setCompanyName(currentCompanyWechat.getCurrentCompanyName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userVisit.insert(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.error("新增用户访问记录失败", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //手机号码授权 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public UserWxBean getWxMobile(String code, String userId, HttpServletRequest request) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserWxBean userWxBean = new UserWxBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = this.userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null == user) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("用户信息为空" + userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WxMaService maService = wechatLogic.getMaService(currentCompanyWechat.getCompanyWechatId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WxMaPhoneNumberInfo phoneNoInfo = maService.getUserService().getPhoneNoInfo(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String mobile = phoneNoInfo.getPhoneNumber(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isEmpty(mobile)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("手机号授权失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<UserServiceWait> waitList = userServiceWaitService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(UserServiceWait::getCompanyWechatId, currentCompanyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(UserServiceWait::getMobile, mobile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //根据手机号查询是否存在企业微信用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User workUser = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getMobile, mobile) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getStatus, true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(User::getCompanyWechatId, currentCompanyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .one(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (workUser == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //企业微信用户为空,则直接授权手机号。并根据手机号判断是否存在于微信成员表如果存在则为业务员 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.setMobile(mobile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (waitList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                UserServiceWait wait = waitList.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String workUserId = wait.getWorkerId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Long count = userService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getWorkUserId, workUserId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getType, UserTypeEnum.SERVICE.toString()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(User::getCompanyWechatId, currentCompanyWechat.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (count < 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setType(UserTypeEnum.SERVICE.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkName(wait.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkUserId(workUserId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkPhone(wait.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    user.setWorkQrcode(list.get(0).getQrCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setPosition(wait.getPosition()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWebsitId(wait.getWebsitId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWebsitName(wait.getWebsitName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    user.setWorkCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    wait.setUserId(user.getUserId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setIsBind(true) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .setUpdateTime(new Date()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String token = JwtUtils.generateToken(user.getUserId(), user.getOpenId(), user.getNickName(), null, Constant.MINIAPP_API); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BeanUtils.copyProperties(user, userWxBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setToken(token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //企业微信不为空,则将数据绑定到企业微信,并删除授权openid的用户数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            workUser.setOpenId(user.getOpenId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            workUser.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            user.deleteById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String token = JwtUtils.generateToken(user.getUserId(), user.getOpenId(), user.getNickName(), null, Constant.MINIAPP_API); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BeanUtils.copyProperties(workUser, userWxBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setToken(token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return userWxBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 个人信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public UserWxBean userDetail(String userId, HttpServletRequest request) throws RemoteServiceException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException(ResponseHelper.ResponseCode_AUTH_ERROR, "请求不合法"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserWxBean userWxBean = new UserWxBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BeanUtils.copyProperties(user, userWxBean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userWxBean.setShoppingCartNums(shoppingCartLogic.total(userWxBean.getUserId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotBlank(user.getServiceId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            final User serviceUser = userService.getById(user.getServiceId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ServiceWorkerBean bean = new ServiceWorkerBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotBlank(serviceUser.getWebsitId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bean.setWebsitId(Long.parseLong(serviceUser.getWebsitId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bean.setWebsit(serviceUser.getWebsitName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userWxBean.setServiceWorkerBean(bean); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return userWxBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //保存用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public User saveUserInfo(String userId, String nickName, String sex, String avatarUrl, String country, String province, String city) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = new User(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setNickName(nickName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setSex(sex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setAvatar(avatarUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setCountry(country); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setProvince(province); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.setCity(city); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        user.updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return user; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 我的收益 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public MyProfitBean myProfit(String userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        MyProfitBean myProfitBean = customMemberMapper.queryProfitSum(user.getWorkUserId(), user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (myProfitBean != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myProfitBean.setTotalAmount(myProfitBean.getPaidAmount().add(myProfitBean.getWaitingAmount())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myProfitBean = new MyProfitBean(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal zero = new BigDecimal("0.00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myProfitBean.setPaidAmount(zero); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myProfitBean.setWaitingAmount(zero); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            myProfitBean.setTotalAmount(zero); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return myProfitBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public IPage<OrderShare> myProfitList(String userId, String status, Integer pageNum, Integer pageSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return orderShareService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(OrderShare::getOpenId, user.getOpenId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .ne(OrderShare::getWorkUserId, "") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(StringUtils.isNotEmpty(status), OrderShare::getStatus, status) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(OrderShare::getCompanyWechatId, user.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .orderByDesc(OrderShare::getCreateTime) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .page(new Page<>(pageNum, pageSize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 总收益 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public BigDecimal totalProfit(String userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null || StringUtils.isEmpty(user.getWorkUserId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<OrderShare> list = orderShareService.lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(OrderShare::getOpenId, user.getOpenId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(OrderShare::getCompanyWechatId, user.getCompanyWechatId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .and(v -> v.like(OrderShare::getWorkUserId, user.getWorkUserId()).or().like(OrderShare::getWorkUserId, user.getUserId())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq(OrderShare::getStatus, OrderShareStatusEnum.OVER.toString()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .list(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (list.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new BigDecimal(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return list.stream().map(OrderShare::getAmount).reduce(BigDecimal::add).orElse(new BigDecimal(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 我的客户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public IPage<User> customerList(String userId, Integer pageNum, Integer pageSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        IPage<User> page = userService.lambdaQuery().eq(User::getServiceId, userId).page(new Page<>(pageNum, pageSize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 我的经理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public User parentUser(String userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = userService.getById(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotEmpty(user.getServiceId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            User parentUser = userService.getById(user.getServiceId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return parentUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public String renewal(String token) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final Object o = redisUtil.get(Constant.RedisPrefix.TOKEN_MP_WX + token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.isNull(o)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException(ResponseHelper.ResponseCode_AUTH_ERROR, "登录过期"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        User user = (User) o; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final User user1 = userService.getById(user.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String newToken = JwtUtils.refreshToken(token, Constant.MINIAPP_API); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //存放到redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisUtil.set(Constant.RedisPrefix.TOKEN_MP_WX + newToken, user1, 2 * 60 * 60 * 1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return newToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |