[admin] change uploaded & downloaded unit: GB

This commit is contained in:
xiaomlove
2022-05-10 22:08:41 +08:00
parent 3b9125d236
commit e7e708fd91
10 changed files with 91 additions and 26 deletions

View File

@@ -228,7 +228,7 @@
<DialogDisableUser ref="disableUser" :reload="fetchPageData" />
<DialogModComment ref="modComment" />
<DialogResetPassword ref="resetPassword" />
<DialogIncrementDecrement ref="incrementDecrement" :reload="fetchPageData" :title="dialogTitle" />
<DialogIncrementDecrement ref="incrementDecrement" :reload="fetchPageData" :title="dialogTitle" :valuePlaceholder="valuePlaceholder" />
</template>
<script>
@@ -266,7 +266,7 @@ export default {
baseInfo: {},
examInfo: null,
dialogTitle: '',
toChangeField: '',
valuePlaceholder: '',
})
onMounted(() => {
fetchPageData()
@@ -310,7 +310,11 @@ export default {
}
const handleIncrementDecrement = async (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)
}
const handleEnableUser = async () => {

View File

@@ -18,7 +18,7 @@
</el-radio-group>
</el-form-item>
<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 label="Reason" prop="reason">
<el-input type="textarea" v-model="formData.reason"></el-input>
@@ -43,7 +43,8 @@ export default {
name: "DialogIncrementDecrement",
props: {
reload: Function,
title: String
title: String,
valuePlaceholder: String
},
setup(props, context) {
const formRef = ref(null)

View File

@@ -152,7 +152,8 @@ class User extends Authenticatable
public static $commonFields = [
'id', 'username', 'email', 'class', 'status', 'added', 'avatar',
'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

View File

@@ -5,9 +5,11 @@ use App\Exceptions\NexusException;
use App\Http\Resources\ExamUserResource;
use App\Http\Resources\UserResource;
use App\Models\ExamUser;
use App\Models\Message;
use App\Models\Setting;
use App\Models\User;
use App\Models\UserBanLog;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Nexus\Database\NexusDB;
@@ -221,30 +223,60 @@ class UserRepository extends BaseRepository
$sourceField = $fieldMap[$field];
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
$old = $targetUser->{$sourceField};
$valueAtomic = $value;
if (in_array($field, ['uploaded', 'downloaded'])) {
//Frontend unit: GB
$valueAtomic = $value * 1024 * 1024 * 1024;
}
if ($action == 'Increment') {
$new = $old + abs($value);
$new = $old + abs($valueAtomic);
} elseif ($action == 'Decrement') {
$new = $old - abs($value);
$new = $old - abs($valueAtomic);
} else {
throw new \InvalidArgumentException("Invalid action: $action.");
}
$modCommentText = sprintf(
"%s - %s change from %s to %s by %s, reason: %s.",
date('Y-m-d'), $field, $old, $new, $operator->username, $reason
);
//for administrator, use english
$modCommentText = nexus_trans('message.field_value_change_message_body', [
'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");
$update = [
$sourceField => $new,
'modcomment' => NexusDB::raw("if(modcomment = '', '$modCommentText', concat_ws('\n', '$modCommentText', modcomment))"),
];
$affectedRows = User::query()
->where('id', $uid)
->where($sourceField, $old)
->update($update)
;
if ($affectedRows != 1) {
throw new \RuntimeException("Change fail, affected rows != 1($affectedRows)");
}
$locale = $targetUser->locale;
$fieldLabel = nexus_trans("user.labels.$sourceField", [], $locale);
$msg = nexus_trans('message.field_value_change_message_body', [
'field' => $fieldLabel,
'operator' => $operator->username,
'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;
}

View File

@@ -7,5 +7,7 @@ return [
],
'show' => [
'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',
];

View File

@@ -7,5 +7,12 @@ return [
'list' => [
'page_title' => 'User list'
]
]
],
'labels' => [
'seedbonus' => 'Bonus',
'seed_points' => 'Seed points',
'uploaded' => 'Uploaded',
'downloaded' => 'Downloaded',
'invites' => 'Invites',
],
];

View File

@@ -7,5 +7,7 @@ return [
],
'show' => [
'page_title' => '私信详情',
]
],
'field_value_change_message_body' => ':field 被管理员 :operator 从 :old 改为 :new。理由:reason。',
'field_value_change_message_subject' => ':field 改变',
];

View File

@@ -7,5 +7,12 @@ return [
'list' => [
'page_title' => '用户列表'
]
]
],
'labels' => [
'seedbonus' => '魔力',
'seed_points' => '做种积分',
'uploaded' => '上传量',
'downloaded' => '下载量',
'invites' => '邀请',
],
];

View File

@@ -7,5 +7,7 @@ return [
],
'show' => [
'page_title' => '私信詳情',
]
],
'field_value_change_message_body' => ':field 被管理員 :operator 從 :old 改為 :new。理由:reason。',
'field_value_change_message_subject' => ':field 改變',
];

View File

@@ -7,5 +7,12 @@ return [
'list' => [
'page_title' => '用戶列表'
]
]
],
'labels' => [
'seedbonus' => '魔力',
'seed_points' => '做種積分',
'uploaded' => '上傳量',
'downloaded' => '下載量',
'invites' => '邀請',
],
];