Bläddra i källkod

Merge branch 'kevin' into Nate

maa3444 2 år sedan
förälder
incheckning
e083d42458

+ 1 - 2
app/Http/Controllers/API/UserController.php

@@ -17,7 +17,7 @@ class UserController extends Controller
     public function index()
     {
         //
-        $user = User::all()->pluck('name','id');
+        $user = User::all()->pluck('name', 'user_id');
         return $user;
     }
 
@@ -52,7 +52,6 @@ class UserController extends Controller
     {
         $results = DB::select('SELECT * FROM [permissions].[dbo].[User] WHERE [UserID] = ?', array($id));
         return json_encode($results, JSON_UNESCAPED_UNICODE);
-    
     }
 
     /**

+ 108 - 0
app/Http/Controllers/CheckInController.php

@@ -0,0 +1,108 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\CheckIn;
+use App\Models\User;
+use App\Http\Requests\StoreCheckInRequest;
+use App\Http\Requests\UpdateCheckInRequest;
+
+class CheckInController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    public function draw_user_when_check_in(StoreCheckInRequest $request)
+    {
+        return CheckIn::where('is_checked_in', 'true')->get()->random($request->number);
+    }
+
+    public function draw_user_with_place(StoreCheckInRequest $request)
+    {
+        return CheckIn::where('is_checked_in', 'true')
+            ->whereTime('check_ins.updated_at', '<=', '2023-02-08 08:23:42')
+            ->whereIn('region', $request->region)
+            ->get()
+            ->random($request->number);
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \App\Http\Requests\StoreCheckInRequest  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(StoreCheckInRequest $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Http\Response
+     */
+    public function show(CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \App\Http\Requests\UpdateCheckInRequest  $request
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Http\Response
+     */
+    public function update(UpdateCheckInRequest $request, CheckIn $checkIn)
+    {
+        CheckIn::where('user_id', $request->userId)->update(['is_check_in' => true]);
+        return 'success';
+    }
+
+    public function check_out(UpdateCheckInRequest $request, CheckIn $checkIn)
+    {
+        CheckIn::where('user_id', $request->userId)->update(['is_check_in' => false]);
+        return 'success';
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(CheckIn $checkIn)
+    {
+        //
+    }
+}

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

@@ -15,7 +15,12 @@ class PrizeController extends Controller
      */
     public function index()
     {
-        //
+        return Prize::all();
+    }
+
+    public function drawable_prizes()
+    {
+        return Prize::where('count', '>', 0)->get();
     }
 
     /**
@@ -73,6 +78,24 @@ class PrizeController extends Controller
         //
     }
 
+    public function draw(UpdatePrizeRequest $request, Prize $prize)
+    {
+        $prize = Prize::where('id', $request->prizeId)->first();
+        if (!$prize) {
+            // return 'prize not found';
+            return false;
+        }
+        if ($prize->count > 0) {
+            $prize->update([
+                'count' => $prize->count - 1,
+                'updated_at' => now(),
+            ]);
+            return true;
+        }
+        // return 'prize is empty';
+        return false;
+    }
+
     /**
      * Remove the specified resource from storage.
      *

+ 12 - 4
app/Http/Controllers/RecipientsController.php

@@ -15,9 +15,9 @@ class RecipientsController extends Controller
      */
     public function index()
     {
-        //
+        return Recipients::all();
     }
-
+    
     /**
      * Show the form for creating a new resource.
      *
@@ -36,7 +36,14 @@ class RecipientsController extends Controller
      */
     public function store(StoreRecipientsRequest $request)
     {
-        //
+        Recipients::insert([
+            'prize_id' => $request->prizeId,
+            'user_id' => $request->userId,
+            'is_claimed' => false,
+            'created_at' => now(),
+            'updated_at' => now(),
+        ]);
+        return 'success';
     }
 
     /**
@@ -70,7 +77,8 @@ class RecipientsController extends Controller
      */
     public function update(UpdateRecipientsRequest $request, Recipients $recipients)
     {
-        //
+        Recipients::where('user_id', $request->userId)->update(['prize_id' => $request->prizeId]);
+        return 'success';
     }
 
     /**

+ 30 - 0
app/Http/Requests/StoreCheckInRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class StoreCheckInRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, mixed>
+     */
+    public function rules()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 1 - 1
app/Http/Requests/StoreRecipientsRequest.php

@@ -13,7 +13,7 @@ class StoreRecipientsRequest extends FormRequest
      */
     public function authorize()
     {
-        return false;
+        return true;
     }
 
     /**

+ 30 - 0
app/Http/Requests/UpdateCheckInRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class UpdateCheckInRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, mixed>
+     */
+    public function rules()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 1 - 1
app/Http/Requests/UpdatePrizeRequest.php

@@ -13,7 +13,7 @@ class UpdatePrizeRequest extends FormRequest
      */
     public function authorize()
     {
-        return false;
+        return true;
     }
 
     /**

+ 1 - 1
app/Http/Requests/UpdateRecipientsRequest.php

@@ -13,7 +13,7 @@ class UpdateRecipientsRequest extends FormRequest
      */
     public function authorize()
     {
-        return false;
+        return true;
     }
 
     /**

+ 1 - 1
app/Models/Activity.php

@@ -16,6 +16,6 @@ class Activity extends Model
         'date',
         'place',
         'user_id',
+        'deadline',
     ];
-
 }

+ 20 - 0
app/Models/CheckIn.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class CheckIn extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'user_id',
+        'name',
+        'department_id',
+        'region',
+        'is_checked_in',
+        'activity_id',
+    ];
+}

+ 1 - 1
app/Models/Recipients.php

@@ -10,8 +10,8 @@ class Recipients extends Model
     use HasFactory;
 
     protected $fillable = [
-        'prize_id',
         'user_id',
+        'prize_id',
         'is_claimed',
     ];
 }

+ 94 - 0
app/Policies/ActivityPolicy.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Activity;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ActivityPolicy
+{
+    use HandlesAuthorization;
+
+    /**
+     * Determine whether the user can view any models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function viewAny(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can view the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Activity  $activity
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function view(User $user, Activity $activity)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can create models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function create(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can update the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Activity  $activity
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function update(User $user, Activity $activity)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Activity  $activity
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function delete(User $user, Activity $activity)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can restore the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Activity  $activity
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function restore(User $user, Activity $activity)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can permanently delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Activity  $activity
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function forceDelete(User $user, Activity $activity)
+    {
+        //
+    }
+}

+ 94 - 0
app/Policies/CheckInPolicy.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\CheckIn;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class CheckInPolicy
+{
+    use HandlesAuthorization;
+
+    /**
+     * Determine whether the user can view any models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function viewAny(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can view the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function view(User $user, CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can create models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function create(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can update the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function update(User $user, CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function delete(User $user, CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can restore the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function restore(User $user, CheckIn $checkIn)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can permanently delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\CheckIn  $checkIn
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function forceDelete(User $user, CheckIn $checkIn)
+    {
+        //
+    }
+}

+ 23 - 0
database/factories/CheckInFactory.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/**
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\CheckIn>
+ */
+class CheckInFactory extends Factory
+{
+    /**
+     * Define the model's default state.
+     *
+     * @return array<string, mixed>
+     */
+    public function definition()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 1 - 1
database/factories/RecipientsFactory.php

@@ -19,8 +19,8 @@ class RecipientsFactory extends Factory
     public function definition()
     {
         return [
-            'prize_id' => $this->faker->randomElement(Prize::query()->get('id')),
             'user_id' => $this->faker->randomElement(User::query()->get('id')),
+            'prize_id' => $this->faker->randomElement(Prize::query()->get('id')),
             'is_claimed' => false,
         ];
     }

+ 1 - 1
database/migrations/2023_02_02_064840_create_recipients_table.php

@@ -15,8 +15,8 @@ return new class extends Migration
     {
         Schema::create('recipients', function (Blueprint $table) {
             $table->id();
-            $table->string('prize_id');
             $table->string('user_id');
+            $table->string('prize_id');
             $table->boolean('is_claimed');
             $table->timestamps();
         });

+ 37 - 0
database/migrations/2023_02_06_030248_create_check_ins_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('check_ins', function (Blueprint $table) {
+            $table->id();
+            $table->string('user_id');
+            $table->string('name');
+            $table->string('department_id')->nullable();
+            $table->string('region');
+            $table->boolean('is_checked_in');
+            $table->string('activity_id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('check_ins');
+    }
+};

+ 36 - 0
database/migrations/2023_02_08_065236_create_activities_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('activities', function (Blueprint $table) {
+            $table->id();
+            $table->string('activity_name');
+            $table->dateTime('date');
+            $table->string('place');
+            $table->string('user_id');
+            $table->dateTime('deadline');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('activities');
+    }
+};

+ 56 - 0
database/seeders/CheckInSeeder.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace Database\Seeders;
+
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+use App\Models\CheckIn;
+use Illuminate\Support\Facades\File;
+
+class CheckInSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        CheckIn::truncate();
+        $json = File::get("database/MAA.json");
+        $countries = json_decode($json);
+
+        foreach ($countries as $key => $value) {
+            switch ($value->department_id) { 
+                case 'B00':
+                    $region = '南區';
+                    break; 
+                case 'B10':
+                    $region = '中區';
+                    break;
+                default:
+                    $region = '北區';
+            }
+            CheckIn::create([
+                'user_id' => $value->user_id,
+                'name' => $value->name,
+                'department_id' => $value->department_id,
+                'region' => $region,
+                'is_checked_in' => true,
+                'activity_id' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ]);
+        }
+        CheckIn::create([
+            'user_id' => 'A1000',
+            'name' => '來賓1000',
+            'department_id' => null,
+            'region' => '來賓',
+            'is_checked_in' => true,
+            'activity_id' => 1,
+            'created_at' => now(),
+            'updated_at' => now(),
+        ]);
+    }
+}

+ 13 - 1
database/seeders/DatabaseSeeder.php

@@ -6,9 +6,14 @@ use Illuminate\Database\Console\Seeds\WithoutModelEvents;
 use Illuminate\Database\Seeder;
 use App\Models\User;
 use Illuminate\Support\Str;
-use File;
+use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Hash;
 
+use Database\Seeders\ActivitySeeder;
+use Database\Seeders\CheckInSeeder;
+use Database\Seeders\PrizeSeeder;
+use Database\Seeders\RecipientsSeeder;
+
 class DatabaseSeeder extends Seeder
 {
     use WithoutModelEvents;
@@ -39,5 +44,12 @@ class DatabaseSeeder extends Seeder
             ]);
         
         }
