diff --git a/app/Models/User.php b/app/Models/User.php index 763668ac..f9b774d7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -61,6 +61,21 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac 'status' => 'int', ]; + /** + * {@inheritdoc} + */ + protected static function booted() + { + parent::created(function ($user) { + //初始化钱包 + $user->wallet()->create(); + //初始化余额 + $user->balance()->create(); + //初始化经销商信息 + $user->dealer()->create(); + }); + } + /** * 属于此用户的个人信息 * @@ -379,6 +394,10 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac { $user = static::query()->create($attributes); + if ($inviter === null) { + $inviter = static::find(1); + } + // 邀请人的深度 $depth = (int) $inviter?->userInfo?->depth; @@ -386,15 +405,9 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac 'inviter_id' => $inviter?->id, 'depth' => $depth + 1, 'path' => Str::finish($inviter?->userInfo?->full_path, '-'), + 'real_inviter_id' => $inviter?->id, ]); - //初始化钱包 - $user->wallet()->create(); - //初始化余额 - $user->balance()->create(); - //初始化经销商信息 - $user->dealer()->create(); - return $user; } } diff --git a/app/Models/UserInfo.php b/app/Models/UserInfo.php index 2ddc988d..60ac21b8 100644 --- a/app/Models/UserInfo.php +++ b/app/Models/UserInfo.php @@ -60,6 +60,7 @@ class UserInfo extends Model 'growth_value', 'pre_growth_value', 'group_sales_value', + 'real_inviter_id', ]; /** diff --git a/database/migrations/2022_01_14_095902_add_real_inviter_id_to_user_infos_table.php b/database/migrations/2022_01_14_095902_add_real_inviter_id_to_user_infos_table.php new file mode 100644 index 00000000..b0558078 --- /dev/null +++ b/database/migrations/2022_01_14_095902_add_real_inviter_id_to_user_infos_table.php @@ -0,0 +1,32 @@ +unsignedBigInteger('real_inviter_id')->nullable()->comment('真实邀请人ID'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('user_infos', function (Blueprint $table) { + $table->dropColumn('real_inviter_id'); + }); + } +}