From f0acb97e91f456c9b402977416e73951b708a157 Mon Sep 17 00:00:00 2001
From: jiangqs <343695869@qq.com>
Date: 星期一, 19 六月 2023 23:23:23 +0800
Subject: [PATCH] 营销统计

---
 ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/member/MemberServiceImpl.java |  287 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 237 insertions(+), 50 deletions(-)

diff --git a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/member/MemberServiceImpl.java b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/member/MemberServiceImpl.java
index f794ba1..15affd3 100644
--- a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/member/MemberServiceImpl.java
+++ b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/member/MemberServiceImpl.java
@@ -1,21 +1,19 @@
 package com.ruoyi.member.service.impl.member;
-import com.google.common.collect.Lists;
-import java.util.Date;
 
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.DateUtils;
+import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
 import com.ruoyi.common.core.utils.uuid.IdUtils;
 import com.ruoyi.common.redis.service.RedisService;
+import com.ruoyi.common.security.utils.CodeFactoryUtil;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.member.domain.dto.*;
 import com.ruoyi.member.domain.pojo.member.IntegralRecord;
@@ -24,34 +22,26 @@
 import com.ruoyi.member.domain.vo.*;
 import com.ruoyi.member.mapper.member.MemberMapper;
 import com.ruoyi.member.service.member.*;
-import com.ruoyi.member.util.CodeFactoryUtil;
 import com.ruoyi.member.util.HttpUtils;
-import com.ruoyi.system.api.domain.dto.AppMiniRegisterDto;
-import com.ruoyi.system.api.domain.poji.config.Activeness;
-import com.ruoyi.system.api.domain.vo.AppMiniRegisterVo;
-import com.ruoyi.system.api.service.RemoteConfigService;
-import com.ruoyi.system.api.service.RemoteOrderService;
-import com.ruoyi.system.api.service.RemoteShopService;
-import com.ruoyi.system.api.service.RemoteUserService;
 import com.ruoyi.system.api.constant.AppErrorConstant;
 import com.ruoyi.system.api.constant.SecurityConstant;
-import com.ruoyi.system.api.domain.dto.AppEditUserDto;
-import com.ruoyi.system.api.domain.dto.AppMemberBindingDto;
-import com.ruoyi.system.api.domain.dto.AppMemberGoodsTypeDto;
+import com.ruoyi.system.api.domain.dto.*;
+import com.ruoyi.system.api.domain.poji.config.Activeness;
 import com.ruoyi.system.api.domain.poji.config.SysTag;
 import com.ruoyi.system.api.domain.poji.member.Member;
 import com.ruoyi.system.api.domain.poji.shop.Shop;
 import com.ruoyi.system.api.domain.poji.sys.SysUser;
-import com.ruoyi.system.api.domain.vo.AppOrderTotalVo;
+import com.ruoyi.system.api.domain.vo.*;
 import com.ruoyi.system.api.model.AppMiniLoginDto;
 import com.ruoyi.system.api.model.AppMiniLoginVo;
-import io.swagger.models.auth.In;
+import com.ruoyi.system.api.service.RemoteConfigService;
+import com.ruoyi.system.api.service.RemoteOrderService;
+import com.ruoyi.system.api.service.RemoteShopService;
+import com.ruoyi.system.api.service.RemoteUserService;
 import lombok.extern.log4j.Log4j2;
-import com.ruoyi.common.core.utils.StringUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.util.EntityUtils;
-import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -112,6 +102,7 @@
     @Resource
     private MemberArchiveService memberArchiveService;
 
+    
 
     /**
      * @description: TODO
@@ -651,7 +642,7 @@
      * @return
      */
     private String createMemberNo(){
-        int memberTotal = memberMapper.selectCount(new LambdaQueryWrapper<Member>().eq(Member::getDelFlag, 0));
+        int memberTotal = memberMapper.selectCount(new LambdaQueryWrapper<Member>());
         String memberNo = CodeFactoryUtil.getMemberNo(Long.valueOf(memberTotal+1));
         return memberNo;
     }
