vip会员支持补差升级
This commit is contained in:
+37
-1
@@ -73,11 +73,47 @@ class VipLevel extends Model
|
||||
'exp_multiplier' => 'float',
|
||||
'jjb_multiplier' => 'float',
|
||||
'sort_order' => 'integer',
|
||||
'price' => 'integer',
|
||||
'price' => 'float',
|
||||
'duration_days' => 'integer',
|
||||
'allow_custom_messages' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* 判断当前等级是否高于指定等级。
|
||||
* 依靠 sort_order 判断。
|
||||
*/
|
||||
public function isHigherThan(self|int|null $other): bool
|
||||
{
|
||||
if ($other === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$otherOrder = ($other instanceof self)
|
||||
? $other->sort_order
|
||||
: self::where('id', $other)->value('sort_order') ?? 0;
|
||||
|
||||
return $this->sort_order > $otherOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算相对于另一个等级的差价。
|
||||
* 如果当前等级价格更低,则返回 0。
|
||||
*/
|
||||
public function getUpgradePrice(self|int|null $other): float
|
||||
{
|
||||
if ($other === null) {
|
||||
return (float) $this->price;
|
||||
}
|
||||
|
||||
$otherPrice = ($other instanceof self)
|
||||
? (float) $other->price
|
||||
: (float) (self::where('id', $other)->value('price') ?? 0);
|
||||
|
||||
$diff = (float) $this->price - $otherPrice;
|
||||
|
||||
return max(0.0, $diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联:该等级下的所有用户
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user