Resgin.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. session_start();
  3. include_once("../../untils/conn.php");
  4. mysqli_query($con, "set names utf8");
  5. $proxy_acc = $_POST['account'];
  6. $proxy_pass = $_POST['password'];
  7. $proxy_upid = $_POST['puid'];
  8. $proxy_name = $_POST['username'];
  9. $cr_time = time();
  10. // 检查用户名是否为中文
  11. // if (preg_match('/[\x{4e00}-\x{9fa5}]+/u', $proxy_name)) {
  12. // $response = array("code" => -4, "msg" => "用户名不能为中文");
  13. // echo json_encode($response);
  14. // exit();
  15. // }
  16. // 查询proxy表里是否存在相同的用户名
  17. $checkUsernameQuery = "SELECT * FROM proxy WHERE proxy_acc = '$proxy_acc'";
  18. $checkUsernameResult = mysqli_query($con, $checkUsernameQuery);
  19. if (mysqli_num_rows($checkUsernameResult) > 0) {
  20. // 用户名已存在
  21. $response = array("code" => -1, "msg" => "用户名已存在");
  22. echo json_encode($response);
  23. } else {
  24. // 验证密码是否符合要求(包含字母和数字,不低于10位)
  25. if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/', $proxy_pass)) {
  26. // 密码过于简单
  27. $response = array("code" => -2, "msg" => "密码过于简单,请设置包含不低于8位的字母和数字");
  28. echo json_encode($response);
  29. } else {
  30. // 验证邀请码是否存在
  31. $checkInvitationCodeQuery = "SELECT * FROM proxy WHERE proxy_id = '$proxy_upid'";
  32. $checkInvitationCodeResult = mysqli_query($con, $checkInvitationCodeQuery);
  33. if (mysqli_num_rows($checkInvitationCodeResult) == 0) {
  34. // 邀请码不存在
  35. $response = array("code" => 3, "msg" => "邀请码不存在");
  36. echo json_encode($response);
  37. } else {
  38. $group_id = "";
  39. $group_name = "";
  40. // 查询代理组信息
  41. $getGroupQuery = "SELECT * FROM proxy_group WHERE group_id IN (
  42. SELECT group_id FROM proxy WHERE proxy_id = '$proxy_upid'
  43. )";
  44. $getGroupResult = mysqli_query($con, $getGroupQuery);
  45. if (mysqli_num_rows($getGroupResult) > 0) {
  46. $groupData = mysqli_fetch_assoc($getGroupResult);
  47. $group_id = $groupData['group_id'];
  48. $group_name = $groupData['group_name'];
  49. }
  50. // 根据代理组信息查询新的group_id
  51. $newgroup_id = "";
  52. if ($group_name == "运营平台") {
  53. $getNewGroupQuery = "SELECT group_id FROM proxy_group WHERE group_name = '一级代理'";
  54. $getNewGroupResult = mysqli_query($con, $getNewGroupQuery);
  55. if (mysqli_num_rows($getNewGroupResult) > 0) {
  56. $newGroupData = mysqli_fetch_assoc($getNewGroupResult);
  57. $newgroup_id = $newGroupData['group_id'];
  58. }
  59. } elseif ($group_name == "一级代理") {
  60. $getNewGroupQuery = "SELECT group_id FROM proxy_group WHERE group_name = '二级代理'";
  61. $getNewGroupResult = mysqli_query($con, $getNewGroupQuery);
  62. if (mysqli_num_rows($getNewGroupResult) > 0) {
  63. $newGroupData = mysqli_fetch_assoc($getNewGroupResult);
  64. $newgroup_id = $newGroupData['group_id'];
  65. }
  66. } elseif ($group_name == "二级代理") {
  67. $getNewGroupQuery = "SELECT group_id FROM proxy_group WHERE group_name = '三级代理'";
  68. $getNewGroupResult = mysqli_query($con, $getNewGroupQuery);
  69. if (mysqli_num_rows($getNewGroupResult) > 0) {
  70. $newGroupData = mysqli_fetch_assoc($getNewGroupResult);
  71. $newgroup_id = $newGroupData['group_id'];
  72. }
  73. } elseif ($group_name == "三级代理") {
  74. // 该邀请码无法发展下级
  75. $response = array("code" => 4, "msg" => "该邀请码无法发展下级");
  76. echo json_encode($response);
  77. exit();
  78. }
  79. // 插入新数据到proxy表
  80. $insertQuery = "INSERT INTO proxy (proxy_acc, proxy_pass, proxy_upid, cr_time, group_id, proxy_name) VALUES ('$proxy_acc', '$proxy_pass', '$proxy_upid', '$cr_time', '$newgroup_id', '$proxy_name')";
  81. $insertResult = mysqli_query($con, $insertQuery);
  82. if ($insertResult) {
  83. $proxy_id = mysqli_insert_id($con); // 获取刚刚插入数据的自增ID
  84. // 将proxy_id插入到shopsy表中的puid字段中
  85. $sql = "INSERT INTO shopsy (puid, shop_name) VALUES ('$proxy_id', '$proxy_name')";
  86. $insertShopsyResult = mysqli_query($con, $sql);
  87. if ($insertShopsyResult) {
  88. // 注册成功
  89. $response = array("code" => 2, "msg" => "注册成功!请返回登录!");
  90. echo json_encode($response);
  91. } else {
  92. // 系统错误,请稍后再试
  93. $response = array("code" => -3, "msg" => "系统错误,请稍后再试!");
  94. echo json_encode($response);
  95. }
  96. } else {
  97. // 系统错误,请稍后再试
  98. $response = array("code" => -3, "msg" => "系统错误,请稍后再试!");
  99. echo json_encode($response);
  100. }
  101. }
  102. }
  103. }
  104. ?>