mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
[admin] change uploaded & downloaded unit: GB
This commit is contained in:
@@ -228,7 +228,7 @@
|
|||||||
<DialogDisableUser ref="disableUser" :reload="fetchPageData" />
|
<DialogDisableUser ref="disableUser" :reload="fetchPageData" />
|
||||||
<DialogModComment ref="modComment" />
|
<DialogModComment ref="modComment" />
|
||||||
<DialogResetPassword ref="resetPassword" />
|
<DialogResetPassword ref="resetPassword" />
|
||||||
<DialogIncrementDecrement ref="incrementDecrement" :reload="fetchPageData" :title="dialogTitle" />
|
<DialogIncrementDecrement ref="incrementDecrement" :reload="fetchPageData" :title="dialogTitle" :valuePlaceholder="valuePlaceholder" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -266,7 +266,7 @@ export default {
|
|||||||
baseInfo: {},
|
baseInfo: {},
|
||||||
examInfo: null,
|
examInfo: null,
|
||||||
dialogTitle: '',
|
dialogTitle: '',
|
||||||
toChangeField: '',
|
valuePlaceholder: '',
|
||||||
})
|
})
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchPageData()
|
fetchPageData()
|
||||||
@@ -310,7 +310,11 @@ export default {
|
|||||||
}
|
}
|
||||||
const handleIncrementDecrement = async (field) => {
|
const handleIncrementDecrement = async (field) => {
|
||||||
state.dialogTitle = 'Change ' + field
|
state.dialogTitle = 'Change ' + field
|
||||||
state.toChangeField = field
|
if (['uploaded', 'downloaded'].includes(field)) {
|
||||||
|
state.valuePlaceholder = 'Unit: GB'
|
||||||
|
} else {
|
||||||
|
state.valuePlaceholder = ''
|
||||||
|
}
|
||||||
incrementDecrement.value.open(id, field)
|
incrementDecrement.value.open(id, field)
|
||||||
}
|
}
|
||||||
const handleEnableUser = async () => {
|
const handleEnableUser = async () => {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Value" prop="value">
|
<el-form-item label="Value" prop="value">
|
||||||
<el-input v-model="formData.value" type="number" />
|
<el-input v-model="formData.value" type="number" :placeholder="valuePlaceholder" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="Reason" prop="reason">
|
<el-form-item label="Reason" prop="reason">
|
||||||
<el-input type="textarea" v-model="formData.reason"></el-input>
|
<el-input type="textarea" v-model="formData.reason"></el-input>
|
||||||
@@ -43,7 +43,8 @@ export default {
|
|||||||
name: "DialogIncrementDecrement",
|
name: "DialogIncrementDecrement",
|
||||||
props: {
|
props: {
|
||||||
reload: Function,
|
reload: Function,
|
||||||
title: String
|
title: String,
|
||||||
|
valuePlaceholder: String
|
||||||
},
|
},
|
||||||
setup(props, context) {
|
setup(props, context) {
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
|
|||||||
+2
-1
@@ -152,7 +152,8 @@ class User extends Authenticatable
|
|||||||
public static $commonFields = [
|
public static $commonFields = [
|
||||||
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
|
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
|
||||||
'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime',
|
'uploaded', 'downloaded', 'seedbonus', 'seedtime', 'leechtime',
|
||||||
'invited_by', 'enabled', 'seed_points', 'last_access', 'invites'
|
'invited_by', 'enabled', 'seed_points', 'last_access', 'invites',
|
||||||
|
'lang',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function getDefaultUserAttributes(): array
|
public static function getDefaultUserAttributes(): array
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ use App\Exceptions\NexusException;
|
|||||||
use App\Http\Resources\ExamUserResource;
|
use App\Http\Resources\ExamUserResource;
|
||||||
use App\Http\Resources\UserResource;
|
use App\Http\Resources\UserResource;
|
||||||
use App\Models\ExamUser;
|
use App\Models\ExamUser;
|
||||||
|
use App\Models\Message;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserBanLog;
|
use App\Models\UserBanLog;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Nexus\Database\NexusDB;
|
use Nexus\Database\NexusDB;
|
||||||
@@ -221,30 +223,60 @@ class UserRepository extends BaseRepository
|
|||||||
$sourceField = $fieldMap[$field];
|
$sourceField = $fieldMap[$field];
|
||||||
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
|
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
|
||||||
$old = $targetUser->{$sourceField};
|
$old = $targetUser->{$sourceField};
|
||||||
|
$valueAtomic = $value;
|
||||||
|
if (in_array($field, ['uploaded', 'downloaded'])) {
|
||||||
|
//Frontend unit: GB
|
||||||
|
$valueAtomic = $value * 1024 * 1024 * 1024;
|
||||||
|
}
|
||||||
if ($action == 'Increment') {
|
if ($action == 'Increment') {
|
||||||
$new = $old + abs($value);
|
$new = $old + abs($valueAtomic);
|
||||||
} elseif ($action == 'Decrement') {
|
} elseif ($action == 'Decrement') {
|
||||||
$new = $old - abs($value);
|
$new = $old - abs($valueAtomic);
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException("Invalid action: $action.");
|
throw new \InvalidArgumentException("Invalid action: $action.");
|
||||||
}
|
}
|
||||||
$modCommentText = sprintf(
|
//for administrator, use english
|
||||||
"%s - %s change from %s to %s by %s, reason: %s.",
|
$modCommentText = nexus_trans('message.field_value_change_message_body', [
|
||||||
date('Y-m-d'), $field, $old, $new, $operator->username, $reason
|
'field' => nexus_trans("user.labels.$sourceField", [], 'en'),
|
||||||
);
|
'operator' => $operator->username,
|
||||||
|
'old' => $old,
|
||||||
|
'new' => $new,
|
||||||
|
'reason' => $reason,
|
||||||
|
], 'en');
|
||||||
|
$modCommentText = date('Y-m-d') . " - $modCommentText";
|
||||||
do_log("user: $uid, $modCommentText");
|
do_log("user: $uid, $modCommentText");
|
||||||
$update = [
|
$update = [
|
||||||
$sourceField => $new,
|
$sourceField => $new,
|
||||||
'modcomment' => NexusDB::raw("if(modcomment = '', '$modCommentText', concat_ws('\n', '$modCommentText', modcomment))"),
|
'modcomment' => NexusDB::raw("if(modcomment = '', '$modCommentText', concat_ws('\n', '$modCommentText', modcomment))"),
|
||||||
];
|
];
|
||||||
$affectedRows = User::query()
|
|
||||||
->where('id', $uid)
|
$locale = $targetUser->locale;
|
||||||
->where($sourceField, $old)
|
$fieldLabel = nexus_trans("user.labels.$sourceField", [], $locale);
|
||||||
->update($update)
|
$msg = nexus_trans('message.field_value_change_message_body', [
|
||||||
;
|
'field' => $fieldLabel,
|
||||||
if ($affectedRows != 1) {
|
'operator' => $operator->username,
|
||||||
throw new \RuntimeException("Change fail, affected rows != 1($affectedRows)");
|
'old' => $old,
|
||||||
}
|
'new' => $new,
|
||||||
|
'reason' => $reason,
|
||||||
|
], $locale);
|
||||||
|
$message = [
|
||||||
|
'sender' => 0,
|
||||||
|
'receiver' => $targetUser->id,
|
||||||
|
'subject' => nexus_trans("message.field_value_change_message_subject", ['field' => $fieldLabel], $locale),
|
||||||
|
'msg' => $msg,
|
||||||
|
'added' => Carbon::now(),
|
||||||
|
];
|
||||||
|
NexusDB::transaction(function () use ($uid, $sourceField, $old, $new, $update, $message) {
|
||||||
|
$affectedRows = User::query()
|
||||||
|
->where('id', $uid)
|
||||||
|
->where($sourceField, $old)
|
||||||
|
->update($update)
|
||||||
|
;
|
||||||
|
if ($affectedRows != 1) {
|
||||||
|
throw new \RuntimeException("Change fail, affected rows != 1($affectedRows)");
|
||||||
|
}
|
||||||
|
Message::query()->insert($message);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ return [
|
|||||||
],
|
],
|
||||||
'show' => [
|
'show' => [
|
||||||
'page_title' => 'Message detail',
|
'page_title' => 'Message detail',
|
||||||
]
|
],
|
||||||
|
'field_value_change_message_body' => ':field is changed from :old to :new by :operator. Reason::reason.',
|
||||||
|
'field_value_change_message_subject' => ':field changed',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,5 +7,12 @@ return [
|
|||||||
'list' => [
|
'list' => [
|
||||||
'page_title' => 'User list'
|
'page_title' => 'User list'
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
'labels' => [
|
||||||
|
'seedbonus' => 'Bonus',
|
||||||
|
'seed_points' => 'Seed points',
|
||||||
|
'uploaded' => 'Uploaded',
|
||||||
|
'downloaded' => 'Downloaded',
|
||||||
|
'invites' => 'Invites',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ return [
|
|||||||
],
|
],
|
||||||
'show' => [
|
'show' => [
|
||||||
'page_title' => '私信详情',
|
'page_title' => '私信详情',
|
||||||
]
|
],
|
||||||
|
'field_value_change_message_body' => ':field 被管理员 :operator 从 :old 改为 :new。理由::reason。',
|
||||||
|
'field_value_change_message_subject' => ':field 改变',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,5 +7,12 @@ return [
|
|||||||
'list' => [
|
'list' => [
|
||||||
'page_title' => '用户列表'
|
'page_title' => '用户列表'
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
'labels' => [
|
||||||
|
'seedbonus' => '魔力',
|
||||||
|
'seed_points' => '做种积分',
|
||||||
|
'uploaded' => '上传量',
|
||||||
|
'downloaded' => '下载量',
|
||||||
|
'invites' => '邀请',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ return [
|
|||||||
],
|
],
|
||||||
'show' => [
|
'show' => [
|
||||||
'page_title' => '私信詳情',
|
'page_title' => '私信詳情',
|
||||||
]
|
],
|
||||||
|
'field_value_change_message_body' => ':field 被管理員 :operator 從 :old 改為 :new。理由::reason。',
|
||||||
|
'field_value_change_message_subject' => ':field 改變',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,5 +7,12 @@ return [
|
|||||||
'list' => [
|
'list' => [
|
||||||
'page_title' => '用戶列表'
|
'page_title' => '用戶列表'
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
'labels' => [
|
||||||
|
'seedbonus' => '魔力',
|
||||||
|
'seed_points' => '做種積分',
|
||||||
|
'uploaded' => '上傳量',
|
||||||
|
'downloaded' => '下載量',
|
||||||
|
'invites' => '邀請',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user