roboticsexpert/balance-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

roboticsexpert/balance-manager

Composer 安装命令:

composer require roboticsexpert/balance-manager

包简介

Add balance (credit) for your users easily

README 文档

README

in many projects, you need to have credit (balance) concept for your user that make you distract from your main business logic.

with this package you will have balance for your users easily without being worry about Race Condition and Double Spending.

this project mainly designed for exchange systems, but you can use it in any project.

Installation

composer require roboticsexpert/balance-manager

after instaling composer package, if you use auto discovery for service providers, everything ok, but if you blocked that just add this line to config/app.php in providers section:

Roboticsexpert\BalanceManager\BalanceManagerServiceProvider::class

after that you should run

php artisan migrate

and this:

php artisan vendor:publish --provider="Roboticsexpert\BalanceManager\BalanceManagerServiceProvider"

it will create balance.php file in your config file.

Usage

First of all, you should decide with currencies you want to have in your system, and consider a KEY for each currency and add those keys in balance.php config file

return [

    // add symbols of your currencies
    // symbols must be lower than 16 char

    'currencies'=>[
        'BTC',
        'TMN',
        'DOGE',
    ]
];

you can use this project with 2 strategy,Facade or Dependency injection!

I suggest to you to use it with dependecy injection for IDE auto complete feature but use it as you prefer!

after that you can get BalanceManager from with these to methods:

Facade

you can get BalanceManager service like this:

use Roboticsexpert\BalanceManager\BalanceManagerFacade as BalanceManager;


BalanceManager::getAllBalancesByUserId(1)

Dependency Injection

you can get BalanceManager service from app() like this:

use Roboticsexpert\BalanceManager\Services\BalanceManager;

$balanceManager=app(BalanceManager::class); 

$balanceManager->getAllBalancesByUserId(1);

or get from laravel automatic dependency injection

use Roboticsexpert\BalanceManager\Services\BalanceManager;
class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function index(BalanceManager $balanceManager){
        dd($balanceManager->getAllBalancesByUserId(1));
    }
}

Methods

Get all balance for user

it will return array of Balance model

$balances= $balanceManager->getAllBalancesByUserId("USER_ID");
dd($balances);

Change balance of user

$balanceChangeResult= $balanceManager->changeBalanceByUserIdAndCurrency(
        int $userId, //user id
        string $currency, // like USDT, TMN
        string $reason, // a unique string for each action
        IBalanceHistoryRelated $model, // a model that is author of change balance
        Decimal $valueChange, // value you want to add or sub from user balance
        Decimal $lockedValueChange // in general usage it should be new \Decimal\Decimal(0)
);

统计信息

  • 总下载量: 214
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固