@@ -667,14 +658,20 @@
     public List<MgtMemberPageVo> pageMgtMember(Page page,MgtMemberPageDto merMemberPageDto){
         List<Activeness> activenessList = remoteConfigService.listActiveness().getData();
         Date nowDay = new Date();
-        //处理活跃度筛选
-        activenessList.stream()
-                .filter(activeness -> activeness.getActivenessId().equals(merMemberPageDto.getActivenessId()))
-                .findFirst()
-                .ifPresent(activeness -> {
-                    merMemberPageDto.setActStartDate(DateUtils.addDays(nowDay, activeness.getEndDay()));
-                    merMemberPageDto.setActEndDate(DateUtils.addDays(nowDay, activeness.getStartDay()));
-                });
+        if(merMemberPageDto.getActivenessId()!=null){
+            //处理活跃度筛选
+            activenessList.stream()
+                    .filter(activeness -> activeness.getActivenessId().equals(merMemberPageDto.getActivenessId()))
+                    .findFirst()
+                    .ifPresent(activeness -> {
+                        merMemberPageDto.setActStartDate(DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.addDays(nowDay, activeness.getEndDay())));
+                        merMemberPageDto.setActEndDate(DateUtils.parseDateToStr("yyyy-MM-dd",DateUtils.addDays(nowDay, activeness.getStartDay())));
+                    });
+        }
+        //处理标签为正则表达
+        if(StringUtils.isNotBlank(merMemberPageDto.getMemberTags())){
+            merMemberPageDto.setMemberTags(merMemberPageDto.getMemberTags().replace(",","|"));
+        }
         //查询获取结果列表
         List<MgtMemberPageVo> memberPageVoList = memberMapper.pageMgtMember(page, merMemberPageDto);
         //处理活跃度返回
@@ -717,14 +714,20 @@
      */
     @Override
     public void editMemberRelationShop(MgtMemberRelEditDto mgtMemberRelEditDto){
-        Member member = this.getByUserId(mgtMemberRelEditDto.getMemberUserId());
-        Shop shop = shopService.getShop(mgtMemberRelEditDto.getShopId()).getData();
-        member.setRelationShopId(shop.getShopId());
-        member.setRelationShopName(shop.getShopName());
-        member.setBindingFlag(1);
-        member.setUpdateTime(new Date());
-        member.setUpdateUserId(mgtMemberRelEditDto.getUserId());
-        this.saveOrUpdate(member);
+        if(StringUtils.isNotBlank(mgtMemberRelEditDto.getMemberUserIds())){
+            Shop shop = shopService.getShop(mgtMemberRelEditDto.getShopId()).getData();
+            String memberUserIds = mgtMemberRelEditDto.getMemberUserIds();
+            String[] memberUserIdArr = memberUserIds.split(",");
+            for(String str : memberUserIdArr){
+                Member member = this.getByUserId(Long.valueOf(str));
+                member.setRelationShopId(shop.getShopId());
+                member.setRelationShopName(shop.getShopName());
+                member.setBindingFlag(1);
+                member.setUpdateTime(new Date());
+                member.setUpdateUserId(mgtMemberRelEditDto.getUserId());
+                this.saveOrUpdate(member);
+            }
+        }
     }
 
 
