From 0169b3c71efc064577a45c5058d458c9ef1cb94a Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 15 Jun 2020 16:36:37 +0800
Subject: [PATCH] modify

---
 src/main/resources/templates/febs/views/modules/agent/agent.html                   |    6 
 src/main/java/com/xcong/excoin/system/mapper/UserMapper.java                       |    2 
 src/main/java/com/xcong/excoin/modules/agent/service/IAgentService.java            |    2 
 src/main/java/com/xcong/excoin/modules/agent/controller/ViewController.java        |   17 ++++
 src/main/resources/mapper/modules/AgentFriendRelationMapper.xml                    |    6 +
 src/main/java/com/xcong/excoin/modules/agent/mapper/AgentFriendRelationMapper.java |    2 
 src/main/java/com/xcong/excoin/system/entity/User.java                             |    3 
 src/main/java/com/xcong/excoin/modules/agent/service/impl/AgentServiceImpl.java    |   25 ++++++
 src/main/resources/mapper/modules/MemberMapper.xml                                 |    7 +
 src/main/java/com/xcong/excoin/modules/agent/controller/MemberController.java      |    4 +
 src/main/java/com/xcong/excoin/system/service/impl/UserServiceImpl.java            |    5 +
 src/main/java/com/xcong/excoin/system/service/IUserService.java                    |    2 
 src/main/resources/templates/febs/views/modules/agent/agentEdit.html               |  100 +++++++++++++++++++++++++
 src/main/resources/mapper/system/UserMapper.xml                                    |   16 +++
 src/main/resources/templates/febs/views/modules/agent/member.html                  |    3 
 src/main/java/com/xcong/excoin/modules/agent/controller/AgentController.java       |    9 ++
 16 files changed, 199 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/agent/controller/AgentController.java b/src/main/java/com/xcong/excoin/modules/agent/controller/AgentController.java
index 62d1c14..375f44d 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/controller/AgentController.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/controller/AgentController.java
@@ -66,4 +66,13 @@
         agentService.resetPwd(id);
         return new FebsResponse().success();
     }
+
+    @PostMapping("edit")
+    @RequiresPermissions("agent:edit")
+    @ControllerEndpoint(operation = "修改代理商", exceptionMessage = "修改代理商失败")
+    public FebsResponse edit(@Valid AgentUser agentUser) {
+        User user = getCurrentUser();
+        agentService.editAgent(agentUser, user);
+        return new FebsResponse().success();
+    }
 }
diff --git a/src/main/java/com/xcong/excoin/modules/agent/controller/MemberController.java b/src/main/java/com/xcong/excoin/modules/agent/controller/MemberController.java
index 70a3d5f..978b2d1 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/controller/MemberController.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/controller/MemberController.java
@@ -1,10 +1,12 @@
 package com.xcong.excoin.modules.agent.controller;
 
 import com.xcong.excoin.common.controller.BaseController;
+import com.xcong.excoin.common.entity.FebsConstant;
 import com.xcong.excoin.common.entity.FebsResponse;
 import com.xcong.excoin.common.entity.QueryRequest;
 import com.xcong.excoin.modules.agent.entity.MemberEntity;
 import com.xcong.excoin.modules.agent.service.IMemberService;
+import com.xcong.excoin.system.entity.User;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.validation.annotation.Validated;
@@ -29,6 +31,8 @@
 
     @GetMapping("getList")
     public FebsResponse getList(MemberEntity member, QueryRequest request) {
+        User user = getCurrentUser();
+        member.setInviteId(FebsConstant.USER_TYPE_ADMIN.equals(user.getType()) ? FebsConstant.DEFAULT_REFERER_ID : user.getInviteId());
         Map<String, Object> data = getDataTable(memberService.findMemberListInPage(member, request));
         return new FebsResponse().success().data(data);
     }
