2017 © Pedro Peláez
 

library yii2-balance

Supports user balance and transactions, calculating actual balance from history

image

tapakan/yii2-balance

Supports user balance and transactions, calculating actual balance from history

  • Tuesday, April 25, 2017
  • by Tapakan
  • Repository
  • 1 Watchers
  • 4 Stars
  • 506 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 13 % Grown

The README.md

Yii2 Balance Manager

Build Status Coverage Status Dependency Status Latest Stable Version Total Downloads, (*1)

Yii2 Balance can perform simple operations with the user's balance. History of operations remains., (*2)

Installation

Run following command, (*3)

composer require tapakan/yii2-balance

or add, (*4)

"tapakan/yii2-balance": "*"

to the require section of your composer.json, (*5)

Configuration

    'components' => [
        'balance' => [
            'class'                  => 'Tapakan\Balance\ManagerActiveRecord',
            'accountClass'           => 'common\models\UserBalance',
            'transactionClass'       => 'common\models\UserBalanceHistory',
            'accountLinkAttribute'   => 'account_id',
            'amountAttribute'        => 'value',
            'balanceAttribute'       => 'value',
            'accountUserIdAttribute' => 'user_id'
        ],
    ],

Usage

Add some value to user php Yii:$app->balance->increase($accountId_OR_userId_OR_condition, 500); Or take, (*6)

Yii:$app->balance->decrease($accountId_OR_userId_OR_condition, 100);

Calculate balance from history, (*7)

echo Yii:$app->balance->calculateBalance($accountId_OR_userId); // 400

With additional information that may be stored in the balance history table, (*8)

Yii:$app->balance->increase($accountId_OR_userId_OR_condition, 750, [
    'order_id' => 1,
    // other usefull info
]);
Since 0.1.1 version you can revert a transaction.

Let's allow transaction #35 it is removal of 200 points from the account of the user. The following command will return them into the account., (*9)

Yii:$app->balance->revert($transactionId)

Example of table structure

        // History of operations
        $this->createTable('balance_history', [
            'account_id' => $this->integer(),
            'value'      => $this->decimal(13, 4),
            'order_id'   => $this->integer(),
            // Other usefull information
        ]);

        // Calculated balance
        $this->createTable('balance', [
            'id'         => $this->primaryKey(),
            'user_id'    => $this->integer(),
            'value'      => $this->decimal(13, 4)
        ]);

The Versions

25/04 2017

dev-master

9999999-dev https://github.com/Tapakan/yii2-balance.git

Supports user balance and transactions, calculating actual balance from history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Oganov

extension yii2 transaction balance

25/04 2017

0.3.2

0.3.2.0 https://github.com/Tapakan/yii2-balance.git

Supports user balance and transactions, calculating actual balance from history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Oganov

extension yii2 transaction balance

25/04 2017

dev-dev

dev-dev https://github.com/Tapakan/yii2-balance.git

Supports user balance and transactions, calculating actual balance from history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Oganov

extension yii2 transaction balance

13/02 2017

0.2.0

0.2.0.0 https://github.com/Tapakan/yii2-balance.git

Supports user balance and transactions, calculating actual balance from history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Oganov

extension yii2 transaction balance

11/02 2017

0.1.1

0.1.1.0 https://github.com/Tapakan/yii2-balance.git

Supports user balance and transactions, calculating actual balance from history

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Oganov

extension yii2 transaction balance