ttbooking / accounting
会计库
Requires
- php: ^8.0
- illuminate/contracts: ^9.31 || ^10.0 || ^11.0
- illuminate/database: ^9.31 || ^10.0 || ^11.0
- illuminate/support: ^9.31 || ^10.0 || ^11.0
- moneyphp/money: ^4.0
- ramsey/uuid: ^4.2.2
- ttbooking/castable-money: ^1.0
- ttbooking/class-factory: ^1.0
- ttbooking/entity-locator: *
- ttbooking/money-serializer: ^1.0
Requires (Dev)
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.5.10 || ^10.0 || ^11.0
Suggests
- illuminate/console: Required to control cash flow via console commands (^9.31 || ^10.0 || ^11.0).
- illuminate/events: Required to utilize transaction events (^9.31 || ^10.0 || ^11.0).
- dev-master
- v0.0.106
- v0.0.105
- v0.0.104
- v0.0.103
- v0.0.102
- v0.0.101
- v0.0.100
- v0.0.99
- v0.0.98
- v0.0.97
- v0.0.96
- v0.0.95
- v0.0.94
- v0.0.93
- v0.0.92
- v0.0.91
- v0.0.90
- v0.0.89
- v0.0.88
- v0.0.87
- v0.0.86
- v0.0.85
- v0.0.84
- v0.0.83
- v0.0.82
- v0.0.81
- v0.0.80
- v0.0.79
- v0.0.78
- v0.0.77
- v0.0.76
- v0.0.75
- v0.0.74
- v0.0.73
- v0.0.72
- v0.0.71
- v0.0.70
- v0.0.69
- v0.0.68
- v0.0.67
- v0.0.66
- v0.0.65
- v0.0.64
- v0.0.63
- v0.0.62
- v0.0.61
- v0.0.60
- v0.0.59
- v0.0.58
- v0.0.57
- v0.0.56
- v0.0.55
- v0.0.54
- v0.0.53
- v0.0.52
- v0.0.51
- v0.0.50
- v0.0.49
- v0.0.48
- v0.0.47
- v0.0.46
- v0.0.45
- v0.0.44
- v0.0.43
- v0.0.42
- v0.0.41
- v0.0.40
- v0.0.39
- v0.0.38
- v0.0.37
- v0.0.36
- v0.0.35
- v0.0.34
- v0.0.33
- v0.0.32
- v0.0.31
- v0.0.30
- v0.0.29
- v0.0.28
- v0.0.27
- v0.0.26
- v0.0.25
- v0.0.24
- v0.0.23
- v0.0.22
- v0.0.21
- v0.0.20
- v0.0.19
- v0.0.18
- v0.0.17
- v0.0.16
- v0.0.15
- v0.0.14
- v0.0.13
- v0.0.12
- v0.0.11
- v0.0.10
- v0.0.9
- v0.0.8
- v0.0.7
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
This package is auto-updated.
Last update: 2024-09-21 16:44:16 UTC
README
此Laravel包提供了在虚拟账户之间进行强大、事务性资金或资产转账的支持。
特性
- 基于DBMS的事务和悲观锁定
- UUID以实现无缝集成和扩展
- 通过MoneyPHP库支持大整数和任意精度数学
- 支持货币转换
- 区块链用于数据完整性检查
- 通过控制台命令实现完全控制
要求
至少需要PHP 8.0和Laravel 9.31。
支持原生JSON字段的RDBMS(推荐)。
安装
使用Composer
$ composer require ttbooking/accounting
配置
安装后,您需要配置包,此时您有两个选择
- 通过环境变量(您的应用程序的
.env
文件) - 使用包的配置文件
如果您选择第二个选项,您需要通过以下命令将配置文件复制到您的应用程序的配置目录中
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider --tag=config
如果您需要了解更多关于每个选项及其用法的信息,可以查看accounting.php
配置文件。
如果您需要更改数据库表名或修改模式,您还需要执行以下命令
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider --tag=migrations
如果您需要发布配置文件和数据库迁移,可以省略"--tag"选项
$ artisan vendor:publish --provider=TTBooking\Accounting\AccountingServiceProvider
在完成所有数据库相关修改(如果需要)后,您需要执行artisan migrate
命令。
建议为每个可能的账户所有者实体类型配置形态映射。
有关更多信息,请参阅https://laravel.net.cn/docs/10.x/eloquent-relationships#custom-polymorphic-types。
用法
要创建账户并将其链接到现有实体,您可以使用Account外观(或相应的AccountManager接口)
$account = Account::create($user);
...将为用户$user
创建账户。
要按所有者查找现有账户,尝试以下操作
$account = Account::find($user);
...如果存在,将找到$user
的账户,否则将失败。
注意:如果您已启用账户自动创建,则不会失败。相反,它将创建缺少的账户。
要在两个账户之间转账资金,您可以使用Transaction外观(或相应的TransactionManager接口)
$transaction = Transaction::create($account1, $account2, new Money(10000, new Currency('USD')));
...将创建从$account1
转到$account2
的100美元转账的交易。
当您需要提交此交易时,只需执行$transaction->commit();
。
如果您不需要在项目中单独执行创建/提交操作,您可以配置自动提交功能。
要按UUID检索账户或交易,尝试以下操作
$account = Account::get($uuid);
...以获取账户或
$transaction = Transaction::get($uuid);
...以获取交易。