member_put.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once __DIR__."/../public/snowflakeid.php";
  6. $snowflake = new SnowFlakeId();
  7. $respond = array("status" => 0, "message" => "");
  8. set_exception_handler(function($e){
  9. $respond['status'] = 1;
  10. $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
  11. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  12. exit;
  13. });
  14. if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
  15. PDO_Connect("" . _FILE_DB_GROUP_);
  16. #先查是否有加人权限 0:拥有者,1.管理员
  17. $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
  18. $power = PDO_FetchRow($query, array($_COOKIE["userid"], $_POST["groupid"]));
  19. if (!$power || $power["power"] > 1) {
  20. $respond['status'] = 1;
  21. $respond['message'] = "no power to add memeber";
  22. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  23. exit;
  24. }
  25. #查询组信息
  26. $query = "SELECT * from "._TABLE_GROUP_INFO_." where uid=?";
  27. $g_curr = PDO_FetchRow($query, array($_POST["groupid"]));
  28. if (!$g_curr) {
  29. $respond['status'] = 1;
  30. $respond['message'] = '组不存在';
  31. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  32. exit;
  33. }
  34. #查询是否有重复记录
  35. $query = "SELECT * from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=?";
  36. $isExist = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
  37. if ($isExist) {
  38. $respond['status'] = 1;
  39. $respond['message'] = '组员已经存在';
  40. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  41. exit;
  42. }
  43. $query = "INSERT INTO "._TABLE_GROUP_MEMBER_." (id, user_id , group_id , power , group_name , level , status )
  44. VALUES ( ? , ? , ? , ? , ? ,? ,?) ";
  45. $sth = $PDO->prepare($query);
  46. $sth->execute(array($snowflake->id(),$_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], 0, 1));
  47. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  48. $error = PDO_ErrorInfo();
  49. $respond['status'] = 1;
  50. $respond['message'] = $error[2];
  51. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  52. exit;
  53. }
  54. }
  55. echo json_encode($respond, JSON_UNESCAPED_UNICODE);