diff --git a/src/main/java/com/xcong/excoin/modules/agent/controller/ViewController.java b/src/main/java/com/xcong/excoin/modules/agent/controller/ViewController.java
index 57a68ed..74b18b8 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/controller/ViewController.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/controller/ViewController.java
@@ -2,9 +2,14 @@
 
 import com.xcong.excoin.common.entity.FebsConstant;
 import com.xcong.excoin.common.utils.FebsUtil;
+import com.xcong.excoin.system.entity.User;
+import com.xcong.excoin.system.service.IUserService;
+import lombok.RequiredArgsConstructor;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 /**
@@ -13,14 +18,16 @@
  **/
 @Controller("memberView")
 @RequestMapping(FebsConstant.VIEW_PREFIX + "/agent")
+@RequiredArgsConstructor
 public class ViewController {
+
+    private final IUserService userService;
 
     @GetMapping("member")
     @RequiresPermissions("amember:view")
     public String member() {
         return FebsUtil.view("modules/agent/member");
     }
-
 
     @GetMapping("agent")
     @RequiresPermissions("agent:view")
@@ -33,4 +40,12 @@
     public String agentAdd() {
         return FebsUtil.view("modules/agent/agentAdd");
     }
+
+    @GetMapping("agentEdit/{id}")
+    @RequiresPermissions("agent:edit")
+    public String agentEdit(@PathVariable Long id, Model model) {
+        User user = userService.findUserInfoById(id);
+        model.addAttribute("user", user);
+        return FebsUtil.view("modules/agent/agentEdit");
+    }
 }
diff --git a/src/main/java/com/xcong/excoin/modules/agent/mapper/AgentFriendRelationMapper.java b/src/main/java/com/xcong/excoin/modules/agent/mapper/AgentFriendRelationMapper.java
index 6e2bb7c..79604e8 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/mapper/AgentFriendRelationMapper.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/mapper/AgentFriendRelationMapper.java
@@ -11,4 +11,6 @@
 public interface AgentFriendRelationMapper extends BaseMapper<AgentFriendRelationEntity> {
 
     AgentFriendRelationEntity selectAgentFriendRelationByUserId(@Param("userId") Long userId);
+
+    int updateByUserId(@Param("record") AgentFriendRelationEntity agentFriendRelationEntity);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/agent/service/IAgentService.java b/src/main/java/com/xcong/excoin/modules/agent/service/IAgentService.java
index 0e92366..f3974e8 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/service/IAgentService.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/service/IAgentService.java
@@ -17,4 +17,6 @@
     void delAgent(String[] ids);
 
     void resetPwd(Long id);
+
+    void editAgent(AgentUser agentUser, User user);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/agent/service/impl/AgentServiceImpl.java b/src/main/java/com/xcong/excoin/modules/agent/service/impl/AgentServiceImpl.java
index 7dfc27a..bc8fccd 100644
--- a/src/main/java/com/xcong/excoin/modules/agent/service/impl/AgentServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/agent/service/impl/AgentServiceImpl.java
@@ -21,6 +21,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import sun.management.Agent;
 
 import java.util.Arrays;
 import java.util.Date;
@@ -85,6 +86,7 @@
         addUser.setType(FebsConstant.USER_TYPE_AGENT);
         addUser.setSystem(FebsConstant.SYSTEM_AGENT);
         addUser.setCreateTime(new Date());
+        addUser.setMobile(agentUser.getTelphone());
         addUser.setInviteId(agentUser.getInviteId());
         addUser.setAgentName(agentUser.getName());
         addUser.setPassword(Md5Util.encrypt(addUser.getUsername(), User.DEFAULT_PASSWORD));
@@ -110,6 +112,7 @@
         agentFriendRelationMapper.insert(agentFriendRelation);
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public void delAgent(String[] ids) {
         List<String> list = Arrays.asList(ids);
@@ -124,4 +127,26 @@
         user.setPassword(Md5Util.encrypt(user.getUsername(), User.DEFAULT_PASSWORD));
         userMapper.updateById(user);
     }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void editAgent(AgentUser agentUser, User user) {
+        if (!FebsConstant.USER_TYPE_ADMIN.equals(user.getType())) {
+            AgentFriendRelationEntity friendRelationEntity = agentFriendRelationMapper.selectAgentFriendRelationByUserId(user.getUserId());
+            if (agentUser.getReturnRatio().compareTo(friendRelationEntity.getReturnRatio()) > 0) {
+                throw new FebsException("返佣比例需小于上级的返佣比例");
+            }
+        }
+
+        User editUser = new User();
+        editUser.setUserId(agentUser.getId());
+        editUser.setMobile(agentUser.getTelphone());
+        editUser.setAgentName(agentUser.getName());
+        userMapper.updateById(editUser);
+
+        AgentFriendRelationEntity relationEntity = new AgentFriendRelationEntity();
+        relationEntity.setUserId(agentUser.getId());
+        relationEntity.setReturnRatio(agentUser.getReturnRatio());
+        agentFriendRelationMapper.updateByUserId(relationEntity);
+    }
 }
