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.
 
 
 
 

133 lines
5.0 KiB

  1. <?php
  2. /*
  3. Author:XM
  4. Compeny:Spiders Travel
  5. */
  6. //酒店房型 添加和修改的接口
  7. require_once __DIR__.'/../Common/Mysql.php';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. writeLog("酒店添加修改产品".json_encode($_POST));
  11. $userid=getUserId();
  12. if ($userid ===false){
  13. echo json_encode(array("errcode"=>1,"errinfo"=>"用户未登录"));
  14. exit;
  15. }
  16. $method=isset($_POST['method'])?$_POST['method']:'';
  17. if ($method == ''){
  18. echo json_encode(array("errcode"=>2,"errinfo"=>"method参数错误"));
  19. exit;
  20. }
  21. $pdo=conn();
  22. if ($method=='add'){
  23. $hotelid=isset($_POST['hotel_testa'])?$_POST['hotel_testa']:0;
  24. $supplier=isset($_POST['supplier_test_id'])?$_POST['supplier_test_id']:0;
  25. $added=isset($_POST['checkbox_test'])?$_POST['checkbox_test']:0;
  26. $payway=isset($_POST['readyPay'])?$_POST['readyPay']:0;
  27. $paytimelimit=isset($_POST['payTime'])?$_POST['payTime']:0;
  28. $confirm=isset($_POST['affirmStyle'])?$_POST['affirmStyle']:0;
  29. $oversold=isset($_POST['overSale'])?$_POST['overSale']:0;
  30. $prod=isset($_POST['textcount'])?(empty($_POST['textcount'])?0:$_POST['textcount']):0;
  31. if($hotelid==0 || $supplier==0 || $payway ==0 || $paytimelimit==0 || $confirm==0 ||$oversold==0 || $prod==0){
  32. echo json_encode(array("errcode"=>3,"errinfo"=>"参数错误"));
  33. exit;
  34. }
  35. //$prodArr=explode("^*^", $prod);
  36. //$json=0;
  37. if(is_object($pdo)){
  38. $m=0;
  39. $n=0;//总数量
  40. for($i=0;$i<$prod;$i++){
  41. if(isset($_POST['productName'.$i])){
  42. $n+=1;
  43. $prodname=$_POST['productName'.$i];
  44. $roomid=$_POST['select_hotelType'.$i];
  45. $bedtypeid=$_POST['select_bed'.$i];
  46. $breakfast=$_POST['select_breakfast'.$i];
  47. $addbed=$_POST['ifsup'.$i];
  48. $sql="CALL HT_ROOM_RUN_NEW_SAVE(".$userid.",'".$prodname."',".$hotelid.",".$roomid.",".$bedtypeid.",".$breakfast.",".$addbed.",".$supplier.",".$added.",".$payway.",".$paytimelimit.",".$confirm.",".$oversold.")";
  49. $result=$pdo->query($sql);
  50. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  51. $result->closeCursor();
  52. if($rowset[0]['errcode']==0){
  53. $m+=1;//成功的数量
  54. }
  55. writeLog("hotel_room_save_modify.php method=add".$sql."::".json_encode($rowset));
  56. }
  57. }
  58. /* try {
  59. $pdo->beginTransaction(); // 开启一个事务
  60. foreach ($prodArr as $v){
  61. $vArr=explode(",", $v);
  62. if(count($vArr) != 5){
  63. continue;
  64. }
  65. $prodname=$vArr[0];
  66. $roomid=$vArr[1];
  67. $bedtypeid=$vArr[2];
  68. $breakfast=$vArr[3];
  69. $addbed=$vArr[4];
  70. $sql="CALL HT_ROOM_RUN_NEW_SAVE(".$userid.",'".$prodname."',".$hotelid.",".$roomid.",".$bedtypeid.",".$breakfast.",".$addbed.",".$supplier.",".$added.",".$payway.",".$paytimelimit.",".$confirm.",".$oversold.")";
  71. $result=$pdo->query($sql);
  72. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  73. $result->closeCursor();
  74. writeLog($sql."::".json_encode($rowset));
  75. }
  76. $pdo->commit();
  77. } catch (PDOException $e) {
  78. $pdo->rollback(); // 执行失败,事务回滚
  79. writeLog("CALL HT_ROOM_RUN_NEW_SAVE:".$e->getMessage());
  80. $json=1;
  81. } */
  82. }
  83. /* if($m==$n)
  84. echo json_encode(array("errcode"=>0,"errinfo"=>"成功添加".$m."条记录"));
  85. else
  86. echo json_encode(array("errcode"=>0,"errinfo"=>"有".($n-$m)."条添加失败")); */
  87. if($m>0){
  88. $url= "http://".$_SERVER['HTTP_HOST']."/hotel_list.html";
  89. echo "<script>alert('成功添加".$m."条记录');document.location.href='".$url."'</script>";
  90. //header("Location: $url");
  91. exit;
  92. }else{
  93. $url= "http://".$_SERVER['HTTP_HOST']."/add_hotel.html";
  94. echo "<script>alert('添加失败');document.location.href='".$url."'</script>";
  95. exit;
  96. }
  97. }else if ($method =='modify'){
  98. $prod_id=isset($_POST['produID'])?$_POST['produID']:0;
  99. $added=isset($_POST['checkbox_test'])?$_POST['checkbox_test']:0;
  100. $bedtypeid=isset($_POST['select_bed'])?$_POST['select_bed']:0;
  101. $breakfast=isset($_POST['select_breakfast'])?$_POST['select_breakfast']:0;
  102. $addbed=isset($_POST['ifsup'])?$_POST['ifsup']:0;
  103. $supplier=isset($_POST['supplier_test_id'])?$_POST['supplier_test_id']:0;
  104. $payway=isset($_POST['readyPay'])?$_POST['readyPay']:0;
  105. $paytimelimit=isset($_POST['payTime'])?$_POST['payTime']:0;
  106. $confirm=isset($_POST['affirmStyle'])?$_POST['affirmStyle']:0;
  107. $oversold=isset($_POST['overSale'])?$_POST['overSale']:0;
  108. if($prod_id == 0 || $bedtypeid==0 || $breakfast==0 || $supplier==0 || $payway ==0 || $paytimelimit==0 || $confirm==0 ||$oversold==0){
  109. echo json_encode(array("errcode"=>2,"errinfo"=>"参数错误"));
  110. exit;
  111. }
  112. $sql="CALL HT_ROOM_RUN_NEW_MODIFY(".$userid.",".$prod_id.",".$added.",".$bedtypeid.",".$breakfast.",".$addbed.",".$supplier.",".$payway.",".$paytimelimit.",".$confirm.",".$oversold.")";
  113. $result=$pdo->query($sql);
  114. $rowset=$result->fetchAll(PDO::FETCH_ASSOC);
  115. $result->closeCursor();
  116. writeLog("hotel_room_save_modify.php method=modify".$sql."::".json_encode($rowset));
  117. $url= "http://".$_SERVER['HTTP_HOST']."/change_hotel.html?productId=".$prod_id;
  118. if ($rowset[0]['errcode']==0){
  119. echo "<script>alert('修改成功');document.location.href='".$url."'</script>";
  120. exit;
  121. }else{
  122. echo "<script>alert('修改失败');document.location.href='".$url."'</script>";
  123. exit;
  124. }
  125. }