Browse Source

新增個人資訊查詢

maa3606 2 years ago
parent
commit
5c23e4bde4

+ 18 - 0
app/Http/Controllers/DrawController.php

@@ -82,4 +82,22 @@ class DrawController extends Controller
     {
         return 'success';
     }
+
+    public function search_user_status(Request $request)
+    {
+        return CheckIn::where('check_ins.activity_id', $request->activity_id)
+            ->leftjoin('recipients', 'check_ins.user_id', '=', 'recipients.user_id')
+            ->leftjoin('prizes', 'recipients.prize_id', '=', 'prizes.id')
+            ->select(
+                'check_ins.user_id',
+                'check_ins.name as user_name',
+                'check_ins.department_id',
+                'prizes.name as prize_name',
+                'check_ins.is_checked_in',
+                'check_ins.is_awarded',
+                'recipients.is_claimed'
+            )
+            ->where('check_ins.user_id', $request->user_id)
+            ->first();
+    }
 }

+ 22 - 0
resources/js/src/router/config.js

@@ -230,6 +230,28 @@ export const settings = {
 
             },
         },
+        {
+            path: '/search/:activity_id',
+            name: 'search',
+            component: () => import('@/views/lottery/Search.vue'),
+            meta: {
+                pageTitle: '查詢系統',
+                breadcrumb: [{
+                        text: '活動列表',
+                        to: '/activityList'
+                    },
+                    {
+                        text: '活動功能頁面',
+                        to: '/activityPage'
+                    },
+                    {
+                        text: '查詢系統',
+                        active: true,
+                    },
+                ],
+                requiresAuth: true,
+            },
+        },
     ],
 }
 export const _ = undefined

+ 8 - 0
resources/js/src/views/lottery/Activities/ActivityPage.vue

@@ -67,6 +67,14 @@
                     </b-card-body>
                 </b-card>
             </b-col>
+            <b-col md="6" :lg="lg">
+                <b-card no-body border-variant="info" class="text-center">
+                    <b-card-body>
+                        <b-button variant="success"
+                            :to="{ name: 'search', params: { 'activity_id': this.$route.params.activity_id } }">查詢個人資訊</b-button>
+                    </b-card-body>
+                </b-card>
+            </b-col>
         </b-row>
     </div>
 </template>

+ 148 - 0
resources/js/src/views/lottery/Search.vue

