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.
 
 
 
 

188 lines
12 KiB

  1. <?php
  2. //create by fudr
  3. //2016-10-11
  4. require_once "Api/ApiBase.php";
  5. require_once "Lib/Action/SaleRule.class.php";
  6. require_once "Lib/Action/MakeHotelOrder.class.php";
  7. class SaleRuleInfo extends APiBase
  8. {
  9. // 得到销售规则
  10. function getSaleRule()
  11. {
  12. // writeLog('执行到这里了!');
  13. $para_hotel_id = isset($_POST['para_hotel_id']) ? $_POST['para_hotel_id'] : (isset($_GET['para_hotel_id']) ? $_GET['para_hotel_id'] : ""); // 不为空
  14. $para_base_room_type = isset($_POST['para_base_room_type']) ? $_POST['para_base_room_type'] : (isset($_GET['para_base_room_type']) ? $_GET['para_base_room_type'] : ""); // 不为空 默认给今天
  15. $para_room_type = isset($_POST['para_room_type']) ? $_POST['para_room_type'] : (isset($_GET['para_room_type']) ? $_GET['para_room_type'] : ""); // 可为空
  16. $para_distrib_name = isset($_POST['para_distrib_name']) ? $_POST['para_distrib_name'] : (isset($_GET['para_distrib_name']) ? $_GET['para_distrib_name'] : ""); // 可为空
  17. $para_start_date = isset($_POST['para_start_date']) ? $_POST['para_start_date'] : (isset($_GET['para_start_date']) ? $_GET['para_start_date'] : ""); // 可为空
  18. $current = isset($_REQUEST['current']) ? $_REQUEST['current'] : '1';
  19. $page_size = isset($_REQUEST['page_size']) ? $_REQUEST['page_size'] : '5';
  20. if ($para_hotel_id == "") {
  21. $data['code'] = "3";
  22. $data['info'] = "缺少hotel_id参数";
  23. return $data;
  24. }
  25. $saleRule = new SaleRule();
  26. $data_temp = $saleRule->getSaleRule($para_hotel_id, $para_base_room_type, $para_room_type, $para_distrib_name, $para_start_date, $current, $page_size);
  27. //$data_temp=$saleRule->getSaleRule('235', '10608', '1', '', '2016-11-10', '1', '5');
  28. $data = array();
  29. $data['code'] = "0";
  30. $data['info'] = "";
  31. $data['currpage'] = $data_temp['rowset'][0][0]['currpage'];
  32. $data['total_page'] = $data_temp['rowset'][0][0]['total_page'];
  33. $data['total'] = $data_temp['rowset'][0][0]['total'];
  34. $data['page_size'] = $data_temp['rowset'][0][0]['page_size'];
  35. $data['result'] = $data_temp['rowset'][1];
  36. return $data;
  37. }
  38. //authorize_status=" + 1 + "&hotel_id=" + hotel_id + "&parent_room_type=" + parent_room_type + "&room_type=" + room_type_id + "&op=updateAuthorizeStatus&distrib_id_string=" + distrib_id;
  39. function updateAuthorizeStatus()
  40. {
  41. // writeLog('执行到这里了!');
  42. $authorize_status = isset($_POST['authorize_status']) ? $_POST['authorize_status'] : (isset($_GET['authorize_status']) ? $_GET['authorize_status'] : ""); // 不为空
  43. $hotel_id = isset($_POST['hotel_id']) ? $_POST['hotel_id'] : (isset($_GET['hotel_id']) ? $_GET['hotel_id'] : ""); // 不为空 默认给今天
  44. $parent_room_type = isset($_POST['parent_room_type']) ? $_POST['parent_room_type'] : (isset($_GET['parent_room_type']) ? $_GET['parent_room_type'] : ""); // 可为空
  45. $room_type = isset($_POST['room_type']) ? $_POST['room_type'] : (isset($_GET['room_type']) ? $_GET['room_type'] : ""); // 可为空
  46. $para_start_date = isset($_POST['para_start_date']) ? $_POST['para_start_date'] : (isset($_GET['para_start_date']) ? $_GET['para_start_date'] : ""); // 可为空
  47. $distrib_id_string = isset($_POST['distrib_id_string']) ? $_POST['distrib_id_string'] : (isset($_GET['distrib_id_string']) ? $_GET['distrib_id_string'] : "");
  48. $saleRule = new SaleRule();
  49. $data_temp = $saleRule->updateAuthorizeStatus($authorize_status, $hotel_id, $parent_room_type, $room_type, $para_start_date, $distrib_id_string);
  50. // $data_temp=$saleRule->getSaleRule(3,274,1,"",'2016-09-15');
  51. $data = array();
  52. $data['code'] = "0";
  53. $data['info'] = "";
  54. return $data;
  55. }
  56. function updateAuthorizeInfo()
  57. {
  58. $para_user_id = isset($_POST['para_user_id']) ? $_POST['para_user_id'] : (isset($_GET['para_user_id']) ? $_GET['para_user_id'] : ""); // 不为空
  59. $para_hotel_id = isset($_POST['para_hotel_id']) ? $_POST['para_hotel_id'] : (isset($_GET['para_hotel_id']) ? $_GET['para_hotel_id'] : ""); // 不为空
  60. $para_base_room_type = isset($_POST['para_base_room_type']) ? $_POST['para_base_room_type'] : (isset($_GET['para_base_room_type']) ? $_GET['para_base_room_type'] : ""); // 不为空
  61. $para_room_type = isset($_POST['para_room_type']) ? $_POST['para_room_type'] : (isset($_GET['para_room_type']) ? $_GET['para_room_type'] : ""); // 不为空
  62. $para_distrib_list = isset($_POST['para_distrib_list']) ? $_POST['para_distrib_list'] : (isset($_GET['para_distrib_list']) ? $_GET['para_distrib_list'] : ""); // 不为空
  63. $para_start_date = isset($_POST['para_start_date']) ? $_POST['para_start_date'] : (isset($_GET['para_start_date']) ? $_GET['para_start_date'] : ""); // 不为空
  64. $para_end_date = isset($_POST['para_end_date']) ? $_POST['para_end_date'] : (isset($_GET['para_end_date']) ? $_GET['para_end_date'] : ""); // 不为空
  65. $para_week_day = isset($_POST['para_week_day']) ? $_POST['para_week_day'] : (isset($_GET['para_week_day']) ? $_GET['para_week_day'] : ""); // 不为空
  66. $para_stock_type = isset($_POST['para_stock_type']) ? $_POST['para_stock_type'] : (isset($_GET['para_stock_type']) ? $_GET['para_stock_type'] : ""); // 不为空
  67. $para_stock_num = isset($_POST['para_stock_num']) ? $_POST['para_stock_num'] : (isset($_GET['para_stock_num']) ? $_GET['para_stock_num'] : ""); // 不为空
  68. $para_prod_price = isset($_POST['para_prod_price']) ? $_POST['para_prod_price'] : (isset($_GET['para_prod_price']) ? $_GET['para_prod_price'] : ""); // 不为空
  69. $para_cus_price = isset($_POST['para_cus_price']) ? $_POST['para_cus_price'] : (isset($_GET['para_cus_price']) ? $_GET['para_cus_price'] : ""); // 不为空
  70. $para_over_sale = isset($_POST['para_over_sale']) ? $_POST['para_over_sale'] : (isset($_GET['para_over_sale']) ? $_GET['para_over_sale'] : ""); // 超卖
  71. if (empty($para_user_id) || empty($para_hotel_id)
  72. || empty($para_base_room_type) || empty($para_room_type)
  73. || empty($para_distrib_list) || empty($para_start_date)
  74. || empty($para_end_date) || empty($para_week_day)
  75. || empty($para_stock_type)
  76. ) {
  77. $data['code'] = "16";
  78. $data['info'] = "错误的请求参数";
  79. return $data;
  80. }
  81. // elseif (($para_prod_price==0 && $para_cus_price==0)||($para_prod_price>0 && $para_cus_price>0)){
  82. // $data['code'] = "16";
  83. // $data['info'] = "请正确输入价格";
  84. // return $data;
  85. // }
  86. elseif ($para_stock_num === '' || $para_stock_num < 0) {
  87. $data['code'] = "17";
  88. $data['info'] = "请正确输入库存数量";
  89. return $data;
  90. }
  91. //$para_stock_num 数量判断,不能少于已售库存
  92. $hotelOrder = new MakeHotelOrder();
  93. //现在 修改数量是修改剩余数量,不需要限制最小数量
  94. if($para_over_sale == 0){
  95. if ($para_stock_type == 329) {
  96. $para_stock_num = 0;
  97. } else {
  98. $tmp = $hotelOrder->getSaled($para_start_date, $para_end_date, $para_hotel_id, $para_room_type, $para_distrib_list, $para_stock_num);
  99. if (!empty($tmp['order_list'])) {
  100. $data['code'] = "18";
  101. $data['info'] = "库存数量不能少于已售数量";
  102. return $data;
  103. }
  104. }
  105. }
  106. //固定数值,数量不能大于
  107. // if($para_over_sale == 0){
  108. $max = $hotelOrder->getMaxCount($para_start_date, $para_end_date, $para_hotel_id, $para_stock_num);
  109. if ($max['code'] != 0) {
  110. return $max;
  111. }
  112. // }
  113. //其他渠道商已经占用的库存数量
  114. $used = $hotelOrder->getUsedCount($para_start_date, $para_end_date, $para_hotel_id, $para_base_room_type, $para_stock_num, $para_distrib_list, $max['rowset'][0]['tot']);
  115. if ($used['code'] != 0) {
  116. return $used;
  117. }
  118. $authorize_info = array();
  119. $authorize_info['para_user_id'] = $para_user_id;
  120. $authorize_info['para_hotel_id'] = $para_hotel_id;
  121. $authorize_info['para_base_room_type'] = $para_base_room_type;
  122. $authorize_info['para_room_type'] = $para_room_type;
  123. $authorize_info['para_distrib_list'] = $para_distrib_list;
  124. $authorize_info['para_start_date'] = $para_start_date;
  125. $authorize_info['para_end_date'] = $para_end_date;
  126. $authorize_info['para_week_day'] = $para_week_day;
  127. $authorize_info['para_stock_type'] = $para_stock_type;
  128. $authorize_info['para_stock_num'] = $para_stock_num;
  129. $authorize_info['para_prod_price'] = $para_prod_price;
  130. $authorize_info['para_cus_price'] = $para_cus_price;
  131. $authorize_info['para_over_sale'] = $para_over_sale;
  132. $saleRule = new SaleRule;
  133. $data = $saleRule->updateAuthorizeInfo($authorize_info);
  134. return $data;
  135. }
  136. function getMaxStockNumber()
  137. {
  138. $para_hotel_id = isset($_POST['para_hotel_id']) ? $_POST['para_hotel_id'] : (isset($_GET['para_hotel_id']) ? $_GET['para_hotel_id'] : ""); // 不为空
  139. $para_distrib_list = isset($_POST['para_distrib_list']) ? $_POST['para_distrib_list'] : (isset($_GET['para_distrib_list']) ? $_GET['para_distrib_list'] : ""); // 不为空
  140. $para_start_date = isset($_POST['para_start_date']) ? $_POST['para_start_date'] : (isset($_GET['para_start_date']) ? $_GET['para_start_date'] : ""); // 不为空
  141. $para_end_date = isset($_POST['para_end_date']) ? $_POST['para_end_date'] : (isset($_GET['para_end_date']) ? $_GET['para_end_date'] : ""); // 不为空
  142. $para_room_type = isset($_POST['para_room_type']) ? $_POST['para_room_type'] : (isset($_GET['para_room_type']) ? $_GET['para_room_type'] : ""); // 不为空
  143. $base_room_type = isset($_POST['para_base_room_type']) ? $_POST['para_base_room_type'] : (isset($_GET['para_base_room_type']) ? $_GET['para_base_room_type'] : ""); // 不为空
  144. $hotelOrder = new MakeHotelOrder();
  145. //9999不需要查看数字
  146. $max = $hotelOrder->getMaxCount($para_start_date, $para_end_date, $para_hotel_id, 9999);
  147. if (isset($max['rowset']) && count($max['rowset']) > 0) {
  148. } else {
  149. return 0;
  150. }
  151. $used = $hotelOrder->getUsedCount($para_start_date, $para_end_date, $para_hotel_id, $base_room_type, 9999, $para_distrib_list, $max['rowset'][0]['tot']);
  152. if (isset($used['rowset']) && count($used['rowset']) > 0) {
  153. return $max['rowset'][0]['tot'] > $used['rowset'][0]['tot'] ? $max['rowset'][0]['tot'] - $used['rowset'][0]['tot'] : 0;
  154. } else {
  155. return $max['rowset'][0]['tot'];
  156. }
  157. }
  158. }
  159. $op = isset($_POST['op']) ? $_POST['op'] : (isset($_GET['op']) ? $_GET['op'] : ""); // 不为空
  160. $saleRules = new SaleRuleInfo();
  161. if ($op == 'getSaleRule') {
  162. $data = $saleRules->getSaleRule();
  163. } else if ($op == 'updateAuthorizeStatus') { //更改授权状态
  164. $data = $saleRules->updateAuthorizeStatus();
  165. } else if ($op == 'updateAuthorizeInfo') { //批量修改
  166. $data = $saleRules->updateAuthorizeInfo();
  167. } else if ($op == 'getMaxStockNumber') { //批量修改
  168. $data = $saleRules->getMaxStockNumber();
  169. }
  170. echo json_encode($data);
  171. ?>