+
+        $this->call([
+            ActivitySeeder::class,
+            CheckInSeeder::class,
+            PrizeSeeder::class,
+            RecipientsSeeder::class,
+        ]);
     }
 }

+ 9 - 8
database/seeders/PrizeSeeder.php

@@ -15,7 +15,16 @@ class PrizeSeeder extends Seeder
      */
     public function run()
     {
+        Prize::truncate();
         Prize::insert([
+            [
+                'activity_id' => '0',
+                'name' => '普獎現金 1,200 元',
+                'provider' => '亞新',
+                'count' => 0,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
             [
                 'activity_id' => '0',
                 'name' => '現金 16,800 元',
@@ -104,14 +113,6 @@ class PrizeSeeder extends Seeder
                 'created_at' => now(),
                 'updated_at' => now(),
             ],
-            [
-                'activity_id' => '0',
-                'name' => '普獎現金 1,200 元',
-                'provider' => '亞新',
-                'count' => 0,
-                'created_at' => now(),
-                'updated_at' => now(),
-            ],
         ]);
     }
 }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 5256 - 6585
package-lock.json


+ 1 - 1
package.json

@@ -85,7 +85,7 @@
     "vue-quill-editor": "^3.0.6",
     "vue-ripple-directive": "^2.0.1",
     "vue-router": "^3.5.2",
