GroupUserController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Validator;
  6. class GroupUserController extends Controller
  7. {
  8. public function GroupAddUser(Request $request)
  9. {
  10. $validator = Validator::make($request->all(), [
  11. "gid" => "required|integer|min:1",
  12. "uid" => "required|integer|min:1",
  13. ]);
  14. if ($validator->fails()) {
  15. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  16. }
  17. $currentUid = 0;
  18. // 判断当前用户是否可以为群组添加用户
  19. $gid = (int)$request->input("gid");
  20. $uid = (int)$request->input("uid");
  21. $groupUser = new Models\GroupUser();
  22. $result = $groupUser->GroupAddUser($gid, $uid);
  23. if ($result["code"] == 0) {
  24. return $this->success($result["data"]);
  25. }
  26. return $this->fail($result["code"], $this->error[$result["code"]]);
  27. }
  28. public function GroupRemoveUser(Request $request)
  29. {
  30. $validator = Validator::make($request->all(), [
  31. "id" => "required|integer|min:1",
  32. ]);
  33. if ($validator->fails()) {
  34. return $this->fail(REQUEST_PARAM_ERROR, $this->error[REQUEST_PARAM_ERROR], $validator->errors());
  35. }
  36. $currentUid = 0;
  37. // 判断当前用户是否可以为群组刪除用户
  38. $id = (int)$request->input("id");
  39. $groupUser = new Models\GroupUser();
  40. $code = $groupUser->GroupRemoveUser($id);
  41. return $this->response($code, $this->error[$code]);
  42. }
  43. }