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)
);

roboticsexpert/balance-manager 适用场景与选型建议

roboticsexpert/balance-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 214 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 roboticsexpert/balance-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 roboticsexpert/balance-manager 我们能提供哪些服务?
定制开发 / 二次开发

基于 roboticsexpert/balance-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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