Browse Source

Merge branch 'kevin'

maa3606 2 years ago
parent
commit
41898d0f3d

+ 26 - 2
app/Http/Controllers/RecipientsController.php

@@ -133,9 +133,9 @@ class RecipientsController extends Controller
         $user = CheckIn::where('activity_id', '=', $activity_id)
             ->where('user_id', '=', $user_id)->get()[0];
         $department_id = CheckIn::where('user_id', '=', $user_id)->get()[0]->department_id;
-        if($department_id != '空'){
+        if ($department_id != '空') {
             $department_name = Department::where('department_id', '=', $department_id)->get()[0]->department_name;
-        }else{
+        } else {
             $department_name = '空';
         }
 
@@ -177,6 +177,30 @@ class RecipientsController extends Controller
         return $recipient;
     }
 
+    public function export(Request $request)
+    {
+        $recipients = Recipients::join('prizes', 'recipients.prize_id', '=', 'prizes.id')
+            ->join('check_ins', 'recipients.user_id', '=', 'check_ins.user_id')
+            ->select('prizes.activity_id', 'prizes.id', 'prizes.name as prize', 'check_ins.name', 'prizes.created_at')
+            ->where('prizes.activity_id', '=', $request->activity_id)
+            ->orderBy('prizes.id')
+            ->get();
+
+        $filename = "recipients_list_" . date('Y_m_d_H_i_s',time()) . ".csv";
+        $filepath = "./upload/".$filename;
+        $handle = fopen($filepath, 'w+');
+        fputcsv($handle, array('prize', 'name', 'created_at'));
+
+        foreach ($recipients as $element) {
+            fputcsv($handle, array($element->prize, $element->name, $element->created_at));
+        }
+        fclose($handle);
+        $headers = array(
+            'Content-Type' => 'text/csv',
+        );
+        return response()->download($filepath, $filename, $headers);
+    }
+
     public function indexByPrize(Request $request)
     {
         //

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

@@ -41,6 +41,14 @@
                     </b-card-body>
                 </b-card>
             </b-col>
+            <b-col v-if="this.userData.role == 'Admin'" md="6" :lg="lg">
+                <b-card no-body border-variant="info" class="text-center">
+                    <b-card-body>
+                        <b-button variant="success"
+                            @click="downloadRecipients">匯出得獎名單</b-button>
+                    </b-card-body>
+                </b-card>
+            </b-col>
         </b-row>
     </div>
 </template>
@@ -90,6 +98,20 @@ export default {
                 this.input = "";
             });
 
+        },
+        downloadRecipients() {
+            useJwt.postData('/api/recipients/export', { 'activity_id': this.$route.params.activity_id }).then(response => {
+                let blob = new Blob([response.data], {
+                    type: 'application/csv'
+                })
+                let link = document.createElement('a')
+                link.href = window.URL.createObjectURL(blob)
+                link.download = response.headers["content-disposition"].split('filename=')[1]
+                link.click()
+            }).catch(error => {
+                console.log(error)
+            });
+
         }
     }
 }

+ 30 - 21
resources/js/src/views/lottery/Draw.vue

@@ -3,8 +3,8 @@
     <b-row class="prize-list-wrapper">
       <b-col md="6">
         <b-card title="獎項列表" style="height:75vh;">
-          <b-table responsive hover sticky-header=true :items="getPrizeList(prizeList)" bordered :fields="fields" @row-clicked="click"
-            style="max-height: 57vh; overflow: auto;">
+          <b-table responsive hover sticky-header=true :items="getPrizeList(prizeList)" bordered :fields="fields"
+            @row-clicked="click" style="max-height: 57vh; overflow: auto;">
             <template #cell(ICON)="data" class="text-center">
               <div class="text-center">
                 <feather-icon :icon="data.value" />
@@ -18,7 +18,7 @@
         </b-card>
       </b-col>
 
-      <b-modal ref="draw-modal" centered title="抽獎" no-stacking hide-footer>
+      <b-modal ref="draw-modal" id="draw-modal" centered title="抽獎" no-stacking hide-footer>
         <label>獎品:</label>
         <b-form-input v-model="prize" :disabled=true />
         <br>
@@ -26,7 +26,14 @@
         <v-select multiple v-model="region" :options="regionOption" />
         <br>
         <label>數量: </label>
