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.

HTChildRoom.class.php 9.6 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. //Author:fuhc
  3. //Date:20160921
  4. //新增子房型
  5. require_once __DIR__ . '/../HotelLib.php';
  6. class HTChildRoom extends HotelLib
  7. {
  8. // 添加子房型
  9. function addChildRoom($roomModel)
  10. {
  11. $sql = "CALL ht_run_sub_room_save(" . $roomModel['user_id'] . "," . $roomModel['hotel_id'] . "," . $roomModel['parent_room_type'] .
  12. ",'" . $roomModel['start_date'] . "','" . $roomModel['end_date'] . "','" . $roomModel['week_day'] .
  13. "'," . $roomModel['run_status'] . "," . $roomModel['price_buyout'] . "," . $roomModel['price_reserve'] . "," .
  14. $roomModel['price_inquiry'] . "," . $roomModel['person_limit'] .
  15. "," . $roomModel['breakfast'] . ",'" . $roomModel['room_name'] . "')";
  16. writeLog(__FUNCTION__ . " sql= " . $sql);
  17. $data_r = array();
  18. $data = array();
  19. $rowset = $this->DBTool->execProcedure($sql);
  20. $data_r['code'] = $rowset['code'];
  21. $data_r['info'] = $rowset['info'];
  22. $data_r['rowset'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array();
  23. if ($data_r['code'] != "0") {
  24. $data['code'] = $data_r['code'];
  25. $data['info'] = $data_r['info'];
  26. return $data;
  27. }
  28. if ($data_r['rowset'][0]['errcode'] == "0") {
  29. $model = array(
  30. "user_id" => $roomModel['user_id'],
  31. "log_type" => 2,
  32. "hotel_id" => $roomModel['hotel_id'],
  33. "room_type" => $roomModel['parent_room_type'],
  34. "log_desc" => "添加子房型" . $roomModel["room_name"] . " 买断价:" . $roomModel['price_buyout'] . " 保留价:" . $roomModel['price_reserve'] . " 现询价:" . $roomModel['price_inquiry']
  35. );
  36. $this->DBLog->insertLog($model, '添加子房型');
  37. }
  38. $data['code'] = $data_r['rowset'][0]['errcode'];
  39. $data['info'] = $data_r['rowset'][0]['errinfo'];
  40. return $data;
  41. }
  42. // 根据酒店查询房型
  43. function getRoomByHotel($hotel_id)
  44. {
  45. $sql = "select room_type_all,room_type_sale from opera_hotel as A where A.hotel_id=" . $hotel_id . " and A.cancel_flag=0;";
  46. $rowset = $this->DBTool->queryBySql($sql);
  47. $data['code'] = $rowset['code'];
  48. $data['info'] = $rowset['info'];
  49. $data['rowset'] = $rowset['rowset'];
  50. if ($data['code'] != "0") {
  51. return $data;
  52. }
  53. $room_type_all = $data['rowset'][0]['room_type_all'];
  54. $room_type_all = $room_type_all == "" ? "0" : $room_type_all;
  55. $room_type_sale = $data['rowset'][0]['room_type_sale'];
  56. if ($room_type_sale == "") {
  57. $room_type_sale = "0";
  58. }
  59. // $sql="select res_id as room_id,res_name as room_name from base_resource where res_id in (".$room_type_all.") and cancel_flag=0;";
  60. $sql = "select res_id as room_id,res_name as room_name,
  61. case when res_id in (" . $room_type_sale . ") then 1 else 0 end as checked
  62. from base_resource where res_id in (" . $room_type_all . ") and cancel_flag=0;";
  63. writeLog(__FUNCTION__ . " sql=" . $sql);
  64. $data = array();
  65. $rowset = $this->DBTool->queryBySql($sql);
  66. $data['code'] = $rowset['code'];
  67. $data['info'] = $rowset['info'];
  68. $data['room_list'] = $rowset['rowset'];
  69. return $data;
  70. }
  71. // 修改子房型
  72. function updateChildRoom($Child)
  73. {
  74. $user_id = $Child['user_id'];
  75. $run_status = $Child['run_status'];
  76. $run_date = $Child['run_date'];
  77. $room_type = $Child['room_type'];
  78. $hotel_id = $Child['hotel_id'];
  79. $price_buyout = $Child['price_buyout'];
  80. $price_reserve = $Child['price_reserve'];
  81. $price_inquiry = $Child['price_inquiry'];
  82. // foreach ($Child as $v) {
  83. // if (empty($v)) {
  84. // $data['code'] = "16";
  85. // $data['info'] = "参数错误";
  86. // return $data;
  87. // }
  88. // }
  89. $sql = "update run_hotel_sub_room set update_user_id={$user_id},run_status={$run_status},
  90. BASE_PRICE_BUYOUT='{$price_buyout}' ,BASE_PRICE_RESERVE='{$price_reserve}' ,BASE_PRICE_INQUIRY='{$price_inquiry}'
  91. where run_date='{$run_date}' and room_type={$room_type} and hotel_id={$hotel_id} and BASE_ROOM_TYPE>0";
  92. writeLog(__FUNCTION__ . " sql= " . $sql);
  93. $data = array();
  94. $rowset = $this->DBTool->execSql($sql);
  95. if ($rowset['code'] == "0") {
  96. $desc = '修改子房型';
  97. $t = $run_status == "1" ? "开房" : "关房";
  98. $model = array(
  99. "user_id" => $user_id,
  100. "log_type" => 2,
  101. "hotel_id" => $hotel_id,
  102. "room_type" => $room_type,
  103. "log_desc" => $desc . $t . " 价格为 买断价:" . $Child['price_buyout'] . " 保留价:" . $Child['price_reserve'] . " 现询价:" . $Child['price_inquiry']
  104. );
  105. $this->DBLog->insertLog($model, '修改子房型');
  106. }
  107. $data['code'] = $rowset['code'];
  108. $data['info'] = $rowset['info'];
  109. return $data;
  110. }
  111. // 上
  112. function onLine($user_id, $room_type, $hotel_id)
  113. {
  114. $sql = "update run_hotel_sub_room set is_onsale=1,update_user_id={$user_id} where hotel_id={$hotel_id} and room_type={$room_type}";
  115. //上下线维度由原来的天 变为子房型。
  116. $sql2 = "update opera_hotel_room set is_onsale = 1,update_user_id = {$user_id} where hotel_id = {$hotel_id} and room_type = {$room_type}";
  117. writeLog('top sql= ' . $sql);
  118. $data = array();
  119. $rowset = $this->DBTool->execSql($sql);
  120. $this->DBTool->execSql($sql2);
  121. if ($rowset['code'] == "0") {
  122. $model = array(
  123. "user_id" => $user_id,
  124. "log_type" => 2,
  125. "hotel_id" => $hotel_id,
  126. "room_type" => $room_type,
  127. "log_desc" => "修改子房型" . "上线"
  128. );
  129. $this->DBLog->insertLog($model, '修改子房型');
  130. }
  131. $data['code'] = $rowset['code'];
  132. $data['info'] = $rowset['info'];
  133. return $data;
  134. }
  135. // 下
  136. function offLine($user_id, $room_type, $hotel_id)
  137. {
  138. $sql = "update run_hotel_sub_room set is_onsale=0,update_user_id={$user_id} where hotel_id={$hotel_id} and room_type={$room_type}";
  139. //上下线维度由原来的天 变为子房型。
  140. $sql2 = "update opera_hotel_room set is_onsale = 0,update_user_id = {$user_id} where hotel_id = {$hotel_id} and room_type = {$room_type}";
  141. writeLog('bottom sql= ' . $sql);
  142. $data = array();
  143. $rowset = $this->DBTool->execSql($sql);
  144. $this->DBTool->execSql($sql2);
  145. if ($rowset['code'] == "0") {
  146. $model = array(
  147. "user_id" => $user_id,
  148. "log_type" => 2,
  149. "hotel_id" => $hotel_id,
  150. "room_type" => $room_type,
  151. "log_desc" => "修改子房型" . "下线"
  152. );
  153. $this->DBLog->insertLog($model, '修改子房型');
  154. }
  155. $data['code'] = $rowset['code'];
  156. $data['info'] = $rowset['info'];
  157. return $data;
  158. }
  159. //查询基础房型ID
  160. function getBaseroomId($baseroomname)
  161. {
  162. $sql = "select res_id from base_resource WHERE res_type_id=26 AND res_name='$baseroomname' AND cancel_flag=0";
  163. writeLog(__FUNCTION__ . " sql= " . $sql);
  164. $rowset = $this->DBTool->queryBySql($sql);
  165. return $rowset['rowset'];
  166. }
  167. //根据查询条件 查出满足固定酒店和基础房型的并且没有库存的数据 如果有就不能删
  168. function getRoomName($res_id, $hotel_id)
  169. {
  170. $sql = "select id from run_hotel WHERE hotel_id='$hotel_id' AND parent_room_type=0 AND room_type='$res_id' AND total_count>saled_count";
  171. writeLog(__FUNCTION__ . " sql= " . $sql);
  172. $rowset = $this->DBTool->queryBySql($sql);
  173. return $rowset;
  174. }
  175. //删除子房型
  176. function doCancelChildRoom($user_id, $room_type, $hotel_id)
  177. {
  178. //只有所有订单均为已完成或已取消 才能删除该子房型
  179. $sql_count = "select count(1) as order_num from order_main where prod_id = $room_type and parent_prod_id = $hotel_id and cancel_flag = 0 and order_status in (145,313,198,382,314)";
  180. $res = $this->DBTool->queryBySql($sql_count);
  181. //只有下线的子房型才能删除
  182. $sql_is_onsale = "select is_onsale from opera_hotel_room where hotel_id ={$hotel_id} and room_type ={$room_type} limit 1";
  183. $res1 = $this->DBTool->queryBySql($sql_is_onsale);
  184. if ($res['rowset'][0]['order_num'] != 0) {
  185. $data['code'] = 5;
  186. $data['info'] = '只有当该子房型的所有订单均为已完成和已取消时才能删除该子房型';
  187. return $data;
  188. }
  189. if ($res1['rowset'][0]['is_onsale']!=0){
  190. $data['code'] = 6;
  191. $data['info'] = '只有该子房型下线后才能删除该子房型';
  192. return $data;
  193. }
  194. $sql = "update opera_hotel_room set cancel_flag = 1,update_user_id={$user_id} where hotel_id={$hotel_id} and room_type={$room_type}";
  195. writeLog(__FUNCTION__ . "sql=" . $sql);
  196. $rowset = $this->DBTool->execSql($sql);
  197. if ($rowset['code'] == "0") {
  198. $model = array(
  199. "user_id" => $user_id,
  200. "log_type" => 2,
  201. "hotel_id" => $hotel_id,
  202. "room_type" => $room_type,
  203. "log_desc" => "不显示该子房型"
  204. );
  205. $this->DBLog->insertLog($model, '不显示子房型');
  206. }
  207. $data['code'] = $rowset['code'];
  208. $data['info'] = $rowset['info'];
  209. return $data;
  210. }
  211. }