mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
medal add bonus addition duration
This commit is contained in:
@@ -75,6 +75,14 @@ class MedalResource extends Resource
|
||||
->label(__('medal.fields.bonus_addition_factor'))
|
||||
->helperText(__('medal.fields.bonus_addition_factor_help'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(0)
|
||||
,
|
||||
Forms\Components\TextInput::make('bonus_addition_duration')
|
||||
->label(__('medal.fields.bonus_addition_duration'))
|
||||
->helperText(__('medal.fields.bonus_addition_duration_help'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(0)
|
||||
,
|
||||
Forms\Components\TextInput::make('gift_fee_factor')
|
||||
@@ -109,6 +117,7 @@ class MedalResource extends Resource
|
||||
->formatStateUsing(fn ($record) => new HtmlString(sprintf('%s ~<br/>%s', $record->sale_begin_time ?? nexus_trans('nexus.no_limit'), $record->sale_end_time ?? nexus_trans('nexus.no_limit'))))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('bonus_addition_factor')->label(__('medal.fields.bonus_addition_factor')),
|
||||
Tables\Columns\TextColumn::make('bonus_addition_duration')->label(__('medal.fields.bonus_addition_duration')),
|
||||
Tables\Columns\TextColumn::make('gift_fee_factor')->label(__('medal.fields.gift_fee_factor')),
|
||||
Tables\Columns\TextColumn::make('price')->label(__('label.price'))->formatStateUsing(fn ($state) => number_format($state)),
|
||||
|
||||
|
||||
@@ -18,7 +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', 'priority'
|
||||
'gift_fee_factor', 'priority', 'bonus_addition_duration'
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
class UserMedal extends NexusModel
|
||||
{
|
||||
protected $fillable = ['uid', 'medal_id', 'expire_at', 'status'];
|
||||
protected $fillable = ['uid', 'medal_id', 'expire_at', 'status', 'bonus_addition_expire_at'];
|
||||
|
||||
const STATUS_NOT_WEARING = 0;
|
||||
const STATUS_WEARING = 1;
|
||||
|
||||
@@ -70,11 +70,8 @@ class BonusRepository extends BaseRepository
|
||||
], $user->locale);
|
||||
do_log("comment: $comment");
|
||||
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_MEDAL, "$comment(medal ID: {$medal->id})");
|
||||
$expireAt = null;
|
||||
if ($medal->duration > 0) {
|
||||
$expireAt = Carbon::now()->addDays((int)$medal->duration)->toDateTimeString();
|
||||
}
|
||||
$user->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
||||
$medalRep = new MedalRepository();
|
||||
$medalRep->userAttachMedal($user, $medal);
|
||||
if ($medal->inventory !== null) {
|
||||
$affectedRows = NexusDB::table('medals')
|
||||
->where('id', $medal->id)
|
||||
|
||||
@@ -68,12 +68,27 @@ class MedalRepository extends BaseRepository
|
||||
if ($exists) {
|
||||
throw new \LogicException("user: $uid already own this medal: $medalId.");
|
||||
}
|
||||
$this->userAttachMedal($user, $medal);
|
||||
}
|
||||
|
||||
public function userAttachMedal(User $user, Medal $medal): void
|
||||
{
|
||||
$expireAt = null;
|
||||
if ($duration > 0) {
|
||||
$expireAt = Carbon::now()->addDays(intval($duration))->toDateTimeString();
|
||||
$bonusAdditionExpireAt = null;
|
||||
if ($medal->duration > 0) {
|
||||
$expireAt = Carbon::now()->addDays((int)$medal->duration)->toDateTimeString();
|
||||
}
|
||||
clear_user_cache($uid);
|
||||
return $user->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
||||
if ($medal->bonus_addition_duration > 0) {
|
||||
$bonusAdditionExpireAt = Carbon::now()->addDays((int)$medal->bonus_addition_duration)->toDateTimeString();
|
||||
}
|
||||
$user->medals()->attach([
|
||||
$medal->id => [
|
||||
'expire_at' => $expireAt,
|
||||
'bonus_addition_expire_at' => $bonusAdditionExpireAt,
|
||||
'status' => UserMedal::STATUS_NOT_WEARING,
|
||||
]
|
||||
]);
|
||||
clear_user_cache($user->id);
|
||||
}
|
||||
|
||||
public function toggleUserMedalStatus($id, $userId)
|
||||
|
||||
Reference in New Issue
Block a user