LtOderApi.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. require('SendSms.php');
  3. session_start();
  4. include_once("../../untils/conn.php");
  5. mysqli_query($con, "set names utf8");
  6. $goods = mysqli_real_escape_string($con, $_POST['goods']);
  7. $name = mysqli_real_escape_string($con, $_POST['name']);
  8. $uid = mysqli_real_escape_string($con, $_POST['uid']);
  9. $phone = mysqli_real_escape_string($con, $_POST['phone']);
  10. $sf = mysqli_real_escape_string($con, $_POST['sf']);
  11. $city = mysqli_real_escape_string($con, $_POST['city']);
  12. $xian = mysqli_real_escape_string($con, $_POST['xian']);
  13. $dizhi = mysqli_real_escape_string($con, $_POST['dizhi']);
  14. $oderid = mysqli_real_escape_string($con, $_POST['oderid']);
  15. $time = mysqli_real_escape_string($con, $_POST['time']);
  16. $price = mysqli_real_escape_string($con, $_POST['price']);
  17. $proxy_id = mysqli_real_escape_string($con, $_POST['proxyid']);
  18. $proxy_price = mysqli_real_escape_string($con, $_POST['proxy_prices']);
  19. $api_type = mysqli_real_escape_string($con, $_POST['apiType']);
  20. // 外加佣金参数
  21. $beizhu = "订单号:" . $oderid . "返佣¥" . $proxy_price;
  22. $beizhus = "已经提交运营商审核";
  23. //联通接口使用
  24. // 执行查询
  25. $sql = "SELECT * FROM cityCode WHERE postProvinceName = '$sf' AND postCityName = '$city' AND postDistrictName = '$xian'";
  26. $result = $con->query($sql);
  27. // 检查是否有匹配的结果
  28. if ($result->num_rows > 0) {
  29. // 获取查询结果的第一行数据
  30. $row = $result->fetch_assoc();
  31. // 提取需要的字段值并存储为变量
  32. $postProvinceCode = $row['postProvinceCode'];
  33. $postCityCode = $row['postCityCode'];
  34. $postDistrictCode = $row['postDistrictCode'];
  35. } else {
  36. // echo "没有对应代码~,请联系管理员更新~";
  37. }
  38. // 执行查询
  39. $sqlconfig = "SELECT * FROM config_api WHERE groups = 'Unicom'";
  40. $result = $con->query($sqlconfig);
  41. // 检查是否有匹配的结果
  42. if ($result->num_rows > 0) {
  43. // 获取查询结果的第一行数据
  44. $row = $result->fetch_assoc();
  45. // 提取需要的字段值并存储为变量
  46. $channellt = $row['channel'];
  47. $unicomMallUid = $row['unicomMallUid'];
  48. $historyId = $row['historyId'];
  49. $id = $row ['uid'];
  50. $referer = $row ['referer'];
  51. $pageKey = $row ['pageKey'];
  52. } else {
  53. // echo "没有配置接口~,请联系管理员配置~";
  54. }
  55. //结束联通接口
  56. // 查询 proxy 表,根据 proxy_id 获取代理级别、proxy_upid 和 proxy_acc
  57. $sql = "SELECT * FROM proxy WHERE proxy_id = '$proxy_id'";
  58. $result = mysqli_query($con, $sql);
  59. if ($result) {
  60. $row = mysqli_fetch_assoc($result);
  61. $group_id = $row['group_id'];
  62. $proxy_upid = $row['proxy_upid'];
  63. $proxy_acc = $row['proxy_acc'];
  64. // 查询 proxy_group 表,获取对应的 group_name 和 group_portion
  65. $group_name = "";
  66. $group_portion = 0;
  67. $sql = "SELECT * FROM proxy_group WHERE group_id = '$group_id'";
  68. $result = mysqli_query($con, $sql);
  69. if ($result) {
  70. $row = mysqli_fetch_assoc($result);
  71. $group_name = $row['group_name'];
  72. $group_portion = $row['group_portion'];
  73. }
  74. // 根据代理级别进行不同的查询
  75. if ($group_name == '三级代理') {
  76. // 查询上级代理
  77. $sql = "SELECT * FROM proxy WHERE proxy_id = '$proxy_upid'";
  78. $result = mysqli_query($con, $sql);
  79. if ($result) {
  80. $row = mysqli_fetch_assoc($result);
  81. $proxy_upid_2 = $row['proxy_upid'];
  82. $proxy_acc_2 = $row['proxy_acc'];
  83. $group_id_2 = $row['group_id'];
  84. //取比例
  85. $sql_group_2 = "SELECT * FROM proxy_group WHERE group_id = '$group_id_2'";
  86. $result_group_2 = mysqli_query($con, $sql_group_2);
  87. if ($result_group_2) {
  88. $row_group_2 = mysqli_fetch_assoc($result_group_2);
  89. $group_portion_2 = $row_group_2['group_portion'];
  90. }
  91. $newprice_a = $proxy_price + $group_portion;
  92. $newprice_b = $proxy_price + $group_portion - $group_portion_2;
  93. $newprice_2 = $newprice_a - $newprice_b;
  94. // 查询上上级代理
  95. $sql = "SELECT * FROM proxy WHERE proxy_id = '$proxy_upid_2'";
  96. $result = mysqli_query($con, $sql);
  97. if ($result) {
  98. $row = mysqli_fetch_assoc($result);
  99. $proxy_acc_3 = $row['proxy_acc'];
  100. $group_id_3 = $row['group_id'];
  101. //取比例
  102. $sql_group_3 = "SELECT * FROM proxy_group WHERE group_id = '$group_id_3'";
  103. $result_group_3 = mysqli_query($con, $sql_group_3);
  104. if ($result_group_3) {
  105. $row_group_3 = mysqli_fetch_assoc($result_group_3);
  106. $group_portion_3 = $row_group_3['group_portion'];
  107. }
  108. $newprice_a = $proxy_price + $group_portion;
  109. $newprice_b = $proxy_price + $group_portion - $group_portion_3;
  110. $newprice_3 = $newprice_a - $newprice_b;
  111. // 判断是否有name,uid,phone,dizhi这四项信息,如果有任何一项为空,则返回错误信息
  112. if (empty($name) || empty($uid) || empty($phone) || empty($dizhi)) {
  113. $response = array('status' => -1, 'msg' => '信息不完整,请重新输入');
  114. echo json_encode($response);
  115. return;
  116. }
  117. // 判断订单是否已经提交过
  118. session_start();
  119. if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) {
  120. $response = array('status' => 1, 'msg' => '订单已经提交过了');
  121. echo json_encode($response);
  122. return;
  123. }
  124. $data_query = mysqli_query($con, "select * from oder where uid='$uid'");
  125. $count = mysqli_num_rows($data_query);
  126. if ($count > 10) {
  127. // 用户已经申请过了,返回状态码1和提示信息
  128. $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服');
  129. echo json_encode($response);
  130. } else {
  131. // 订单写入数据库成功后执行写入佣金表
  132. $data_insert = mysqli_query($con, "INSERT INTO oder(goods, name, uid, phone, sf, city, xian, dizhi, oderid, time, proxy_id, proxy_price, price, api_type) VALUES ('$goods', '$name', '$uid', '$phone', '$sf', '$city', '$xian', '$dizhi', '$oderid', '$time', '$proxy_id', '$proxy_price', '$price', '$api_type')");
  133. // 写入佣金表
  134. $data_revenue = mysqli_query($con, "INSERT INTO revenue(account, oderid, name, price, beizhu, cr_time, proxy_upid, proxy_prices, proxy_upids, proxy_pricess) VALUES ('$proxy_acc', '$oderid', '$name', '$proxy_price', '$beizhu', '$time', '$proxy_acc_2', '$newprice_2', '$proxy_acc_3', '$newprice_3')");
  135. }
  136. }
  137. }
  138. } elseif ($group_name == '二级代理') {
  139. // 查询上级代理
  140. $sql = "SELECT * FROM proxy WHERE proxy_id = '$proxy_upid'";
  141. $result = mysqli_query($con, $sql);
  142. if ($result) {
  143. $row = mysqli_fetch_assoc($result);
  144. $proxy_acc_2 = $row['proxy_acc'];
  145. $group_id_2 = $row['group_id'];
  146. //取比例
  147. $sql_group_2 = "SELECT * FROM proxy_group WHERE group_id = '$group_id_2'";
  148. $result_group_2 = mysqli_query($con, $sql_group_2);
  149. if ($result_group_2) {
  150. $row_group_2 = mysqli_fetch_assoc($result_group_2);
  151. $group_portion_2 = $row_group_2['group_portion'];
  152. }
  153. $newprice_a = $proxy_price + $group_portion;
  154. $newprice_b = $proxy_price + $group_portion - $group_portion_2;
  155. $newprice_2 = $newprice_a - $newprice_b;
  156. // 判断是否有name,uid,phone,dizhi这四项信息,如果有任何一项为空,则返回错误信息
  157. if (empty($name) || empty($uid) || empty($phone) || empty($dizhi)) {
  158. $response = array('status' => -1, 'msg' => '信息不完整,请重新输入');
  159. echo json_encode($response);
  160. return;
  161. }
  162. // 判断订单是否已经提交过
  163. session_start();
  164. if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) {
  165. $response = array('status' => 1, 'msg' => '订单已经提交过了');
  166. echo json_encode($response);
  167. return;
  168. }
  169. $data_query = mysqli_query($con, "select * from oder where uid='$uid'");
  170. $count = mysqli_num_rows($data_query);
  171. if ($count > 10) {
  172. // 用户已经申请过了,返回状态码1和提示信息
  173. $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服');
  174. echo json_encode($response);
  175. } else {
  176. // 订单写入数据库成功后执行写入佣金表
  177. $data_insert = mysqli_query($con, "INSERT INTO oder(goods, name, uid, phone, sf, city, xian, dizhi, oderid, time, proxy_id, proxy_price, price ,api_type) VALUES ('$goods', '$name', '$uid', '$phone', '$sf', '$city', '$xian', '$dizhi', '$oderid', '$time', '$proxy_id', '$proxy_price', '$price', '$api_type')");
  178. // 写入佣金表
  179. $data_revenue = mysqli_query($con, "INSERT INTO revenue(account, oderid, name, price, beizhu, cr_time, proxy_upid, proxy_prices) VALUES ('$proxy_acc', '$oderid', '$name', '$proxy_price', '$beizhu', '$time', '$proxy_acc_2', '$newprice_2')");
  180. }
  181. }
  182. }elseif ($group_name == '一级代理') {
  183. // 判断是否有name,uid,phone,dizhi这四项信息,如果有任何一项为空,则返回错误信息
  184. if (empty($name) || empty($uid) || empty($phone) || empty($dizhi)) {
  185. $response = array('status' => -1, 'msg' => '信息不完整,请重新输入');
  186. echo json_encode($response);
  187. return;
  188. }
  189. // 判断订单是否已经提交过
  190. session_start();
  191. if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) {
  192. $response = array('status' => 1, 'msg' => '订单已经提交过了');
  193. echo json_encode($response);
  194. return;
  195. }
  196. $data_query = mysqli_query($con, "select * from oder where uid='$uid'");
  197. $count = mysqli_num_rows($data_query);
  198. if ($count > 10) {
  199. // 用户已经申请过了,返回状态码1和提示信息
  200. $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服');
  201. echo json_encode($response);
  202. } else {
  203. // 订单写入数据库成功后执行写入佣金表
  204. $data_insert = mysqli_query($con, "INSERT INTO oder(goods, name, uid, phone, sf, city, xian, dizhi, oderid, time, proxy_id, proxy_price, price ,api_type) VALUES ('$goods', '$name', '$uid', '$phone', '$sf', '$city', '$xian', '$dizhi', '$oderid', '$time', '$proxy_id', '$proxy_price', '$price' , '$api_type')");
  205. // 写入佣金表
  206. $data_revenue = mysqli_query($con, "INSERT INTO revenue(account, oderid, name, price, beizhu, cr_time) VALUES ('$proxy_acc', '$oderid', '$name', '$proxy_price', '$beizhu', '$time')");
  207. }
  208. } elseif ($group_name == '运营平台') {
  209. // 判断是否有name,uid,phone,dizhi这四项信息,如果有任何一项为空,则返回错误信息
  210. if (empty($name) || empty($uid) || empty($phone) || empty($dizhi)) {
  211. $response = array('status' => -1, 'msg' => '信息不完整,请重新输入');
  212. echo json_encode($response);
  213. return;
  214. }
  215. // 判断订单是否已经提交过
  216. session_start();
  217. if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) {
  218. $response = array('status' => 1, 'msg' => '订单已经提交过了');
  219. echo json_encode($response);
  220. return;
  221. }
  222. $data_query = mysqli_query($con, "select * from oder where uid='$uid'");
  223. $count = mysqli_num_rows($data_query);
  224. if ($count > 10) {
  225. // 用户已经申请过了,返回状态码1和提示信息
  226. $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服');
  227. echo json_encode($response);
  228. } else {
  229. // 订单写入数据库成功后执行写入佣金表
  230. $data_insert = mysqli_query($con, "INSERT INTO oder(goods, name, uid, phone, sf, city, xian, dizhi, oderid, time, proxy_id, proxy_price, price ,api_type) VALUES ('$goods', '$name', '$uid', '$phone', '$sf', '$city', '$xian', '$dizhi', '$oderid', '$time', '$proxy_id', '$proxy_price', '$price' , '$api_type')");
  231. // 写入佣金表
  232. $data_revenue = mysqli_query($con, "INSERT INTO revenue(account, oderid, name, price, beizhu, cr_time) VALUES ('$proxy_acc', '$oderid', '$name', '$proxy_price', '$beizhu', '$time')");
  233. }
  234. }
  235. $sql = "SELECT haokaid FROM list WHERE name='$goods'";
  236. $res = mysqli_query($con, $sql);
  237. if (mysqli_num_rows($res) > 0) {
  238. $row = mysqli_fetch_assoc($res);
  239. $haokaid = $row['haokaid'];
  240. }
  241. if ($haokaid == 0) {
  242. // haokaid等于0,直接输出申请成功
  243. $response = array('status' => 0, 'msg' => '申请成功');
  244. echo json_encode($response);
  245. // 将订单号写入session
  246. $_SESSION['order_id'] = $oderid;
  247. //发送短信通知
  248. sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign);
  249. exit;
  250. } else {
  251. // 构造请求参数
  252. $params = array(
  253. 'pageKey' => $pageKey,
  254. 'referer'=> $referer,
  255. 'id' => $id,
  256. 'productType' => $haokaid,
  257. 'channel' => $channellt,
  258. 'certName' => $name,
  259. 'certNo' => $uid,
  260. 'contactNum' => $phone,
  261. 'postProvinceCode' => $postProvinceCode,
  262. 'postCityCode' => $postCityCode,
  263. 'postDistrictCode' => $postDistrictCode,
  264. 'postProvince' => $sf,
  265. 'postCity' => $city,
  266. 'postDistrict' => $xian,
  267. 'postAddr' => $dizhi,
  268. 'postName' => $name,
  269. 'fromWx' => false,
  270. 'provinceCode' => "50",
  271. 'cityCode' => "501",
  272. 'province' => "海南",
  273. 'city' => "海口",
  274. 'phoneNum' => $thirdphone,
  275. 'consentSign' => false,
  276. 'historyId' => $historyId,
  277. 'pageRouter' => "commonOrder5G_common",
  278. 'unicomMallUid' => $unicomMallUid,
  279. 'saleTurn' => "",
  280. );
  281. // 构造请求头
  282. $headers = array(
  283. 'Content-Type: application/json', // 修改为 application/json
  284. );
  285. // 发送请求
  286. $ch = curl_init();
  287. curl_setopt($ch, CURLOPT_URL, 'https://kapi.10010.com/kcardorder/intentionalOrder/preSelect');
  288. curl_setopt($ch, CURLOPT_POST, true);
  289. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); // 将请求参数转换为 JSON 格式
  290. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  291. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  292. $response = curl_exec($ch);
  293. curl_close($ch);
  294. // 解析响应数据
  295. $result = json_decode($response, true);
  296. if ($result['code'] == 20000) {
  297. // 更新订单状态
  298. $update_sql = "UPDATE oder SET status=1, beizhu='$beizhus' WHERE oderid='$oderid'";
  299. $update_sql_revenue = "UPDATE revenue SET oder_sta=1 WHERE oderid='$oderid'";
  300. $update_query = mysqli_query($con, $update_sql);
  301. if ($update_query) {
  302. // 更新成功,返回状态码0和提示信息
  303. $response = array('status' => 0, 'msg' => '申请成功');
  304. echo json_encode($response);
  305. // 将订单号写入session
  306. $_SESSION['order_id'] = $oderid;
  307. //发送短信通知
  308. sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign);
  309. } else {
  310. // 更新失败,返回状态码-2和提示信息
  311. $response = array('status' => -2, 'msg' => '更新订单状态失败');
  312. echo json_encode($response);
  313. }
  314. } else {
  315. // 下单失败,返回接口返回的错误信息
  316. $update_sql = "UPDATE oder SET status=4, beizhu='" . $result['message'] . "' WHERE oderid='$oderid'";
  317. $update_query = mysqli_query($con, $update_sql);
  318. $response = array('status' => $result['code'], 'msg' => $result['message']);
  319. echo json_encode($response);
  320. }
  321. }
  322. }