CheckInController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 = CheckIn::where('user_id', '=', $request->id)->where('activity_id', '=', $request->activity_id)->first();
  65. $department = Department::where('department_id', '=', $checkIn->department_id)->first();
  66. $checkIn->department = $department->department_name;
  67. $response = [
  68. 'checkIn' => $checkIn,
  69. ];
  70. return response($response, 201);
  71. }
  72. /**
  73. * Show the form for editing the specified resource.
  74. *
  75. * @param \App\Models\CheckIn $checkIn
  76. * @return \Illuminate\Http\Response
  77. */
  78. public function edit(CheckIn $checkIn)
  79. {
  80. //
  81. }
  82. /**
  83. * Update the specified resource in storage.
  84. *
  85. * @param \App\Http\Requests\UpdateCheckInRequest $request
  86. * @param \App\Models\CheckIn $checkIn
  87. * @return \Illuminate\Http\Response
  88. */
  89. public function update(UpdateCheckInRequest $request, CheckIn $checkIn)
  90. {
  91. CheckIn::where('user_id', $request->user_id)->update(['is_checked_in' => true]);
  92. return 'success';
  93. }
  94. public function check_out(UpdateCheckInRequest $request, CheckIn $checkIn)
  95. {
  96. CheckIn::where('user_id', $request->user_id)->update(['is_checked_in' => false]);
  97. return 'success';
  98. }
  99. /**
  100. * Remove the specified resource from storage.
  101. *
  102. * @param \App\Models\CheckIn $checkIn
  103. * @return \Illuminate\Http\Response
  104. */
  105. public function destroy(CheckIn $checkIn)
  106. {
  107. //
  108. }
  109. }