定制 notchafrica/balance 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

notchafrica/balance

最新稳定版本:1.0

Composer 安装命令:

composer require notchafrica/balance

包简介

Maintains a history of balance movements in the eloquent models. This simple package will keep track of the balance of your models. You can increase, decrease, reset and set the balance. It is also possible to check if a model has a positive balance or no balance.

README 文档

README

Maintains a history of balance movements in the eloquent models. This simple package will keep track of the balance of your models. You can increase, decrease, reset and set the balance. It is also possible to check if a model has a positive balance or no balance.

Installation

You can install the package via composer:

composer require mreduar/laravel-balance

You can publish and run the migrations with:

php artisan vendor:publish --provider="MrEduar\Balance\BalanceServiceProvider" --tag="migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="MrEduar\Balance\BalanceServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Table name
    |--------------------------------------------------------------------------
    |
    | Table name to use to store balance history transactions.
    |
    */

    'table' => 'balance_history',

];

Usage

Adding the HasBalance trait will enable balance functionality on the Model.

use Illuminate\Foundation\Auth\User as Authenticatable;
use MrEduar\Balance\HasBalance;

class User extends Authenticatable
{
    use HasBalance;
}

Basic operations

$user->increaseBalance(2575);
$user->balance; // 25.75

$user->decreaseBalance(2575);
$user->balance; // 0

$user->modifyBalance(-2537);
$user->balance; // -25.37

$user->modifyBalance(3037);
$user->balance; // 5

Reset balance

It's also possible to reset the balance and directly setting a new value.

$user->resetBalance(); // 0

$user->resetBalance(10); // 10

Check if model has balance

Check if there is a positive balance or a balance greater than that provided.

$user->hasBalance();
$user->hasBalance(2575);

Check if model has no balance

Check if there is no more balance.

$user->hasNoBalance();

Add reference and description to history

It is possible to add a reference to any of the above methods by passing an array as a second parameter with the data of the referenced model and a description.

use App\Models\Podcast;

$podcast = Podcast::find(1);

$user->decreaseBalance(2575, [
    'description' => 'Purchase of a podcast.',
    'reference' => $podcast
]);

$user->increaseBalance(2575, [
    'description' => 'Paypal Deposit.'
]);

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-07