選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

279 行
10 KiB

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