CheckInController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\CheckIn;
  4. use App\Models\User;
  5. use Illuminate\Http\Request;
  6. use App\Http\Requests\StoreCheckInRequest;
  7. use App\Http\Requests\UpdateCheckInRequest;
  8. use App\Models\Department;
  9. class CheckInController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. *
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function index()
  17. {
  18. //
  19. }
  20. public function index_by_activity(UpdateCheckInRequest $request)
  21. {
  22. return CheckIn::where('activity_id', $request->activityId)->get();
  23. }
  24. public function draw_user_when_check_in(StoreCheckInRequest $request)
  25. {
  26. return CheckIn::where('is_checked_in', 'true')->get()->random($request->number);
  27. }
  28. public function draw_user_by_region(StoreCheckInRequest $request)
  29. {
  30. return CheckIn::where('is_checked_in', 'true')
  31. ->whereTime('check_ins.updated_at', '<=', $request->deadline)
  32. ->whereIn('region', $request->region)
  33. ->get()
  34. ->random($request->number);
  35. }
  36. /**
  37. * Show the form for creating a new resource.
  38. *
  39. * @return \Illuminate\Http\Response
  40. */
  41. public function create()
  42. {
  43. //
  44. }
  45. /**
  46. * Store a newly created resource in storage.
  47. *
  48. * @param \App\Http\Requests\StoreCheckInRequest $request
  49. * @return \Illuminate\Http\Response
  50. */
  51. public function store(StoreCheckInRequest $request)
  52. {
  53. //
  54. }
  55. /**
  56. * Display the specified resource.
  57. *
  58. * @param \App\Models\CheckIn $checkIn
  59. * @return \Illuminate\Http\Response
  60. */
  61. public function show(Request $request, CheckIn $checkIn)
  62. {
  63. //
  64. $checkIn = $request->activity_id ?
  65. CheckIn::where('user_id', '=', $request->user_id)->where('activity_id', '=', $request->activity_id)->first()
  66. : CheckIn::where('user_id', '=', $request->user_id)->first();
  67. $department = Department::where('department_id', '=', $checkIn->department_id)->first();
  68. $checkIn->department = $department->department_name ?? '暫無部門';
  69. $response = [
  70. 'user' => $checkIn,
  71. ];
  72. return response($response, 201);
  73. }
  74. /**
  75. * Show the form for editing the specified resource.
  76. *
  77. * @param \App\Models\CheckIn $checkIn
  78. * @return \Illuminate\Http\Response
  79. */
  80. public function edit(CheckIn $checkIn)
  81. {
  82. //
  83. }
  84. /**
  85. * Update the specified resource in storage.
  86. *
  87. * @param \App\Http\Requests\UpdateCheckInRequest $request
  88. * @param \App\Models\CheckIn $checkIn
  89. * @return \Illuminate\Http\Response
  90. */
  91. public function update(UpdateCheckInRequest $request, CheckIn $checkIn)
  92. {
  93. CheckIn::where('user_id', $request->user_id)->update(['is_checked_in' => true]);
  94. return 'success';
  95. }
  96. public function check_out(UpdateCheckInRequest $request, CheckIn $checkIn)
  97. {
  98. CheckIn::where('user_id', $request->user_id)->update(['is_checked_in' => false]);
  99. return 'success';
  100. }
  101. /**
  102. * Remove the specified resource from storage.
  103. *
  104. * @param \App\Models\CheckIn $checkIn
  105. * @return \Illuminate\Http\Response
  106. */
  107. public function destroy(CheckIn $checkIn)
  108. {
  109. //
  110. }
  111. }