1
0

提交代码

This commit is contained in:
2020-08-06 14:45:56 +08:00
commit 9d0d5f4be9
361 changed files with 36445 additions and 0 deletions

2
packages/bonus/README.md Normal file
View File

@@ -0,0 +1,2 @@
# Bonus 奖金结算系统

View 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"
]
}
}
}

View File

@@ -0,0 +1,13 @@
<?php
return [
'user_model' => \App\Models\User::class,
'Settlement' => [
'Direct' => [
'integral' => 100,
'layer' => 9,
'point' => 5,
],
],
'full_point' => 10,
];

View 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();
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace RuLong\Bonus\Contracts;
interface Settlement
{
/**
* 子规则的实际计算过程
* @Author:<C.Jason>
* @Date:2018-10-31T14:22:48+0800
*/
function fire();
}

View File

@@ -0,0 +1,14 @@
<?php
namespace RuLong\Bonus\Exceptions;
use RuntimeException;
class BonusException extends RuntimeException
{
public function __construct($message)
{
parent::__construct($message);
}
}

View 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);
}
}

View 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'));
}
}

View 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');
}
}

View 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();
}
}

View 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()));
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace RuLong\Bonus\Traits;
trait UserHasBonus
{
}

View 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)

View 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"
]
}
}
}

View File

@@ -0,0 +1,9 @@
<?php
return [
'user_model' => \App\Models\User::class,
'channel' => [
'AutoUp' => '自动升级',
'EmptyUp' => '后台升级',
],
'default_identity' => '普通用户',
];

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace RuLong\Identity\Contracts;
interface IdentityContracts
{
/**
* 子规则的实际计算过程
* @Author:<C.Jason>
* @Date:2018-10-31T14:22:48+0800
*/
function fire();
}

View 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,
]);
}
}

View 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]);
}
}

View 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();
}
}

View 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;
}
}
}

View 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) ?? '无';
}
}

View 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');
}
}

View 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 "";
}
}
}

View 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');
}
}

View 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()));
}
}

View 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]);
}
}