LtOderApi.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. require('SendSms.php');
  3. $goods = $_POST['goods'];
  4. $name = $_POST['name'];
  5. $uid = $_POST['uid'];
  6. $phone = $_POST['phone'];
  7. $sf = $_POST['sf'];
  8. $city = $_POST['city'];
  9. $xian = $_POST['xian'];
  10. $dizhi = $_POST['dizhi'];
  11. $oderid = $_POST['oderid'];
  12. $time = $_POST['time'];
  13. $channel = $_POST['channel'];
  14. $price = $_POST['price'];
  15. $thirdphone = $_POST['thirdphone'];
  16. $beizhu = "已经提交运营商审核";
  17. include_once("../untils/conn.php");
  18. // 执行查询
  19. $sql = "SELECT * FROM cityCode WHERE postProvinceName = '$sf' AND postCityName = '$city' AND postDistrictName = '$xian'";
  20. $result = $con->query($sql);
  21. // 检查是否有匹配的结果
  22. if ($result->num_rows > 0) {
  23. // 获取查询结果的第一行数据
  24. $row = $result->fetch_assoc();
  25. // 提取需要的字段值并存储为变量
  26. $postProvinceCode = $row['postProvinceCode'];
  27. $postCityCode = $row['postCityCode'];
  28. $postDistrictCode = $row['postDistrictCode'];
  29. } else {
  30. // echo "没有对应代码~,请联系管理员更新~";
  31. }
  32. // 执行查询
  33. $sqlconfig = "SELECT * FROM config_api WHERE groups = 'Unicom'";
  34. $result = $con->query($sqlconfig);
  35. // 检查是否有匹配的结果
  36. if ($result->num_rows > 0) {
  37. // 获取查询结果的第一行数据
  38. $row = $result->fetch_assoc();
  39. // 提取需要的字段值并存储为变量
  40. $channellt = $row['channel'];
  41. $unicomMallUid = $row['unicomMallUid'];
  42. $historyId = $row['historyId'];
  43. $id = $row ['uid'];
  44. $referer = $row ['referer'];
  45. $pageKey = $row ['pageKey'];
  46. } else {
  47. // echo "没有配置接口~,请联系管理员配置~";
  48. }
  49. if ($con) {
  50. mysqli_query($con, "set names utf8");
  51. // 判断是否有name,uid,phone,dizhi这四项信息,如果有任何一项为空,则返回错误信息
  52. if (empty($name) || empty($uid) || empty($phone) || empty($dizhi)) {
  53. $response = array('status' => -1, 'msg' => '信息不完整,请重新输入');
  54. echo json_encode($response);
  55. return;
  56. }
  57. // 判断订单是否已经提交过
  58. session_start();
  59. if (isset($_SESSION['order_id']) && $_SESSION['order_id'] == $oderid) {
  60. $response = array('status' => 1, 'msg' => '订单已经提交过了');
  61. echo json_encode($response);
  62. return;
  63. }
  64. $data_query = mysqli_query($con, "select * from oder where uid='$uid'");
  65. $count = mysqli_num_rows($data_query);
  66. if ($count > 10) {
  67. // 用户已经申请过了,返回状态码1和提示信息
  68. $response = array('status' => 1, 'msg' => '您申请的订单已超限,请联系客服');
  69. echo json_encode($response);
  70. } else {
  71. // 判断$channel变量是否为空,如果为空则将其赋值为null
  72. if(empty($channel)){
  73. $channel = 0;
  74. }
  75. $data_insert = mysqli_query($con, "insert into oder(goods,name,uid,phone,sf,city,xian,dizhi,oderid,time,price,channel,thirdphone) values('$goods','$name','$uid','$phone','$sf','$city','$xian','$dizhi','$oderid','$time','$price','$channel','$thirdphone')");
  76. if ($data_insert) {
  77. $sql = "SELECT haokaid FROM list WHERE name='$goods'";
  78. $res = mysqli_query($con, $sql);
  79. if(mysqli_num_rows($res) > 0){
  80. $row = mysqli_fetch_assoc($res);
  81. $haokaid = $row['haokaid'];
  82. }
  83. if ($haokaid == 0) {
  84. // haokaid等于0,直接输出申请成功
  85. $response = array('status' => 0, 'msg' => '申请成功');
  86. echo json_encode($response);
  87. //发送短信通知
  88. sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign);
  89. } else {
  90. // 构造请求参数
  91. $params = array(
  92. 'pageKey' => $pageKey,
  93. 'referer'=> $referer,
  94. 'id' => $id,
  95. 'productType' => $haokaid,
  96. 'channel' => $channellt,
  97. 'certName' => $name,
  98. 'certNo' => $uid,
  99. 'contactNum' => $phone,
  100. 'postProvinceCode' => $postProvinceCode,
  101. 'postCityCode' => $postCityCode,
  102. 'postDistrictCode' => $postDistrictCode,
  103. 'postProvince' => $sf,
  104. 'postCity' => $city,
  105. 'postDistrict' => $xian,
  106. 'postAddr' => $dizhi,
  107. 'postName' => $name,
  108. 'fromWx' => false,
  109. 'provinceCode' => "50",
  110. 'cityCode' => "501",
  111. 'province' => "海南",
  112. 'city' => "海口",
  113. 'phoneNum' => $thirdphone,
  114. 'consentSign' => false,
  115. 'historyId' => $historyId,
  116. 'pageRouter' => "commonOrder5G_common",
  117. 'unicomMallUid' => $unicomMallUid,
  118. 'saleTurn' => "",
  119. );
  120. // 构造请求头
  121. $headers = array(
  122. 'Content-Type: application/json', // 修改为 application/json
  123. );
  124. // 发送请求
  125. $ch = curl_init();
  126. curl_setopt($ch, CURLOPT_URL, 'https://kapi.10010.com/kcardorder/intentionalOrder/preSelect');
  127. curl_setopt($ch, CURLOPT_POST, true);
  128. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); // 将请求参数转换为 JSON 格式
  129. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  130. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  131. $response = curl_exec($ch);
  132. curl_close($ch);
  133. // 解析响应数据
  134. $result = json_decode($response, true);
  135. if ($result['code'] == 20000) {
  136. // 更新订单状态
  137. $update_sql = "UPDATE oder SET status=1, beizhu='$beizhu' WHERE oderid='$oderid'";
  138. $update_query = mysqli_query($con, $update_sql);
  139. if ($update_query) {
  140. // 更新成功,返回状态码0和提示信息
  141. $response = array('status' => 0, 'msg' => '申请成功');
  142. echo json_encode($response);
  143. // 将订单号写入session
  144. $_SESSION['order_id'] = $oderid;
  145. //发送短信通知
  146. sendSms($appId, $appKey, $phoneNumber, $templateId, $smsSign);
  147. } else {
  148. // 更新失败,返回状态码-2和提示信息
  149. $response = array('status' => -2, 'msg' => '更新订单状态失败');
  150. echo json_encode($response);
  151. }
  152. } else {
  153. // 下单失败,返回接口返回的错误信息
  154. $update_sql = "UPDATE oder SET status=4, beizhu='" . $result['message'] . "' WHERE oderid='$oderid'";
  155. $update_query = mysqli_query($con, $update_sql);
  156. $response = array('status' => $result['code'], 'msg' => $result['message']);
  157. echo json_encode($response);
  158. }
  159. }
  160. } else {
  161. // 信息不全,返回状态码-1和提示信息
  162. $response = array('status' => -1, 'msg' => '哦豁,又出错了,找客服吧~');
  163. echo json_encode($response);
  164. }
  165. }
  166. }
  167. ?>