artjoker / laravel-scoring
Laravel 评分系统集成
v3.0
2024-01-25 11:03 UTC
Requires
- php: ^8.1
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^7.5|^8.0|^9.0
README
Laravel 评分系统集成。该包提供集成评分系统
- RiskTools
安装
您可以通过 composer 安装此包
composer require artjoker/laravel-scoring
您可以发布配置文件
php artisan vendor:publish --provider="Artjoker\LaravelScoring\ScoringServiceProvider" --tag="config"
设置环境变量 (.env
)
RISK_TOOLS_URL=
RISK_TOOLS_KEY=
用法
获取评分数据
您可以从评分系统获取数据如下
$result = Scoring::scoring('risk_tools', $attributes);
- 'risk_tools' - 评分系统;
- $attributes - 来自信用模型的根据
config/scoring.php
中变量映射的数据(数组)。此映射建立了您的模型属性与评分系统所需查询字段之间的对应关系。
'model_data' => [
// For "scoring" method
'id' => 'public_id', // ID of loan
'user_id' => 'client_id', // ID of client
'social_number' => 'inn', // INN of client
'phone' => 'phone', // Phone of client
'email' => 'email', // Email of client
'passport_number' => 'passport', // Passport (example АА123456 or number ID-card)
'passport_date' => 'passport_date', // Passport issue date (example "2001-12-01")
'first_name' => 'firstName', // First name
'last_name' => 'lastName', // Last name
'other_name' => 'middleName', // Middle name
'birth_date' => 'birth_date', // Birth date (example "2001-12-01")
'gender_id' => 'gender_id', // Gender (1 - male, 2 - female)
'loan_amount' => 'sum', // Amount of credit
'loan_days' => 'period', // Number days of credit
'applied_at' => 'created_at', // Date and time created loan (example "2018-04-05T19:29:51+03:00")
'ip' => 'ip', // IP of client
'user_agent' => 'user_agent', // User-Agent of browser of client
'ubki' => 'ubki', // XML-data from UBKI
// For updating of statuses
'status_id' => 'status_code', // Status code of credit (1 - NEW, 2 - REJECT, 3 - APPROVED, 4 - ISSUED, 5 - CLOSED, 6 - OVERDUE)
'closed_at' => 'closed_at', // Date and time close loan (example "2018-04-25T10:05:00+03:00")
'amount_to_pay' => 'amount_debt', // Total debt
'total_paid' => 'total_paid', // The sum of all payments
'overdue_days' => 'overdue_days', // The total number of days of delay of loan
],
$result
- 评分系统的响应(数组)。
$result = [
"group" => 4,
"score" => 0.495,
"amount_limit_max" => 1200,
"amount_limit" => 1000.0,
"filters" => [],
"score_model" => [
"version" => "v1_7"
]
]
发送信用状态
按照以下方式将信用状态发送到评分系统
$result = Scoring::status('risk_tools', $attributes);
- 'risk_tools' - 评分系统;
- $attributes - 来自信用模型的数据(数组)
获取 UBKI 报告
按照以下方式从评分系统获取 UBKI 报告
$result = Scoring::ubkiReport('risk_tools', ['public_id' => $public_id]);
- $public_id - 信用 ID
$result = [
"reports": [
[
"report_date" => "2018-12-25",
"xml" => "<xml>"
],
[
"report_date" => "2018-12-25",
"xml" => "<xml>"
]
]
]
获取预评分数据
您可以从预评分系统获取数据如下
$result = Scoring::pre_scoring('risk_tools', ['social_number' => $social_number]);
- $social_number - 客户的社会号码(INN)
特性
将 ScoringTrait
-特性添加到包含客户数据的模型中
use Artjoker\LaravelScoring\Traits\ScoringTrait;
class Loan extends Model
{
use ScoringTrait;
...
}
向类中添加一个新方法 scoringAttributes()
以添加必要的属性并用数据填充它们
use Artjoker\LaravelScoring\Traits\ScoringTrait;
class Loan extends Model
{
use ScoringTrait;
...
public function scoringAttributes()
{
$client_data = json_decode($this->attributes['client_data']);
$this->attributes['client_id'] = trim($client_data->id);
$this->attributes['inn'] = trim($client_data->code);
$this->attributes['lastName'] = trim($client_data->lastName);
...
}
}
您可以使用其他方式创建您在 'model_data'
(config/scoring.php
) 中指定的自定义属性。
将请求记录到数据库
您可以选择将所有 Risk Tools 请求保存到数据库表。
为此,您应将配置参数 query_log
设置为 true
并创建具有以下字段的表 risk_tools_query_logs
$table->bigIncrements('id');
$table->string('public_id');
$table->unsignedInteger('client_id');
$table->string('url');
$table->string('method', 20);
$table->json('params');
$table->timestamp('created_at')->useCurrent();
更新日志
请参阅 更新日志 以获取最近更改的更多信息。
贡献
请参阅 贡献指南 以获取详细信息。
安全性
如果您发现任何安全问题,请通过电子邮件 v.taranenko@artjoker.net 而不是使用问题跟踪器进行报告。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。