12 Commity de73d315a4 ... 42f5de60fc

Autor SHA1 Wiadomość Data
  maa3520 42f5de60fc Merge branch 'master' of http://10.1.1.202:3030/steve07s/lottery 2 lat temu
  maa3520 7d75b9007f 調整報到排版 2 lat temu
  maa3606 b337f7ede6 修正 department 2 lat temu
  maa3606 d96272720f Merge branch 'master' of http://10.1.1.202:3030/steve07s/lottery 2 lat temu
  maa3606 9389310495 修正 department 2 lat temu
  maa3520 7c255e6896 新增 department 2 lat temu
  maa3520 14c0a93457 Merge branch 'master' of http://10.1.1.202:3030/steve07s/lottery 2 lat temu
  maa3520 11e223d119 新增報到 2 lat temu
  maa3606 1409892aed Merge branch 'Nate' into kevin 2 lat temu
  maa3606 517b41e2c8 prize seeder 取消 2 lat temu
  maa3606 87b553027b 抽獎功能完成(缺動畫) 2 lat temu
  maa3606 00c6c08efc 新增 department table 2 lat temu

+ 10 - 3
app/Http/Controllers/API/UserController.php

@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use App\Models\User;
+use App\Models\Department;
 
 class UserController extends Controller
 {
@@ -48,10 +49,16 @@ class UserController extends Controller
      * @param  int  $id
      * @return \Illuminate\Http\Response
      */
-    public function show($id)
+    public function show(Request $request,User $user)
     {
-        $results = DB::select('SELECT * FROM [permissions].[dbo].[User] WHERE [UserID] = ?', array($id));
-        return json_encode($results, JSON_UNESCAPED_UNICODE);
+        $user = User::where('user_id', '=', $request->id)->get()[0];
+        $department = Department::where('department_id','=',$user->department_id)->get()[0];
+        $user->department = $department->department_name;
+        $response = [
+            'user' => $user,
+        ];
+
+        return response($response, 201);
     }
 
     /**

+ 7 - 2
app/Http/Controllers/CheckInController.php

@@ -19,15 +19,20 @@ class CheckInController extends Controller
         //
     }
 
+    public function index_by_activity(UpdateCheckInRequest $request)
+    {
+        return CheckIn::where('activity_id', $request->activityId)->get();
+    }
+
     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)
+    public function draw_user_by_region(StoreCheckInRequest $request)
     {
         return CheckIn::where('is_checked_in', 'true')
-            ->whereTime('check_ins.updated_at', '<=', '2023-02-08 08:23:42')
+            ->whereTime('check_ins.updated_at', '<=', $request->deadline)
             ->whereIn('region', $request->region)
             ->get()
             ->random($request->number);

+ 86 - 0
app/Http/Controllers/DepartmentController.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Department;
+use App\Http\Requests\StoreDepartmentRequest;
+use App\Http\Requests\UpdateDepartmentRequest;
+
+class DepartmentController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * 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\StoreDepartmentRequest  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(StoreDepartmentRequest $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Department $department)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Department $department)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \App\Http\Requests\UpdateDepartmentRequest  $request
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function update(UpdateDepartmentRequest $request, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Department $department)
+    {
+        //
+    }
+}

+ 5 - 0
app/Http/Controllers/PrizeController.php

@@ -18,6 +18,11 @@ class PrizeController extends Controller
         return Prize::all();
     }
 
+    public function index_by_activity(UpdatePrizeRequest $request)
+    {
+        return Prize::where('activity_id', $request->activityId)->get();
+    }
+
     public function drawable_prizes()
     {
         return Prize::where('count', '>', 0)->get();

+ 11 - 1
app/Http/Controllers/RecipientsController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\Models\Recipients;
 use App\Http\Requests\StoreRecipientsRequest;
 use App\Http\Requests\UpdateRecipientsRequest;
+use App\Models\Prize;
 
 class RecipientsController extends Controller
 {
@@ -17,7 +18,16 @@ class RecipientsController extends Controller
     {
         return Recipients::all();
     }
-    
+
+    public function index_by_activity(UpdateRecipientsRequest $request)
+    {
+        return Recipients::join('prizes', 'recipients.prize_id', '=', 'prizes.id')
+            ->select('user_id', 'prizes.activity_id', 'prize_id', 'recipients.created_at')
+            ->where('prizes.activity_id', $request->activityId)
+            ->orderBy('recipients.created_at', 'DESC')
+            ->get();
+    }
+
     /**
      * Show the form for creating a new resource.
      *

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

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

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

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

+ 17 - 0
app/Models/Department.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Department extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'department_id',
+        'department_name',
+        'manager',
+    ];
+}

+ 94 - 0
app/Policies/DepartmentPolicy.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Department;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class DepartmentPolicy
+{
+    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\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function view(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * 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\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function update(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function delete(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can restore the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function restore(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can permanently delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function forceDelete(User $user, Department $department)
+    {
+        //
+    }
+}

+ 182 - 0
database/MAA_department.json

@@ -0,0 +1,182 @@
+[
+  {
+    "department_id": "a00",
+    "department_name": "行政管理部",
+    "manager": "a00"
+  },
+  {
+    "department_id": "a21",
+    "department_name": "行政管理部庶務科",
+    "manager": "a21"
+  },
+  {
+    "department_id": "a22",
+    "department_name": "人力資源科",
+    "manager": "a22"
+  },
+  {
+    "department_id": "a24",
+    "department_name": "行政管理部文書科",
+    "manager": "a24"
+  },
+  {
+    "department_id": "b00",
+    "department_name": "南區辦事處",
+    "manager": "b00"
+  },
+  {
+    "department_id": "b10",
+    "department_name": "中區辦事處",
+    "manager": "b10"
+  },
+  {
+    "department_id": "c00",
+    "department_name": "工程管理一部",
+    "manager": "c00"
+  },
+  {
+    "department_id": "c10",
+    "department_name": "工程管理二部",
+    "manager": "c10"
+  },
+  {
+    "department_id": "d00",
+    "department_name": "發展與企畫部",
+    "manager": "d00"
+  },
+  {
+    "department_id": "e10",
+    "department_name": "工程製圖科",
+    "manager": "e10"
+  },
+  {
+    "department_id": "f10",
+    "department_name": "工務部",
+    "manager": "f10"
+  },
+  {
+    "department_id": "g00",
+    "department_name": "大地工程部",
+    "manager": "g00"
+  },
+  {
+    "department_id": "i00",
+    "department_name": "財務部",
+    "manager": "i00"
+  },
+  {
+    "department_id": "j00",
+    "department_name": "運輸及土木工程部",
+    "manager": "j00"
+  },
+  {
+    "department_id": "j10",
+    "department_name": "城鄉發展部",
+    "manager": "j10"
+  },
+  {
+    "department_id": "j20",
+    "department_name": "軌道工程部",
+    "manager": "j20"
+  },
+  {
+    "department_id": "l00",
+    "department_name": "董事長室",
+    "manager": "l00"
+  },
+  {
+    "department_id": "l10",
+    "department_name": "總經理室",
+    "manager": "l10"
+  },
+  {
+    "department_id": "l40",
+    "department_name": "企業發展中心",
+    "manager": "l40"
+  },
+  {
+    "department_id": "l60",
+    "department_name": "成本中心",
+    "manager": "l60"
+  },
+  {
+    "department_id": "m00",
+    "department_name": "資訊中心",
+    "manager": "m00"
+  },
+  {
+    "department_id": "p00",
+    "department_name": "環境及水資源工程部",
+    "manager": "p00"
+  },
+  {
+    "department_id": "p10",
+    "department_name": "環境水務部",
+    "manager": "p10"
+  },
+  {
+    "department_id": "p20",
+    "department_name": "環境永續部",
+    "manager": "p20"
+  },
+  {
+    "department_id": "r00",
+    "department_name": "機電系統工程部",
+    "manager": "r00"
+  },
+  {
+    "department_id": "s00",
+    "department_name": "結構工程部",
+    "manager": "s00"
+  },
+  {
+    "department_id": "u20",
+    "department_name": "工程設計群",
+    "manager": "u20"
+  },
+  {
+    "department_id": "u30",
+    "department_name": "工程監理群",
+    "manager": "u30"
+  },
+  {
+    "department_id": "u40",
+    "department_name": "總管理處",
+    "manager": "u40"
+  },
+  {
+    "department_id": "u50",
+    "department_name": "建築及設施群",
+    "manager": "u50"
+  },
+  {
+    "department_id": "x05",
+    "department_name": "數位工程發展部",
+    "manager": "x05"
+  },
+  {
+    "department_id": "x06",
+    "department_name": "淡海輕軌計畫監造專案",
+    "manager": "x06"
+  },
+  {
+    "department_id": "x08",
+    "department_name": "安坑輕軌計畫監造專案",
+    "manager": "x08"
+  },
+  {
+    "department_id": "x09",
+    "department_name": "先進技術中心",
+    "manager": "x09"
+  },
+  {
+    "department_id": "x10",
+    "department_name": "塭仔圳市地重劃公共工程專案管理與監造專案",
+    "manager": "x10"
+  },
+  {
+    "department_id": "x12",
+    "department_name": "萬大果菜市場專案",
+    "manager": "x12"
+  }
+]

+ 23 - 0
database/factories/DepartmentFactory.php

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

+ 33 - 0
database/migrations/2023_02_09_055743_create_departments_table.php

@@ -0,0 +1,33 @@
+<?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('departments', function (Blueprint $table) {
+            $table->id();
+            $table->string('department_id');
+            $table->string('department_name');
+            $table->string('manager');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('departments');
+    }
+};

+ 3 - 2
database/seeders/DatabaseSeeder.php

@@ -48,8 +48,9 @@ class DatabaseSeeder extends Seeder
         $this->call([
             ActivitySeeder::class,
             CheckInSeeder::class,
-            PrizeSeeder::class,
-            RecipientsSeeder::class,
+            // PrizeSeeder::class,
+            // RecipientsSeeder::class,
+            DepartmentSeeder::class,
         ]);
     }
 }

+ 31 - 0
database/seeders/DepartmentSeeder.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Database\Seeders;
+
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+use \App\Models\Department;
+use Illuminate\Support\Facades\File;
+
+class DepartmentSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        Department::truncate();
+        $json = File::get("database/MAA_department.json");
+        $countries = json_decode($json);
+
+        foreach ($countries as $key => $value) {
+            Department::insert([
+                'department_id' => $value->department_id,
+                'department_name' => $value->department_name,
+                'manager' => $value->manager,
+            ]);
+        }
+    }
+}

+ 99 - 99
database/seeders/PrizeSeeder.php

@@ -15,104 +15,104 @@ 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 元',
-        //         'provider' => '亞新',
-        //         'count' => 2,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 12,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 1,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 10,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 1,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 10,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 4,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 8,800 元',
-        //         'provider' => '亞新',
-        //         'count' => 5,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 8,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 6,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 6,600 元',
-        //         'provider' => '亞新',
-        //         'count' => 13,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 6,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 10,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 3,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 80,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 2,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 50,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '福利即享券 2,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 50,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        // ]);
+        Prize::truncate();
+        Prize::insert([
+            [
+                'activity_id' => '1',
+                'name' => '普獎現金 1,200 元',
+                'provider' => '亞新',
+                'count' => 0,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 16,800 元',
+                'provider' => '亞新',
+                'count' => 2,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 12,000 元',
+                'provider' => '亞新',
+                'count' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 10,000 元',
+                'provider' => '亞新',
+                'count' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 10,000 元',
+                'provider' => '亞新',
+                'count' => 4,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 8,800 元',
+                'provider' => '亞新',
+                'count' => 5,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 8,000 元',
+                'provider' => '亞新',
+                'count' => 6,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 6,600 元',
+                'provider' => '亞新',
+                'count' => 13,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 6,000 元',
+                'provider' => '亞新',
+                'count' => 10,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 3,000 元',
+                'provider' => '亞新',
+                'count' => 80,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 2,000 元',
+                'provider' => '亞新',
+                'count' => 50,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '福利即享券 2,000 元',
+                'provider' => '亞新',
+                'count' => 50,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+        ]);
     }
 }

+ 18 - 6
resources/js/src/navigation/vertical/index.js

@@ -7,12 +7,24 @@ export default [{
         icon: 'HomeIcon',
     },
     {
-        header: '抽獎系統',
-    },
-    {
-        title: '活動列表',
-        route: 'activityList',
-        icon: 'ActivityIcon',
+        title: '活動抽獎系統',
+        icon: 'AwardIcon',
+        children: [{
+                title: '報到系統',
+                route: 'checkin',
+                icon: 'CheckSquareIcon',
+            },
+            {
+                title: '抽獎',
+                route: 'draw',
+                icon: 'UploadIcon',
+            },
+            {
+                title: '活動列表',
+                route: 'activityList',
+                icon: 'ActivityIcon',
+            }
+        ]
     },
     {
         header: '管理功能',

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

@@ -145,6 +145,20 @@ export const settings = {
                 }, ],
             },
         },
+        {
+            path: '/checkin',
+            name: 'checkin',
+            component: () => import('@/views/lottery/CheckIn.vue'),
+            meta: {
+                pageTitle: '報到系統',
+                breadcrumb: [{
+                    text: '報到系統',
+                    active: true,
+                }, ],
+                requiresAuth: true,
+
+            },
+        },
     ],
 }
 export const _ = undefined

+ 56 - 29
resources/js/src/views/Draw.vue

@@ -2,10 +2,9 @@
   <div>
     <b-row class="prize-list-wrapper">
       <b-col md="6">
-        <b-card title="獎項列表">
-          <b-card-text>所有獎項,點擊獎項以抽取</b-card-text>
+        <b-card title="獎項列表" style="height:75vh;">
           <b-table responsive hover :items="getPrizeList(prizeList)" bordered :fields="fields" @row-clicked="click"
-            v-b-modal.modal-draw-error>
+            v-b-modal.modal-center style="max-height: 65vh; overflow: auto;">
             <template #cell(ICON)="data" class="text-center">
               <div class="text-center">
                 <feather-icon :icon="data.value" />
@@ -14,25 +13,28 @@
           </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 id="modal-center" centered title="抽獎" cancel-variant="outline-secondary" cancel-title="Close"
+        :ok-only="draw_zero" ok-title="Accept" @ok="draw">
+        <div v-if="draw_zero">
+          <label>獎品數量以抽完</label>
+        </div>
+        <div v-else>
+          <label>獎品:</label>
+          <b-form-input v-model="prize" :disabled=true />
+          <br>
+          <label>地區: </label>
+          <v-select multiple v-model="region" :options="regionOption" />
+          <br>
+          <label>數量: </label>
+          <b-form-spinbutton v-model="drawNumber" min="1" :max=drawMax />
+        </div>
       </b-modal>
 
       <b-col md="6">
-        <b-card title="抽獎紀錄">
-          <b-table responsive :items="getRecipientsList(recipientsList)" bordered>
+        <b-card title="抽獎紀錄" style="height:75vh;">
+          <b-table responsive :items="getRecipientsList(recipientsList)" bordered
+            style="max-height: 65vh; overflow: auto;">
             <template #cell(ICON)="data" class="text-center">
               <div class="text-center">
                 <feather-icon :icon="data.value" />
@@ -68,13 +70,15 @@ export default {
   },
   data() {
     return {
+      activity: [],
       userList: [],
+      userIdList: [],
       prizeList: [],
       recipientsList: [],
 
       fields: ['獎項', '數量'],
-      placeOption: ['北區', '中區', '南區', '來賓'],
-      placeSelected: ['北區', '中區', '南區', '來賓'],
+      regionOption: ['北區', '中區', '南區', '來賓'],
+      region: ['北區', '中區', '南區', '來賓'],
       drawMax: 1,
       drawNumber: 1,
 
@@ -84,18 +88,34 @@ export default {
     }
   },
   created() {
-    useJwt.postData('/api/user/index').then(res => {
+    this.activity = this.$route.params.activity;
+    console.log(this.activity);
+
+    useJwt.postData('/api/check_in/index_by_activity', { activityId: this.activity.id }).then(res => {
       this.userList = res.data;
     });
 
-    useJwt.postData('/api/prize/index').then(res => {
+    useJwt.postData('/api/user/index').then(res => {
+      this.userIdList = res.data;
+    });
+
+    useJwt.postData('/api/prize/index_by_activity', { activityId: this.activity.id }).then(res => {
       this.prizeList = res.data;
     });
 
-    useJwt.postData('/api/recipients/index').then(res => {
+    useJwt.postData('/api/recipients/index_by_activity', { activityId: this.activity.id }).then(res => {
       this.recipientsList = res.data;
     });
   },
+  computed: {
+    draw_zero() {
+      if (this.drawMax == 0) {
+        return true;
+      } else {
+        return false;
+      }
+    }
+  },
   methods: {
     getPrizeList(prizeList) {
       var output = [];
@@ -116,7 +136,8 @@ export default {
     getRecipientsList(recipientsList) {
       var output = [];
       recipientsList.forEach(element => {
-        output.push({ '獎項': this.getPrizeName(element.prize_id), '獲獎人': this.userList[element.user_id], '時間': element.created_at });
+        console.log(element.created_at);
+        output.push({ '獎項': this.getPrizeName(element.prize_id), '獲獎人': this.userIdList[element.user_id], '時間': this.dateFormat(element.created_at) });
       });
       return output;
     },
@@ -127,7 +148,7 @@ export default {
       this.drawNumber = 1;
     },
     draw() {
-      useJwt.postData('/api/check_in/drawP', { number: this.drawNumber, region: this.placeSelected }).then(res => {
+      useJwt.postData('/api/check_in/draw_by_region', { deadline: this.activity.deadline, region: this.region, number: this.drawNumber }).then(res => {
         res.data.forEach(element => {
           console.log(element);
           useJwt.postData('/api/prize/draw', { prizeId: this.prizeId }).then(p => {
@@ -144,15 +165,21 @@ export default {
       });
     },
     updateDataset() {
-      useJwt.postData('/api/prize/index').then(res => {
+      useJwt.postData('/api/prize/index_by_activity', { activityId: this.activity.id }).then(res => {
         this.prizeList = res.data;
       });
-      useJwt.postData('/api/recipients/index').then(res => {
+      useJwt.postData('/api/recipients/index_by_activity', { activityId: this.activity.id }).then(res => {
         this.recipientsList = res.data;
       });
     },
-    test() {
-      console.log(this.placeSelected);
+    dateFormat(date) {
+      var d = new Date(date);
+      return d.getFullYear()
+        + '/' + (d.getMonth() + 1).toString().padStart(2, '0')
+        + '/' + d.getDay().toString().padStart(2, '0')
+        + '/' + d.getHours().toString().padStart(2, '0')
+        + ':' + d.getMinutes().toString().padStart(2, '0')
+        + ':' + d.getSeconds().toString().padStart(2, '0');
     },
   },
 }

+ 159 - 0
resources/js/src/views/lottery/CheckIn.vue

@@ -0,0 +1,159 @@
+<template>
+  <b-row>
+    <b-col md="6">
+      <b-card title="報到人員" style="height: 65vh;">
+        <b-media no-body>
+          <b-media-aside>
+            <b-img
+              :src="'/images/profile-picture/' + user.user_id + '.jpg'"
+              blank-color="#ccc"
+              fluid
+              alt="placeholder"
+              style="width:42vh;"
+              onerror="this.src='/images/error.png'" />
+          </b-media-aside>
+
+          <b-media-body class="ml-1" style="font-size: 2rem;">
+            <h2 class="mt-1">
+              姓名
+            </h2>
+            <b-card-text>
+              {{ user.name }}
+            </b-card-text>
+            <h2 class="mt-0">
+              工號
+            </h2>
+            <b-card-text>
+              {{ user.user_id }}
+            </b-card-text>
+            <h2 class="mt-0">
+              部門
+            </h2>
+            <b-card-text>
+              {{ user.department }}
+            </b-card-text>
+          </b-media-body>
+
+        </b-media>
+
+      </b-card>
+    </b-col>
+    <b-col md="6">
+      <b-card title="報到輸入" style="height: 65vh;">
+        <b-form-input v-model="input" @keydown.native="test_keydown_handler"></b-form-input>
+        <br>
+        <b-button
+              v-ripple.400="'rgba(113, 102, 240, 0.15)'"
+              variant="outline-primary"
+              @click="showMsgBoxTwo">
+              報到
+            </b-button>
+      </b-card>
+      
+    </b-col>
+  </b-row>
+</template>
+<script>
+import { BRow, BCol, BCard, BCardText, BButton, BMedia, BFormInput, BImg, BMediaAside, BMediaBody } from 'bootstrap-vue'
+import Ripple from 'vue-ripple-directive'
+import Pusher from 'pusher-js';
+import useJwt from '@/auth/jwt/useJwt'
+
+export default {
+  name: "websocket",
+  components: {
+    BRow,
+    BCol,
+    BCard,
+    BCardText,
+    BButton,
+    BMedia,
+    BFormInput,
+    BImg,
+    BMediaAside,
+    BMediaBody,
+  },
+  directives: {
+    Ripple,
+  },
+  data() {
+    return {
+      boxTwo: '',
+      user: {name:" ",user_id:" ",department:" "},
+      scannerText: "",
+      input: "",
+    }
+  },
+  created() {
+
+
+    Pusher.logToConsole = true;
+
+    var pusher = new Pusher('9fb7f6f0141efc7e1293', {
+      cluster: 'ap3'
+    });
+
+    var channel = pusher.subscribe('my-channel');
+    channel.bind('my-event', data => {
+      useJwt.postData('/api/user/show', { 'id': data.message }).then(response => {
+        this.user = response.data.user;
+      }).catch(error => {
+        console.log(error)
+        this.user = {};
+      });
+    });
+
+
+  },
+  computed: {
+
+  },
+  methods: {
+    test_keydown_handler(event) {
+      if (event.which === 13) {
+        // The key pressed was the enter key
+
+        console.log(this.input)
+
+        useJwt.postData('/api/user/show', { 'id': this.input }).then(response => {
+          this.user = response.data.user;
+          this.input = "";
+        }).catch(error => {
+          console.log(error)
+          this.user = {name:"查無此人",user_id:" ",department:" "};
+          this.input = "";
+        });
+      }
+    },
+    showMsgBoxTwo() {
+      this.boxTwo = ''
+      this.$bvModal
+        .msgBoxConfirm('請確認此人員為本人', {
+          title: '請確認',
+          size: 'sm',
+          okVariant: 'primary',
+          okTitle: '報到',
+          cancelTitle: '取消',
+          cancelVariant: 'outline-secondary',
+          hideHeaderClose: false,
+          centered: true,
+        })
+        .then(value => {
+          this.boxTwo = value
+        })
+    },
+
+  },
+  watch: {
+
+  },
+  mounted() {
+
+  }
+}
+
+</script>
+
+<style>
+
+</style>

+ 6 - 1
routes/api.php

@@ -100,16 +100,21 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
     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']);
+    Route::post('/check_in/draw_by_region', [CheckInController::class, 'draw_user_by_region']);
 
     // Prize
     Route::post('/prize/draw', [PrizeController::class, 'draw']);
 
     // Recipients
     Route::post('/recipients/store', [RecipientsController::class, 'store']);
+
+    Route::post('/user/show', [UserController::class, 'show']);
 });
 Route::post('/user/index', [UserController::class, 'index']);
 Route::post('/prize/index', [PrizeController::class, 'index']);
+Route::post('/check_in/index_by_activity', [CheckInController::class, 'index_by_activity']);
+Route::post('/prize/index_by_activity', [PrizeController::class, 'index_by_activity']);
 Route::post('/recipients/index', [RecipientsController::class, 'index']);
+Route::post('/recipients/index_by_activity', [RecipientsController::class, 'index_by_activity']);
 
 Route::post('/prize/drawable_prizes', [PrizeController::class, 'drawable_prizes']);