From 75d98b5f7175e19c7e254fd778430adca19ab9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Fri, 14 Jan 2022 10:35:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E9=82=80=E8=AF=B7=E4=BA=BAID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/User.php | 27 ++++++++++++---- app/Models/UserInfo.php | 1 + ...dd_real_inviter_id_to_user_infos_table.php | 32 +++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 database/migrations/2022_01_14_095902_add_real_inviter_id_to_user_infos_table.php 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'); + }); + } +}