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.
 
 
 
 

183 lines
7.8 KiB

  1. <?php
  2. require_once __DIR__ . '/../HotelLib.php';
  3. /**
  4. * Created by PhpStorm.
  5. * User: gaohan
  6. * Date: 2016/11/22
  7. * Time: 17:04
  8. */
  9. class OutHotelOrderListModel extends HotelLib
  10. {
  11. //供应商订单列表
  12. function getOrderList($date_type, $start_date, $end_date, $order_status, $supplier_id, $more_search, $current, $page_size)
  13. {
  14. $sql = "CALL ht_get_order_list_for_supplier('$date_type', '$start_date', '$end_date', '$order_status','$supplier_id', '$more_search', $current, $page_size)";
  15. writeLog(__FUNCTION__ . " sql= " . $sql);
  16. $data = array();
  17. $rowset = $this->DBTool->execProcedure($sql);
  18. if ($rowset['code'] == "2") {
  19. $data['code'] = '1';
  20. $data['info'] = "系统异常";
  21. return $data;
  22. }
  23. if ($rowset['rowset'][0]) {
  24. $data['code'] = $rowset['code'];
  25. $data['info'] = $rowset['info'];
  26. $data['num'] = $rowset['rowset'][2];
  27. $data['order_list'] = $rowset['rowset'][0];
  28. $data['current'] = $rowset['rowset'][1][0]['currpage'];
  29. $data['page_size'] = $rowset['rowset'][1][0]['pagesize'];
  30. $data['total'] = $rowset['rowset'][1][0]['num'];
  31. $data['total_page'] = $rowset['rowset'][1][0]['pagecount'];
  32. } else {
  33. $data['code'] = $rowset['code'];
  34. $data['info'] = $rowset['info'];
  35. $data['num'] = $rowset['rowset'][2];
  36. $data['order_list'] = '';
  37. }
  38. return $data;
  39. }
  40. //获取供应商ID
  41. function getSupplierId($user_id)
  42. {
  43. $sql = "select org_id from base_user WHERE id=$user_id";
  44. $res = $this->DBTool->queryBySql($sql);
  45. if ($res['code'] == 0) {
  46. return $res['rowset'][0]['org_id'];
  47. } else {
  48. return 0;
  49. }
  50. }
  51. /**
  52. * 酒店拒单
  53. * @param $cancel_order_id
  54. * @param $user_id
  55. * @param $cancel_order_status
  56. * @return array
  57. */
  58. function getCancelOrder($cancel_order_id, $user_id, $cancel_order_status)
  59. {
  60. $status_name = '';
  61. $today = date('Y-m-d H:i:s', time());
  62. //已取消有2种状态,1、所有正常取消148,2、酒店已安排,我们异常处理并取消了订单383
  63. $sql = "select type_name from dict_type where id = $cancel_order_status";
  64. $res = $this->DBTool->queryBySql($sql);
  65. if ($res['code'] == 0 && !empty($res['rowset']))
  66. $status_name = $res['rowset'][0]['type_name'];
  67. $sql = "CALL ht_cancel_order(" . $user_id . "," . $cancel_order_id . ", 1)";
  68. writeLog(__FUNCTION__ . " sql= " . $sql);
  69. $data = array();
  70. $rowset = $this->DBTool->execProcedure($sql);
  71. if ($rowset['code'] == "0") {
  72. $this->resetMemcache($cancel_order_id);
  73. $supplier_name = $this->getSupplierName($cancel_order_id);
  74. $this->sendMessageToRTX("酒店拒单", "$supplier_name \n拒绝订单:$cancel_order_id ");
  75. $model = array(
  76. "user_id" => $user_id,
  77. "log_type" => 3,
  78. "hotel_id" => 0,
  79. "room_type" => 0,
  80. "log_desc" => "供应商拒单,订单号为" . $cancel_order_id . "的状态由" . $status_name . "变为已取消",
  81. "order_id" => $cancel_order_id
  82. );
  83. $this->DBLog->insertLog($model, '酒店拒单');
  84. }
  85. $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time)
  86. values ($cancel_order_id,148,$cancel_order_status,0,$user_id,'{$today}',$user_id,'{$today}')";
  87. writeLog(__FUNCTION__ . " sql= " . $sql);
  88. $rowset = $this->DBTool->execSql($sql);
  89. $data['code'] = $rowset['code'];
  90. $data['info'] = $rowset['info'];
  91. return $data;
  92. }
  93. //酒店确认退单 type 1, 酒店拒绝退单 type 2 不依据dict_type表
  94. //如果是拒绝退单,需要将订单状态变更为已安排,订单状态order_valid_status要还原为
  95. function htConfirmCancel($order_id, $user_id, $confirm_type=1)
  96. {
  97. $today = date('Y-m-d H:i:s', time());
  98. if($confirm_type == 1)
  99. $sql = "update order_main set order_disable_type = $confirm_type where order_id = {$order_id} or parent_order_id = {$order_id}";
  100. else{
  101. $sql = "update order_main set ORDER_VALID_STATUS = 1 ,order_disable_type = $confirm_type , order_status = 314 where order_id = {$order_id} or parent_order_id = {$order_id}";
  102. }
  103. writeLog(__FUNCTION__ . " sql= " . $sql);
  104. $data = array();
  105. $rowset = $this->DBTool->execProcedure($sql);
  106. if ($rowset['code'] == "0") {
  107. $this->resetMemcache($order_id);
  108. $supplier_name = $this->getSupplierName($order_id);
  109. if($confirm_type == 1)
  110. $msg = "确认";
  111. else
  112. $msg = "拒绝";
  113. $this->sendMessageToRTX("酒店{$msg}退单", "$supplier_name \n订单号:$order_id ");
  114. $model = array(
  115. "user_id" => $user_id,
  116. "log_type" => 3,
  117. "hotel_id" => 0,
  118. "room_type" => 0,
  119. "log_desc" => "供应商{$msg}退单,订单号为" . $order_id,
  120. "order_id" => $order_id
  121. );
  122. $this->DBLog->insertLog($model, "{$msg}退单");
  123. }
  124. $data['code'] = $rowset['code'];
  125. $data['info'] = $rowset['info'];
  126. return $data;
  127. }
  128. //获取订单详情
  129. function getOrderDetail($order_id)
  130. {
  131. $sql = "select order_status,order_confirm_code,parent_prod_name,prod_name,prod_start_station_date,prod_end_station_date,customer_name,customer_mobile,customer_memo
  132. from order_main WHERE order_id='$order_id' AND cancel_flag=0";
  133. writeLog(__FUNCTION__ . " sql= " . $sql);
  134. $rowset = $this->DBTool->queryBySql($sql);
  135. return $rowset['rowset'][0];
  136. }
  137. // 获取订单状态
  138. function getOrderStatus($order_id)
  139. {
  140. $sql = "select order_id,order_status,create_time,(select type_name from dict_type where a.ORDER_STATUS = id ) as order_status_name
  141. from order_ht_status_log a where order_id = $order_id and cancel_flag = 0";
  142. $rowset = $this->DBTool->queryBySql($sql);
  143. writeLog(json_encode($rowset));
  144. $data['order_status'] = $rowset['rowset'];
  145. //$data['order_status'] = array("create_time" => "2016-10-19 11:11:10", "order_status_name" => $rowset['rowset'][0]["order_status_name"]);
  146. return $data;
  147. }
  148. //获取订单详情的子订单信息
  149. function getChildOrderDetail($order_id)
  150. {
  151. $sql = "select A.run_date,count(A.run_date) as num,A.base_price,A.base_price*count(A.run_date) as total,A.run_time
  152. from order_main as A LEFT JOIN run_hotel as B on A.run_id=B.id WHERE A.parent_order_id='$order_id' and A.cancel_flag=0 GROUP BY RUN_DATE";
  153. writeLog(__FUNCTION__ . " sql= " . $sql);
  154. $rowset = $this->DBTool->queryBySql($sql);
  155. return $rowset['rowset'];
  156. }
  157. function getPrice($order_id)
  158. {
  159. // $sql="select count(*) as num ,prod_start_station_date,B.base_price*count(*) as base_price from order_main as A LEFT JOIN run_hotel as B
  160. // on A.run_id=B.id
  161. // WHERE A.cancel_flag = 0 and A.parent_order_id='$order_id' GROUP BY PROD_START_STATION_DATE";
  162. // writeLog(__FUNCTION__ . " sql= " . $sql);
  163. // $rowset = $this->DBTool->queryBySql($sql);
  164. // return $rowset['rowset'];
  165. $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
  166. on A.run_id=B.id
  167. WHERE A.cancel_flag = 0 and A.parent_order_id='$order_id' GROUP BY PROD_START_STATION_DATE";
  168. $rowset = $this->DBTool->queryBySql($sql);
  169. return $rowset['rowset'];
  170. }
  171. }