1 Star 0 Fork 24

jack/guns-distribution

forked from FuFei/guns-distribution 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

Guns-Distribution

[TOC]

前言

建议先看看上述两个项目,了解一些基本的概念,并且我想介绍一些内容,他们已经介绍了哦~

产品前期推广必备分销模块,利用熟人社交,人脉等方式进行产品推广、商品销售等,利用这种裂变方式,可以达到精准投放的效果,使产品能够得到良好的收益和推广,同时也为产品积累用户和活跃度,帮助产品度过最为艰难的初期,最终实现盈利。

不想重复造轮子但是没办法还是自己写了,作者曾使用过大部分分销开源项目作为分销解决方案,但都存在代码复杂晦涩难懂,且存在一些安全和其他漏洞问题,或是系统版本太老不便于与新项目集成,亦或是不利于拓展或者修改新的业务逻辑等,让我们感到十分困扰。因此,决定重新设计一个能解决了上述问题的基于分销层级的分销框架,理论上实现了分销项目的所应具备的基本功能,同时代码逻辑简单,注释充足,也便于改造或者实现自己想要的分销策略。

最终,希望它能够帮助到您。

开源地址

https://gitee.com/fufeii/guns-distribution

环境要求

Mysql

Redis

版权声明

LGPL-3.0开源协议

主要更新

  • 2020-10-14:新增 分润异常通过webhook通知到钉钉群

  • 2020-10-06:新增 Dockerfile和docker-compose方式部署

  • 2020-10-05:初始版本

快速开始

第零步:准备环境

选择一:通过IDEA运行程序

  1. 在数据库中执行./sql/guns_distribution.sql的脚本文件
  2. 修改application-local.yml配置文件中mysql、redis的配置

选择二:通过容器化运行程序

​ 请查看【快速部署】模块

第一步:创建租户

使用guns默认账户 admin/111111 登录本系统 http://localhost:8080/ 在 用户管理 => 平台管理 创建一个平台(租户),设置相关基础信息,创建完成后已经初始化了相关角色、职位、密码(111111)

getstart-tenant-add.png

第二步:登录租户端并设置分销参数

在 分销参数 => 分润参数 创建分润参数 在 分销参数 => 段位参数 创建段位参数 注:此模块定义可根据需要设置不同的参数。以下示例参数不考虑用户类型和用户段位

getstart-profitparam-add.png

getstart-rankparam-add.png

第三步:模拟接口调用

在 开发管理 => 模拟操作 模拟其他外部模块调用

在 开发管理 => 接口文档 查看参数或者调试接口

getstart-mock-index.png

getstart-api-index.png

项目介绍

项目特点

  1. 依托Guns开源版,基于Springboot2.1.6能够快速上手
  2. 分润参数配置化,简单操作即可完成分润参数的构建
  3. 开箱即用,内置三种分润策略
  4. 易于扩展,能够快速实现自己的分润策略
  5. 乐观锁保护,通过aop实现重试机制
  6. 参数校验分离,基于javax.validation注解和自定义aop,将参数校验从代码中脱离
  7. 多线程加持,通过并行解决串行化造成的耗时问题,提升接口相应速度

模块分包

└─distribution   // 分销模块
    ├─aop             // aop模块
    │  ├─retry            // 重试机制
    │  └─vaildate         // 验证机制
    ├─api             // api模块
    │  ├─controller       // 控制器
    │  ├─request          // api请求模型
    │  └─response         // api相应模型 
    ├─controller       // 管理后台控制器模块
    ├─entity           // 实体类包
    ├─enums            // 枚举模块
    │  └─biz               // 业务相关枚举包
    ├─event            // 事件模块
    ├─exception        // 异常模块
    │  └─handler           // 异常处理器
    ├─listener         // 监听器模块
    ├─mapper           // dao模块
    │  └─mapping           // xml文件
    ├─model            // 模型模块
    │  ├─dto               // 管理端前台请求实体
    │  └─vo			       // 前端模型
    ├─profit           // 分润模块
    │  └─strategy          // 分润策略
    ├─service          // 服务层模块
    │  └─impl              // 服务实现类
    ├─socket           // websocket模块
    └─util             // 工具模块

分润模型

分润相关的UML模型可在IDEA中查看,通过spring的事件发布/订阅模型,将分润业务代码和其他业务逻辑分离。

通过spring的事件发布/订阅模型,将分润业务代码和其他业务逻辑分离。

