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.
 
 
 
 

434 lines
17 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:Spiders Travel
  5. */
  6. require_once '../Common/Mysql.php';
  7. if (ALLOW_ORIGIN)
  8. header("Access-Control-Allow-Origin:*");
  9. header("Content-type:text/html;charset=utf-8");
  10. $method = isset($_GET['method']) ? $_GET['method'] : "";
  11. $user_id = getUserId();
  12. if ($user_id == false) {
  13. echo json_encode(array("code" => "1", "info" => "用户未登录"));
  14. exit ;
  15. }
  16. //$user_id=1;
  17. //取消订单原因
  18. if(isset($_GET['reason'])){
  19. $reason=$_GET['reason'];
  20. $order_id=$_GET['order_id'];
  21. $clock=$_GET['clock'];
  22. // $return_data = array();
  23. // $return_data["code"] = 1;
  24. // $return_data["info"] = $reason;
  25. $pdo_insert = conn();
  26. $sql = "insert into order_comment(ORDER_ID,COMMENT_TXT,CREATE_TIME) VALUES ({$order_id},'{$reason}','{$clock}')";
  27. $result = $pdo_insert->exec($sql);
  28. }
  29. if ($method == "cancelOrder") {
  30. $order_id = isset($_GET['order_id']) ? $_GET['order_id'] : "";
  31. $pdo = conn();
  32. $list_d = Find($order_id);
  33. if($list_d['prod_id'] == 449862 || $list_d['prod_id'] == 449867 || $list_d['prod_id'] == 450039 || $list_d['prod_id'] == 450043 || $list_d['prod_id'] == 450541 || $list_d['prod_id'] == 450546 ){
  34. $result = post2('http://wx.zhizhuchuxing.com/ZZDZ2/application/custom_made/control.php',array('type' =>'order_refund','order_id'=>$order_id));
  35. $result = (array)json_decode($result,true);
  36. }else{
  37. $sql = "CALL SP_CANCEL_ORDER(" . $user_id . "," . $order_id . ")";
  38. writeLog('cancelOrder= sql='.$sql);
  39. $result = $pdo -> query($sql);
  40. if( false != $result ) {
  41. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  42. $result = array();
  43. $result['code'] = $rowset[0]['errorcode'];
  44. }
  45. }
  46. if($result){
  47. if(isset($result['code']) && $result['code'] == 0){
  48. $rowset['code'] ='0';
  49. $rowset['info'] ='退票成功';
  50. $data['code'] ='0';
  51. $data['info'] = '退票成功';
  52. $pdo_insert = conn();
  53. $current_time = date("Y-m-d H:i:s");
  54. $cancel_reason = "取消原因:".$reason;
  55. $sql = "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$order_id},$user_id,2,'{$current_time}','{$cancel_reason}','CS系统')";
  56. $result = $pdo_insert->exec($sql);
  57. $post_data['order_id'] = "{$order_id}";
  58. $post_data['order_status'] = "460";
  59. $temp=post2("http://". CS_DOMAIN. "/st-xm/Api/add_order_status_log.php",$post_data);
  60. //在这里加入run_x重排,该取消订单所在的车次的run_x数据
  61. $re_data=array();
  62. $re_data['order_id']=$order_id;
  63. $temp2=post2("http://". CS_DOMAIN. "/api1.0/run_x_reorder.php",$re_data);
  64. $data['extra']=json_decode($temp2);
  65. }else{
  66. $data['code']=isset($rowset[0]['errorcode'])?$rowset[0]['errorcode']:"499";
  67. $data['info']=isset($rowset[0]['errorinfo'])?$rowset[0]['errorinfo']:"未从数据库中获得返回值";
  68. $rowset['code'] = $data['code'];
  69. $rowset['info'] = $data['info'];
  70. $result -> closeCursor();
  71. }
  72. // echo json_encode($data);exit();
  73. }else{
  74. $data['code']="500";
  75. $data['info']="数据库错误";
  76. echo json_encode($data);exit();
  77. }
  78. if (is_array($rowset) && $rowset['code'] == 0 && SEND_MESSAGE == true) {
  79. $res_content = get_msg_info($order_id);
  80. $name = isset($res_content[0])?$res_content[0]:"";
  81. $tel = isset($res_content[1])?$res_content[1]:"";
  82. $content = isset($res_content[2])?$res_content[2]:"";
  83. // $content = "单号:" . $order_id . ',订单状态变更为' . $order_status . "随机数" . rand(1, 10000);
  84. writeLog("巴士取消短信模板内容:【" . $content . "】");
  85. //..取消发短信
  86. $response=null;
  87. $send_success="-100";
  88. // $response = sendTelMessage($tel, $name, $content, $order_id);
  89. // writeLog(json_encode($response));
  90. // $send_success = (int)$response;
  91. $comment_type=0;
  92. $comment_text="";
  93. $sql1 = "CALL HT_ADD_MSG_COMMENT(".$user_id.",'addmsg'," . $order_id . "," . $comment_type . ",'" . $comment_text . "','" . $tel . "','" . $content . "','" . date("Y-m-d H:i:s") . "',{$send_success})";
  94. $result1 = $pdo -> query($sql1);
  95. $rowset1 = $result1 -> fetchAll(PDO::FETCH_ASSOC);
  96. $result1 -> closeCursor();
  97. writeLog("order_list.php HT_ADD_MSG_COMMENT()::" . $sql1);
  98. }
  99. echo json_encode($data);exit();
  100. }else if($method=="getOrderORG"){
  101. $pdo=conn();
  102. // $sql="SELECT ORG_ID AS org_id ,ORG_NAME as soure FROM base_organization where cancel_flag=0;";
  103. $sql="SELECT ID AS org_id ,SUPPLIER_NAME as soure FROM base_supplier where cancel_flag=0 AND SUPPLIER_TYPE=301";
  104. $main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  105. if( $main_corp_id > 0 ) {
  106. $sql .= " AND MAIN_CORP_ID IN(0,{$main_corp_id}) ";
  107. }
  108. if( $main_corp_id != 3 ) {
  109. $sql .= " AND MAIN_CORP_ID NOT IN(3) ";
  110. }
  111. $result=$pdo->query($sql);
  112. $rowset=array("code"=>"0","info"=>"");
  113. $rowset['order_ORG_List']=$result->fetchAll(PDO::FETCH_ASSOC);
  114. $result->closeCursor();
  115. echo json_encode($rowset);exit();
  116. }
  117. else {
  118. $timelimit = isset($_GET['timelimit']) ? $_GET['timelimit'] : '';
  119. $starttime = isset($_GET['starttime']) ? $_GET['starttime'] : '';
  120. $endtime = isset($_GET['endtime']) ? $_GET['endtime'] : '';
  121. $ordersource = isset($_GET['ordersource']) ? (empty($_GET['ordersource']) ? 0 : $_GET['ordersource']) : 0;
  122. $orderstatus = isset($_GET['orderstatus']) ? (empty($_GET['orderstatus']) ? 0 : $_GET['orderstatus']) : 0;
  123. $paystatus = isset($_GET['paystatus']) ? (empty($_GET['paystatus']) ? -1 : $_GET['paystatus']) : -1;
  124. $bus_type= isset($_GET['bus_type']) ? (empty($_GET['bus_type']) ? -1 : $_GET['bus_type']) : -1;
  125. $billingstatus = isset($_GET['billingstatus']) ? $_GET['billingstatus'] : '';
  126. $mealbounce = isset($_GET['mealbounce']) ? $_GET['mealbounce'] : '';
  127. $refund = isset($_GET['refund']) ? $_GET['refund'] : '';
  128. $moresearch = isset($_GET['moresearch']) ? trim($_GET['moresearch']) : '';
  129. $export = isset($_GET['export']) ? $_GET['export'] : '';
  130. //2016-07-15新增
  131. $start_area=isset($_GET['start_area']) ? $_GET['start_area'] : '';
  132. $end_area=isset($_GET['end_area']) ? $_GET['end_area'] : '';
  133. $line=isset($_GET['line']) ? $_GET['line'] : '';
  134. //..暂未加入存储过程
  135. $currpage = isset($_GET['currpage']) ? (empty($_GET['currpage']) ? 1 : $_GET['currpage']) : 1;
  136. $pagesize = isset($_GET['pagesize']) ? (empty($_GET['pagesize']) ? 10 : $_GET['pagesize']) : 10;
  137. $pdo = conn();
  138. $sql = "CALL XM_ORDER_GET_LIST(".$user_id.",'" . $timelimit . "','" . $starttime . "','" . $endtime . "'," . $ordersource . "," . $orderstatus . "," . $paystatus . ",'" . $billingstatus . "','" . $mealbounce . "','" . $refund . "','" . $moresearch . "','" . $export . "'," . $currpage . "," . $pagesize . ",'".$line."','".$start_area."','".$end_area."','".$bus_type."')";
  139. writeLog('order_list.php -- sql== '.$sql);
  140. $result = $pdo -> query($sql);
  141. if( false == $result ) {
  142. echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));exit();
  143. }
  144. $data = array();
  145. do {
  146. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  147. if ($rowset) {
  148. $data[] = $rowset;
  149. }
  150. } while ($result->nextRowset());
  151. $count = count($data);
  152. // print_r(json_encode($data[3]));exit();
  153. if ($count == 1 && isset($data[0][0]['code']) && $data[0][0]['code'] != 0) {
  154. echo json_encode($data[0][0]);
  155. } else if ($count == 4) {
  156. // } else if ($count > 0) {
  157. $data1 = array();
  158. $data2 = array();
  159. $data3 = array();
  160. $order_id_array = array();
  161. $data1=isset($data[1])?$data[1]:array();
  162. foreach($data[1] as $k => $v){
  163. $order_id_array[]=$v['parent_orderNo'];
  164. }
  165. $pdo2 = conn();
  166. $search_extra_sql = " SELECT * FROM order_extra_info WHERE order_id IN (".implode(",",$order_id_array).") ";
  167. $result2 = $pdo2->query($search_extra_sql);
  168. $order_extra_array = $result2->fetchAll();
  169. if( $order_extra_array != false && count($order_extra_array) > 0 ) {
  170. $order_extra_array2 = array();
  171. foreach ( $order_extra_array as $order_extra_info ) {
  172. $order_extra_array2[$order_extra_info["order_id"]] = $order_extra_info;
  173. }
  174. $order_extra_array = $order_extra_array2;
  175. }
  176. $data1_temp = array();
  177. $disp_pay_type = array("221" => "授信支付", "232" => "天猫旗舰店支付", "275" => "授信支付", "278" => "微信支付");
  178. foreach( $data1 as $k=>$data1_info ) {
  179. if( isset($order_extra_array[$data1_info["M_ID"]]) ) {
  180. $data1_info["hotel_price"] = $order_extra_array[$data1_info["M_ID"]]["hotel_price"];
  181. $data1_info["gate_price"] = $order_extra_array[$data1_info["M_ID"]]["gate_price"];
  182. $extra_info_array = array();
  183. if( isset($data1_info["hotel_price"]) && mb_strlen($data1_info["hotel_price"]) > 0 ) {
  184. $extra_info_array[] ="酒店:".$data1_info["hotel_price"];
  185. }
  186. if( isset($data1_info["gate_price"]) && mb_strlen($data1_info["gate_price"]) > 0 ) {
  187. $extra_info_array[] ="门票:".$data1_info["gate_price"];
  188. }
  189. $data1_info["seat"] .= "[br /]".implode(" ", $extra_info_array);
  190. }
  191. if( $data1_info["org_id"] == 17 or $data1_info["org_id"]== 28){
  192. $data1_info["pay_type"] = "授信支付"; //携程与去哪儿汽车票均显示授信支付方式
  193. $data1_temp[] = $data1_info;
  194. }else{
  195. $data1_info["pay_type"] = isset($disp_pay_type[$data1_info["pay_type"]]) ? $disp_pay_type[$data1_info["pay_type"]] : "";
  196. $data1_temp[] = $data1_info;
  197. }
  198. }
  199. $data1 = $data1_temp;
  200. // echo json_encode($data[1]);exit();
  201. $json = array("code" => "0", "info" => "");
  202. $json['totalTickets'] = $data[2][0]['num'];
  203. $json['totalPages'] = $data[2][0]['pagecount'];
  204. $json['currentpage'] = isset($data[2][0]['CURRENTPAGE']) ? $data[2][0]['CURRENTPAGE'] : "1";
  205. $json['pagesize'] = $data[2][0]['PAGESIZE'];
  206. $json['orderSource'] = $data[0];
  207. $json['orderList'] = array_values($data1);
  208. // print_r($data1);echo "<hr />";
  209. $or_st = array();
  210. $or_st['status_all'] = $data[2][0]['num'];
  211. foreach ($data[3] as $da) {
  212. $or_st[$da['order_status']] = $da['order_cnt'];
  213. }
  214. $json['orderStatus'][] = $or_st;
  215. // $json['orderStatus'][$data[3]['order_status']]=
  216. // $row_count_array = array();
  217. // foreach ($data[1] as $k => $v) {
  218. // if (!isset($row_count_array[$v["order_status"]])) {
  219. // $row_count_array[$v["order_status"]] = 0;
  220. // }
  221. // $row_count_array[$v["order_status"]]++;
  222. // }
  223. // $sum = (string)count($data[1]);
  224. // if ($sum == "0") {
  225. // $sum = "";
  226. // }
  227. // $row_count_array['status_all'] = $data[2][0]['num'];
  228. // if (count($row_count_array) > 0) {
  229. // $json['orderStatus'][] = $row_count_array;
  230. // } else {
  231. // $json['orderStatus'][] = array();
  232. // }
  233. //echo json_encode($data1);
  234. echo json_encode($json);
  235. } else {
  236. echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));
  237. }
  238. }
  239. function get_msg_info($ORDER_ID) {
  240. $msg_pdo = conn();
  241. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  242. $content = '';
  243. if (is_object($msg_pdo)) {
  244. $msg_result = $msg_pdo -> query($msg_sql);
  245. $i = 1;
  246. $data = array();
  247. if ($msg_result) {
  248. $data['code'] = "0";
  249. $data['info'] = "";
  250. do {
  251. $row = $msg_result -> fetchAll(PDO::FETCH_ASSOC);
  252. if ($i == 1) {
  253. $data['seat'] = isset($row) ? $row : array();
  254. } else if ($i == 2) {
  255. $data['run_info'] = isset($row) ? $row : array();
  256. } else if ($i == 3) {
  257. $data['driver'] = isset($row) ? $row : array();
  258. } else {
  259. }
  260. $i++;
  261. } while($msg_result->nextRowset());
  262. }
  263. $json_obj = json_decode(json_encode($data), TRUE);
  264. $seat = isset($json_obj['seat'][0])?$json_obj['seat'][0]:array();
  265. $run_info = isset($json_obj['run_info'][0])?$json_obj['run_info'][0]:array();
  266. $driver = isset($json_obj['driver'][0])?$json_obj['driver'][0]:array();
  267. //取消
  268. $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已成功退票,期待下次再为您服务!";
  269. if ($seat) {
  270. $seat_x = $seat['seat_x'];
  271. $seat_y = $seat['seat_y'];
  272. $seat_name = $seat['seat_name'];
  273. $order_main_id = $seat['order_main_id'];
  274. }
  275. if ($run_info) {
  276. $order_count = $run_info['order_count'];
  277. $start_date = $run_info['start_date'];
  278. $start_time = $run_info['start_time'];
  279. $parent_order_id = $run_info['parent_order_id'];
  280. $end_date = $run_info['end_date'];
  281. $start_area = $run_info['start_area'];
  282. $end_area = $run_info['end_area'];
  283. $res_name = $run_info['res_name'];
  284. $prod_name=$run_info['prod_name'];
  285. $prod_name="标准票";
  286. $customer_name = $run_info['customer_name'];
  287. $customer_mobile = $run_info['customer_mobile'];
  288. $start_end_date = $start_date . "," . $start_time;
  289. $content = str_replace("{出发地}", $start_area, $content);
  290. $content = str_replace("{目的地}", $end_area, $content);
  291. $content = str_replace("{出发日期 出发时间}", $start_end_date, $content);
  292. $content = str_replace("{票种名}", $prod_name, $content);
  293. $content = str_replace("{张数}", $order_count, $content);
  294. }
  295. if ($driver) {
  296. $bus_no = $driver['bus_no'];
  297. $driver_name = $driver['driver_name'];
  298. $driver_mobile = $driver['driver_mobile'];
  299. }
  300. return array(isset($customer_name)?$customer_name:"", isset($customer_mobile)?$customer_mobile:"", isset($content)?$content:"短信错误!!!");
  301. }
  302. }
  303. function post2($url, $data){//file_get_content
  304. $postdata = http_build_query(
  305. $data
  306. );
  307. $opts = array('http' =>
  308. array(
  309. 'method' => 'POST',
  310. 'header' => 'Content-type: application/x-www-form-urlencoded',
  311. 'content' => $postdata
  312. )
  313. );
  314. $context = stream_context_create($opts);
  315. $result = file_get_contents($url, false, $context);
  316. return $result;
  317. }
  318. function Find($order_id){
  319. $pdo= conn();
  320. $sql = "select order_description,order_price,order_pay_main_id "
  321. . "from order_main "
  322. . "where order_id=".$order_id;
  323. $result=$pdo->query($sql);
  324. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  325. $order_price = $rowset[0];//订单总价格 订单票的数量
  326. $sql = "SELECT DISTINCT
  327. order_description,parent_order_id,run_date,run_id,run_time,run_bus_order_id,prod_id,parent_prod_id,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME
  328. FROM `order_main`
  329. where PARENT_ORDER_ID=".$order_id;
  330. $result=$pdo->query($sql);
  331. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  332. $order_station = $rowset[0];//订单来往地址 订单时间 订单好
  333. if(empty($order_station))
  334. return false;
  335. $array_order_desc=array();
  336. $arr_temp = explode('|',$order_price['order_description']);
  337. $arr=array();
  338. foreach ($arr_temp as $k=>$v2) {
  339. if(!empty($v2))
  340. $array_order_desc[]= explode (',', $v2); //订单票 * 数量
  341. }
  342. $list = array();
  343. //上海(黄浦旅游集散站) - 乌镇(西栅1号停车场)//反的数组
  344. $list['station'] = $order_station['PROD_START_STATION_AREA_NAME'].'('.$order_station['PROD_START_STATION_RES_NAME'].')'
  345. .'-'.$order_station['PROD_END_STATION_AREA_NAME'].'('.$order_station['PROD_END_STATION_RES_NAME'].')';
  346. $list['start_station']=$order_station['PROD_START_STATION_AREA_NAME'];
  347. $list['end_station']=$order_station['PROD_END_STATION_AREA_NAME'];
  348. $list['start_res_name'] = $order_station['PROD_START_STATION_RES_NAME'];
  349. $list['end_res_name'] = $order_station['PROD_END_STATION_RES_NAME'];
  350. $list['run_date'] = $order_station['run_date'];
  351. $list['run_time'] = $order_station['run_date'].' '.$order_station['run_time'];
  352. $list['count']='';
  353. $list['tic_num'] = 0;
  354. foreach ($array_order_desc as $v){
  355. $list['count'] .= ' '.$v[0].' × '.$v[2];
  356. $list['tic_num'] +=$v[2] ;
  357. }
  358. $list['order_price'] = $order_price['order_price'];
  359. $sql = "select pay_serial_number from order_pay_detail where pay_main_id =".$order_price['order_pay_main_id'];
  360. $result=$pdo->query($sql);
  361. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  362. $list['pay_num'] = $rowset[0]['pay_serial_number'];
  363. $list['line_id'] = $order_station['parent_prod_id'];
  364. $list['run_id'] = $order_station['run_id'];//run_bus_order_id
  365. $list['run_bus_order_id'] = $order_station['run_bus_order_id'];//parent_order_id
  366. $list['parent_order_id'] = $order_station['parent_order_id'];
  367. $list['prod_id'] = $order_station['prod_id'];
  368. return $list;
  369. }
  370. exit();