-        <b-form-spinbutton v-model="drawNumber" min="1" :max=drawMax />
+        <div class="demo-inline-spacing">
+          <b-form-radio v-model="drawOne" name="some-radios" :value=true>
+            單抽
+          </b-form-radio>
+          <b-form-radio v-model="drawOne" name="some-radios" :value=false>
+            全抽
+          </b-form-radio>
+        </div>
 
         <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
           @click="hideModal">
@@ -60,7 +67,7 @@
           </div>
         </div>
 
-        <div v-if="onlyOne(drawNumber)">
+        <div v-if="drawOne">
           <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="outline-primary" block
             @click="donate">
             捐出
@@ -108,7 +115,7 @@
 </template>
 
 <script>
-import { BRow, BCol, BCard, BCardText, BLink, BTable, BModal, BFormInput, BFormSpinbutton, BButton } from 'bootstrap-vue'
+import { BRow, BCol, BCard, BCardText, BLink, BTable, BModal, BFormInput, BFormSpinbutton, BButton, BFormCheckbox, BFormRadio } from 'bootstrap-vue'
 import useJwt from '@/auth/jwt/useJwt'
 import { VueGoodTable } from 'vue-good-table'
 import vSelect from 'vue-select'
@@ -127,6 +134,8 @@ export default {
     BFormInput,
     BFormSpinbutton,
     BButton,
+    BFormCheckbox,
+    BFormRadio,
     VueGoodTable,
     vSelect,
   },
@@ -146,7 +155,7 @@ export default {
       regionOption: ['北區', '中區', '南區', '來賓'],
       region: ['北區', '中區', '南區', '來賓'],
       drawMax: 1,
-      drawNumber: 1,
+      drawOne: true,
 
       prize: '',
       prizeId: '',
@@ -260,11 +269,11 @@ export default {
     counterId(id) {
       return "counter_" + id;
     },
-    onlyOne(number) {
-      if (number == 1) {
-        return true;
+    drawNumber() {
+      if (this.drawOne) {
+        return 1;
       }
-      return false;
+      return this.drawMax;
     },
     showDraw() {
       this.$refs['draw-modal'].show();
@@ -296,8 +305,8 @@ export default {
     click(params) {
       this.prize = this.getPrizeName(params.id);
       this.prizeId = params.id;
+      this.drawOne = true;
       this.drawMax = params["數量"];
-      this.drawNumber = 1;
       this.drawList = [];
       if (this.drawMax == 0) {
         this.showDrawError();
@@ -306,11 +315,11 @@ export default {
       }
     },
     draw() {
-      useJwt.postData('/api/draw/draw', { 
-        activity_id: this.activityId, 
-        prize_id: this.prizeId, 
-        region: this.region, 
-        number: this.drawNumber 
+      useJwt.postData('/api/draw/draw', {
+        activity_id: this.activityId,
+        prize_id: this.prizeId,
+        region: this.region,
+        number: this.drawNumber()
       }).then(res => {
         if (res.data) {
           this.drawList = res.data;
@@ -329,10 +338,10 @@ export default {
       this.drawList.forEach(element => {
         idList.push(element.user_id);
       });
-      useJwt.postData('/api/draw/store', { 
-        users: idList, 
-        prize_id: String(this.prizeId), 
-        number: this.drawNumber 
+      useJwt.postData('/api/draw/store', {
+        users: idList,
+        prize_id: String(this.prizeId),
+        number: this.drawNumber()
       }).then(res => {
         if (res.data) {
           console.log("store success");

+ 1 - 2
routes/api.php

@@ -102,7 +102,6 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
     // CheckIn
     Route::post('/check_in/update', [CheckInController::class, 'update']);
     Route::post('/check_in/check_out', [CheckInController::class, 'check_out']);
-    Route::post('/check_in/draw', [CheckInController::class, 'draw_user_when_check_in']);
     Route::post('/checkin/show', [CheckInController::class, 'show']);
     Route::post('/checkin/export', [CheckInController::class, 'export']);
 
@@ -130,4 +129,4 @@ Route::post('/prize/index_by_activity', [PrizeController::class, 'index_by_activ
 Route::post('/check_in/index_by_activity', [CheckInController::class, 'index_by_activity']);
 Route::post('/recipients/index_by_activity', [RecipientsController::class, 'index_by_activity']);
 
-Route::post('/prize/prizeDrawable', [PrizeController::class, 'prize_is_drawable']);
+Route::post('/recipients/export', [RecipientsController::class, 'export']);