You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

143 lines
6.4 KiB

  1. <?php
  2. require_once '../Common/Mysql.php';
  3. require_once '../Common/zizai_orderAPI.php';
  4. $pdo=conn();
  5. $prod_id = $_GET['prod'];
  6. $prod = explode("|",$prod_id);
  7. $prod = $prod[0];
  8. $prod = explode("p",$prod);
  9. $prod_id = str_replace("{m",'',$prod[0]);
  10. $ticket_num = $prod[1];
  11. $customer = $_GET['customer'];
  12. $customer = str_replace("{",'',$customer);
  13. $customer = str_replace("}",'',$customer);
  14. $customer = explode("^",$customer);
  15. $customer_name = $customer[1];
  16. $customer_mobile = $customer[3];
  17. $customer_id_no = $customer[5];
  18. $passenger_txt = $customer[9];
  19. $from_order_no = $_GET['order_from_org_id'];
  20. $ctrip_order_no = $_GET['outside_order_id'];
  21. $from_org_name = "";
  22. $sql = " SELECT SUPPLIER_NAME FROM base_supplier WHERE ID={$from_order_no} ";
  23. $sql = " SELECT ORG_NAME as SUPPLIER_NAME FROM base_organization WHERE ORG_ID={$from_order_no} ";//
  24. $result=$pdo->query($sql);
  25. if( $result != false ) {
  26. $rowset = $result->fetchAll();
  27. $result->closeCursor();
  28. if( $rowset != false && count($rowset) > 0 ) {
  29. $from_org_name = $rowset[0]["SUPPLIER_NAME"];
  30. }
  31. }
  32. $sql = " SELECT * FROM outside_run WHERE prod_code='".$prod_id."' AND cancel_flag = 0 ";
  33. $result=$pdo->query($sql);
  34. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  35. $result->closeCursor();
  36. $return_data = array();
  37. if( $result == false ) {
  38. $return_data['errcode']='501';
  39. $return_data['errinfo']='该班次为无效班次';
  40. echo json_encode($return_data);
  41. exit();
  42. }
  43. $run_info = $rowset[0];
  44. $remain_count = $run_info['remain_count'];
  45. if( $remain_count < $ticket_num ) {
  46. $return_data['errcode'] = '500';
  47. $return_data['errinfo'] = '该班次剩余库存不足';
  48. echo json_encode($return_data);exit();
  49. }
  50. $run_code = $run_info["run_code"];
  51. //出发地和目的地的area_id
  52. $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["start_area"]."%%\" AND cancel_flag = 0 ";
  53. $result=$pdo->query($sql);
  54. $rowset=$result->fetchAll();
  55. $result->closeCursor();
  56. if( $rowset == false ) {
  57. $start_area_id = 791;
  58. } else {
  59. $start_area_id = $rowset[0]["ID"];
  60. }
  61. $sql = " SELECT ID,AREA_NAME FROM base_area WHERE AREA_NAME like \"".$run_info["end_area"]."%%\" AND cancel_flag = 0 ";
  62. $result=$pdo->query($sql);
  63. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  64. $result->closeCursor();
  65. if( $rowset == false ) {
  66. $end_area_id = 791;
  67. } else {
  68. $end_area_id = $rowset[0]["ID"];
  69. }
  70. $current_time = date("Y-m-d H:i:s");
  71. $userid = getUserId();
  72. $prod_id = 380001;
  73. $run_code = 0;
  74. $myprod = '{m'.$prod_id.'p'.$ticket_num.'|r'.$run_code.'}';
  75. $mycustomer = "{,".$customer_name.",,".$customer_mobile.",150,".$customer_id_no.",,,,".$passenger_txt."}";
  76. $run_info_txt = "{0,普通座票,".$run_info["line_name"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_res"].",".$run_info["start_date"].",".$run_info["start_time"].",".$run_info["start_area"].",".$run_info["end_res"].",,,".$run_info["end_area"].",".$start_area_id.",".$end_area_id."}";
  77. $sql_insert="call sp_make_order_for_zizai(".$userid.",'".$myprod."','".$mycustomer."',". $from_order_no.", '".$ctrip_order_no."',".$run_info["cus_price"].", '".$run_info_txt."')";
  78. writeLog($sql_insert);
  79. $result=$pdo->query($sql_insert);
  80. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  81. $result->closeCursor();
  82. $prod_id = $run_info['prod_code'];
  83. $setOrder = new orderService();
  84. $lock_order = $setOrder->createOrder(zizaiArgs::$USER, $prod_id."P".$ticket_num."|", $customer_name,$customer_mobile,$customer_id_no,'', 0);
  85. if ($lock_order['code'] != 0) {
  86. $post_data = array();
  87. $post_data["errcode"] = 1;
  88. $post_data["errinfo"] = "出票失败:该线路已停售";
  89. echo json_encode($post_data);exit();
  90. } else {
  91. $tradeno = $lock_order['tradeno'];
  92. $customerlist = "";
  93. $passengers = explode("/", $passenger_txt);
  94. foreach( $passengers as $passenger_info ) {
  95. $passenger_array = explode("*",$passenger_info);
  96. if( isset($passenger_array[1]) ) {
  97. $customerlist .= '{'.$prod_id.'|'.$passenger_array[0].'|'.$customer_mobile.'|'.$passenger_array[1].'}';
  98. }
  99. }
  100. if( mb_strlen($customerlist) > 0 ) {
  101. $return_info = $setOrder->customer(zizaiArgs::$USER, $tradeno, $customerlist);
  102. }
  103. $post_data = array();
  104. $order_id=$rowset[0]['order_id'];
  105. $post_data['errcode'] = $rowset[0]['errcode'];
  106. $post_data['errinfo'] = "订票成功";
  107. $post_data['order_id'] = $order_id;
  108. $line_name = str_replace("舟山","普陀山",$run_info["line_name"]);
  109. $send_usr_message = "您已成功订购了{$line_name}[{$run_info["prod_name"]}]{$ticket_num}张。出发时间:{$run_info["start_date"]} {$run_info["start_time"]}。上车地点:{$run_info["start_res"]}。请于发车前到上车站点的服务台领票。咨询电话4008872626";
  110. $response = sendTelMessage($customer_mobile, $customer_name, $send_usr_message, $order_id);
  111. $comment_type=0;
  112. $comment_text="";
  113. $send_success = 0;
  114. $sql1 = "CALL HT_ADD_MSG_COMMENT(2,'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $send_usr_message . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  115. $pdo_update3 = conn();
  116. $result1 = $pdo_update3->query($sql1);
  117. $rowset1 = $result1->fetchAll(PDO::FETCH_ASSOC);
  118. $result1->closeCursor();
  119. $sql_order_status = "update order_main set order_status =146 where order_id= ".$order_id." or parent_order_id = ".$order_id;
  120. $pdo_update3->exec($sql_order_status);
  121. $opera_all_price = $run_info["cus_price"] * $ticket_num;
  122. $pdo_insert2 = conn();
  123. $opera_detail = "创建订单,出发日期{$run_info["start_date"]},订单渠道{$from_org_name},单价{$run_info["cus_price"]},总额{$opera_all_price},联系人信息:{$customer_name},{$customer_mobile},{$customer_id_no},备注信息:";
  124. $sql_log = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},{$userid},1,'{$current_time}','{$opera_detail}','CS系统')";
  125. $pdo_insert2->exec($sql_log);
  126. echo json_encode($post_data);exit();
  127. }
  128. ?>