owlgrin / throttle
速率限制和用法跟踪器
v0.2.0
2015-04-09 06:59 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is not auto-updated.
Last update: 2024-09-28 16:36:25 UTC
README
Throttle 允许你在计划和功能之间保持集成。
安装
要安装此包,请在 composer.json 中包含以下内容。
"owlgrin/throttle": "dev-master"
然后,在 app.php 中包含以下服务提供者。
'Owlgrin\Throttle\ThrottleServiceProvider'
最后,发布配置。
php artisan config:publish owlgrin/throttle
用法
在你的 artisan 中写入此命令以创建迁移
throttle:table
现在将所有表迁移到你的 mysql 数据库中
php artisan migrate
新计划的录入
现在是时候通过使用 Owlgrin\Plan\PlanRepo 的 add 函数创建一个新计划了
计划的格式如下
$plan = {
"plan":{
"name" : "Simple",
"identifier" :"simple",
"description" :"this is a simple plan",
"features": [
{
"name":"Horn",
"identifier":"horn",
"tier" :[
{
"rate":"4",
"per_quantity":1,
"limit":"500"
},
{
"rate":"3",
"per_quantity":1,
"limit":"5000"
}
]
},
{
"name":"Mail",
"identifier":"mail",
"tier" :[
{
"rate":"4",
"per_quantity":1,
"limit":"100"
},
{
"rate":"3",
"per_quantity":1,
"limit":"1000"
}
]
}
]
}
}
用户订阅
你可以使用以下方法通过计划 ID 订阅用户
Owlgrin\Throttle\Subscriber\SubscriberRepo
subscribe($userId, $planId)
账单
你可以通过以下方式计算账单
Owlgrin\Throttle\Biller\Biller
calculate($userId)
或者可以通过以下方式估算账单
estimate($plan)
$plan = {'plan_id':1,
'feature':{
{feature_id}:{usage},
{feature_id}:{usage}
}
}