261 lines
14 KiB

  1. <?php
  2. require_once __DIR__ . '/../HotelLib.php';
  3. /**
  4. * Created by PhpStorm.
  5. * User: luocj
  6. * Date: 2016/10/18
  7. * Time: 10:00
  8. */
  9. class ModifyHotelOrder extends HotelLib
  10. {
  11. function getOrderInfo($order_id)
  12. {
  13. $sql = "select count(*) as total,stock_type,order_id,order_description,run_date,parent_order_id,prod_id,count(*)*order_price as all_price,prod_name,order_price,base_price,(order_price - base_price)*count(*) as benefit,run_time as checkin_time,order_confirm_code,outside_sale_org_id
  14. from order_main where parent_order_id=$order_id and cancel_flag = 0 and order_prod_type in (25,26) group by run_date ";
  15. $rowset = $this->DBTool->queryBySql($sql);
  16. $data['hotel_child_order_detail'] = $rowset['rowset'];
  17. $sql = "select order_status,order_description,outside_order_no,parent_prod_name as hotel_name,order_confirm_code,refuse_flag,
  18. prod_name as product_name,prod_start_station_date as start_date,prod_end_station_date as end_date,
  19. run_date,run_time as checkin_time,customer_memo,customer_name,customer_mobile,order_price,create_time,order_pay_time
  20. from order_main where order_prod_type in (25,26) and order_id = $order_id and cancel_flag = 0 and parent_order_id = 0 or outside_order_no = $order_id ";
  21. $rowset = $this->DBTool->queryBySql($sql);
  22. $data['hotel_order_detail'][0] = array_change_key_case($rowset['rowset'][0], CASE_LOWER);
  23. // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
  24. // from run_hotel_distrib as a
  25. // inner join run_hotel as b on b.id=a.run_id
  26. // inner join opera_hotel c on c.hotel_id = b.hotel_id
  27. // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
  28. // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
  29. // writeLog('sql= ' . $sql);
  30. // $order_list = $this->DBTool->queryBySql($sql);
  31. // $data['yongjinRule'] = $order_list['rowset'];
  32. return $data;
  33. }
  34. // function getOrderList($start_date, $end_date, $hotel_id, $room_type, $org_id, $order_id)
  35. // {
  36. // //获取库存
  37. // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
  38. // from run_hotel_distrib as a
  39. // inner join run_hotel as b on b.id=a.run_id
  40. // inner join opera_hotel c on c.hotel_id = b.hotel_id
  41. // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
  42. // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and a.saled_count < a.total_count and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
  43. // writeLog('sql= ' . $sql);
  44. // $order_list = $this->DBTool->queryBySql($sql);
  45. // $data['order_stock'] = $order_list['rowset'];
  46. // $sql = "select order_status,order_description,outside_order_no,parent_prod_name as hotel_name,order_confirm_code,refuse_flag,
  47. // prod_name as product_name,prod_start_station_date as start_date,prod_end_station_date as end_date,
  48. // run_date,run_time as checkin_time,customer_memo,customer_name,customer_mobile,order_price,create_time,order_pay_time
  49. // from order_main where order_id = $order_id and cancel_flag = 0 or outside_order_no = $order_id and parent_order_id = 0 ";
  50. // $rowset = $this->DBTool->queryBySql($sql);
  51. // $data['hotel_order_detail'] = $rowset['rowset'];
  52. // $sql = "select count(*) as total,order_id,order_description,run_date,parent_order_id,prod_id,count(*)*order_price as all_price,prod_name,order_price,base_price,(order_price - base_price)*count(*) as benefit,run_time as checkin_time,order_confirm_code,outside_sale_org_id
  53. // from order_main where parent_order_id=$order_id and cancel_flag = 0 group by run_date";
  54. // $rowset = $this->DBTool->queryBySql($sql);
  55. // $data['hotel_child_order_detail'] = $rowset['rowset'];
  56. //
  57. // //当库存为0时,专门获取佣金等
  58. // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
  59. // from run_hotel_distrib as a
  60. // inner join run_hotel as b on b.id=a.run_id
  61. // inner join opera_hotel c on c.hotel_id = b.hotel_id
  62. // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
  63. // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
  64. // writeLog('sql= ' . $sql);
  65. // $order_list = $this->DBTool->queryBySql($sql);
  66. // $data['yongjinRule'] = $order_list['rowset'];
  67. // return $data;
  68. // }
  69. // 获取订单状态
  70. function getOrderStatus($order_id)
  71. {
  72. $sql = "select order_id,order_status,create_time,(select type_name from dict_type where a.ORDER_STATUS = id ) as order_status_name from order_ht_status_log a where order_id = $order_id and cancel_flag = 0";
  73. $rowset = $this->DBTool->queryBySql($sql);
  74. writeLog(json_encode($rowset));
  75. $data['order_status'] = $rowset['rowset'];
  76. //$data['order_status'] = array("create_time" => "2016-10-19 11:11:10", "order_status_name" => $rowset['rowset'][0]["order_status_name"]);
  77. return $data;
  78. }
  79. //修改订单提交
  80. function getModifyOrderList($user_id, $hotel_id, $room_type, $org_id, $org_num, $room_list, $cus_list, $checkin_time, $if_cancel, $benefit, $total_commission, $order_id, $logList)
  81. {
  82. $MakeOrder = new MakeHotelOrder();
  83. $rowset = $MakeOrder->makeOrderList($user_id, $hotel_id, $room_type, $org_id, $org_num, $room_list, $cus_list, $checkin_time, $if_cancel, $benefit, $total_commission, $order_id);
  84. if ($rowset['code'] == "0") {
  85. $sql = "select PROD_ID, PARENT_PROD_ID from order_main where order_id = $order_id and cancel_flag=0";
  86. $order = $this->DBTool->queryBySql($sql);
  87. if ($order['code'] == 0) {
  88. $hotel_id = $order['rowset'][0]['PARENT_PROD_ID'];
  89. $room_type = $order['rowset'][0]['PROD_ID'];
  90. } else {
  91. $hotel_id = 0;
  92. $room_type = 0;
  93. }
  94. $log = '';
  95. if (is_array($logList) && (count($logList) > 0)) {
  96. foreach ($logList as $item) {
  97. $ext_old = '';
  98. $ext_new = '';
  99. if ($item['name'] == 'memo') { //备注特殊处理,添加和删除
  100. $old = explode('||', $item['old_val']);
  101. $new = explode('||', $item['new_val']);
  102. $old_arr = array();
  103. $new_arr = array();
  104. foreach ($old as $temp) {
  105. $tmp = explode('|', $temp);
  106. array_push($old_arr, $tmp[3]);
  107. }
  108. foreach ($new as $key => $temp) {
  109. $tmp = explode('|', $temp);
  110. $pos = array_search($tmp[3], $old_arr);
  111. if ($pos || $pos === 0) {
  112. unset($old_arr[$pos]);
  113. unset($new_arr[$key]);
  114. } else
  115. array_push($new_arr, $tmp[3]);
  116. }
  117. $ext_old .= implode(';', $old_arr);
  118. $ext_new .= implode(';', $new_arr);
  119. $item['old_val'] = $ext_old;
  120. $item['new_val'] = $ext_new;
  121. if ($ext_old != '')
  122. $ext_old = '删除备注“' . $item['old_val'] . '”';
  123. if ($ext_new != '')
  124. $ext_new = '添加备注“' . $item['new_val'] . '”';
  125. $log .= $ext_old . $ext_new;
  126. } else{
  127. $log .= "修改" . getLabel($item['name']) . '“' . $item['old_val'] . '”为“' . $item['new_val'] . '”;';
  128. }
  129. }
  130. }
  131. if($order_id != 0){
  132. $this->setMemcache($order_id, 313);
  133. }
  134. $model = array(
  135. "user_id" => $user_id,
  136. "log_type" => 3,
  137. "hotel_id" => $hotel_id,
  138. "room_type" => $room_type,
  139. "log_desc" => "修改订单号为" . $order_id . "的订单: $log",
  140. "order_id" => $order_id
  141. );
  142. $this->DBLog->insertLog($model, '修改订单');
  143. }
  144. $data['code'] = $rowset['code'];
  145. $data['info'] = $rowset['info'];
  146. return $data;
  147. }
  148. /**
  149. * 获取真实姓名
  150. * @param $user_id
  151. * @return mixed
  152. */
  153. function getTrueName($user_id)
  154. {
  155. $sql = "select true_name from base_user where ID=$user_id AND CANCEL_FLAG=0 LIMIT 1";
  156. $rowset = $this->DBTool->queryBySql($sql);
  157. return $rowset['rowset'][0];
  158. }
  159. function getBookInfo($order_id)
  160. {
  161. $sql = "select A.order_status,F.true_name,A.order_description,A.outside_order_no,A.parent_prod_name as hotel_name,A.order_confirm_code,
  162. A.prod_name as product_name,A.prod_start_station_date as start_date,A.prod_end_station_date as end_date,
  163. A.run_date,A.run_time as checkin_time,A.customer_memo,A.customer_name,A.customer_mobile,A.order_price,A.create_time,A.order_pay_time,B.CONFIRM_FROM as org_id,C.org_name,
  164. (SELECT type_name from dict_type WHERE ID=D.SETT_TYPE) as type_name,
  165. (SELECT type_name from dict_type WHERE ID=D.SETT_FREQUENCY) as type_time
  166. from order_main A LEFT JOIN opera_hotel B ON A.PARENT_PROD_ID=B.hotel_id LEFT JOIN base_confirm_organization C
  167. on B.CONFIRM_FROM=C.ID LEFT JOIN base_supplier D ON B.SUPPLIER_ID=D.ID
  168. LEFT JOIN base_user F ON A.CREATE_USER_ID=F.ID
  169. where (A.order_id = '{$order_id}' or A.outside_order_no = '{$order_id}') and A.cancel_flag = 0
  170. and A.parent_order_id = 0 and C.CANCEL_FLAG=0 AND D.CANCEL_FLAG=0 and A.order_prod_type in (25,26)";
  171. $rowset = $this->DBTool->queryBySql($sql);
  172. $data['hotel_order_detail'] = $rowset['rowset'];
  173. return $data;
  174. }
  175. //判断是否经过修改
  176. function isUpdate($order_id)
  177. {
  178. $sql = "select id from order_main WHERE parent_order_id=$order_id AND cancel_flag=1";
  179. $rowset = $this->DBTool->queryBySql($sql);
  180. return $rowset;
  181. }
  182. function getPrice($order_id)
  183. {
  184. // $sql = "select count(*) as num ,prod_start_station_date,
  185. // (select case stock_type when 228 then b.base_price_buyout when 229 then b.base_price_inquiry when 230 then base_price_reserve end from run_hotel_sub_room b where a.run_date = b.run_date and a.parent_prod_id =b.hotel_id and a.prod_id = b.room_type )*count(*) as base_price
  186. // from order_main as a
  187. // where a.cancel_flag = 0 and a.parent_order_id='$order_id' group by prod_start_station_date";
  188. // writeLog(__FUNCTION__ . " sql= " . $sql);
  189. // $rowset = $this->DBTool->queryBySql($sql);
  190. // return $rowset['rowset'];
  191. $sql="select count(*) as num ,prod_start_station_date,A.base_price*count(*) as base_price from order_main as A LEFT JOIN run_hotel as B
  192. on A.run_id=B.id
  193. WHERE A.cancel_flag = 0 and A.parent_order_id='$order_id' GROUP BY PROD_START_STATION_DATE";
  194. $rowset = $this->DBTool->queryBySql($sql);
  195. return $rowset['rowset'];
  196. }
  197. // function getO(){
  198. // $sql="select * from opera_hotel";
  199. // $rowset = $this->DBTool->queryBySql($sql);
  200. // $data=$rowset['rowset'];
  201. // return $data;
  202. //
  203. // }
  204. }
  205. //$ModifyHotelOrder = new ModifyHotelOrder();
  206. //$data = $ModifyHotelOrder ->getOrderList('2016-09-09','2016-09-11',3,1,41,455390);
  207. //echo json_encode($data);
  208. //获取备注的字段名称
  209. function getLabel($key)
  210. {
  211. if ($key == '')
  212. return '';
  213. $label = '';
  214. switch ($key) {
  215. case 'org_id':
  216. $label = '渠道商';
  217. break;
  218. case 'org_num':
  219. $label = '渠道订单号';
  220. break;
  221. case 'start_date':
  222. $label = '入住时间';
  223. break;
  224. case 'end_date':
  225. $label = '离店时间';
  226. break;
  227. case 'total':
  228. $label = '间夜数';
  229. break;
  230. case 'contact':
  231. $label = '联系人';
  232. break;
  233. case 'mobile':
  234. $label = '联系电话';
  235. break;
  236. case 'memo':
  237. $label = '备注';
  238. break;
  239. case 'amount':
  240. $label = '结算价';
  241. break;
  242. }
  243. return $label;
  244. }