Index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. session_start();
  3. include_once("../../untils/conn.php");
  4. mysqli_query($con, "set names utf8");
  5. // 获取当前正在登录的账号信息的代理
  6. $proxy_acc = $_SESSION["account"];
  7. // 防止 SQL 注入攻击
  8. $proxy_acc = mysqli_real_escape_string($con, $proxy_acc);
  9. // 查询proxy表,找到符合条件的数据并输出给前端
  10. $sql = "SELECT * FROM proxy WHERE proxy_acc = '$proxy_acc'";
  11. $result = mysqli_query($con, $sql);
  12. if ($result) {
  13. $rows = mysqli_fetch_assoc($result);
  14. $id = $rows["proxy_id"];
  15. // 查询oder表,找到符合条件的数据并计算行数
  16. $sql = "SELECT COUNT(*) AS count FROM oder WHERE proxy_id = '$id'";
  17. $result = mysqli_query($con, $sql);
  18. if ($result) {
  19. $row = mysqli_fetch_assoc($result);
  20. $count = $row['count'];
  21. } else {
  22. $count = 0;
  23. }
  24. // 查询proxy表,找到符合条件的数据并输出给前端
  25. $sql = "SELECT proxy_balance FROM proxy WHERE proxy_id = '$id'";
  26. $result = mysqli_query($con, $sql);
  27. if ($result) {
  28. $row = mysqli_fetch_assoc($result);
  29. $balance = $row['proxy_balance'];
  30. } else {
  31. $balance = 0;
  32. }
  33. // 查询list表,找到符合条件的数据并计算行数
  34. $sql = "SELECT COUNT(*) AS counts FROM list";
  35. $result = mysqli_query($con, $sql);
  36. if ($result) {
  37. $row = mysqli_fetch_assoc($result);
  38. $list = $row['counts'];
  39. } else {
  40. $list = 0;
  41. }
  42. // 查询revenue表,找到符合条件的数据并计算总和
  43. $sql = "SELECT SUM(price) AS total FROM revenue WHERE oder_sta = '3' AND account = '$proxy_acc' AND type = 0";
  44. $result = mysqli_query($con, $sql);
  45. if ($result) {
  46. $row = mysqli_fetch_assoc($result);
  47. $revenue = $row['total'];
  48. } else {
  49. $revenue = 0;
  50. }
  51. // 查询oder表,找到符合条件的数据并计算百分比
  52. $sql = "SELECT COUNT(*) AS total, SUM(CASE WHEN card_sta = 0 THEN 1 ELSE 0 END) AS inactive, SUM(CASE WHEN card_sta = 1 THEN 1 ELSE 0 END) AS active FROM oder WHERE proxy_id = '$id'";
  53. $result = mysqli_query($con, $sql);
  54. if ($result) {
  55. $row = mysqli_fetch_assoc($result);
  56. $total = $row['total'];
  57. $inactive = $row['inactive'];
  58. $active = $row['active'];
  59. $inactive_percentage = $total == 0 ? 0 : round($inactive / $total * 100, 2);
  60. $active_percentage = $total == 0 ? 0 : round($active / $total * 100, 2);
  61. } else {
  62. $total = 0;
  63. $inactive = 0;
  64. $active = 0;
  65. $inactive_percentage = 0;
  66. $active_percentage = 0;
  67. }
  68. // echo $beizhu = "订单数:" . $count . "产品数:" . $list ."代理余额:". $balance . "预估佣金:".$revenue . "未激活:". $inactive_percentage. "已激活:".$active_percentage ;
  69. // 将变量存储到关联数组中
  70. $data = array(
  71. "count" => $count,
  72. "balance" => $balance,
  73. "list" => $list,
  74. "revenue" => $revenue,
  75. "inactive" => $inactive,
  76. "active" => $active,
  77. "inactive_percentage" => $inactive_percentage,
  78. "active_percentage" => $active_percentage
  79. );
  80. // 将关联数组转换为 JSON 格式并输出
  81. echo json_encode($data);
  82. } else {
  83. // echo "查询出错!";
  84. }