PHPackages                             rauwang/settlement - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. rauwang/settlement

ActivePackage

rauwang/settlement
==================

金额结算

00PHP

Since Mar 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/rauwang/settlement)[ Packagist](https://packagist.org/packages/rauwang/settlement)[ RSS](/packages/rauwang-settlement/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

### 金额计算

[](#金额计算)

```
$rmb = Current::instance('rmb', 1, '分'); // 实例化币种
$amount = Amount::instance($rmb, 100); // 实例化金额。默认相对基本面值为1，即1分，所以该金额为100分=1元
$amountCalculation = new AmountCalculation($amount); // 实例化金额计算器
$amountCalculation->join(new AmountValueAddition(Amount::instance($rmb, 100.01, 100))); // 添加一个金额计算，且添加的金额的相对基本面值为100，即100分=1元，所以该金额为100.01元
$amount = $amountCalculation->calc();

echo $amount->getValue() . $rmb->getUnit(); // 所以结果为：10101分=101.01元
```

> 因为内部转换成整型进行计算，所以不存在失真的情况。
>
> 币种实例化时，确定了改币种的最小单位，即币种基本面。
>
> 金额实例化时，确定的是相对于币种的基本面，默认是1。

### 金额流水

[](#金额流水)

```
// 转账操作

$rmb = Current::instance('rmb', 1, '分');

$amount = Amount::instance($rmb, 100, 100); // 交易金额，这里的金额是100元

$amountFlow = new AmountFlow(
    $amount,
    new FeeHandlerImpl( // 费用处理
        Amount::instance($rmb, 10), // 转出费用，费用0.1元
        Amount::instance($rmb, 10) // 转入费用，费用0.1元
    )
);

// 需要注意，在实例化账户时，必须对数据库上锁（排他锁、写锁）
$account1 = new Account(Amount::instance($rmb, 1000, 100)); // 余额1000元
$account2 = new Account(Amount::instance($rmb, 0)); // 余额0元

echo 'account1 余额: ', $account1->getAmount()->getValue() . $rmb->getUnit(), PHP_EOL; // 余额：1000元
echo 'account2 余额: ', $account2->getAmount()->getValue() . $rmb->getUnit(), PHP_EOL; // 余额：0元

$amountFlow->flowOut($account1);
$amountFlow->flowIn($account2);

echo '转账后：', PHP_EOL;
echo 'account1 余额: ', $account1->getAmount()->getValue() . $rmb->getUnit(), PHP_EOL; // 余额：899.9元
echo 'account2 余额: ', $account2->getAmount()->getValue() . $rmb->getUnit(), PHP_EOL; // 余额：99.9元

// 在计算完成后，更新数据库，并解锁
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ba81f6ceda16f5848e16a56c469e0916733778712430d320617cd48d5801ab1?d=identicon)[rauwang](/maintainers/rauwang)

---

Top Contributors

[![rauwang](https://avatars.githubusercontent.com/u/11934944?v=4)](https://github.com/rauwang "rauwang (2 commits)")

### Embed Badge

![Health badge](/badges/rauwang-settlement/health.svg)

```
[![Health](https://phpackages.com/badges/rauwang-settlement/health.svg)](https://phpackages.com/packages/rauwang-settlement)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