-    "vue-select": "^3.12.2",
+    "vue-select": "^3.20.2",
     "vue-server-renderer": "2.6.14",
     "vue-slider-component": "^3.2.14",
     "vue-sweetalert2": "^4.1.1",

+ 5 - 0
resources/js/src/navigation/vertical/index.js

@@ -14,6 +14,11 @@ export default [{
         route: 'activityList',
         icon: 'ActivityIcon',
     },
+    {
+        title: '抽獎',
+        route: 'draw',
+        icon: 'UploadIcon',
+    },
     {
         title: '兌獎',
         route: 'claim',

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

@@ -113,6 +113,18 @@ export const settings = {
             path: '*',
             redirect: 'error-404',
         },
+        {
+            path: '/draw',
+            name: 'draw',
+            component: () => import('@/views/Draw.vue'),
+            meta: {
+                pageTitle: 'Draw',
+                breadcrumb: [{
+                    text: '抽獎',
+                    active: true,
+                }, ],
+            },
+        },
     ],
 }
 export const _ = undefined

+ 163 - 0
resources/js/src/views/Draw.vue

@@ -0,0 +1,163 @@
+<template>
+  <div>
+    <b-row class="prize-list-wrapper">
+      <b-col md="6">
+        <b-card title="獎項列表">
+          <b-card-text>所有獎項,點擊獎項以抽取</b-card-text>
+          <b-table responsive hover :items="getPrizeList(prizeList)" bordered :fields="fields" @row-clicked="click"
+            v-b-modal.modal-draw-error>
+            <template #cell(ICON)="data" class="text-center">
+              <div class="text-center">
+                <feather-icon :icon="data.value" />
+              </div>
+            </template>
+          </b-table>
+        </b-card>
+      </b-col>
+      <b-modal id="modal-center" centered title="抽獎" cancel-variant="outline-secondary" cancel-title="Close"
+        ok-title="Accept" @ok="test">
+        <label>獎品:</label>
+        <b-form-input v-model="prize" :disabled=true />
+        <br>
+        <label>地區: </label>
+        <v-select multiple v-model="placeSelected" :options="placeOption" />
+        <br>
+        <label>數量: </label>
+        <b-form-spinbutton v-model="drawNumber" min="1" :max=drawMax />
+      </b-modal>
+
+      <b-modal id="modal-draw-error" centered title="抽獎" ok-title="Close">
+        <label>獎品數量以抽完</label>
+      </b-modal>
+
+      <b-col md="6">
+        <b-card title="抽獎紀錄">
+          <b-table responsive :items="getRecipientsList(recipientsList)" bordered>
+            <template #cell(ICON)="data" class="text-center">
+              <div class="text-center">
+                <feather-icon :icon="data.value" />
+              </div>
+            </template>
+          </b-table>
+        </b-card>
+      </b-col>
+    </b-row>
+  </div>
+</template>
+
+<script>
+import { BRow, BCol, BCard, BCardText, BLink, BTable, BModal, BFormInput, BFormSpinbutton } from 'bootstrap-vue'
+import useJwt from '@/auth/jwt/useJwt'
+import { VueGoodTable } from 'vue-good-table'
+import vSelect from 'vue-select'
+import 'vue-select/dist/vue-select.css';
+
+export default {
+  components: {
+    BRow,
+    BCol,
+    BCard,
+    BCardText,
+    BLink,
+    BTable,
+    BModal,
+    BFormInput,
+    BFormSpinbutton,
+    VueGoodTable,
+    vSelect,
+  },
+  data() {
+    return {
+      userList: [],
+      prizeList: [],
+      recipientsList: [],
+
+      fields: ['獎項', '數量'],
+      placeOption: ['北區', '中區', '南區', '來賓'],
+      placeSelected: ['北區', '中區', '南區', '來賓'],
+      drawMax: 1,
+      drawNumber: 1,
+
+      prize: '',
+      prizeId: '',
+      drawUsers: [],
+    }
+  },
+  created() {
+    useJwt.postData('/api/user/index').then(res => {
+      this.userList = res.data;
+    });
+
+    useJwt.postData('/api/prize/index').then(res => {
+      this.prizeList = res.data;
+    });
+
+    useJwt.postData('/api/recipients/index').then(res => {
+      this.recipientsList = res.data;
+    });
+  },
+  methods: {
+    getPrizeList(prizeList) {
+      var output = [];
+      prizeList.forEach(element => {
+        output.push({ id: element.id, '獎項': element.name, '數量': element.count });
+      });
+      return output;
+    },
+    getPrizeName(prizeId) {
+      var output = '';
+      this.prizeList.forEach(element => {
+        if (prizeId == element.id) {
+          output = element.name;
+        }
+      });
+      return output;
+    },
+    getRecipientsList(recipientsList) {
+      var output = [];
+      recipientsList.forEach(element => {
+        output.push({ '獎項': this.getPrizeName(element.prize_id), '獲獎人': this.userList[element.user_id], '時間': element.created_at });
+      });
+      return output;
+    },
+    click(params) {
+      this.prize = this.getPrizeName(params.id);
+      this.prizeId = params.id;
+      this.drawMax = params["數量"];
+      this.drawNumber = 1;
+    },
+    draw() {
+      useJwt.postData('/api/check_in/drawP', { number: this.drawNumber, region: this.placeSelected }).then(res => {
+        res.data.forEach(element => {
+          console.log(element);
+          useJwt.postData('/api/prize/draw', { prizeId: this.prizeId }).then(p => {
+            if (p.data) {
+              useJwt.postData('/api/recipients/store', { prizeId: this.prizeId, userId: element.user_id }).then(r => {
+                console.log(r.data);
+                this.updateDataset();
+              });
+            } else {
+              console.log(p.data);
+            }
+          });
+        });
+      });
+    },
+    updateDataset() {
+      useJwt.postData('/api/prize/index').then(res => {
+        this.prizeList = res.data;
+      });
+      useJwt.postData('/api/recipients/index').then(res => {
+        this.recipientsList = res.data;
+      });
+    },
+    test() {
+      console.log(this.placeSelected);
+    },
+  },
+}
+</script>
+
+<style lang="scss">
+@import '~@resources/scss/vue/libs/vue-select.scss';
+</style>

+ 20 - 0
routes/api.php

@@ -9,6 +9,11 @@ use App\Http\Controllers\API\UserController;
 use App\Http\Controllers\TemplateController;
 use App\Models\User;
 use Illuminate\Support\Facades\Hash;
+
+use App\Http\Controllers\PrizeController;
+use App\Http\Controllers\CheckInController;
+use App\Http\Controllers\RecipientsController;
+
 /*
 |--------------------------------------------------------------------------
 | API Routes
@@ -88,5 +93,20 @@ Route::middleware('auth:sanctum')->group(function () {
 
 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('/check_in/drawP', [CheckInController::class, 'draw_user_with_place']);
+
+    // Prize
+    Route::post('/prize/draw', [PrizeController::class, 'draw']);
+
+    // Recipients
+    Route::post('/recipients/store', [RecipientsController::class, 'store']);
 });
+Route::post('/user/index', [UserController::class, 'index']);
+Route::post('/prize/index', [PrizeController::class, 'index']);
+Route::post('/recipients/index', [RecipientsController::class, 'index']);
 
+Route::post('/prize/drawable_prizes', [PrizeController::class, 'drawable_prizes']);

Vissa filer visades inte eftersom för många filer har ändrats