Dorevenue.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. include_once("../../untils/conn.php");
  3. if (empty($_GET['id'])) {
  4. exit('<h1>连接数据库失败</h1>');
  5. }
  6. $id = $_GET['id'];
  7. $dz_time = time();
  8. $cr_time = time();
  9. $note = "下级订单结算,平台返佣¥" . $proxy_prices;
  10. $notes = "下级订单结算,平台返佣¥" . $proxy_pricess;
  11. // 查询revenue表中的数据
  12. $query = "SELECT * FROM revenue WHERE id = $id";
  13. $result = mysqli_query($con, $query);
  14. $row = mysqli_fetch_assoc($result);
  15. // 提取字段值为变量
  16. $account = $row['account'];
  17. $orderid = $row['oderid'];
  18. $name = $row['name'];
  19. $price = $row['price'];
  20. $proxy_upid = $row['proxy_upid'];
  21. $proxy_prices = $row['proxy_prices'];
  22. $proxy_upids = $row['proxy_upids'];
  23. $proxy_pricess = $row['proxy_pricess'];
  24. $note = "下级订单完成,平台返佣¥" . $proxy_prices;
  25. $notes = "下级订单完成,平台返佣¥" . $proxy_pricess;
  26. // 处理第一种情况:只有account和price有值
  27. if (!empty($account) && !empty($price) && empty($proxy_upid) && empty($proxy_prices) && empty($proxy_upids) && empty($proxy_pricess)) {
  28. // 查询proxy表中proxy_acc = account的数据,并给字段proxy_balance的值加上price
  29. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $price WHERE proxy_acc = '$account'";
  30. $updateResult = mysqli_query($con, $updateQuery);
  31. if (!$updateResult) {
  32. echo '<script>alert("结算失败");history.go(-1);</script>';
  33. exit;
  34. }
  35. // 更新revenue表中的数据
  36. $updateQuery = "UPDATE revenue SET state = 2, type = 0, dz_time = $dz_time WHERE id = $id";
  37. $updateResult = mysqli_query($con, $updateQuery);
  38. if (!$updateResult) {
  39. echo '<script>alert("结算失败");history.go(-1);</script>';
  40. exit;
  41. }
  42. echo '<script>alert("结算成功");history.go(-1);</script>';
  43. }
  44. // 处理第二种情况:account、price、proxy_upid和proxy_prices有值
  45. if (!empty($account) && !empty($price) && !empty($proxy_upid) && !empty($proxy_prices) && empty($proxy_upids) && empty($proxy_pricess)) {
  46. // 使用第一种方式更新完成后,查询proxy表中proxy_acc = proxy_upid的数据,并给字段proxy_balance的值加上proxy_prices
  47. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $price WHERE proxy_acc = '$account'";
  48. $updateResult = mysqli_query($con, $updateQuery);
  49. if (!$updateResult) {
  50. echo '<script>alert("结算失败");history.go(-1);</script>';
  51. exit;
  52. }
  53. // 更新revenue表中的数据
  54. $updateQuery = "UPDATE revenue SET state = 2, type = 0, dz_time = $dz_time WHERE id = $id";
  55. $updateResult = mysqli_query($con, $updateQuery);
  56. if (!$updateResult) {
  57. echo '<script>alert("结算失败");history.go(-1);</script>';
  58. exit;
  59. }
  60. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $proxy_prices WHERE proxy_acc = '$proxy_upid'";
  61. $updateResult = mysqli_query($con, $updateQuery);
  62. if (!$updateResult) {
  63. echo '<script>alert("结算失败");history.go(-1);</script>';
  64. exit;
  65. }
  66. // 在revenue表中插入一条数据
  67. $insertQuery = "INSERT INTO revenue (account, oderid, name, price,oder_sta , state, type, dz_time, cr_time, beizhu) VALUES ('$proxy_upid', '$orderid', '$name', $proxy_prices,3, 2, 0, $dz_time, $cr_time, '$note')";
  68. $insertResult = mysqli_query($con, $insertQuery);
  69. if (!$insertResult) {
  70. // echo '<script>alert("结算失败");history.go(-1);</script>';
  71. echo "Error updating record: " . $con->error;
  72. exit;
  73. }
  74. echo '<script>alert("结算成功");history.go(-1);</script>';
  75. }
  76. // 处理第三种情况:account、price、proxy_upid、proxy_prices、proxy_upids和proxy_pricess都有值
  77. if (!empty($account) && !empty($price) && !empty($proxy_upid) && !empty($proxy_prices) && !empty($proxy_upids) && !empty($proxy_pricess)) {
  78. // 使用第一种方式和第二种方式执行完后,查询proxy表中proxy_acc = proxy_upids的数据,并给字段proxy_balance的值加上proxy_pricess
  79. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $price WHERE proxy_acc = '$account'";
  80. $updateResult = mysqli_query($con, $updateQuery);
  81. if (!$updateResult) {
  82. echo '<script>alert("结算失败");history.go(-1);</script>';
  83. exit;
  84. }
  85. // 更新revenue表中的数据
  86. $updateQuery = "UPDATE revenue SET state = 2, type = 0, dz_time = $dz_time WHERE id = $id";
  87. $updateResult = mysqli_query($con, $updateQuery);
  88. if (!$updateResult) {
  89. echo '<script>alert("结算失败");history.go(-1);</script>';
  90. exit;
  91. }
  92. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $proxy_prices WHERE proxy_acc = '$proxy_upid'";
  93. $updateResult = mysqli_query($con, $updateQuery);
  94. if (!$updateResult) {
  95. echo '<script>alert("结算失败");history.go(-1);</script>';
  96. exit;
  97. }
  98. // 在revenue表中插入一条数据
  99. $insertQuery = "INSERT INTO revenue (account, oderid, name, price,oder_sta , state, type, dz_time, cr_time, beizhu) VALUES ('$proxy_upid', '$orderid', '$name', $proxy_prices,3, 2, 0, $dz_time, $cr_time, '$note')";
  100. $insertResult = mysqli_query($con, $insertQuery);
  101. if (!$insertResult) {
  102. // echo '<script>alert("结算失败");history.go(-1);</script>';
  103. echo "Error updating record: " . $con->error;
  104. exit;
  105. }
  106. $updateQuery = "UPDATE proxy SET proxy_balance = proxy_balance + $proxy_pricess WHERE proxy_acc = '$proxy_upids'";
  107. $updateResult = mysqli_query($con, $updateQuery);
  108. if (!$updateResult) {
  109. echo '<script>alert("结算失败");history.go(-1);</script>';
  110. exit;
  111. }
  112. // 在revenue表中插入一条数据
  113. $insertQuery = "INSERT INTO revenue (account, oderid, name, price, oder_sta, state, type, dz_time, cr_time, beizhu) VALUES ('$proxy_upids', '$orderid', '$name', $proxy_pricess,3, 2, 0, $dz_time, $cr_time, '$notes')";
  114. $insertResult = mysqli_query($con, $insertQuery);
  115. if (!$insertResult) {
  116. echo '<script>alert("结算失败");history.go(-1);</script>';
  117. exit;
  118. }
  119. echo '<script>alert("结算成功");history.go(-1);</script>';
  120. }
  121. mysqli_close($con);
  122. ?>