下面将介绍如何快速拓展符合自己业务的分润策略,以邀请分润为例。

// 1、创建邀请会员事件
public class InviteMemberEvent extends ApplicationEvent {

    private static final long serialVersionUID = -5904603262579267324L;

    /**
     * 发出邀请的人
     */
    private final DistMemberDTO inviter;

    public InviteMemberEvent(Object source, DistMemberDTO inviter) {
        super(source);
        this.inviter = inviter;
    }

    public DistMemberDTO getInviter() {
        return inviter;
    }
}

// 2、在监听器组件类中定义对应的事件监听器
public class ProfitEventListener {

    @Autowired
    private ProfitStrategyContext profitStrategyContext;

    /**
     * 监听InviteMemberEvent事件,触发事件所在事务成功提交后
     * 异步执行,注释@Async注解则为同步执行。
     * 默认邀请会员事件的业务在其所促发的模块事务之外。
     *
     * @param inviteMemberEvent 会员邀请事件
     */
    @Async
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
    public void handle(InviteMemberEvent inviteMemberEvent) {
        // 执行邀请分润机制
        profitStrategyContext.getProfitStrategy(ProfitTypeEnum.INVITE).startProfit(inviteMemberEvent.getInviter());
    }
    
}

// 3、实现邀请分润策略的业务逻辑,实现接口
public class InviteProfitStrategy extends AbstractProfit {

    @Override
    protected void setTenantForCurrentThread(ProfitAccess subject) {
        // 此接口如果为异步时需要重写
        TenantHelper.setTenant(((DistMemberDTO) subject).getPlatformUsername());
    }

    @Override
    public void validateBiz(ProfitAccess subject) throws DistributionException {
        // 验证业务合法性
    }

    @Override
    public DistProfitEvent recordEvent(ProfitAccess subject) {
        // 记录分润事件
    }


    @Override
    public void executeProfit(DistProfitEvent event, ProfitAccess subject) {
        // 执行分润
    }

}

// 4、在必要的地方发布邀请会员事件
public class DistMemberServiceImpl extends ServiceImpl<DistMemberMapper, DistMember> implements DistMemberService {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;
    
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(DistMemberDTO param) {
        // 其他会员添加的业务逻辑
        if (isInviteJoin) {
			applicationEventPublisher.publishEvent(new InviteMemberEvent(this, param));        
        }
    }
}

项目预览

主控面板模块

console-preview-pindex.png

用户管理模块

user-member-index.png

user-member-account.png

user-member-team.png

user-account-index.png

user-account-changelist.png

user-accountrecord-index.png

分润参数模块

dist-rank-index.png

dist-profit-index.png

分润中心模块

profitcenter-event-index.png

profitcenter-event-detail.png

profitcenter-profitrecord-index.png

profitcenter-withdrawal.png

其他特性

other-dingding.png

快速部署

使用Dockfile

将项目中的Dockerfile和guns-distribution-starter.jar上传到服务器

[root@centos7 dockerfile]# ls
Dockerfile  guns-distribution-starter.jar

构建镜像并启动容器,注意:默认启动prod配置,所以需要修改prod配置中的redis和mysql配置,启动其他配置请使用 -e ACTIVE=your_active 进行覆盖,此配置等价于 --spring.profiles.active=your_active

[root@centos7 dockerfile]# docker build -t guns-distribution:1.0 ./ && docker run -d -p 8080:8080 -v $(pwd)/logs:/runtime/app_logs -e ACTIVE=prod --name guns-distribution guns-distribution:1.0

访问系统,默认8080端口

使用docker-compose

推荐使用此方法,一键启动,不需要自己搭建mysql和redis环境

将项目中的docker-compose.yml和Dockerfile以及guns-distribution-starter.jar和guns_distribution.sql上传到服务器

[root@centos7 docker-compose]# ls
docker-compose.yml  Dockerfile  guns_distribution.sql  guns-distribution-starter.jar

构建镜像并启动整个项目

[root@centos7 docker-compose]# docker-compose up -d --build

访问系统,默认8081端口

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License. “The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”. The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

多租户分销系统,开箱即用。基于Guns后台框架,动态分销配置调整,内置多种分销策略,文档注释齐全,能够快速上手并与其他模块对接或者自行拓展。如果帮助到你,请Star项目给予作者支持! 展开 收起
Java
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/jack888/guns-distribution.git
git@gitee.com:jack888/guns-distribution.git
jack888
guns-distribution
guns-distribution
master

搜索帮助