mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
grant medal
This commit is contained in:
@@ -24,3 +24,4 @@ yarn-error.log
|
|||||||
/imdb/cache
|
/imdb/cache
|
||||||
/imdb/images
|
/imdb/images
|
||||||
/resources/geoip
|
/resources/geoip
|
||||||
|
.DS_Store
|
||||||
|
|||||||
Generated
+1057
-891
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"element-plus": "^1.0.2-beta.44",
|
"element-plus": "^1.3.0-beta.5",
|
||||||
"vue": "^3.0.5",
|
"vue": "^3.0.5",
|
||||||
"vue-router": "^4.0.6"
|
"vue-router": "^4.0.6"
|
||||||
},
|
},
|
||||||
|
|||||||
Vendored
+1
-1
@@ -2,6 +2,6 @@ import { createApp } from 'vue'
|
|||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import ElementPlus from 'element-plus'
|
import ElementPlus from 'element-plus'
|
||||||
import router from './router/index'
|
import router from './router/index'
|
||||||
import 'element-plus/lib/theme-chalk/index.css'
|
import 'element-plus/theme-chalk/index.css'
|
||||||
import './styles/common.scss'
|
import './styles/common.scss'
|
||||||
createApp(App).use(ElementPlus).use(router).mount('#app')
|
createApp(App).use(ElementPlus).use(router).mount('#app')
|
||||||
|
|||||||
Vendored
+3
@@ -129,6 +129,9 @@ const api = {
|
|||||||
removeUserMedal: (id) => {
|
removeUserMedal: (id) => {
|
||||||
return axios.delete('user-medals/' + id);
|
return axios.delete('user-medals/' + id);
|
||||||
},
|
},
|
||||||
|
storeUserMedal: (params) => {
|
||||||
|
return axios.post('user-medals', params);
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
<el-button type="primary" size="mini" @click="handleGetModComment">Mod comment</el-button>
|
<el-button type="primary" size="mini" @click="handleGetModComment">Mod comment</el-button>
|
||||||
<el-button type="primary" size="mini" @click="handleResetPassword">Reset password</el-button>
|
<el-button type="primary" size="mini" @click="handleResetPassword">Reset password</el-button>
|
||||||
<el-button type="primary" size="mini" @click="handleAssignExam">Assign exam</el-button>
|
<el-button type="primary" size="mini" @click="handleAssignExam">Assign exam</el-button>
|
||||||
|
<el-button type="primary" size="mini" @click="handleGrantMedal">Grant medal</el-button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -206,6 +207,7 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
<DialogAssignExam ref="assignExam" :reload="fetchPageData"/>
|
<DialogAssignExam ref="assignExam" :reload="fetchPageData"/>
|
||||||
|
<DialogGrantMedal ref="grantMedal" :reload="fetchPageData"/>
|
||||||
<DialogViewInviteInfo ref="viewInviteInfo" />
|
<DialogViewInviteInfo ref="viewInviteInfo" />
|
||||||
<DialogDisableUser ref="disableUser" :reload="fetchPageData" />
|
<DialogDisableUser ref="disableUser" :reload="fetchPageData" />
|
||||||
<DialogModComment ref="modComment" />
|
<DialogModComment ref="modComment" />
|
||||||
@@ -222,17 +224,19 @@ import DialogViewInviteInfo from './dialog-invite-info.vue'
|
|||||||
import DialogDisableUser from './dialog-disable-user.vue'
|
import DialogDisableUser from './dialog-disable-user.vue'
|
||||||
import DialogModComment from './dialog-mod-comment.vue'
|
import DialogModComment from './dialog-mod-comment.vue'
|
||||||
import DialogResetPassword from './dialog-reset-password.vue'
|
import DialogResetPassword from './dialog-reset-password.vue'
|
||||||
|
import DialogGrantMedal from './dialog-grant-medal.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "UserDetail",
|
name: "UserDetail",
|
||||||
components: {
|
components: {
|
||||||
DialogAssignExam, DialogViewInviteInfo, DialogDisableUser, DialogModComment, DialogResetPassword
|
DialogAssignExam, DialogViewInviteInfo, DialogDisableUser, DialogModComment, DialogResetPassword, DialogGrantMedal
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { id } = route.query
|
const { id } = route.query
|
||||||
const assignExam = ref(null)
|
const assignExam = ref(null)
|
||||||
|
const grantMedal = ref(null)
|
||||||
const viewInviteInfo = ref(null)
|
const viewInviteInfo = ref(null)
|
||||||
const disableUser = ref(null)
|
const disableUser = ref(null)
|
||||||
const modComment = ref(null)
|
const modComment = ref(null)
|
||||||
@@ -273,6 +277,9 @@ export default {
|
|||||||
const handleAssignExam = async () => {
|
const handleAssignExam = async () => {
|
||||||
assignExam.value.open(id)
|
assignExam.value.open(id)
|
||||||
}
|
}
|
||||||
|
const handleGrantMedal = async () => {
|
||||||
|
grantMedal.value.open(id)
|
||||||
|
}
|
||||||
const handleViewInviteInfo = async () => {
|
const handleViewInviteInfo = async () => {
|
||||||
viewInviteInfo.value.open(id)
|
viewInviteInfo.value.open(id)
|
||||||
}
|
}
|
||||||
@@ -301,6 +308,7 @@ export default {
|
|||||||
handleRemoveExam,
|
handleRemoveExam,
|
||||||
handleAvoidExam,
|
handleAvoidExam,
|
||||||
handleAssignExam,
|
handleAssignExam,
|
||||||
|
handleGrantMedal,
|
||||||
handleRecoverExam,
|
handleRecoverExam,
|
||||||
handleEnableUser,
|
handleEnableUser,
|
||||||
handleViewInviteInfo,
|
handleViewInviteInfo,
|
||||||
@@ -310,6 +318,7 @@ export default {
|
|||||||
fetchPageData,
|
fetchPageData,
|
||||||
handleRemoveUserMedal,
|
handleRemoveUserMedal,
|
||||||
assignExam,
|
assignExam,
|
||||||
|
grantMedal,
|
||||||
viewInviteInfo,
|
viewInviteInfo,
|
||||||
disableUser,
|
disableUser,
|
||||||
modComment,
|
modComment,
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
title="Grant medal to user"
|
||||||
|
v-model="visible"
|
||||||
|
center
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
:model="formData"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="loading"
|
||||||
|
ref="formRef"
|
||||||
|
:rules="rules">
|
||||||
|
<el-form-item label="Medal" prop="medal_id">
|
||||||
|
<el-select v-model="formData.medal_id" placeholder="Select an medal...">
|
||||||
|
<el-option
|
||||||
|
v-for="item in medals"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
:value="item.id">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="Duration" prop="duration">
|
||||||
|
<el-input v-model="formData.duration" placeholder="Unit: day, if empty, it's valid forever"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="visible = false">Cancel</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit">Save</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { onMounted, reactive, ref, toRefs } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import {useRoute, useRouter} from 'vue-router'
|
||||||
|
import api from '../../utils/api'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "DialogGrantMedal",
|
||||||
|
props: {
|
||||||
|
reload: Function
|
||||||
|
},
|
||||||
|
setup(props, context) {
|
||||||
|
const formRef = ref(null)
|
||||||
|
const state = reactive({
|
||||||
|
loading: false,
|
||||||
|
medals: [],
|
||||||
|
visible: false,
|
||||||
|
formData: {
|
||||||
|
uid: 0,
|
||||||
|
medal_id: '',
|
||||||
|
duration: '',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
medal_id: [{ required: 'true'}]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const listMedals = async () => {
|
||||||
|
let res = await api.listMedal()
|
||||||
|
state.medals = res.data.data
|
||||||
|
}
|
||||||
|
const open = (uid) => {
|
||||||
|
state.formData.uid = uid
|
||||||
|
if (state.medals.length == 0) {
|
||||||
|
state.loading = true
|
||||||
|
listMedals()
|
||||||
|
state.loading = false
|
||||||
|
}
|
||||||
|
state.visible = true
|
||||||
|
|
||||||
|
}
|
||||||
|
const handleSubmit = () => {
|
||||||
|
formRef.value.validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
let res = await api.storeUserMedal(state.formData)
|
||||||
|
state.visible = false
|
||||||
|
ElMessage.success(res.msg)
|
||||||
|
if (props.reload) {
|
||||||
|
props.reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
handleSubmit,
|
||||||
|
formRef,
|
||||||
|
open,
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -42,16 +42,13 @@ class UserMedalController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|string',
|
'medal_id' => 'required|integer',
|
||||||
'price' => 'required|integer|min:1',
|
'uid' => 'required|integer',
|
||||||
'image_large' => 'required|url',
|
|
||||||
'image_small' => 'required|url',
|
|
||||||
'duration' => 'nullable|integer|min:-1',
|
'duration' => 'nullable|integer|min:-1',
|
||||||
];
|
];
|
||||||
$request->validate($rules);
|
$request->validate($rules);
|
||||||
$result = $this->repository->store($request->all());
|
$result = $this->repository->grantToUser($request->uid, $request->medal_id, $request->duration);
|
||||||
$resource = new MedalResource($result);
|
return $this->success($result);
|
||||||
return $this->success($resource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
use App\Models\Medal;
|
use App\Models\Medal;
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\UserMedal;
|
use App\Models\UserMedal;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Nexus\Database\NexusDB;
|
use Nexus\Database\NexusDB;
|
||||||
|
|
||||||
class MedalRepository extends BaseRepository
|
class MedalRepository extends BaseRepository
|
||||||
@@ -51,4 +53,20 @@ class MedalRepository extends BaseRepository
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function grantToUser(int $uid, int $medalId, $duration = null)
|
||||||
|
{
|
||||||
|
$user = User::query()->findOrFail($uid, User::$commonFields);
|
||||||
|
$medal = Medal::query()->findOrFail($medalId);
|
||||||
|
$exists = $user->valid_medals()->where('medal_id', $medalId)->exists();
|
||||||
|
do_log(last_query());
|
||||||
|
if ($exists) {
|
||||||
|
throw new \LogicException("user: $uid already own this medal: $medalId.");
|
||||||
|
}
|
||||||
|
$expireAt = null;
|
||||||
|
if ($duration > 0) {
|
||||||
|
$expireAt = Carbon::now()->addDays($duration)->toDateTimeString();
|
||||||
|
}
|
||||||
|
return $user->medals()->attach([$medal->id => ['expire_at' => $expireAt]]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1831
-1860
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user