6
0
Fork 0

同步代理等级

release
李静 2022-01-18 13:46:11 +08:00
parent 2987b097d8
commit f22a9a7cc5
2 changed files with 23 additions and 12 deletions

View File

@ -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
*/

View File

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