nepster-web/php-mlm-matrix

用于操作mlm矩阵的库

v1.0.0 2018-11-11 19:24 UTC

This package is auto-updated.

Last update: 2024-09-23 00:21:17 UTC


README

Latest Version Software License Total Downloads

用于操作MLM矩阵的库。

你发现错误了吗?

如果在代码或语法中发现了错误或任何不准确之处,请创建新问题

什么是MLM矩阵?

在当今众多MLM薪酬计划中,矩阵计划因其结构简单而广受欢迎。由于其理解起来相当简单,因此被认为非常有用且资源丰富,可以轻松集成到MLM业务中。

为了理解矩阵计划,首先理解其结构是有意义的。矩阵
具有固定的行数和列数,以特定的宽度和深度组织数字。通常,大多数MLM矩阵计划遵循两种类型的结构;2x2或3x3,但根据公司要求可能会有例外。矩阵计划中的所有成员都是从上到下或从左到右按顺序定位的。

demo

矩阵填满后,一级用户获得奖励,矩阵本身被分成几个子矩阵(取决于矩阵幂,例如立方矩阵将被分成3个子矩阵)。之后,新的矩阵等待填充,循环重复。

安装

安装此扩展的首选方法是通过composer

运行以下命令:

$ php composer.phar require --prefer-dist nepster-web/php-mlm-matrix "*"

或将以下内容添加到您的composer.json文件的require部分:

"nepster-web/php-mlm-matrix": "*"

结构

  • demo - 库示例
  • doc - GitHub文档文件
  • shema - 示例数据库表结构(MySQL)
  • src - 主库代码
  • tests - 单元测试

使用方法

创建新的矩阵对象

use Nepster\Matrix\Matrix;

$matrix = new Matrix(3, 2);

获取矩阵信息

$matrix->getDepth();
$matrix->getPow();

获取矩阵数组

$matrix->toArray();

管理矩阵中的用户

use Nepster\Matrix\Coord;
use Nepster\Matrix\Matrix;

$matrix = new Matrix(3, 2);

$matrix->addTenant(null, function() {
    // return your user data
})

$matrix->addTenant(new Coord(1, 1), function() {
    // return your user data
})

$matrix->hasTenant(new Coord(0, 0));
$matrix->hasTenant(new Coord(1, 1));

$matrix->removeTenant(new Coord(1, 1));

检查坐标的正确性

$matrix->isValidCoord(new Coord(0, 0));

检查矩阵中是否有空位

$matrix->isFilled();

更多示例请参阅示例文件。

我如何使用数据库来存储矩阵?

根据mlm项目和Web开发工具的不同具体要求,此库仅实现mlm矩阵的操作算法,不提供存储支持。

然而,如果您使用数据库,您可以轻松实现矩阵对象的存储和恢复。您可以在文件中学习示例MySQL结构

例如,创建一个新服务,允许您将矩阵对象写入和/或从数据库恢复

class MatrixService {

    public function findById(int $id): Matrix
    {
        // You need make a query to the `matrix` table that find the required record
        // Use join or another query to retrieve user data from the `matrix_users` table
        // Initialize new Matrix object
        // Using `addTenant` method that add users to Matrix object (based on data from `matrix_users` table)
        // Return the proper Matrix object
    }

    public function save(Matrix $matrix): void
    {
        // Get the matrix array using the `$matrix->toArray()` method
        // Create a valid request to save data to the database
        // - Most likely in a relational database you will have 2 tables (matrices and matrix_users)
        // - Don`t forget to check a new matrix is being created or edited an already existing matrix
        
        // Note1: Write down users with depth and number for further recovery
        // Note2: Don`t write coordinates with empty positions to the database.
    }

}

测试

$ phpunit

$ vendor/bin/phpunit

许可协议

此库受MIT许可协议的许可 - 请参阅LICENSE文件以获取详细信息。