mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
medal add gift_fee_factor and user_medal add priority
This commit is contained in:
@@ -32,6 +32,7 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_BUY_TEMPORARY_INVITE = 15;
|
||||
const BUSINESS_TYPE_BUY_RAINBOW_ID = 16;
|
||||
const BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD = 17;
|
||||
const BUSINESS_TYPE_GIFT_MEDAL = 18;
|
||||
|
||||
public static array $businessTypes = [
|
||||
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
|
||||
@@ -51,6 +52,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_BUY_TEMPORARY_INVITE => ['text' => 'Buy temporary invite'],
|
||||
self::BUSINESS_TYPE_BUY_RAINBOW_ID => ['text' => 'Buy rainbow ID'],
|
||||
self::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD => ['text' => 'Buy change username card'],
|
||||
self::BUSINESS_TYPE_GIFT_MEDAL => ['text' => 'Gift medal to someone'],
|
||||
];
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -459,9 +459,9 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
public function medals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Medal::class, 'user_medals', 'uid', 'medal_id')
|
||||
->withPivot(['id', 'expire_at', 'status'])
|
||||
->withPivot(['id', 'expire_at', 'status', 'priority'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('id', 'desc')
|
||||
->orderByPivot('priority', 'desc')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user