@@ -734,11 +737,17 @@
      */
     @Override
     public void deleteMemberRelationShop(MgtMemberRelDelDto mgtMemberRelDelDto){
-        Member member = this.getById(mgtMemberRelDelDto.getMemberUserId());
-        member.setBindingFlag(0);
-        member.setUpdateTime(new Date());
-        member.setUpdateUserId(mgtMemberRelDelDto.getUserId());
-        this.saveOrUpdate(member);
+        if(StringUtils.isNotBlank(mgtMemberRelDelDto.getMemberUserIds())) {
+            String memberUserIds = mgtMemberRelDelDto.getMemberUserIds();
+            String[] memberUserIdArr = memberUserIds.split(",");
+            for(String str : memberUserIdArr) {
+                Member member = this.getByUserId(Long.valueOf(str));
+                member.setBindingFlag(0);
+                member.setUpdateTime(new Date());
+                member.setUpdateUserId(mgtMemberRelDelDto.getUserId());
+                this.saveOrUpdate(member);
+            }
+        }
     }
 
     /**
@@ -747,15 +756,22 @@
      */
     @Override
     public void editMemberIntegral(MgtMemberIntEditDto mgtMemberIntEditDto){
-        MemberIntegralChangeDto memberIntegralChangeDto = new MemberIntegralChangeDto();
-        Member member = this.getByUserId(mgtMemberIntEditDto.getMemberUserId());
-        memberIntegralChangeDto.setUserId(mgtMemberIntEditDto.getMemberUserId());
-        memberIntegralChangeDto.setMemberId(member.getMemberId());
-        memberIntegralChangeDto.setChangeType(1);
-        memberIntegralChangeDto.setRecordType(3);
-        memberIntegralChangeDto.setIntegral(mgtMemberIntEditDto.getIntegral());
-        //调用积分变动
-        memberIntegralChange(memberIntegralChangeDto);
+        if(StringUtils.isNotBlank(mgtMemberIntEditDto.getMemberUserIds())) {
+            String memberUserIds = mgtMemberIntEditDto.getMemberUserIds();
+            String[] memberUserIdArr = memberUserIds.split(",");
+            MemberIntegralChangeDto memberIntegralChangeDto;
+            for(String str : memberUserIdArr) {
+                memberIntegralChangeDto = new MemberIntegralChangeDto();
+                Member member = this.getByUserId(Long.valueOf(str));
+                memberIntegralChangeDto.setUserId(Long.valueOf(str));
+                memberIntegralChangeDto.setMemberId(member.getMemberId());
+                memberIntegralChangeDto.setChangeType(1);
+                memberIntegralChangeDto.setRecordType(3);
+                memberIntegralChangeDto.setIntegral(mgtMemberIntEditDto.getIntegral());
+                //调用积分变动
+                memberIntegralChange(memberIntegralChangeDto);
+            }
+        }
     }
 
 
@@ -857,4 +873,175 @@
         mgtMemberGetVo.setMemberTags(member.getUserTags());
         return mgtMemberGetVo;
     }
