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