提交代码
This commit is contained in:
2
packages/bonus/README.md
Normal file
2
packages/bonus/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# Bonus 奖金结算系统
|
||||
|
||||
28
packages/bonus/composer.json
Normal file
28
packages/bonus/composer.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "rulong/bonus",
|
||||
"description": "",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "C.Jason",
|
||||
"email": "chenjxlg@163.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
"rulong/user-account": "^1.0",
|
||||
"laravel/framework": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"RuLong\\Bonus": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"RuLong\\Bonus\\ServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
13
packages/bonus/config/rulong_bonus.php
Normal file
13
packages/bonus/config/rulong_bonus.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'user_model' => \App\Models\User::class,
|
||||
'Settlement' => [
|
||||
'Direct' => [
|
||||
'integral' => 100,
|
||||
'layer' => 9,
|
||||
'point' => 5,
|
||||
],
|
||||
],
|
||||
'full_point' => 10,
|
||||
];
|
||||
20
packages/bonus/src/Bonus.php
Normal file
20
packages/bonus/src/Bonus.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus;
|
||||
|
||||
use RuLong\Bonus\Contracts\Settlement;
|
||||
|
||||
class Bonus
|
||||
{
|
||||
protected $settlement;
|
||||
|
||||
public function __construct(Settlement $settlement)
|
||||
{
|
||||
$this->settlement = $settlement;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->settlement->fire();
|
||||
}
|
||||
}
|
||||
15
packages/bonus/src/Contracts/Settlement.php
Normal file
15
packages/bonus/src/Contracts/Settlement.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Contracts;
|
||||
|
||||
interface Settlement
|
||||
{
|
||||
|
||||
/**
|
||||
* 子规则的实际计算过程
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-31T14:22:48+0800
|
||||
*/
|
||||
function fire();
|
||||
|
||||
}
|
||||
0
packages/bonus/src/Demo/这里放结算示例
Normal file
0
packages/bonus/src/Demo/这里放结算示例
Normal file
14
packages/bonus/src/Exceptions/BonusException.php
Normal file
14
packages/bonus/src/Exceptions/BonusException.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Exceptions;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class BonusException extends RuntimeException
|
||||
{
|
||||
|
||||
public function __construct($message)
|
||||
{
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
29
packages/bonus/src/Models/Bonus.php
Normal file
29
packages/bonus/src/Models/Bonus.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Bonus extends Model
|
||||
{
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $dates = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'performs' => 'array',
|
||||
'configs' => 'array',
|
||||
];
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(BonusLog::class);
|
||||
}
|
||||
|
||||
}
|
||||
21
packages/bonus/src/Models/BonusLog.php
Normal file
21
packages/bonus/src/Models/BonusLog.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BonusLog extends Model
|
||||
{
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function bouns()
|
||||
{
|
||||
return $this->belongsTo(Bonus::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('rulong_bonus.user_model'));
|
||||
}
|
||||
}
|
||||
34
packages/bonus/src/ServiceProvider.php
Normal file
34
packages/bonus/src/ServiceProvider.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* 部署时加载
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-06-22T16:01:20+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__ . '/../config/rulong_bonus.php' => config_path('rulong_bonus.php')]);
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册服务提供者
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-06-22T16:01:12+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../config/rulong_bonus.php', 'rulong_bonus');
|
||||
}
|
||||
}
|
||||
20
packages/bonus/src/Traits/BloodLine.php
Normal file
20
packages/bonus/src/Traits/BloodLine.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Traits;
|
||||
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
|
||||
trait BloodLine
|
||||
{
|
||||
public function getUpBloodLine($user, $layer)
|
||||
{
|
||||
$lineArray = explode(',', $this->strLine);
|
||||
return UserRelation::whereIn('user_id', $lineArray)->orderBy('layer', 'desc')->limit($layer)->get();
|
||||
}
|
||||
|
||||
public function getDownBloodLine($user, $layer)
|
||||
{
|
||||
#Todo...
|
||||
return UserRelation::where('bloodline', 'like', "%," . $user->id . ",%")->whereBetween('layer', [$user->relation->layer, $user->relation->layer + $layer])->orderBy('layer', 'asc')->get();
|
||||
}
|
||||
}
|
||||
14
packages/bonus/src/Traits/Settlementable.php
Normal file
14
packages/bonus/src/Traits/Settlementable.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Traits;
|
||||
|
||||
use RuLong\Bonus\Bonus;
|
||||
|
||||
trait Settlementable
|
||||
{
|
||||
|
||||
public static function settlement()
|
||||
{
|
||||
return new Bonus(new static(...func_get_args()));
|
||||
}
|
||||
}
|
||||
8
packages/bonus/src/Traits/UserHasBonus.php
Normal file
8
packages/bonus/src/Traits/UserHasBonus.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Bonus\Traits;
|
||||
|
||||
trait UserHasBonus
|
||||
{
|
||||
|
||||
}
|
||||
4
packages/identity/README.md
Normal file
4
packages/identity/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Identity 身份系统
|
||||
# trait User 模型 涉及函数 RuLong\Identity\Traits\UserHasIdentity
|
||||
# 身份变更 $User->identityUpdate(Identity_id,Channel) // (身份ID,变更渠道)
|
||||
# 身份加权点数 $User->addPoint(Identity_id,Point) // (身份ID,加权数额:默认1)
|
||||
27
packages/identity/composer.json
Normal file
27
packages/identity/composer.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "rulong/identity",
|
||||
"description": "",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "C.Jason",
|
||||
"email": "chenjxlg@163.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.3",
|
||||
"laravel/framework": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"RuLong\\Identity": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"RuLong\\Identity\\ServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
9
packages/identity/config/rulong_identity.php
Normal file
9
packages/identity/config/rulong_identity.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
return [
|
||||
'user_model' => \App\Models\User::class,
|
||||
'channel' => [
|
||||
'AutoUp' => '自动升级',
|
||||
'EmptyUp' => '后台升级',
|
||||
],
|
||||
'default_identity' => '普通用户',
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateIdentitiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('identities', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('identities');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateIdentityLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('identity_logs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('identity_logs');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUserIdentitiesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_identities', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_identities');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateIdentityPointsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('identity_points', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('identity_points');
|
||||
}
|
||||
}
|
||||
15
packages/identity/src/Contracts/IdentityContracts.php
Normal file
15
packages/identity/src/Contracts/IdentityContracts.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Contracts;
|
||||
|
||||
interface IdentityContracts
|
||||
{
|
||||
|
||||
/**
|
||||
* 子规则的实际计算过程
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-31T14:22:48+0800
|
||||
*/
|
||||
function fire();
|
||||
|
||||
}
|
||||
47
packages/identity/src/Events/IdentityPoint.php
Normal file
47
packages/identity/src/Events/IdentityPoint.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Events;
|
||||
|
||||
use App\User;
|
||||
use RuLong\Identity\Contracts\IdentityContracts;
|
||||
use RuLong\Identity\Models\IdentityPoint as IdentityPointModel;
|
||||
use RuLong\Identity\Traits\Identityable;
|
||||
|
||||
class IdentityPoint implements IdentityContracts
|
||||
{
|
||||
use Identityable;
|
||||
|
||||
public $user;
|
||||
public $identity_id;
|
||||
public $point;
|
||||
|
||||
public function __construct($user, array $other = null)
|
||||
{
|
||||
$this->user = User::find($user->id);
|
||||
$this->identity_id = $other['identity_id'];
|
||||
if (isset($other['point']) && is_numeric($other['point'])) {
|
||||
$this->point = $other['point'];
|
||||
} else {
|
||||
$this->point = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建及修改身份
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-11-05T13:21:47+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
if ($this->user->id === 1) {
|
||||
return false;
|
||||
}
|
||||
IdentityPointModel::create([
|
||||
'user_id' => $this->user->id,
|
||||
'identity_id' => $this->identity_id,
|
||||
'point' => $this->point,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
51
packages/identity/src/Events/IdentityUpdate.php
Normal file
51
packages/identity/src/Events/IdentityUpdate.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Events;
|
||||
|
||||
use RuLong\Identity\Contracts\IdentityContracts;
|
||||
use RuLong\Identity\Models\IdentityLog as IdentityLogModel;
|
||||
use RuLong\Identity\Models\UserIdentity as UserIdentityModel;
|
||||
use RuLong\Identity\Traits\Identityable;
|
||||
|
||||
class IdentityUpdate implements IdentityContracts
|
||||
{
|
||||
use Identityable;
|
||||
|
||||
public $user;
|
||||
public $identity_id;
|
||||
public $channel;
|
||||
public $other;
|
||||
public function __construct($user, array $other = null)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->identity_id = $other['identity_id'];
|
||||
$this->channel = $other['channel'] ?? '';
|
||||
$this->other = $other;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建及修改身份
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-11-05T13:21:47+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$before = 0;
|
||||
|
||||
$identity_info = UserIdentityModel::where('user_id', $this->user->id)->first();
|
||||
if ($identity_info) {
|
||||
$before = $identity_info->identity_id;
|
||||
$identity_info->identity_id = $this->identity_id;
|
||||
$identity_info->save();
|
||||
} else {
|
||||
$data = [
|
||||
'user_id' => $this->user->id,
|
||||
'identity_id' => $this->identity_id,
|
||||
];
|
||||
UserIdentityModel::create($data);
|
||||
}
|
||||
$log = IdentityLogModel::create(['user_id' => $this->user->id, 'before' => $before, 'after' => $this->identity_id, 'channel' => $this->channel, 'other' => $this->other]);
|
||||
}
|
||||
|
||||
}
|
||||
20
packages/identity/src/Identity.php
Normal file
20
packages/identity/src/Identity.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity;
|
||||
|
||||
use RuLong\Identity\Contracts\IdentityContracts;
|
||||
|
||||
class Identity
|
||||
{
|
||||
protected $contracts;
|
||||
|
||||
public function __construct(IdentityContracts $contracts)
|
||||
{
|
||||
$this->contracts = $contracts;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->contracts->fire();
|
||||
}
|
||||
}
|
||||
36
packages/identity/src/Models/Identity.php
Normal file
36
packages/identity/src/Models/Identity.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Models;
|
||||
|
||||
use App\Models\IdentityPrice;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Identity extends Model
|
||||
{
|
||||
//
|
||||
protected $casts = [
|
||||
'configs' => 'array',
|
||||
];
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany(IdentityPrice::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取身份指定日期的佣金设定值
|
||||
* @Date:2019-09-16T13:53:36+0800
|
||||
* @param string $date [Y-m-d H:i:s]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getPrice($date = '')
|
||||
{
|
||||
$date = $date ?: now()->endOfDay()->format('Y-m-d H:i:s');
|
||||
$info = IdentityPrice::where('identity_id', $this->id)->where('created_at', '<', $date)->orderBy('created_at', 'desc')->first();
|
||||
if ($info) {
|
||||
return $info->configs;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
packages/identity/src/Models/IdentityLog.php
Normal file
35
packages/identity/src/Models/IdentityLog.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IdentityLog extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'other' => 'array',
|
||||
];
|
||||
|
||||
//
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('user_account.user_model'))->withDefault();
|
||||
}
|
||||
|
||||
protected function getBeforeIdentityTitleAttribute()
|
||||
{
|
||||
return Identity::where('id', $this->before)->value('title') ?: '普通用户';
|
||||
}
|
||||
|
||||
protected function getIdentityTitleAttribute()
|
||||
{
|
||||
return Identity::where('id', $this->after)->value('title') ?: '';
|
||||
}
|
||||
|
||||
public function getChannelTextAttribute()
|
||||
{
|
||||
return config('rulong_identity.channel.' . $this->channel) ?? '无';
|
||||
}
|
||||
}
|
||||
15
packages/identity/src/Models/IdentityPoint.php
Normal file
15
packages/identity/src/Models/IdentityPoint.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IdentityPoint extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('user_account.user_model'), 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
38
packages/identity/src/Models/UserIdentity.php
Normal file
38
packages/identity/src/Models/UserIdentity.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserIdentity extends Model
|
||||
{
|
||||
protected $primaryKey = 'user_id';
|
||||
public $incrementing = false;
|
||||
protected $guarded = [];
|
||||
|
||||
public function info()
|
||||
{
|
||||
return $this->belongsTo(Identity::class, 'identity_id');
|
||||
}
|
||||
|
||||
public function logs()
|
||||
{
|
||||
return $this->hasMany(IdentityLog::class, 'user_id', 'user_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(config('user_account.user_model'))->withDefault();
|
||||
}
|
||||
|
||||
public function getEmptyTextAttribute()
|
||||
{
|
||||
$info = IdentityLog::where('channel', 'EmptyUp')->first();
|
||||
if ($info) {
|
||||
return "是";
|
||||
} else {
|
||||
return "否";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
34
packages/identity/src/ServiceProvider.php
Normal file
34
packages/identity/src/ServiceProvider.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||
|
||||
class ServiceProvider extends LaravelServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* 部署时加载
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-06-22T16:01:20+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->publishes([__DIR__ . '/../config/rulong_identity.php' => config_path('rulong_identity.php')]);
|
||||
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册服务提供者
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-06-22T16:01:12+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__ . '/../config/rulong_identity.php', 'rulong_identity');
|
||||
}
|
||||
}
|
||||
13
packages/identity/src/Traits/Identityable.php
Normal file
13
packages/identity/src/Traits/Identityable.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Traits;
|
||||
|
||||
use RuLong\Identity\Identity;
|
||||
|
||||
trait Identityable
|
||||
{
|
||||
public static function start()
|
||||
{
|
||||
return new Identity(new static(...func_get_args()));
|
||||
}
|
||||
}
|
||||
73
packages/identity/src/Traits/UserHasIdentity.php
Normal file
73
packages/identity/src/Traits/UserHasIdentity.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace RuLong\Identity\Traits;
|
||||
|
||||
use RuLong\Identity\Models\Identity;
|
||||
use RuLong\Identity\Models\UserIdentity;
|
||||
use \RuLong\Identity\Events\IdentityPoint;
|
||||
use \RuLong\Identity\Events\IdentityUpdate;
|
||||
use \RuLong\Identity\Models\IdentityPoint as IdentityPointModel;
|
||||
|
||||
trait UserHasIdentity
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取身份标题
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-09T17:00:39+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getIdentityTextAttribute()
|
||||
{
|
||||
return Identity::where('id', $this->identity->identity_id)->value('title') ?: config('rulong_identity.default_identity');
|
||||
}
|
||||
|
||||
public function getIdentityIdAttribute()
|
||||
{
|
||||
return $this->identity->identity_id;
|
||||
}
|
||||
|
||||
public function getNameTextAttribute()
|
||||
{
|
||||
return Identity::where('id', $this->identity->identity_id)->value('name') ?: config('rulong_identity.default_identity');
|
||||
}
|
||||
|
||||
public function pointlogs()
|
||||
{
|
||||
return $this->hasMany(IdentityPointModel::class);
|
||||
}
|
||||
|
||||
public function identity()
|
||||
{
|
||||
return $this->hasOne(UserIdentity::class)->withDefault(['identity_id' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* User模型涉及函数,辅助快速执行修改身份,
|
||||
* [identityUpdate description]
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-11-07T16:24:44+0800
|
||||
* @param [type] $id [身份ID]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function identityUpdate($id, $channel = 'AutoUp', $other = [])
|
||||
{
|
||||
$data = ['identity_id' => $id, 'channel' => $channel];
|
||||
if (!empty($other)) {
|
||||
$data = array_merge($data, $other);
|
||||
}
|
||||
return IdentityUpdate::start($this, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* User模型设计函数,辅助快速增加身份积分。
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-11-07T16:25:45+0800
|
||||
* @param [type] $id [description]
|
||||
* @param integer $point [description]
|
||||
*/
|
||||
public function addPoint($id, $point = 1)
|
||||
{
|
||||
return IdentityPoint::start($this, ['identity_id' => $id, 'point' => $point]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user