+
+    /**
+     * @description  删除标签
+     * @author  jqs
+     * @date    2023/6/8 15:18
+     * @param memberTag
+     * @return  void
+     */
+    @Override
+    public void deleteMemberTag(String memberTag){
+        memberMapper.deleteMemberTag(memberTag);
+    }
+
+    /**
+     * @description  通过发送类型获取userId
+     * @author  jqs
+     * @date    2023/6/13 17:53
+     * @param sendType
+     * @return  List<Long>
+     */
+    @Override
+    public List<Long> listIdBySendType(Integer sendType){
+        //1.手动领取2.全部用户3.会员用户4非会员用户5自定义
+        return memberMapper.listIdBySendType(sendType);
+    }
+
+    /**
+     * @description  通过ids获取用户简易返回
+     * @author  jqs
+     * @date    2023/6/16 11:06
+     * @param userIds
+     * @return  List<MgtSimpleMemberVo>
+     */
+    @Override
+    public List<MgtSimpleMemberVo> listSimpleVoByIds(String userIds){
+        return memberMapper.listSimpleVoByIds(userIds);
+    }
+
+    /**
+     * @description
+     * @author  jqs
+     * @date    2023/6/16 12:41
+     * @param mgtUserIdByKeywordDto
+     * @return  MgtUserIdByKeywordVo
+     */
+    @Override
+    public MgtUserIdByKeywordVo getUserIdByKeyword(MgtUserIdByKeywordDto mgtUserIdByKeywordDto){
+        MgtUserIdByKeywordVo mgtUserIdByKeywordVo = new MgtUserIdByKeywordVo();
+        List<Long> userIdList = memberMapper.getUserIdByKeyword(mgtUserIdByKeywordDto);
+        if(userIdList!=null&&!userIdList.isEmpty()){
+            String userIdStr = userIdList.stream()
+                    .map(Object::toString)
+                    .collect(Collectors.joining(","));
+            mgtUserIdByKeywordVo.setUserIds(userIdStr);
+        }
+        return mgtUserIdByKeywordVo;
+    }
+
+    /**
+     * @description boardMemberTotal
+     * @param
+     * @return MgtBulletinBoardVo
+     * @author jqs34
+     * @date 2023/6/18 16:45
+     */
+    @Override
+    public MgtBulletinBoardVo boardMemberTotal(){
+        MgtBulletinBoardVo mgtBulletinBoardVo = new MgtBulletinBoardVo();
+        mgtBulletinBoardVo.setMemberTotal(memberMapper.memberTotal());
+        mgtBulletinBoardVo.setMemberToday(memberMapper.memberToday());
+        return mgtBulletinBoardVo;
+    }
+
+    /**
+     * @description  会员人数统计
+     * @author  jqs
+     * @date    2023/6/19 15:26
+     * @param
+     * @return  MgtTotalMemberTotalVo
+     */
+    @Override
+    public MgtTotalMemberTotalVo getTotalMemberTotal(MgtBaseShopDto mgtBaseShopDto){
+        Date nowDay = DateUtils.getNowDate();
+        // 获取店铺ID
+        Long shopId = mgtBaseShopDto.getShopId();
+        // 获取总会员数和不同年龄段的会员数
+        MgtTotalMemberTotalVo mgtTotalMemberTotalVo = memberMapper.getTotalMemberTotal(mgtBaseShopDto);
+        MgtAgeTotalVo mgtAgeTotalVo = memberMapper.getTotalMemberTotalAge(mgtBaseShopDto);
+        // 年龄段数组
+        String[] ageKey = {"<20", "21-30", "31-40", "41-50", ">50"};
+        // 不同年龄段的会员数数组
+        Integer[] ageValue = {mgtAgeTotalVo.getTenAge(), mgtAgeTotalVo.getTwentyAge(), mgtAgeTotalVo.getThirtyAge(), mgtAgeTotalVo.getFortyAge(), mgtAgeTotalVo.getFiftyAge()};
+        // 设置年龄段数组和不同年龄段的会员数数组
+        mgtTotalMemberTotalVo.setAgeKey(ageKey);
+        mgtTotalMemberTotalVo.setAgeValue(ageValue);
+        // 获取不同护理类型的会员数
+        List<MgtMapTotalVo> nurseTotalVos = memberMapper.getTotalMemberTotalNurse(mgtBaseShopDto);
+        if (nurseTotalVos != null && nurseTotalVos.size() > 0) {
+            String[] nurseKey = new String[nurseTotalVos.size()];
+            Integer[] nurseValue = new Integer[nurseTotalVos.size()];
+            // 遍历不同护理类型的会员数列表,设置护理类型数组和对应的会员数数组
+            for (int i = 0; i < nurseTotalVos.size(); i++) {
+                nurseKey[i] = nurseTotalVos.get(i).getMapKey();
+                nurseValue[i] = nurseTotalVos.get(i).getMapValue();
+            }
+            mgtTotalMemberTotalVo.setNurseKey(nurseKey);
+            mgtTotalMemberTotalVo.setNurseValue(nurseValue);
+        }
+        // 获取不同商品类型的会员数
+        List<MgtMapTotalVo> goodsTypeTotalVos = memberMapper.getTotalMemberTotalGoodsType(mgtBaseShopDto);
+        if (goodsTypeTotalVos != null && goodsTypeTotalVos.size() > 0) {
+            String[] goodsTypeKey = new String[goodsTypeTotalVos.size()];
+            Integer[] goodsTypeValue = new Integer[goodsTypeTotalVos.size()];
+            // 遍历不同商品类型的会员数列表,设置商品类型数组和对应的会员数数组
+            for (int i = 0; i < goodsTypeTotalVos.size(); i++) {
+                goodsTypeKey[i] = goodsTypeTotalVos.get(i).getMapKey();
+                goodsTypeValue[i] = goodsTypeTotalVos.get(i).getMapValue();
+            }
+            mgtTotalMemberTotalVo.setGoodsTypeKey(goodsTypeKey);
+            mgtTotalMemberTotalVo.setGoodsTypeValue(goodsTypeValue);
+        }
+        // 获取不同活跃度的会员数
+        List<Activeness> activenessList = remoteConfigService.listActiveness().getData();
+        if (activenessList != null && !activenessList.isEmpty()) {
+            String[] activenessKey = new String[activenessList.size()];
+            Integer[] activenessValue = new Integer[activenessList.size()];
+            Activeness activeness;
+            String actStartDate;
+            String actEndDate;
+            Integer count;
+            // 遍历不同活跃度列表,设置活跃度数组和对应的会员数数组
+            for (int i = 0; i < activenessList.size(); i++) {
+                activeness = activenessList.get(i);
+                actStartDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(nowDay, activeness.getEndDay()));
+                actEndDate = DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(nowDay, activeness.getStartDay()));
+                count = memberMapper.getTotalMemberTotalActiveness(shopId, actStartDate, actEndDate);
+                activenessKey[i] = activeness.getActivenessName();
+                activenessValue[i] = count;
+            }
+            mgtTotalMemberTotalVo.setActivenessKey(activenessKey);
+            mgtTotalMemberTotalVo.setActivenessValue(activenessValue);
+        }
+        //获取会员消费排名
+        List<MgtMapTotalVo> memberPayList = memberMapper.getTotalMemberRankPay(mgtBaseShopDto);
+        if (memberPayList != null && memberPayList.size() > 0) {
+            String[] memberPayKey = new String[memberPayList.size()];
+            Integer[] memberPayValue = new Integer[memberPayList.size()];
+            // 遍历不同商品类型的会员数列表,设置商品类型数组和对应的会员数数组
+            for (int i = 0; i < memberPayList.size(); i++) {
+                memberPayKey[i] = memberPayList.get(i).getMapKey();
+                memberPayValue[i] = memberPayList.get(i).getMapValue();
+            }
+            mgtTotalMemberTotalVo.setOrderRankKey(memberPayKey);
+            mgtTotalMemberTotalVo.setOrderRankValue(memberPayValue);
+        }
+        //获取来源渠道排名
+        List<MgtMapTotalVo> customerSourceList = memberMapper.getTotalMemberRankCustomerSource(mgtBaseShopDto);
+        if (customerSourceList != null && customerSourceList.size() > 0) {
+            String[] customerSourceKey = new String[customerSourceList.size()];
+            Integer[] customerSourceValue = new Integer[customerSourceList.size()];
+            // 遍历不同商品类型的会员数列表,设置商品类型数组和对应的会员数数组
+            for (int i = 0; i < customerSourceList.size(); i++) {
+                customerSourceKey[i] = customerSourceList.get(i).getMapKey();
+                customerSourceValue[i] = customerSourceList.get(i).getMapValue();
+            }
+            mgtTotalMemberTotalVo.setCustomerSourceKey(customerSourceKey);
+            mgtTotalMemberTotalVo.setCustomerSourceValue(customerSourceValue);
+        }
+        // 返回总会员数和不同类型会员数的统计结果
+        return mgtTotalMemberTotalVo;
+    }
 }

--
Gitblit v1.7.1