0
0

更新代码

This commit is contained in:
2020-08-04 10:09:42 +08:00
parent 6118b5b63b
commit c2ac5d964e
478 changed files with 34410 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,18 @@
<?php
return [
'user_model' => \App\User::class,
'Settlement' => [
'Direct' => [
'integral' => 200,
'layer' => 2, //两级分润
'point' => [
'1' => 100,
'2' => 15,
],
],
'Repeat' => 0.1,
],
'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,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/coupon",
"description": "",
"license": "MIT",
"authors": [
{
"name": "C.Jason",
"email": "chenjxlg@163.com"
}
],
"require": {
"php": ">=7.1.3",
"laravel/framework": "*"
},
"autoload": {
"psr-0": {
"RuLong\\Coupon": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"RuLong\\Coupon\\ServiceProvider"
]
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
return [
'user_model' => \App\User::class,
'type' => [
'direct' => '直购',
'discount' => '折扣',
'reduction' => '满减',
'lesson' => '报名课程',
'lottery' => '抽奖',
],
'time_type' => [
'specified' => '指定时间',
'obtain' => '获取后',
],
'channel' => [
'Buy' => '购买',
'Gift' => '赠与',
],
];

View File

@@ -0,0 +1,17 @@
<?php
namespace RuLong\Coupon;
class Coupon
{
protected $contracts;
public function __construct(IdentityContracts $contracts)
{
}
public function __destruct()
{
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace RuLong\Coupon\Models;
use RuLong\Coupon\Models\CouponUserLog;
use RuLong\Order\Contracts\Orderable;
class CouponInfo extends Model implements Orderable
{
protected $dates = [
'start_at',
'end_at',
];
//返回券码类型
public function getTypeTextAttribute()
{
return config('rulong_coupon.type')[$this->type] ?? '无';
}
public function seller()
{
return $this->belongsTo(Seller::class)->withDefault();
}
public function getStateAttribute()
{
//下架
if ($this->status != 1) {
return 2;
}
//未开始
if ($this->start_at > now()) {
return 0;
}
//已结束
if ($this->end_at < now()) {
return -1;
}
//正常
if ($this->start_at <= now() && $this->end_at >= now()) {
return 1;
}
}
protected function getStatusTextAttribute()
{
if ($this->state === 0) {
return "<span style='color:blue'>未开始</span>";
} elseif ($this->state == 1) {
return "<span style='color:green'>正常</span>";
} elseif ($this->state == -1) {
return "<span style='color:blue'>已过期</span>";
} elseif ($this->state == 2) {
return "<span style='color:red'>已下架</span>";
}
}
public function logs()
{
return $this->hasMany(CouponUserLog::class, 'coupon_id', 'id');
}
/**
* 是否可下架
* @Author:<ZhaoxiaWang>
* @Date:2018-12-10
* @return boolean
*/
public function canCancel(): bool
{
return $this->status == 1 ? true : false;
}
public function getTitle()
{
return $this->title . '-' . $this->bouns;
}
public function getPrice()
{
return $this->bouns;
}
public function getScore()
{
return 0;
}
public function getStock()
{
return 0;
}
public function getSellerPrice()
{
return $this->bouns;
}
public function deductStock($stock)
{
}
public function addStock($stock)
{
}
public function getStorage()
{
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace RuLong\Coupon\Models;
class CouponLog extends Model
{
//
}

View File

@@ -0,0 +1,8 @@
<?php
namespace RuLong\Coupon\Models;
class CouponRule extends Model
{
//
}

View File

@@ -0,0 +1,8 @@
<?php
namespace RuLong\Coupon\Models;
class CouponUse extends Model
{
//
}

View File

@@ -0,0 +1,19 @@
<?php
namespace RuLong\Coupon\Models;
use App\User;
use RuLong\Coupon\Models\CouponInfo;
class CouponUserLog extends Model
{
public function info()
{
return $this->belongsTo(CouponInfo::class, 'coupon_id', 'id');
}
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace RuLong\Coupon\Models;
use Illuminate\Database\Eloquent\Model as EloquentModel;
class Model extends EloquentModel
{
protected $guarded = [];
}

View File

@@ -0,0 +1,34 @@
<?php
namespace RuLong\Coupon;
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_coupon.php' => config_path('rulong_coupon.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_coupon.php', 'rulong_coupon');
}
}

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,8 @@
<?php
return [
'user_model' => \App\User::class,
'channel' => [
'AutoUp' => '自动升级',
'AdminUp' => '后台升级',
],
];

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,39 @@
<?php
namespace RuLong\Identity\Events;
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;
$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()
{
IdentityPointModel::create(['user_id' => $this->user->id, 'identity_id' => $this->identity_id, 'point' => $this->point]);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace RuLong\Identity\Events;
use RuLong\Identity\Contracts\IdentityContracts;
use RuLong\Identity\Models\Identity as IdentityModel;
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 $maxKey;
public function __construct($user, array $other = null)
{
$this->user = $user;
$this->identity_id = $other['identity_id'];
$this->channel = $other['channel'] ?? '';
$this->maxKey = $other['max_key'] ?? 0;
if ($this->channel == 'AdminUp') {
$info = IdentityModel::find($this->identity_id);
if ($other['pay'] == 1) {
$this->other = [
'full' => $info->configs['full'] ?? '',
'cost' => $info->configs['cost'] ?? '',
];
}
}
}
/**
* 创建及修改身份
* @Author:<Leady>
* @Date:2018-11-05T13:21:47+0800
* @return [type] [description]
*/
public function fire()
{
$before = 0;
if ($this->user->identity->identity_id === 0) {
$data = [
'user_id' => $this->user->id,
'identity_id' => $this->identity_id,
'max_key' => $this->maxKey,
];
UserIdentityModel::create($data);
} else {
$before = $this->user->identity->identity_id;
UserIdentityModel::where('user_id', $this->user->id)->update(['identity_id' => $this->identity_id, 'max_key' => $this->maxKey]);
}
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,13 @@
<?php
namespace RuLong\Identity\Models;
use Illuminate\Database\Eloquent\Model;
class Identity extends Model
{
//
protected $casts = [
'configs' => 'array',
];
}

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',
];
//
protected function user()
{
return $this->belongsTo(config('user_account.user_model'))->withDefault();
}
protected function getIdentityTitleAttribute()
{
return Identity::where('id', $this->after)->value('title') ?: '';
}
public function getChannelTextAttribute()
{
return config('rulong_identity.channel.' . $this->channel) ?? '无';
}
public function user_obj()
{
return $this->belongsTo(config('rulong_bonus.user_model'),'user_id','id');
}
}

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,81 @@
<?php
namespace RuLong\Identity\Models;
use Illuminate\Database\Eloquent\Model;
use RuLong\UserRelation\Models\UserRelation;
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 getActivationChildsAttribute()
{
$childrenIds = $this->user->children()->pluck('id'); //拉入直推会员ID
$direct = self::when($childrenIds, function ($query) use ($childrenIds) {
$query->whereIn('user_id', $childrenIds);
})->count() ?: 0;
return $direct;
}
public function childrentime($timeBetween = '')
{
$childrenIds = $this->user->children()->pluck('id'); //拉入直推会员ID
return self::when($childrenIds, function ($query) use ($childrenIds) {
$query->whereIn('user_id', $childrenIds);
})->when($timeBetween, function ($query) use ($timeBetween) {
$query->whereBetween('created_at', $timeBetween);
})->count() ?: 0;
}
public function user()
{
return $this->belongsTo(config('user_account.user_model'))->withDefault();
}
/**
* 按指定层数内获取推荐人ID
* @Author:<Leady>
* @Date:2018-12-06T11:45:44+0800
* @return [type] [description]
*/
public function relationid($layer = 6)
{
$users = UserRelation::where('bloodline', 'like', "%," . $this->user_id . ",%")->where('layer', '<=', $this->user->relation->layer + $layer)->pluck('user_id');
return $users; //拉入9层
}
/**
* 按指定层数获取推荐人ID
* @Author:<Leady>
* @Date:2018-12-06T11:45:44+0800
* @return [type] [description]
*/
public function realrelationid($layer = 6)
{
$users = UserRelation::where('bloodline', 'like', "%," . $this->user_id . ",%")->where('layer', $this->user->relation->layer + $layer)->pluck('user_id');
return $users; //拉入9层
}
public function getRelationCountAttribute()
{
$childrenIds = self::relationid(1); //拉入直推会员ID
$direct = self::when($childrenIds, function ($query) use ($childrenIds) {
$query->whereIn('user_id', $childrenIds);
})->count() ?: 0;
return $direct;
}
}

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,59 @@
<?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') ?: '注册用户';
}
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', $pay = 0, $max_key = 0)
{
return IdentityUpdate::start($this, ['identity_id' => $id, 'channel' => $channel, 'pay' => $pay, 'max_key' => $max_key]);
}
/**
* 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]);
}
}