arttiger / laravel-scoring
Laravel评分系统集成
v1.2.0
2024-05-15 14:32 UTC
Requires
- php: ^7.1|^8.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0
- styleci/cli: ^1.1
This package is auto-updated.
Last update: 2024-09-15 15:13:04 UTC
README
Laravel评分系统集成。该软件包提供了集成评分系统的功能
- RiskTools
安装
使用composer安装此包
composer require arttiger/laravel-scoring
配置
要编辑默认配置,您可以执行以下操作
php artisan vendor:publish --provider="Arttiger\Scoring\ScoringServiceProvider" --tag="config"
之后,将创建 config/scoring.php
。
环境
设置环境变量 (.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 Arttiger\Scoring\Traits\ScoringTrait;
class Loan extends Model
{
use ScoringTrait;
...
}
向类中添加一个新方法 scoringAttributes()
,添加必要的属性并将它们填充数据
use Arttiger\Scoring\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
)中指定的自定义属性。
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息和使用待办事项列表,请参阅contributing.md。
安全
如果您发现任何安全相关的问题,请通过电子邮件发送给作者,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。