GroupController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Controllers\Admin\Pair;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Fpdx\GroupModel;
  6. class GroupController extends Controller
  7. {
  8. /**
  9. * 创建群组
  10. * @param Request $request
  11. * @return array
  12. */
  13. public function store(Request $request)
  14. {
  15. $this->validate($request, [
  16. 'group_name' => 'required|max:32',
  17. 'stage_id' => 'required|integer',
  18. 'activity_type' => 'in:72h,qbj',
  19. 'number' => 'required|integer',
  20. 'qrcode' => 'required|url',
  21. 'type' => 'required|in:pair,alone',
  22. 'qq_group_number' => 'required|integer',
  23. ]);
  24. $group = new GroupModel();
  25. $group->fill($request->post());
  26. $group->save();
  27. return response([
  28. 'code' => 200,
  29. 'message' => 'success',
  30. 'data' => $group
  31. ]);
  32. }
  33. /**
  34. * 查看群组
  35. * @param Request $request
  36. * @return array
  37. */
  38. public function show($id)
  39. {
  40. $group = GroupModel::findOrFail($id);
  41. return response([
  42. 'code' => 200,
  43. 'message' => 'success',
  44. 'data' => $group
  45. ]);
  46. }
  47. /**
  48. * 群组列表
  49. * @param Request $request
  50. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  51. */
  52. public function index(Request $request)
  53. {
  54. $this->validate($request, [
  55. 'stage_id' => 'integer',
  56. 'activity_type' => 'in:72h,qbj',
  57. ]);
  58. $groups = GroupModel::when($request->filled('stage_id'), function ($query) use ($request) {
  59. return $query->where('stage_id', $request->stage_id);
  60. })->when($request->filled('activity_type'), function ($query) use ($request) {
  61. return $query->where('activity_type', $request->activity_type);
  62. })
  63. ->orderBy('id', 'desc')
  64. ->get();
  65. return response([
  66. 'code' => 200,
  67. 'message' => 'success',
  68. 'data' => $groups
  69. ]);
  70. }
  71. /**
  72. * 修改群组
  73. * @param Request $request
  74. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  75. */
  76. public function update(Request $request, $id)
  77. {
  78. $this->validate($request, [
  79. 'group_name' => 'filled|max:32',
  80. 'stage_id' => 'filled|integer',
  81. 'activity_type' => 'in:72h,qbj',
  82. 'number' => 'filled|integer',
  83. 'qrcode' => 'filled|url',
  84. 'type' => 'filled|in:pair,alone',
  85. 'qq_group_number' => 'filled|integer',
  86. ]);
  87. $group = GroupModel::findOrFail($id);
  88. $group->fill($request->all());
  89. $group->save();
  90. return response([
  91. 'code' => 200,
  92. 'message' => 'success',
  93. 'data' => $group
  94. ]);
  95. }
  96. }