|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <?php
- //Author:fuhc
- //Date:20160909
- //酒店基类
-
- require_once $_SERVER['DOCUMENT_ROOT'].'/domain.php';
-
- class BaseHotel
- {
- public $version; //酒店更新版本
- public $update_date; //酒店更新时间
- public $company; //所属公司
- public $fax; //传真
- public $tel; //联系电话
- public $address; //公司地址
-
- function __construct()
- {
- $version = "1.0";
- $update_date = "20160909";
- $company = "蜘蛛行网络科技有限公司";
- $fax = "021-33280184";
- $tel = "021-52218088";
- $address = "上海市闵行区申长路988弄虹桥万科中心1号楼701";
- }
-
- /**
- * User: wangxj
- *
- * 添加订单到memcache
- *
- * @supplier_id string 供应商ID
- * @order_id string 订单号
- * @status integer 订单状态, 313待发单、382异常处理待发单,383异常处理已取消,148正常已取消,147已完成,198待确认,314已安排。
- * @room_name string 房型
- * @expire string 默认为0,memcache时效
- *
- */
- function setMemcache($order_id, $type, $prod_top_org_id, $prod_name, $expire = 0)
- {
-
- $mem = new Memcache;
- $mem->connect("127.0.0.1", 11211);
- $this->resetMemcache($order_id);
- $newOrder = $mem->get('hotel_newOrder');
- $tmp = array();
- if ($order_id) {
- if ($newOrder && count($newOrder) > 0) {
- //按天为单位读取缓存
- // if(isset($newOrder[date('Y-m-d')])){
- // $tmp = $newOrder[date('Y-m-d')];
- // }
- if (isset($newOrder[$prod_top_org_id])) {
-
- array_push($newOrder[$prod_top_org_id], array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
- } else {
- $newOrder[$prod_top_org_id] = array(array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
- }
- $tmp = $newOrder;
-
- } else {
- $tmp[$prod_top_org_id] = array(array('order_id' => $order_id, 'type' => $type, 'room_name' => $prod_name, 'status' => 0));
- }
- $mem->set('hotel_newOrder', $tmp, 0, $expire);
- }
-
-
- }
-
- /**
- * User: wangxj
- *
- * 清除memcache
- *
- * @order_id integer 订单号
- *
- */
- function resetMemcache($order_id)
- {
- $mem = new Memcache;
- $mem->connect("127.0.0.1", 11211);
- $newOrder = $mem->get('hotel_newOrder');
- if ($newOrder && count($newOrder) > 0) {
- foreach ($newOrder as &$hotels) {
- if (count($hotels) > 0) {
- foreach ($hotels as $key => &$order) {
- if ($order['order_id'] == $order_id) {
- unset($hotels[$key]);
- $mem->set('hotel_newOrder', $newOrder);
- }
- }
-
- }
- }
- }
- }
-
- /**
- * User: wangxj
- *
- * 返回memcache中对应酒店的缓存订单,查询过 1 次之后,置status为1
- *
- * @supplier_id 供应商ID
- *
- * @flag 是否设置status为1
- *
- * @return
- */
- function getMemcache($hotel_id)
- {
- $mem = new Memcache;
- $mem->connect("127.0.0.1", 11211);
- $newOrder = $mem->get('hotel_newOrder');
- if ($newOrder && count($newOrder) > 0) {
- if (isset($newOrder[$hotel_id])) {
- $tmp = $newOrder[$hotel_id];
- foreach ($newOrder[$hotel_id] as &$order) {
- $order['status'] = in_array($order['type'], array(198, 383)) ? 1 : 0;
- }
- $mem->set('hotel_newOrder', $newOrder);
- return $tmp;
- }
- }
- return array();
-
- }
-
- /**
- * User:Steven
- *
- * CS系统任务通知(每15分钟检查一次还需要待处理的订单)
- */
- public function reportforCS()
- {
- $mem = new Memcache;
- $mem->connect("127.0.0.1", 11211);
- $newOrder = $mem->get('hotel_newOrder');
- foreach ($newOrder as $value) {
- foreach ($value as $k => $v) {
- //313待发单、382异常处理待发单,383异常处理已取消,148正常已取消,147已完成,198待确认,314已安排。
- $data[$v['type']][] = $v;
- }
- }
- $msg = '';
- foreach ($data as $d_k => $d_v) {
- if (count($data[$d_k]) > 0) {
- if ($d_k == 313) {
- $msg .= "待发单:" . count($data[$d_k]) . "个\n";
- }
- if ($d_k == 198) {
- $msg .= "待确认:" . count($data[$d_k]) . "个";
- }
- }
- }
- $title = "温馨提示:\n";
- $this->sendMessageToRTX($title, $msg);
- }
-
- /**
- * User:Steven
- *
- * 想RTX发送推送消息
- *
- * $title 通知标题
- * $msg 通知内容
- */
- public function sendMessageToRTX($title, $msg)
- {
- $msg = $msg . "\n\n点击处理 " . $this->sinaShortenUrl('http://'. CS_DOMAIN. '/zz-jd/hotel_order_list.html');
- $cuntomer_list = 'gaoj,panlj,jitf,zhengz,wanr,wangn,shaojt,xuwj,duanry,zhucy,wangxj,chenyb,luocj'; //目的地资源部客服
- $arr = array(
- 'title' => $title,
- 'receiver' => $cuntomer_list,
- 'msg' => $msg,
- );
- $res = $this->httpsPost('http://180.168.4.58:8012/SendNotify.cgi', $arr);
- if(!$res){
- writeLog($res);
- }
- }
-
-
- function httpsPost($url, $param = array())
- {
- $ch = curl_init(); // 初始化一个 cURL 对象
- curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
- curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
- // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
- ));
- $rtn = curl_exec($ch); // 运行cURL,请求网页
- if ($errno = curl_errno($ch)) {
- throw new Exception ('Curl Error(' . $errno . '):' . curl_error($ch));
- }
- curl_close($ch); // 关闭URL请求
- return $rtn; // 返回获取的数据
- }
-
- /**
- * User:Steven
- *
- * $url url
- * mixed
- */
- function curlQuery($url)
- {
- //设置附加HTTP头
- $addHead = array(
- "Content-type: application/json"
- );
- //初始化curl,当然,你也可以用fsockopen代替
- $curl_obj = curl_init();
- //设置网址
- curl_setopt($curl_obj, CURLOPT_URL, $url);
- //附加Head内容
- curl_setopt($curl_obj, CURLOPT_HTTPHEADER, $addHead);
- //是否输出返回头信息
- curl_setopt($curl_obj, CURLOPT_HEADER, 0);
- //将curl_exec的结果返回
- curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, 1);
- //设置超时时间
- curl_setopt($curl_obj, CURLOPT_TIMEOUT, 15);
- //执行
- $result = curl_exec($curl_obj);
- //关闭curl回话
- curl_close($curl_obj);
- return $result;
- }
-
- //获取短网址
- function sinaShortenUrl($long_url)
- {
- $url = 'http://api.t.sina.com.cn/short_url/shorten.json?source=31641035' . '&url_long=' . $long_url;
- //获取请求结果
- $result = $this->curlQuery($url);
- $json = json_decode($result);
- //异常情况返回false
- if (isset($json->error) || !isset($json[0]->url_short) || $json[0]->url_short == '')
- return false;
- else
- return $json[0]->url_short;
- }
-
-
- }
|