owlgrin/wallet

此包最新版本(v2.1.0)没有提供许可证信息。

轻松将钱包系统集成到任何应用程序中

v2.1.0 2015-06-01 12:37 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:18:38 UTC


README

钱包允许您为您的用户维护积分。

安装

要安装此包,请将以下内容包含在您的 composer.json 中。

"owlgrin/wallet": "dev-master"

然后,在您的 app.php 中包含以下服务提供者。

'Owlgrin\Wallet\WalletServiceProvider'

最后,发布配置。

php artisan config:publish owlgrin/wallet

用法

在 artisan 中编写此命令以创建迁移

php artisan wallet:table

现在将所有表迁移到您的 mysql 数据库中

php artisan migrate

您可以通过以下方式启动钱包

Wallet::user($userId)

其中 $userId 是您的用户的唯一标识符

积分

您可以添加用户的积分

Wallet::credits($credits, $redemptions)

其中 $credits 是您希望为用户添加的积分数量,而 $redemptions 是您希望用户使用这些积分的次数

兑换

您可以通过以下方式兑换积分

Wallet::redeem($amount)

其中 $amount 是您希望访问的请求金额

剩余积分

您可以使用以下方式查看剩余积分

Wallet::left();

异常

钱包附带自定义异常,以便更容易处理。以下是可以使用的以下自定义异常

Owlgrin\Wallet\Exceptions\CreditsLimitReachedException;
Owlgrin\Wallet\Exceptions\NoCreditsException;
Owlgrin\Wallet\Exceptions\InternalException;

这些异常都是扩展了抽象类 Owlgrin\Wallet\Exceptions\Exception

您可以使用如下方式使用它

try
{
	Wallet::Redeem(5445);
}
catch(Owlgrin\Wallet\Exceptions\NoCreditsException $e)
{
	return $e;
}
catch(Owlgrin\Wallet\Exceptions $e)
{
	return $e;
}