diff --git a/src/main/java/com/xcong/excoin/system/entity/User.java b/src/main/java/com/xcong/excoin/system/entity/User.java
index c68b9ec..52b4764 100644
--- a/src/main/java/com/xcong/excoin/system/entity/User.java
+++ b/src/main/java/com/xcong/excoin/system/entity/User.java
@@ -17,6 +17,7 @@
 import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.Size;
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -220,6 +221,8 @@
     @TableField(exist = false)
     private String deptIds;
 
+    private BigDecimal returnRatio;
+
     public Long getId() {
         return userId;
     }
diff --git a/src/main/java/com/xcong/excoin/system/mapper/UserMapper.java b/src/main/java/com/xcong/excoin/system/mapper/UserMapper.java
index 0fb90e2..f0b1148 100644
--- a/src/main/java/com/xcong/excoin/system/mapper/UserMapper.java
+++ b/src/main/java/com/xcong/excoin/system/mapper/UserMapper.java
@@ -53,4 +53,6 @@
 
     User selectUserByInviteId(@Param("inviteId") String inviteId);
 
+    User selectUserInfoById(@Param("id") Long id);
+
 }
diff --git a/src/main/java/com/xcong/excoin/system/service/IUserService.java b/src/main/java/com/xcong/excoin/system/service/IUserService.java
index fdd72e0..69cc06c 100644
--- a/src/main/java/com/xcong/excoin/system/service/IUserService.java
+++ b/src/main/java/com/xcong/excoin/system/service/IUserService.java
@@ -112,4 +112,6 @@
      * @param user 个人信息
      */
     void updateProfile(User user);
+
+    User findUserInfoById(Long id);
 }
diff --git a/src/main/java/com/xcong/excoin/system/service/impl/UserServiceImpl.java b/src/main/java/com/xcong/excoin/system/service/impl/UserServiceImpl.java
index 991bd97..38fc55c 100644
--- a/src/main/java/com/xcong/excoin/system/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/system/service/impl/UserServiceImpl.java
@@ -236,4 +236,9 @@
         User currentUser = FebsUtil.getCurrentUser();
         return currentUser.getUserId().equals(id);
     }
+
+    @Override
+    public User findUserInfoById(Long id) {
+        return this.baseMapper.selectUserInfoById(id);
+    }
 }
diff --git a/src/main/resources/mapper/modules/AgentFriendRelationMapper.xml b/src/main/resources/mapper/modules/AgentFriendRelationMapper.xml
index 68a1891..ff2b985 100644
--- a/src/main/resources/mapper/modules/AgentFriendRelationMapper.xml
+++ b/src/main/resources/mapper/modules/AgentFriendRelationMapper.xml
@@ -6,4 +6,10 @@
         select * from agent_friend_relation
         where user_id=#{userId}
     </select>
+
+    <update id="updateByUserId">
+        update agent_friend_relation
+        set return_ratio = #{record.returnRatio}
+        where user_id=#{record.userId}
+    </update>
 </mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/modules/MemberMapper.xml b/src/main/resources/mapper/modules/MemberMapper.xml
