mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-16 05:50:55 +08:00
medal add gift_fee_factor and user_medal add priority
This commit is contained in:
@@ -18,6 +18,7 @@ class Medal extends NexusModel
|
||||
protected $fillable = [
|
||||
'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type',
|
||||
'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor',
|
||||
'gift_fee_factor',
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
@@ -55,6 +56,23 @@ class Medal extends NexusModel
|
||||
return nexus_trans("label.permanent");
|
||||
}
|
||||
|
||||
public function checkCanBeBuy()
|
||||
{
|
||||
if ($this->get_type == self::GET_TYPE_GRANT) {
|
||||
throw new \RuntimeException(nexus_trans('medal.grant_only'));
|
||||
}
|
||||
$now = now();
|
||||
if ($this->sale_begin_time && $this->sale_begin_time->gt($now)) {
|
||||
throw new \RuntimeException(nexus_trans('medal.before_sale_begin_time'));
|
||||
}
|
||||
if ($this->sale_end_time && $this->sale_end_time->lt($now)) {
|
||||
throw new \RuntimeException(nexus_trans('medal.after_sale_end_time'));
|
||||
}
|
||||
if ($this->inventory !== null && $this->inventory <= 0) {
|
||||
throw new \RuntimeException(nexus_trans('medal.inventory_empty'));
|
||||
}
|
||||
}
|
||||
|
||||
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_medals', 'medal_id', 'uid')->withTimestamps();
|
||||
|
||||
Reference in New Issue
Block a user