From 3a2708eaf348f09e523975e3a73605c06d31c539 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 02 Jan 2024 12:37:41 +0800
Subject: [PATCH] 修改推荐人

---
 src/main/resources/templates/febs/views/modules/mallMember/updateRefererId.html |   15 ++++++++-------
 src/main/java/cc/mrbird/febs/mall/controller/ViewMallMemberController.java      |    9 ++++++++-
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java  |    9 +++++++--
 src/main/resources/templates/febs/views/modules/mallMember/mallMemberList.html  |    3 ++-
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/controller/ViewMallMemberController.java b/src/main/java/cc/mrbird/febs/mall/controller/ViewMallMemberController.java
index 09bfe1a..7945eee 100644
--- a/src/main/java/cc/mrbird/febs/mall/controller/ViewMallMemberController.java
+++ b/src/main/java/cc/mrbird/febs/mall/controller/ViewMallMemberController.java
@@ -9,6 +9,7 @@
 import cc.mrbird.febs.mall.mapper.MallSalesmanMapper;
 import cc.mrbird.febs.mall.service.IAdminMallMemberService;
 import cc.mrbird.febs.mall.vo.*;
+import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.stereotype.Controller;
@@ -261,7 +262,13 @@
     @GetMapping("updateReferer/{id}")
     public String updateReferer(@PathVariable("id") Long id, Model model) {
         MallMember member = mallMemberService.getById(id);
-        model.addAttribute("referer", mallMemberService.findByInviteId(member.getReferrerId()));
+        MallMember byInviteId = null;
+        byInviteId = mallMemberService.findByInviteId(member.getReferrerId());
+        if(ObjectUtil.isEmpty(byInviteId)){
+            byInviteId = new MallMember();
+            byInviteId.setName("无推荐人");
+        }
+        model.addAttribute("referer", byInviteId);
         model.addAttribute("id", id);
         return FebsUtil.view("modules/mallMember/updateRefererId");
     }
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
index fb05383..c0f98ad 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
@@ -702,11 +702,16 @@
         if (referer == null) {
             throw new FebsException("推荐人不存在");
         }
-        String refererId = member.getReferrerId();//新推荐人的邀请码
+        String refererId = referer.getInviteId();//新推荐人的邀请码
 
         member = this.baseMapper.selectById(member.getId());//修改的用户
+        if(StrUtil.isNotEmpty(referer.getReferrerIds())){
+            if (referer.getReferrerIds().contains(member.getInviteId())) {
+                throw new FebsException("修改的推荐关系不符合规则");
+            }
+        }
 
-        String beforeReferer = member.getReferrerId();
+//        String beforeReferer = member.getReferrerId();
         member.setReferrerId(refererId);//更新用户的上级推荐人为新推荐人的邀请码refererId
         String refererIds = refererIds(refererId);
         member.setReferrerIds(refererIds);
diff --git a/src/main/resources/templates/febs/views/modules/mallMember/mallMemberList.html b/src/main/resources/templates/febs/views/modules/mallMember/mallMemberList.html
index 53803d4..21bbc81 100644
--- a/src/main/resources/templates/febs/views/modules/mallMember/mallMemberList.html
+++ b/src/main/resources/templates/febs/views/modules/mallMember/mallMemberList.html
@@ -363,8 +363,9 @@
             if (layEvent == 'updateReferer') {
                 if (checkData.length > 1) {
                     febs.alert.warn('每次只能修改一个用户');
+                    return;
                 }
-                febs.modal.open( '修改推荐人', 'modules/mallMember/updateReferer/' + data.id, {
+                febs.modal.open( '修改推荐人', 'modules/mallMember/updateReferer/' + checkData[0].id, {
                     btn: ['提交', '取消'],
                     yes: function (index, layero) {
                         $('#referer-update').find('#submit').trigger('click');
diff --git a/src/main/resources/templates/febs/views/modules/mallMember/updateRefererId.html b/src/main/resources/templates/febs/views/modules/mallMember/updateRefererId.html
index b656380..5e4b98e 100644
--- a/src/main/resources/templates/febs/views/modules/mallMember/updateRefererId.html
+++ b/src/main/resources/templates/febs/views/modules/mallMember/updateRefererId.html
@@ -34,16 +34,17 @@
                 <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input" readonly>
             </div>
         </div>
+<!--        <div class="layui-form-item">-->
+<!--            <label class="layui-form-label febs-form-item-require">推荐人ID:</label>-->
+<!--            <div class="layui-input-block">-->
+<!--                <input type="text" name="inviteId" lay-verify="required" autocomplete="off" class="layui-input" readonly>-->
+<!--            </div>-->
+<!--        </div>-->
         <div class="layui-form-item">
-            <label class="layui-form-label febs-form-item-require">推荐人ID:</label>
-            <div class="layui-input-block">
-                <input type="text" name="inviteId" lay-verify="required" autocomplete="off" class="layui-input" readonly>
-            </div>
-        </div>
-        <div class="layui-form-item">
-            <label class="layui-form-label febs-form-item-require">修改推荐人ID:</label>
+            <label class="layui-form-label febs-form-item-require">修改为:</label>
             <div class="layui-input-block">
                 <input type="text" name="referrerId" lay-verify="required" autocomplete="off" class="layui-input">
+                <div class="layui-form-mid layui-word-aux">填写用户的邀请码(会员列表中的邀请码)</div>
             </div>
         </div>
         <div class="layui-form-item febs-hide">

--
Gitblit v1.9.1