From f22a9a7cc5dc350b10bc69ee86d78687c6e7acbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 18 Jan 2022 13:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=90=86=E7=AD=89?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/DealerLvl.php | 15 +++++++++++++++ app/Models/Dealer.php | 20 ++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/Enums/DealerLvl.php b/app/Enums/DealerLvl.php index 86ae791a..ff05420b 100644 --- a/app/Enums/DealerLvl.php +++ b/app/Enums/DealerLvl.php @@ -10,6 +10,21 @@ enum DealerLvl: int { case Secondary = 5; case Top = 6; + /** + * 代理等级 + */ + public function agentLvl() + { + return match ($this) { + static::None => 1, + static::Gold => 3, + static::Special => 4, + static::Contracted => 5, + static::Secondary => 6, + static::Top => 7, + }; + } + /** * @return string */ diff --git a/app/Models/Dealer.php b/app/Models/Dealer.php index 732a1920..fbed1f50 100644 --- a/app/Models/Dealer.php +++ b/app/Models/Dealer.php @@ -34,18 +34,6 @@ class Dealer extends Model 'contracted_lvl_at', ]; - /** - * {@inheritdoc} - */ - protected static function booted() - { - static::creating(function ($dealer) { - if ($dealer->last_upgrade_at === null) { - $dealer->last_upgrade_at = now(); - } - }); - } - public function user() { return $this->belongsTo(User::class, 'user_id'); @@ -179,5 +167,13 @@ class Dealer extends Model 'change_lvl' => $lvl, 'remark' => $remark, ]); + + // 变更代理等级 + $mapAgentLvl = $this->lvl->agentLvl(); + + if ($this->userInfo->agent_level < $mapAgentLvl) { + $this->userInfo->agent_level = $mapAgentLvl; + $this->userInfo->save(); + } } }