backend change class to vip can set until time

This commit is contained in:
xiaomlove
2023-06-16 01:26:27 +08:00
parent ae77dfa0f6
commit 8dfc125a37
12 changed files with 90 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Filament\Resources\User;
use App\Filament\Resources\User\UserMedalResource\Pages;
use App\Filament\Resources\User\UserMedalResource\RelationManagers;
use App\Models\Medal;
use App\Models\NexusModel;
use App\Models\UserMedal;
use Filament\Forms;
use Filament\Resources\Form;
@@ -57,6 +58,7 @@ class UserMedalResource extends Resource
Tables\Columns\TextColumn::make('medal.name')->label(__('label.medal.label'))->searchable(),
Tables\Columns\ImageColumn::make('medal.image_large')->label(__('label.image')),
Tables\Columns\TextColumn::make('expire_at')->label(__('label.expire_at'))->dateTime(),
Tables\Columns\TextColumn::make('wearingStatusText')->label(__('label.status')),
])
->defaultSort('id', 'desc')
->filters([
@@ -76,10 +78,13 @@ class UserMedalResource extends Resource
,
])
->actions([
Tables\Actions\DeleteAction::make(),
Tables\Actions\DeleteAction::make()->using(function (NexusModel $record) {
$record->delete();
clear_user_cache($record->uid);
})
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Resources\User;
use App\Filament\Resources\User\UserMetaResource\Pages;
use App\Filament\Resources\User\UserMetaResource\RelationManagers;
use App\Models\NexusModel;
use App\Models\UserMeta;
use Filament\Forms;
use Filament\Resources\Form;
@@ -12,6 +13,7 @@ use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\HtmlString;
class UserMetaResource extends Resource
@@ -81,10 +83,13 @@ class UserMetaResource extends Resource
,
])
->actions([
// Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()->using(function (NexusModel $record) {
$record->delete();
clear_user_cache($record->uid);
do_log(sprintf("user: %d meta: %s was del by %s", $record->uid, $record->meta_key, Auth::user()->username));
}),
])
->bulkActions([
// Tables\Actions\DeleteBulkAction::make(),
]);
}

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Resources\User\UserResource\Pages;
use App\Filament\OptionsTrait;
use App\Filament\Resources\User\UserResource;
use App\Models\Invite;
use App\Models\Medal;
@@ -24,6 +25,7 @@ class UserProfile extends ViewRecord
{
use InteractsWithRecord;
use HasRelationManagers;
use OptionsTrait;
private static $rep;
@@ -369,6 +371,20 @@ class UserProfile extends ViewRecord
->default($this->record->class)
->label(__('user.labels.class'))
->required()
->reactive()
,
Forms\Components\Radio::make('vip_added')
->options(self::getYesNoOptions('yes', 'no'))
->default($this->record->vip_added)
->label(__('user.labels.vip_added'))
->helperText(__('user.labels.vip_added_help'))
->hidden(fn (\Closure $get) => $get('class') != User::CLASS_VIP)
,
Forms\Components\DateTimePicker::make('vip_until')
->default($this->record->vip_until)
->label(__('user.labels.vip_until'))
->helperText(__('user.labels.vip_until_help'))
->hidden(fn (\Closure $get) => $get('class') != User::CLASS_VIP)
,
Forms\Components\TextInput::make('reason')
->label(__('admin.resources.user.actions.enable_disable_reason'))
@@ -378,7 +394,7 @@ class UserProfile extends ViewRecord
->action(function ($data) {
$userRep = $this->getRep();
try {
$userRep->changeClass(Auth::user(), $this->record, $data['class'], $data['reason']);
$userRep->changeClass(Auth::user(), $this->record, $data['class'], $data['reason'], $data);
$this->notify('success', 'Success!');
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
} catch (\Exception $exception) {

View File

@@ -9,6 +9,11 @@ class UserMedal extends NexusModel
const STATUS_NOT_WEARING = 0;
const STATUS_WEARING = 1;
public function getWearingStatusTextAttribute()
{
return nexus_trans("medal.wearing_status_text." . $this->status);
}
public function medal()
{
return $this->belongsTo(Medal::class, 'medal_id');

View File

@@ -468,7 +468,7 @@ class UserRepository extends BaseRepository
return true;
}
public function changeClass($operator, $targetUser, $newClass, $reason = ''): bool
public function changeClass($operator, $targetUser, $newClass, $reason = '', array $extra = []): bool
{
user_can('user-change-class', true);
$operator = $this->getUser($operator);
@@ -477,7 +477,7 @@ class UserRepository extends BaseRepository
if ($operator->class <= $targetUser->class || $operator->class <= $newClass)
throw new InsufficientPermissionException();
}
if ($targetUser->class == $newClass) {
if ($targetUser->class == $newClass && $newClass != User::CLASS_VIP) {
return true;
}
$locale = $targetUser->locale;
@@ -495,11 +495,34 @@ class UserRepository extends BaseRepository
'msg' => $body,
'added' => Carbon::now(),
];
NexusDB::transaction(function () use ($targetUser, $newClass, $message) {
$userUpdates = [
'class' => $newClass,
];
if ($newClass == User::CLASS_VIP) {
if (!empty($extra['vip_added']) && in_array($extra['vip_added'], ['yes', 'no'])) {
$userUpdates['vip_added'] = $extra['vip_added'];
} else {
$userUpdates['vip_added'] = 'no';
}
if (!empty($extra['vip_until'])) {
$until = Carbon::parse($extra['vip_until']);
$userUpdates['vip_until'] = $until;
} else {
$userUpdates['vip_until'] = null;
}
} else {
$userUpdates['vip_added'] = 'no';
$userUpdates['vip_until'] = null;
}
do_log("userUpdates: " . json_encode($userUpdates));
NexusDB::transaction(function () use ($targetUser, $userUpdates, $message) {
$modComment = date('Y-m-d') . " - " . $message['msg'];
$targetUser->updateWithModComment(['class' => $newClass], $modComment);
Message::add($message);
if ($targetUser->class != $userUpdates['class']) {
$targetUser->updateWithModComment($userUpdates, $modComment);
Message::add($message);
} else {
$targetUser->update($userUpdates);
}
$this->clearCache($targetUser);
});

View File

@@ -168,7 +168,7 @@ class Install
$disabledFunctions = [];
foreach ($this->requiredFunctions as $fn) {
if (str_starts_with($fn, "pcntl_")) {
if (str_starts_with($fn, "pcntl_") && function_exists('exec')) {
$phpPath = nexus_env('PHP_PATH') ?: 'php';
$exists = executeCommand("$phpPath -r 'var_export(function_exists(\"$fn\"));'") == 'true';
if (!$exists) {

View File

@@ -44,4 +44,8 @@ return [
'gift_btn' => 'Gift',
'confirm_to_gift' => 'Confirm to gift to user ',
'max_allow_wearing' => 'A maximum of :count medals can be worn at the same time',
'wearing_status_text' => [
0 => 'Wearing',
1 => 'Not wearing'
],
];

View File

@@ -17,6 +17,10 @@ return [
'attendance_card' => 'Attend card',
'props' => 'Props',
'class' => 'Class',
'vip_added' => 'VIP status is obtained by bonus',
'vip_added_help' => 'Is the VIP status redeemed by bonus.',
'vip_until' => 'VIP status end time',
'vip_until_help' => "The time format is 'Year-Year-Month-Day Hour:Minute:Second The time when the VIP status ends.' VIP status is obtained by bonus' must be set to 'Yes' for this rule to take effect.",
],
'class_names' => [
\App\Models\User::CLASS_VIP => 'Vip',

View File

@@ -44,4 +44,8 @@ return [
'gift_btn' => '赠送',
'confirm_to_gift' => '确定要赠送给用户 ',
'max_allow_wearing' => '最多允许同时佩戴 :count 个勋章',
'wearing_status_text' => [
0 => '未佩戴',
1 => '已佩戴'
],
];

View File

@@ -17,6 +17,10 @@ return [
'attendance_card' => '补签卡',
'props' => '道具',
'class' => '等级',
'vip_added' => '贵宾资格为通过魔力值获得',
'vip_added_help' => '该贵宾资格是否为通过魔力值换取。',
'vip_until' => '贵宾资格结束时间',
'vip_until_help' => "时间格式为'年年年年-月月-日日 时时:分分:秒秒'。贵宾资格结束的时间。'贵宾资格为通过魔力值获得'必须设为'是'此规则才能生效。",
],
'class_names' => [
\App\Models\User::CLASS_VIP => '贵宾',

View File

@@ -44,4 +44,8 @@ return [
'gift_btn' => '贈送',
'confirm_to_gift' => '確定要贈送給用戶 ',
'max_allow_wearing' => '最多允許同時佩戴 :count 個勛章',
'wearing_status_text' => [
0 => '未佩戴',
1 => '已佩戴'
],
];

View File

@@ -17,6 +17,10 @@ return [
'attendance_card' => '補簽卡',
'props' => '道具',
'class' => '等級',
'vip_added' => '貴賓資格為通過魔力值獲得',
'vip_added_help' => '該貴賓資格是否為通過魔力值換取。',
'vip_until' => '貴賓資格結束時間',
'vip_until_help' => "時間格式為'年年年年-月月-日日 時時:分分:秒秒'。貴賓資格結束的時間。'貴賓資格為通過魔力值獲得'必須設為'是'此規則才能生效。",
],
'class_names' => [
\App\Models\User::CLASS_VIP => '貴賓',