Goods.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // 查询代理的所有信息字段
  8. $sql = "SELECT * FROM `proxy` WHERE `proxy_acc`='$proxy_acc'";
  9. $result = mysqli_query($con, $sql);
  10. // 取出 group_id 并存为变量
  11. if ($result && $row = mysqli_fetch_assoc($result)) {
  12. $group_id = $row["group_id"];
  13. $puid = $row["proxy_id"];
  14. }
  15. // 查询代理所在的代理组信息
  16. $sql = "SELECT * FROM `proxy_group` WHERE `group_id`=$group_id";
  17. $result = mysqli_query($con, $sql);
  18. // 取出 group_portion 并存为变量
  19. if ($result && $row = mysqli_fetch_assoc($result)) {
  20. $group_portion = $row["group_portion"];
  21. $portion = $group_portion;
  22. }
  23. // 查询 goodsta 表,如果有 puid=$puid 的数据,则取出 spid 和 status 存为变量
  24. $sql = "SELECT * FROM `goodsta` WHERE `puid`=$puid";
  25. $result = mysqli_query($con, $sql);
  26. // 定义一个空数组,用来保存 goodsta 表中的数据
  27. $goodsta_data = array();
  28. while ($result && $row = mysqli_fetch_assoc($result)) {
  29. $spid = $row["spid"];
  30. $status = $row["status"];
  31. // 将记录存入数组中
  32. $goodsta_data[] = array(
  33. 'spid' => $spid,
  34. 'status' => $status
  35. );
  36. }
  37. // 获取所有记录
  38. $sql = "SELECT * FROM list WHERE state=0";
  39. $result = mysqli_query($con, $sql);
  40. // 定义一个空数组,用来保存查询结果
  41. $data = array();
  42. // 逐条取出记录,存为变量
  43. while ($result && $row = mysqli_fetch_assoc($result)) {
  44. $id = $row['id'];
  45. $name = $row['name'];
  46. $intro = $row['jieshao'];
  47. $zhutu = $row['zhutu'];
  48. $yys = $row['yys'];
  49. $gsd = $row['gsd'];
  50. $proxy_price = $row['proxy_price'];
  51. $notes = $row['notes'];
  52. $state = 0;
  53. // 遍历 goodsta_data 数组,查找 spid 等于当前记录 id 的记录
  54. foreach ($goodsta_data as $goodsta) {
  55. if ($goodsta['spid'] == $id) {
  56. $state = $goodsta['status'] == 1 ? $goodsta['status'] : 0;
  57. break;
  58. }
  59. }
  60. $price = $proxy_price - $portion;
  61. // 将记录存入数组中
  62. $data[] = array(
  63. 'id' => $id,
  64. 'name' => $name,
  65. 'intro' => $intro,
  66. 'zhutu' => $zhutu,
  67. 'yys' => $yys,
  68. 'gsd' => $gsd,
  69. 'price' => $price,
  70. 'notes' => $notes,
  71. 'state' => $state
  72. );
  73. }
  74. // 将数组转换为 JSON 格式并输出
  75. echo json_encode($data);
  76. ?>