GroupController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. class GroupController extends Controller
  7. {
  8. public function CreateGroup(Request $request)
  9. {
  10. $validator = Validator::make($request->all(), [
  11. "name" => "required|between:1,64",
  12. "description" => "max:255",
  13. "icon" => "max:255",
  14. ]);
  15. if ($validator->fails()) {
  16. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  17. }
  18. $params = [];
  19. $params["name"] = $request->input("name");
  20. $params["description"] = $request->input("description");
  21. $params["icon"] = $request->input("icon");
  22. $group = new Models\Group();
  23. $result = $group->CreateGroup($params);
  24. if ($result["code"] == 0) {
  25. return $this->success($result["data"]);
  26. }
  27. return $this->response($result["code"], $this->error[$result["code"]]);
  28. }
  29. public function ModifyGroup(Request $request)
  30. {
  31. $validator = Validator::make($request->all(), [
  32. "id" => "required|integer|min:1",
  33. "name" => "between:1,64",
  34. "description" => "max:255",
  35. "icon" => "max:255",
  36. ]);
  37. if ($validator->fails()) {
  38. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  39. }
  40. $params = [];
  41. $params["id"] = $request->input("id");
  42. $params["name"] = $request->input("name");
  43. $params["description"] = $request->input("description");
  44. $params["icon"] = $request->input("icon");
  45. $group = new Models\Group();
  46. $code = $group->ModifyGroup($params);
  47. return $this->response($code, $this->error[$code]);
  48. }
  49. public function DeleteGroup(Request $request)
  50. {
  51. $validator = Validator::make($request->all(), [
  52. "id" => "required|integer|min:1",
  53. ]);
  54. if ($validator->fails()) {
  55. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  56. }
  57. $params = [];
  58. $params["id"] = $request->input("id");
  59. $group = new Models\Group();
  60. $code = $group->DeleteGroup($params);
  61. return $this->response($code, $this->error[$code]);
  62. }
  63. /**
  64. * 此方法待定
  65. *
  66. * @param Request $request
  67. * @return \Illuminate\Http\JsonResponse
  68. */
  69. public function ListGroup(Request $request)
  70. {
  71. $validator = Validator::make($request->all(), [
  72. "page" => "integer|min:1",
  73. "pageCount" => "integer|min:1",
  74. ]);
  75. if ($validator->fails()) {
  76. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  77. }
  78. $params = [];
  79. $params["page"] = $request->input("page");
  80. $params["pageCount"] = $request->input("pageCount");
  81. $params["keyword"] = $request->input("keyword");
  82. $group = new Models\Group();
  83. $result = $group->ListGroup($params);
  84. return $this->success($result);
  85. }
  86. }