@@ -0,0 +1,148 @@
+<template>
+    <div>
+        <b-row>
+            <b-col md="12">
+                <b-card title="輸入工號查詢個人資訊">
+                    <b-input-group prepend="編號" class="mt-3">
+                        <b-form-input v-model="user_id" @keydown.native="keyListener"
+                            placeholder="請輸入員工編號或來賓編號..."></b-form-input>
+                        <b-input-group-append>
+                            <b-button @click="getUserStatus" variant="info">送出</b-button>
+                        </b-input-group-append>
+                    </b-input-group>
+                </b-card>
+            </b-col>
+        </b-row>
+        <b-row>
+            <b-col md="12">
+                <b-card>
+                    <b-row>
+                        <b-col>
+                            <b-img :src="avatar(searchData.user_id)" blank-color="#ccc" fluid alt="placeholder"
+                                onerror="this.src='/images/error.png'" />
+                        </b-col>
+                        <b-col>
+                            <div style="font-size: 2rem;">
+                                <div>
+                                    <span style="color: #0085DD">
+                                        姓名
+                                    </span>
+                                    <span>
+                                        {{ searchData.user_name }}
+                                    </span>
+                                </div>
+                                <div>
+                                    <span style="color: #0085DD">
+                                        工號
+                                    </span>
+                                    <span>
+                                        {{ searchData.user_id }}
+                                    </span>
+                                </div>
+                                <div>
+                                    <span style="color: #0085DD">
+                                        部門
+                                    </span>
+                                    <span>
+                                        {{ departmentList[searchData.department_id] }}
+                                    </span>
+                                </div>
+                                <div>
+                                    <span :style="statusColoer(searchData.is_checked_in)">
+                                        {{ checkinStatus(searchData.is_checked_in) }}
+                                    </span>
+                                </div>
+                                <div v-if="searchData.is_checked_in">
+                                    <span :style="statusColoer(searchData.is_awarded)">
+                                        {{ awardStatus(searchData.is_awarded, searchData.prize_name) }}
+                                    </span>
+                                </div>
+                                <div v-if="searchData.prize_name">
+                                    <span :style="statusColoer(searchData.is_claimed)">
+                                        {{ claimStatus(searchData.is_claimed) }}
+                                    </span>
+                                </div>
+                            </div>
+                        </b-col>
+                    </b-row>
+                </b-card>
+            </b-col>
+        </b-row>
+    </div>
+</template>
+
+<script>
+import { BRow, BCol, BCard, BCardText, BButton, BFormInput, BImg, BInputGroup, BInputGroupAppend } from 'bootstrap-vue'
+import useJwt from '@/auth/jwt/useJwt'
+import Ripple from 'vue-ripple-directive'
+import ToastificationContent from '@core/components/toastification/ToastificationContent.vue'
+
+export default {
+    components: {
+        BRow,
+        BCol,
+        BCard,
+        BCardText,
+        BButton,
+        BFormInput,
+        BImg,
+        BInputGroup,
+        BInputGroupAppend,
+        ToastificationContent,
+    },
+    directives: {
+        Ripple,
+    },
+    data() {
+        return {
+            activity_id: this.$route.params.activity_id,
+            user_id: '',
+            searchData: [],
+            departmentList: [],
+        }
+    },
+    created() {
+        useJwt.postData('/api/department/index').then(res => {
+            this.departmentList = res.data;
+        });
+    },
+    methods: {
+        statusColoer(status) {
+            return status == true ? 'color: #00DD88' : 'color: #868686';
+        },
+        keyListener(event) {
+            if (event.which === 13) {
+                this.getUserStatus()
+            }
+        },
+        avatar(user_id) {
+            if (this.searchData && this.searchData.department_id == "來賓") {
+                return '/images/vip.jpg';
+            } else {
+                return '/images/profile-picture/' + user_id + '.jpg';
+            }
+        },
+        getUserStatus() {
+            useJwt.postData('/api/draw/search_user_status', { activity_id: this.activity_id, user_id: this.user_id }).then(res => {
+                this.searchData = res.data;
+            });
+        },
+        checkinStatus(status) {
+            return status == true ? "已經報到" : "尚未報到";
+        },
+        awardStatus(is_awarded, prize_name) {
+            if (is_awarded == true) {
+                return prize_name ? prize_name : "獎品已捐出"
+            }
+            return "未中獎";
+        },
+        claimStatus(status) {
+            return status == true ? "已領獎" : "尚未領獎";
+        },
+    },
+}
+</script>
+
+<style lang="scss">
+@import '~@resources/scss/vue/libs/vue-select.scss';
+</style>

+ 1 - 1
routes/api.php

@@ -110,6 +110,7 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
     Route::post('/draw/store', [DrawController::class, 'store']);
     Route::post('/draw/donate', [DrawController::class, 'donate']);
     Route::post('/draw/test', [DrawController::class, 'test']);
+    Route::post('/draw/search_user_status', [DrawController::class, 'search_user_status']);
 
     // Prize
     Route::post('/prize/store', [PrizeController::class, 'store']);
@@ -118,7 +119,6 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
     // Recipients
     Route::post('/recipient/claim', [RecipientsController::class, 'claim']);
     Route::post('/recipient/isClaimed', [RecipientsController::class, 'isClaimed']);
-    
 });
 
 Route::post('/recipient/indexByPrize', [RecipientsController::class, 'indexByPrize']);