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.

BaseHotel.php 8.3 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. //Author:fuhc
  3. //Date:20160909
  4. //酒店基类
  5. require_once $_SERVER['DOCUMENT_ROOT'].'/domain.php';
  6. class BaseHotel
  7. {
  8. public $version; //酒店更新版本
  9. public $update_date; //酒店更新时间
  10. public $company; //所属公司
  11. public $fax; //传真
  12. public $tel; //联系电话
  13. public $address; //公司地址
  14. function __construct()
  15. {
  16. $version = "1.0";
  17. $update_date = "20160909";
  18. $company = "蜘蛛行网络科技有限公司";
  19. $fax = "021-33280184";
  20. $tel = "021-52218088";
  21. $address = "上海市闵行区申长路988弄虹桥万科中心1号楼701";
  22. }
  23. /**
  24. * User: wangxj
  25. *
  26. * 添加订单到memcache
  27. *
  28. * @supplier_id string 供应商ID
  29. * @order_id string 订单号
  30. * @status integer 订单状态, 313待发单、382异常处理待发单,383异常处理已取消,148正常已取消,147已完成,198待确认,314已安排。
  31. * @room_name string 房型
  32. * @expire string 默认为0,memcache时效
  33. *
  34. */
  35. function setMemcache($order_id, $type, $prod_top_org_id, $prod_name, $expire = 0)
  36. {
  37. $mem = new Memcache;
  38. $mem->connect("127.0.0.1", 11211);
  39. $this->resetMemcache($order_id);
  40. $newOrder = $mem->get('hotel_newOrder');
  41. $tmp = array();
  42. if ($order_id) {
  43. if ($newOrder && count($newOrder) > 0) {
  44. //按天为单位读取缓存
  45. // if(isset($newOrder[date('Y-m-d')])){
  46. // $tmp = $newOrder[date('Y-m-d')];
  47. // }
  48. if (isset($newOrder[$prod_top_org_id])) {
  49. array_push($newOrder[$prod_top_org_id], array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
  50. } else {
  51. $newOrder[$prod_top_org_id] = array(array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
  52. }
  53. $tmp = $newOrder;
  54. } else {
  55. $tmp[$prod_top_org_id] = array(array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
  56. }
  57. $mem->set('hotel_newOrder', $tmp, 0, $expire);
  58. }
  59. }
  60. /**
  61. * User: wangxj
  62. *
  63. * 清除memcache
  64. *
  65. * @order_id integer 订单号
  66. *
  67. */
  68. function resetMemcache($order_id)
  69. {
  70. $mem = new Memcache;
  71. $mem->connect("127.0.0.1", 11211);
  72. $newOrder = $mem->get('hotel_newOrder');
  73. if ($newOrder && count($newOrder) > 0) {
  74. foreach ($newOrder as &$hotels) {
  75. if (count($hotels) > 0) {
  76. foreach ($hotels as $key => &$order) {
  77. if ($order['order_id'] == $order_id) {
  78. unset($hotels[$key]);
  79. $mem->set('hotel_newOrder', $newOrder);
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. /**
  87. * User: wangxj
  88. *
  89. * 返回memcache中对应酒店的缓存订单,查询过 1 次之后,置status为1
  90. *
  91. * @supplier_id 供应商ID
  92. *
  93. * @flag 是否设置status为1
  94. *
  95. * @return
  96. */
  97. function getMemcache($hotel_id)
  98. {
  99. $mem = new Memcache;
  100. $mem->connect("127.0.0.1", 11211);
  101. $newOrder = $mem->get('hotel_newOrder');
  102. if ($newOrder && count($newOrder) > 0) {
  103. if (isset($newOrder[$hotel_id])) {
  104. $tmp = $newOrder[$hotel_id];
  105. foreach ($newOrder[$hotel_id] as &$order) {
  106. $order['status'] = in_array($order['type'], array(198, 383)) ? 1 : 0;
  107. }
  108. $mem->set('hotel_newOrder', $newOrder);
  109. return $tmp;
  110. }
  111. }
  112. return array();
  113. }
  114. /**
  115. * User:Steven
  116. *
  117. * CS系统任务通知(每15分钟检查一次还需要待处理的订单)
  118. */
  119. public function reportforCS()
  120. {
  121. $mem = new Memcache;
  122. $mem->connect("127.0.0.1", 11211);
  123. $newOrder = $mem->get('hotel_newOrder');
  124. foreach ($newOrder as $value) {
  125. foreach ($value as $k => $v) {
  126. //313待发单、382异常处理待发单,383异常处理已取消,148正常已取消,147已完成,198待确认,314已安排。
  127. $data[$v['type']][] = $v;
  128. }
  129. }
  130. $msg = '';
  131. foreach ($data as $d_k => $d_v) {
  132. if (count($data[$d_k]) > 0) {
  133. if ($d_k == 313) {
  134. $msg .= "待发单:" . count($data[$d_k]) . "个\n";
  135. }
  136. if ($d_k == 198) {
  137. $msg .= "待确认:" . count($data[$d_k]) . "个";
  138. }
  139. }
  140. }
  141. $title = "温馨提示:\n";
  142. $this->sendMessageToRTX($title, $msg);
  143. }
  144. /**
  145. * User:Steven
  146. *
  147. * 想RTX发送推送消息
  148. *
  149. * $title 通知标题
  150. * $msg 通知内容
  151. */
  152. public function sendMessageToRTX($title, $msg)
  153. {
  154. $msg = $msg . "\n\n点击处理 " . $this->sinaShortenUrl('http://'. CS_DOMAIN. '/zz-jd/hotel_order_list.html');
  155. $cuntomer_list = 'gaoj,panlj,jitf,zhengz,wanr,wangn,shaojt,xuwj,duanry,zhucy,wangxj,chenyb,luocj'; //目的地资源部客服
  156. $arr = array(
  157. 'title' => $title,
  158. 'receiver' => $cuntomer_list,
  159. 'msg' => $msg,
  160. );
  161. $res = $this->httpsPost('http://180.168.4.58:8012/SendNotify.cgi', $arr);
  162. if(!$res){
  163. writeLog($res);
  164. }
  165. }
  166. function httpsPost($url, $param = array())
  167. {
  168. $ch = curl_init(); // 初始化一个 cURL 对象
  169. curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
  170. curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
  171. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  172. // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
  173. curl_setopt($ch, CURLOPT_POST, 1);
  174. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
  175. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  176. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  177. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  178. 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
  179. ));
  180. $rtn = curl_exec($ch); // 运行cURL,请求网页
  181. if ($errno = curl_errno($ch)) {
  182. throw new Exception ('Curl Error(' . $errno . '):' . curl_error($ch));
  183. }
  184. curl_close($ch); // 关闭URL请求
  185. return $rtn; // 返回获取的数据
  186. }
  187. /**
  188. * User:Steven
  189. *
  190. * $url url
  191. * mixed
  192. */
  193. function curlQuery($url)
  194. {
  195. //设置附加HTTP头
  196. $addHead = array(
  197. "Content-type: application/json"
  198. );
  199. //初始化curl,当然,你也可以用fsockopen代替
  200. $curl_obj = curl_init();
  201. //设置网址
  202. curl_setopt($curl_obj, CURLOPT_URL, $url);
  203. //附加Head内容
  204. curl_setopt($curl_obj, CURLOPT_HTTPHEADER, $addHead);
  205. //是否输出返回头信息
  206. curl_setopt($curl_obj, CURLOPT_HEADER, 0);
  207. //将curl_exec的结果返回
  208. curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, 1);
  209. //设置超时时间
  210. curl_setopt($curl_obj, CURLOPT_TIMEOUT, 15);
  211. //执行
  212. $result = curl_exec($curl_obj);
  213. //关闭curl回话
  214. curl_close($curl_obj);
  215. return $result;
  216. }
  217. //获取短网址
  218. function sinaShortenUrl($long_url)
  219. {
  220. $url = 'http://api.t.sina.com.cn/short_url/shorten.json?source=31641035' . '&url_long=' . $long_url;
  221. //获取请求结果
  222. $result = $this->curlQuery($url);
  223. $json = json_decode($result);
  224. //异常情况返回false
  225. if (isset($json->error) || !isset($json[0]->url_short) || $json[0]->url_short == '')
  226. return false;
  227. else
  228. return $json[0]->url_short;
  229. }
  230. }