maa3606 hace 2 años
padre
commit
6d3615a411

+ 9 - 1
app/Http/Controllers/PrizeController.php

@@ -51,7 +51,15 @@ class PrizeController extends Controller
      */
     public function store(StorePrizeRequest $request)
     {
-        //
+        Prize::insert([
+            'activity_id' => $request->activity_id,
+            'name' => $request->name,
+            'provider' => $request->provider,
+            'count' => $request->count,
+            'created_at' => now(),
+            'updated_at' => now(),
+        ]);
+        return true;
     }
 
     /**

+ 63 - 10
resources/js/src/views/lottery/Draw.vue

@@ -4,13 +4,17 @@
       <b-col md="6">
         <b-card title="獎項列表" style="height:75vh;">
           <b-table responsive hover :items="getPrizeList(prizeList)" bordered :fields="fields" @row-clicked="click"
-            style="max-height: 65vh; overflow: auto;">
+            style="max-height: 57vh; overflow: auto;">
             <template #cell(ICON)="data" class="text-center">
               <div class="text-center">
                 <feather-icon :icon="data.value" />
               </div>
             </template>
           </b-table>
+          <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-primary" block
+            @click="showAddPrize">
+            加碼
+          </b-button>
         </b-card>
       </b-col>
 
@@ -31,10 +35,9 @@
         <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block @click="draw">
           Accept
         </b-button>
-
       </b-modal>
 
-      <b-modal ref="draw-error" centered title="抽獎" no-stacking hide-footer>
+      <b-modal ref="draw-error" centered title="抽獎錯誤" no-stacking hide-footer>
         <b-card-text class="my-1 text-center">
           抽獎錯誤
         </b-card-text>
@@ -44,7 +47,7 @@
         </b-button>
       </b-modal>
 
-      <b-modal ref="draw-animation" title="抽獎" centered no-stacking hide-footer>
+      <b-modal ref="draw-animation" title="得獎者是......" centered no-stacking hide-footer>
         <br>
         <div :key="index" v-for="(item, index) in drawList" :class=counterId(index)>
           <i :datafinal=item.department>部門</i>
@@ -64,8 +67,26 @@
           </b-button>
         </div>
 
-        <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block
-          @click="store">
+        <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block @click="store">
+          Accept
+        </b-button>
+      </b-modal>
+
+      <b-modal ref="add-prize" centered title="加碼" no-stacking hide-footer>
+        <label>獎品:</label>
+        <b-form-input v-model="addPrizeName" />
+        <br>
+        <label>加碼者: </label>
+        <b-form-input v-model="addPrizeUser" />
+        <br>
+        <label>數量: </label>
+        <b-form-spinbutton v-model="addPrizeNumber" min="1" />
+
+        <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-3" variant="outline-secondary" block
+          @click="hideModal">
+          Close
+        </b-button>
+        <b-button v-ripple.400="'rgba(255, 255, 255, 0.15)'" class="mt-2" variant="primary" block @click="addPrize">
           Accept
         </b-button>
       </b-modal>
@@ -131,6 +152,10 @@ export default {
       prizeId: '',
       drawList: [],
 
+      addPrizeName: '',
+      addPrizeUser: '',
+      addPrizeNumber: 1,
+
       departments: [
         "行政管理部",
         "行政管理部庶務科",
@@ -247,6 +272,9 @@ export default {
     showDrawAnimation() {
       this.$refs['draw-animation'].show();
     },
+    showAddPrize() {
+      this.$refs['add-prize'].show();
+    },
     showDrawError() {
       this.$refs['draw-error'].show();
     },
@@ -254,6 +282,7 @@ export default {
       this.$refs['draw-modal'].hide();
       this.$refs['draw-error'].hide();
       this.$refs['draw-animation'].hide();
+      this.$refs['add-prize'].hide();
       this.updateDataset();
     },
     updateDataset() {
@@ -277,7 +306,12 @@ export default {
       }
     },
     draw() {
-      useJwt.postData('/api/draw/draw', { activity_id: this.activityId, prize_id: this.prizeId, region: this.region, number: this.drawNumber }).then(res => {
+      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;
           setTimeout(() => {
@@ -295,9 +329,13 @@ 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 }).then(res => {
+      useJwt.postData('/api/draw/store', { 
+        users: idList, 
+        prize_id: String(this.prizeId), 
+        number: this.drawNumber 
+      }).then(res => {
         if (res.data) {
-          console.log("success");
+          console.log("store success");
         } else {
           console.log("store error");
         }
@@ -311,13 +349,28 @@ export default {
       });
       useJwt.postData('/api/draw/donate', { users: idList }).then(res => {
         if (res.data) {
-          console.log("success");
+          console.log("donate success");
         } else {
           console.log("donate error");
         }
         this.hideModal();
       });
     },
+    addPrize() {
+      useJwt.postData('/api/prize/store', {
+        activity_id: this.activityId,
+        name: this.addPrizeName,
+        provider: this.addPrizeUser,
+        count: this.addPrizeNumber
+      }).then(res => {
+        if (res.data) {
+          console.log("add prize success");
+        } else {
+          console.log("add prize error");
+        }
+        this.hideModal();
+      });
+    },
     count() {
       var departments = this.departments;
       var numbers = "0123456789"

+ 1 - 0
routes/api.php

@@ -111,6 +111,7 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
     Route::post('/draw/test', [DrawController::class, 'test']);
 
     // Prize
+    Route::post('/prize/store', [PrizeController::class, 'store']);
 
     // Recipients