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.
 
 
 
 

452 lines
20 KiB

  1. <?php
  2. if (ALLOW_ORIGIN)
  3. header("Access-Control-Allow-Origin:*");
  4. date_default_timezone_set('PRC');
  5. //require_once '../../Common/Mysql.php';
  6. $user_id =getUserId();
  7. $order_from_org_id = 0;
  8. $top_org_id=0;
  9. //echo $order_from_org_id;die;
  10. if (!$user_id) {
  11. echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "用户未登录"));
  12. exit ;
  13. }
  14. $list_tic = get_memcache('disney_ticket_info');
  15. if( $list_tic == false ) {
  16. //echo json_encode(array("code" => 1,"iflogin"=>1, "info" => "获取迪士尼门票信息失败,请联系技术部"));
  17. //get from db
  18. $current_day = date("Y-m-d");
  19. $pdo = conn1();
  20. $sql = " SELECT * FROM outside_ticket WHERE prod_code IN('SHDSN','SHDSN2') AND ticket_date >= '{$current_day}' AND cancel_flag = 0 ORDER BY ticket_date ";
  21. $result = $pdo->query($sql);
  22. $rowset = $result->fetchAll();
  23. $disney_ticket_array = array();
  24. foreach( $rowset as $row_info ) {
  25. $ticket_date = $row_info["ticket_date"];
  26. if( !isset($disney_ticket_array[$ticket_date]) ) {
  27. $disney_ticket_array[$ticket_date] = array();
  28. $disney_ticket_array[$ticket_date]["tic_info"] = array(0,0,0,0,0,0);
  29. $disney_ticket_array[$ticket_date]["price"] = array(0,0,0,0,0,0);
  30. $disney_ticket_array[$ticket_date]["ticket_array"] = array();
  31. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日成人票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
  32. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日儿童票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
  33. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "单日老人票", "ticketprice" => 499, "ticketcount" => 0, "agentprice" => 464 );
  34. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日成人票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
  35. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日儿童票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
  36. $disney_ticket_array[$ticket_date]["ticket_array"][] = array( "ticketid" => "", "ticketname" => "二日老人票", "ticketprice" => 900, "ticketcount" => 0, "agentprice" => 845 );
  37. }
  38. $ticket_name = $row_info["ticket_name"];
  39. $ticket_index = 0;
  40. if( mb_strpos($ticket_name, "儿童") ) {
  41. $ticket_index = 1;
  42. } else if( mb_strpos($ticket_name, "老人") ) {
  43. $ticket_index = 2;
  44. }
  45. if( $row_info["prod_code"] == 'SHDSN2' ) {
  46. $ticket_index += 3;
  47. }
  48. $ticket_info_temp = $disney_ticket_array[$ticket_date];
  49. $ticket_info_temp["tic_info"][$ticket_index] = $row_info["ticket_num"];
  50. $ticket_info_temp["price"][$ticket_index] = (int)$row_info["ticket_price"];
  51. $ticket_info_temp["ticket_array"][$ticket_index]["ticketid"] = $row_info["ticket_code"];
  52. $ticket_info_temp["ticket_array"][$ticket_index]["ticketprice"] = (int)$row_info["ticket_price"];
  53. $ticket_info_temp["ticket_array"][$ticket_index]["ticketcount"] = $row_info["ticket_num"];
  54. $ticket_info_temp["ticket_array"][$ticket_index]["agentprice"] = (int)$row_info["agent_price"];
  55. $disney_ticket_array[$ticket_date] = $ticket_info_temp;
  56. }
  57. foreach( $disney_ticket_array as $disney_date => $disney_ticket ) {
  58. $disney_memory[$disney_date] = $disney_ticket;
  59. }
  60. set_memcache('disney_ticket_info', $disney_memory);
  61. $list_tic = $disney_memory;
  62. }
  63. if(isset($_POST['get_tic'])){
  64. $date=$_POST['get_tic'];
  65. $tic_info = $list_tic[$date];
  66. //$tic_info = get_disney_all_info($date);
  67. echo json_encode(array("code" => 0,"info" => $tic_info['tic_info'],'price'=>$tic_info['price'] ));
  68. exit ;
  69. }
  70. $pay_status =146;
  71. $pay_type = 275;
  72. if(isset($_POST)){
  73. $date = isset($_POST['date_time'])?$_POST['date_time']:'0';
  74. $outside_no = isset($_POST['outside_no'])?$_POST['outside_no']:'';
  75. $order_from_org_id = isset($_POST['outside_org_id'])?$_POST['outside_org_id']:'0';
  76. $current_day = date('Y-m-d', time());
  77. $diff_seconds = strtotime($date) - strtotime($current_day);
  78. $diff_day = floor($diff_seconds/3600/24);
  79. if($diff_day < 0){
  80. echo json_encode(array("code" => 1, "info" => "不在预定时间段"));
  81. exit ;
  82. }
  83. $cust_name = isset($_POST['customer_name'])?$_POST['customer_name']:'匿名者';
  84. $cust_phone = isset($_POST['customer_phone'])?$_POST['customer_phone']:'123456789';
  85. $id_type = isset($_POST['customer_id_type'])? $_POST['customer_id_type']:'150'; // 150身份证 153 护照
  86. $customer_id = isset($_POST['customer_id'])?$_POST['customer_id']:'123456789';
  87. //票种和数量价格 prod_id=>票的数量
  88. $ticket=array(
  89. 'D'=>isset($_POST['D'])?$_POST['D']:0,
  90. 'C'=>isset($_POST['C'])?$_POST['C']:0,
  91. 'O'=>isset($_POST['O'])?$_POST['O']:0,
  92. 'D2'=>isset($_POST['D2'])?$_POST['D2']:0,
  93. 'C2'=>isset($_POST['C2'])?$_POST['C2']:0,
  94. 'O2'=>isset($_POST['O2'])?$_POST['O2']:0,
  95. );
  96. $ticket_no=array(
  97. '0'=>isset($_POST['D'])?$_POST['D']:0,
  98. '1'=>isset($_POST['C'])?$_POST['C']:0,
  99. '2'=>isset($_POST['O'])?$_POST['O']:0,
  100. '3'=>isset($_POST['D2'])?$_POST['D2']:0,
  101. '4'=>isset($_POST['C2'])?$_POST['C2']:0,
  102. '5'=>isset($_POST['O2'])?$_POST['O2']:0,
  103. );
  104. }
  105. //check ticket num
  106. foreach( $ticket_no as $buy_key => $buy_count ) {
  107. $ticket_remain_count = $list_tic[$date]['tic_info'][$buy_key];
  108. if( $ticket_remain_count < $buy_count ) {
  109. echo json_encode(array("code" => 1, "info" => '预订票数超出余票数量'));
  110. exit ;
  111. }
  112. }
  113. $num1=0;
  114. $num2=0;
  115. foreach ($ticket_no as $k=>$v) {
  116. if($k<=2){
  117. $num1+=$v;
  118. }else{
  119. $num2+=$v;
  120. }
  121. }
  122. if($num1 && $num2){
  123. echo json_encode(array("code" => 1, "info" => '单日票和双日票不可在同一订单'));
  124. exit ;
  125. }
  126. $disney_all_array = $list_tic[$date]["ticket_array"];
  127. $return_info = array();
  128. $return_no = buy_disney_ticket( $cust_name, $cust_phone, $customer_id, $ticket_no, $date, $disney_all_array, $return_info );
  129. if($return_no == '-1' || $return_no == '0'){
  130. echo json_encode(array("code" => 1, "info" => '出票失败|'.json_encode($return_info) ));
  131. exit ;
  132. }
  133. //echo $return_no;die;
  134. $order_customer_memo = "自在订单号({$return_no})";
  135. $pdo = conn();
  136. $sql = "select a.prod_id,a.prod_name,b.prod_price,b.prod_type_id "
  137. . "from opera_product a inner join opera_product_price b on a.prod_id = b.prod_id "
  138. . "where a.parent_id = 387267";
  139. $result=$pdo->query($sql);
  140. $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  141. $info = array();
  142. foreach ($rowset as $v) {
  143. $info[$v['prod_id']] = $v;
  144. }
  145. $sql_p = "select prod_id,prod_name "
  146. . " from opera_product "
  147. . " where prod_id = 387267";
  148. $result_p=$pdo->query($sql_p);
  149. $rowset_p = $result_p -> fetchAll(PDO::FETCH_ASSOC);
  150. $info_p = $rowset_p[0];
  151. /**
  152. * 迪士尼票种信息
  153. * 152990 =>
  154. array
  155. 'prod_id' => string '152990' (length=6)
  156. 'prod_name' => string '迪士尼门票(成人票)' (length=30)
  157. 'prod_price' => string '20.00' (length=5)
  158. 'prod_type_id' => string '262' (length=3)
  159. */
  160. //$tic_info = get_disney_all_info($date);
  161. $tic_info = $list_tic[$date];
  162. $num=0;
  163. $order_description = "";
  164. $price=0;
  165. $return_info='';
  166. foreach ($ticket as $k=>$v) {
  167. $num+=$v;
  168. if($v){
  169. switch ($k){
  170. case 'D':
  171. $price+=$tic_info['price'][0]*$v;
  172. $return_info.='标准一日票 × '.$v;
  173. $order_description.=" 标准一日票,". date('Y-m-d',time()).",".$v."|";
  174. break;
  175. case 'C':
  176. $price+=$tic_info['price'][1]*$v;
  177. $return_info.=' 儿童一日票 × '.$v;
  178. $order_description.="儿童一日票,". date('Y-m-d',time()).",".$v."|";
  179. break;
  180. case 'O':
  181. $price+=$tic_info['price'][2]*$v;
  182. $return_info.=' 老人一日票 × '.$v;
  183. $order_description.="老人一日票,". date('Y-m-d',time()).",".$v."|";
  184. break;
  185. case 'C2':
  186. $price+=$tic_info['price'][4]*$v;
  187. $return_info.=' 儿童两日票 × '.$v;
  188. $order_description.="儿童两日票,". date('Y-m-d',time()).",".$v."|";
  189. break;
  190. case 'D2':
  191. $price+=$tic_info['price'][3]*$v;
  192. $return_info.=' 标准两日票 × '.$v;
  193. $order_description.="标准两日票,". date('Y-m-d',time()).",".$v."|";
  194. break;
  195. case 'O2':
  196. $price+=$tic_info['price'][5]*$v;
  197. $return_info.=' 老人两日票 × '.$v;
  198. $order_description.="老人两日票,". date('Y-m-d',time()).",".$v."|";
  199. break;
  200. }
  201. }
  202. }
  203. if($num>5 || $num<=0){
  204. echo json_encode(array("code" => 1, "info" => "最多定票五张"));
  205. exit ;
  206. }
  207. //订单插入需要的字段 id = order_id create_time update_time order_pay_satatus 0 未支付 order_description order_price order_prod_type
  208. // prod_name order_status customer_name customer_mobile customer_id_type customer_id _no
  209. // 至订单需要的之短 parent_order_id prod_id parent_prod_id prod_name parent_prod_name order_price
  210. //function getUniqeId(){
  211. // $pdo= conn();
  212. // $result=$pdo->query("select FUNC_GET_UNIQUE_ID('1','1') id");
  213. // $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  214. // return $rowset[0]['id'];
  215. //}
  216. $id_p = getUniqeId();
  217. $order_id_p = $id_p;
  218. $pay_main_id = getUniqeId();
  219. $create_time = date('Y-m-d H:i:s',time());
  220. $update_time = $create_time;
  221. $order_pay_status = 0;
  222. //查找数据库中关于迪士尼的信息
  223. $sql_in=" insert into order_main
  224. (`id`,
  225. `order_id`,
  226. `create_time`,`update_time`,
  227. `order_pay_status`,`order_description`,`customer_memo`,
  228. `order_price`,`order_prod_type`,`prod_name`,`order_status`,
  229. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  230. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`prod_id`,`run_date`,`main_create_user_id`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`)
  231. values ('".$id_p."','".$order_id_p."','".$create_time."','".$update_time."','0','".$order_description."','{$order_customer_memo}','"
  232. .$price."','258','".$info_p['prod_name']."','".$pay_status."','
  233. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."','1','0','".$info_p['prod_id']."','".$date."','".$user_id."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}')";
  234. for_insert($sql_in);
  235. //插入支付方式等信息
  236. $sql_pay="insert INTO"
  237. . " `order_pay_main`(id,CREATe_user_id,CREATE_time,update_user_id,pay_total) "
  238. . "VALUES(".$pay_main_id.",".$user_id.",'".date('Y-m-d H-i-s', time())."',".$user_id.",".$price.");"
  239. . "insert INTO `order_pay_detail`
  240. (id,CREATe_user_id,CREATE_time,update_user_id,pay_main_id,pay_type_id_1,pay_money)
  241. VALUES(".$pay_main_id.",".$user_id.",'".date('Y-m-d H-i-s', time())."',".$user_id.",".$pay_main_id.",".$pay_type.",".$price.");";
  242. for_insert($sql_pay);
  243. foreach ($ticket as $k => $v) {
  244. if($v){
  245. switch ($k){
  246. case 'D':
  247. for($i=1;$i<=$v;$i++){
  248. $id =$order_id =getUniqeId();
  249. $sql = " insert into order_main
  250. (`id`,
  251. `order_id`,`customer_memo`,
  252. `create_time`,`update_time`,
  253. `order_pay_status`,
  254. `order_prod_type`,`order_status`,
  255. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  256. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  257. values ('".$id."','"
  258. .$order_id."','{$order_customer_memo}',
  259. '".$create_time."','".$update_time."',
  260. '0','258','".$pay_status."','
  261. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  262. '0','0','".$id_p."','".$info['387538']['prod_id']."','".$info_p['prod_id']."','".$info['387538']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][0]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  263. for_insert($sql);
  264. }
  265. break;
  266. case 'C':
  267. for($i=1;$i<=$v;$i++){
  268. $id =$order_id =getUniqeId();
  269. $sql = " insert into order_main
  270. (`id`,
  271. `order_id`,`customer_memo`,
  272. `create_time`,`update_time`,
  273. `order_pay_status`,
  274. `order_prod_type`,`order_status`,
  275. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  276. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  277. values ('".$id."','"
  278. .$order_id."','{$order_customer_memo}',
  279. '".$create_time."','".$update_time."',
  280. '0','258','".$pay_status."','
  281. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  282. '0','0','".$id_p."','".$info['387540']['prod_id']."','".$info_p['prod_id']."','".$info['387540']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][1]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  283. for_insert($sql);
  284. }
  285. break;
  286. case 'O':
  287. for($i=1;$i<=$v;$i++){
  288. $id =$order_id =getUniqeId();
  289. $sql = " insert into order_main
  290. (`id`,
  291. `order_id`,`customer_memo`,
  292. `create_time`,`update_time`,
  293. `order_pay_status`,
  294. `order_prod_type`,`order_status`,
  295. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  296. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  297. values ('".$id."','"
  298. .$order_id."','{$order_customer_memo}',
  299. '".$create_time."','".$update_time."',
  300. '0','258','".$pay_status."','
  301. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  302. '0','0','".$id_p."','".$info['387539']['prod_id']."','".$info_p['prod_id']."','".$info['387539']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][2]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  303. for_insert($sql);
  304. }
  305. break;
  306. case 'C2':
  307. for($i=1;$i<=$v;$i++){
  308. $id =$order_id =getUniqeId();
  309. $sql = " insert into order_main
  310. (`id`,
  311. `order_id`,`customer_memo`,
  312. `create_time`,`update_time`,
  313. `order_pay_status`,
  314. `order_prod_type`,`order_status`,
  315. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  316. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  317. values ('".$id."','"
  318. .$order_id."','{$order_customer_memo}',
  319. '".$create_time."','".$update_time."',
  320. '0','258','".$pay_status."','
  321. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  322. '0','0','".$id_p."','".$info['387543']['prod_id']."','".$info_p['prod_id']."','".$info['387543']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][4]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  323. for_insert($sql);
  324. }
  325. break;
  326. case 'D2':
  327. for($i=1;$i<=$v;$i++){
  328. $id =$order_id =getUniqeId();
  329. $sql = " insert into order_main
  330. (`id`,
  331. `order_id`,`customer_memo`,
  332. `create_time`,`update_time`,
  333. `order_pay_status`,
  334. `order_prod_type`,`order_status`,
  335. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  336. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  337. values ('".$id."','"
  338. .$order_id."','{$order_customer_memo}',
  339. '".$create_time."','".$update_time."',
  340. '0','258','".$pay_status."','
  341. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  342. '0','0','".$id_p."','".$info['387541']['prod_id']."','".$info_p['prod_id']."','".$info['387541']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][3]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  343. for_insert($sql);
  344. }
  345. break;
  346. case 'O2':
  347. for($i=1;$i<=$v;$i++){
  348. $id =$order_id =getUniqeId();
  349. $sql = " insert into order_main
  350. (`id`,
  351. `order_id`,`customer_memo`,
  352. `create_time`,`update_time`,
  353. `order_pay_status`,
  354. `order_prod_type`,`order_status`,
  355. `customer_name`,`customer_mobile`,`customer_id_type`,`customer_id_no`,
  356. `order_book_status`,`PROD_START_STATION_TIME_MINUTES`,`parent_order_id`,`prod_id`,`parent_prod_id`,`prod_name`,`parent_prod_name`,`order_price`,`run_date`,`order_pay_main_id`,`outside_sale_org_id`,`outside_order_no`,`main_create_user_id`)
  357. values ('".$id."','"
  358. .$order_id."','{$order_customer_memo}',
  359. '".$create_time."','".$update_time."',
  360. '0','258','".$pay_status."','
  361. ".$cust_name."','".$cust_phone."','".$id_type."','".$customer_id."',
  362. '0','0','".$id_p."','".$info['387542']['prod_id']."','".$info_p['prod_id']."','".$info['387542']['prod_name']."','".$info_p['prod_name']."','".$tic_info['price'][5]."','".$date."','".$pay_main_id."','".$order_from_org_id."','{$outside_no}','".$user_id."')";
  363. for_insert($sql);
  364. }
  365. break;
  366. }
  367. }
  368. }
  369. function for_insert($sql){
  370. $pdo = conn();
  371. $re = $pdo->exec($sql);
  372. if($re==0){
  373. echo json_encode(array("code" => 1, "info" => $sql));
  374. exit ;
  375. }
  376. }
  377. // $json=array();
  378. // $code =0;
  379. // $info = 0;
  380. // $massge = 'success';
  381. // $list = "";
  382. // $json['code'] = $code;
  383. // $json['info'] = $info;
  384. // $json['massge'] = $massge;
  385. // $json['list'] = $list;
  386. $list =array();
  387. $list['type'] = $info_p['prod_name'];
  388. $list['date'] = $date;
  389. $list['desc'] = $return_info;
  390. $list['price'] = $price;
  391. $list['name'] = $cust_name;
  392. $list['phone'] = $cust_phone;
  393. $list['order_id'] = $id_p;
  394. $return_true_buy = true_buy_disney($return_no);
  395. if( $return_true_buy == 0 ) {
  396. echo json_encode(array("code" => 1, 'order_id' => $id_p, "info" => "最终确认失败,请检查自在余额。自在订单号:".$return_no));
  397. } else {
  398. echo json_encode(array("code" => 0, 'order_id' => $id_p, "info" => date('H:i:s', time()), 'ifdisney' => 1, "list" => $list));
  399. }
  400. exit ;