index 99a3e52..0c74203 100644
--- a/src/main/resources/mapper/modules/MemberMapper.xml
+++ b/src/main/resources/mapper/modules/MemberMapper.xml
@@ -6,7 +6,10 @@
     <select id="selectMemberListInPage" resultType="com.xcong.excoin.modules.agent.entity.MemberEntity">
         select * from member
         <where>
-            <if test="record != null" >
+            <if test="record != null">
+                <if test="record.inviteId !=null and record.inviteId!=''">
+                    and find_in_set(#{record.inviteId}, referer_ids)
+                </if>
                 <if test="record.startTime!=null">
                     and create_time >=#{record.startTime}
                 </if>
@@ -19,7 +22,7 @@
                 <if test="record.accountStatus!=null">
                     and account_status = #{record.accountStatus}
                 </if>
-                <if test="record.accountType != null" >
+                <if test="record.accountType != null">
                     and account_type = #{record.accountType}
                 </if>
                 <if test="record.certifyStatus != null">
diff --git a/src/main/resources/mapper/system/UserMapper.xml b/src/main/resources/mapper/system/UserMapper.xml
index 96e72c1..7c0c290 100644
--- a/src/main/resources/mapper/system/UserMapper.xml
+++ b/src/main/resources/mapper/system/UserMapper.xml
@@ -175,8 +175,7 @@
             a.create_time,
             a.status,
             b.return_ratio,
-            c.phone telphone,
-            c.email,
+            a.mobile telphone,
             c.referer_id refererId,
             c.certify_status
         from t_user a
@@ -194,4 +193,17 @@
     <select id="selectUserByInviteId" resultType="user">
         select * from t_user where invite_id=#{inviteId}
     </select>
+
+    <select id="selectUserInfoById" resultType="user">
+        select
+            a.user_id,
+            a.agent_name,
+            a.username,
+            a.mobile,
+            a.invite_id,
+            b.return_ratio
+        from t_user a
+        left join agent_friend_relation b on a.user_id=b.user_id
+        where a.user_id=#{id}
+    </select>
 </mapper>
diff --git a/src/main/resources/templates/febs/views/modules/agent/agent.html b/src/main/resources/templates/febs/views/modules/agent/agent.html
index ab44fdd..32f3d9d 100644
--- a/src/main/resources/templates/febs/views/modules/agent/agent.html
+++ b/src/main/resources/templates/febs/views/modules/agent/agent.html
@@ -209,7 +209,7 @@
                 });
             }
             if (layEvent === 'edit') {
-                febs.modal.open('修改用户', 'system/user/update/' + data.username, {
+                febs.modal.open('修改用户', '/agent/agentEdit/' + data.id, {
                     area: $(window).width() <= 750 ? '90%' : '50%',
                     offset: '30px',
                     btn: ['提交', '取消'],
@@ -248,8 +248,8 @@
                     {field: 'name', title: '代理姓名', minWidth: 100, align: 'center'},
                     {field: 'account', title: '代理账号', minWidth: 100, align: 'center'},
                     {field: 'inviteId', title: '代理UID', minWidth: 100, align: 'center'},
-                    {field: 'phone', title: '手机号', minWidth: 130, align: 'center'},
-                    {field: 'email', title: '邮箱', minWidth: 180, align: 'center'},
+                    {field: 'phone', title: '联系方式', minWidth: 130, align: 'center'},
+                    // {field: 'email', title: '邮箱', minWidth: 180, align: 'center'},
                     {field: 'refererId', title: '上级UID', minWidth: 100, align: 'center'},
                     {title: '是否实名', templet: '#certify-status', minWidth: 100, align: 'center'},
                     {field: 'childCnt', title: '发展代理数', minWidth: 100, align: 'center'},
diff --git a/src/main/resources/templates/febs/views/modules/agent/agentEdit.html b/src/main/resources/templates/febs/views/modules/agent/agentEdit.html
new file mode 100644
index 0000000..31f4b39
--- /dev/null
+++ b/src/main/resources/templates/febs/views/modules/agent/agentEdit.html
@@ -0,0 +1,100 @@
+<style>
+    #user-update {
+        padding: 20px 25px 25px 0;
+    }
+
+    #user-update .layui-treeSelect .ztree li a, .ztree li span {
+        margin: 0 0 2px 3px !important;
+    }
+
+    #user-update #data-permission-tree-block {
+        border: 1px solid #eee;
+        border-radius: 2px;
+        padding: 3px 0;
+    }
+
+    #user-update .layui-treeSelect .ztree li span.button.switch {
+        top: 1px;
+        left: 3px;
+    }
+</style>
+<div class="layui-fluid" id="user-update">
+    <form class="layui-form" action="" lay-filter="user-update-form">
+        <div class="layui-form-item febs-hide">
+            <label class="layui-form-label febs-form-item-require">用户id:</label>
+            <div class="layui-input-block">
+                <input type="text" name="id" data-th-value="${user.userId}">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label febs-form-item-require">用户名:</label>
+            <div class="layui-input-block">
+                <input type="text" name="account" lay-verify="required" data-th-id="${user.userId}" readonly autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label febs-form-item-require">代理姓名:</label>
+            <div class="layui-input-block">
+                <input type="text" name="name" minlength="2" maxlength="25" lay-verify="range" autocomplete="off"
+                       class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label febs-form-item-require">联系电话:</label>
+            <div class="layui-input-block">
+                <input type="tel" name="telphone" lay-verify="phone" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label febs-form-item-require">代理UID:</label>
+            <div class="layui-input-block">
+                <input type="text" name="inviteId" lay-verify="required" readonly autocomplete="off"
+                       class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label febs-form-item-require">返佣比例:</label>
+            <div class="layui-input-block">
+                <input type="text" name="returnRatio" lay-verify="slot" autocomplete="off" class="layui-input">
+            </div>
+        </div>
+        <div class="layui-form-item febs-hide">
+            <button class="layui-btn" lay-submit="" lay-filter="user-update-form-submit" id="submit"></button>
+            <button type="reset" class="layui-btn" id="reset"></button>
+        </div>
+    </form>
+</div>
+
+<script data-th-inline="javascript">
+    layui.use(['febs', 'form', 'validate'], function () {
+        var $ = layui.$,
+            febs = layui.febs,
+            layer = layui.layer,
+            form = layui.form,
+            user = [[${user}]],
+            validate = layui.validate;
+
+        form.verify(validate);
+        form.render();
+
+        initFormValue();
+
+        function initFormValue() {
+            form.val("user-update-form", {
+                "account": user.username,
+                "name": user.agentName,
+                "telphone": user.mobile,
+                "inviteId": user.inviteId,
+                "returnRatio" : user.returnRatio
+            });
+        }
+
+        form.on('submit(user-update-form-submit)', function (data) {
+            febs.post(ctx + 'agent/edit', data.field, function () {
+                layer.closeAll();
+                $('#febs-user').find('#query').click();
+            });
+            return false;
+        });
+    });
+</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/febs/views/modules/agent/member.html b/src/main/resources/templates/febs/views/modules/agent/member.html
index e987cae..6918e0d 100644
--- a/src/main/resources/templates/febs/views/modules/agent/member.html
+++ b/src/main/resources/templates/febs/views/modules/agent/member.html
@@ -286,8 +286,7 @@
                     {title: '账号类型', templet: '#account-type'},
                     {title: '账号状态', templet: '#account-status'},
                     {title: '审核状态', templet: '#certify-status'},
-                    {field: 'createTime', title: '注册时间', minWidth: 180},
-                    {title: '操作', toolbar: '#user-option', minWidth: 140, fixed : 'right'}
+                    {field: 'createTime', title: '注册时间', minWidth: 180}
                 ]]
             });
         }

--
Gitblit v1.9.1