Commit 11c9eeda authored by 吴贤德's avatar 吴贤德

Api

parent 6736c928
......@@ -6,10 +6,6 @@
* Date: 2019/6/27
* Time: 14:16
* 中心服务接口
* 系统配置接口
* 合作方配置接口
* 推送日志记录接口
* 云端片库修改接口
*/
class CenterAction extends Action
{
......@@ -147,7 +143,7 @@ class CenterAction extends Action
$total = $totalArr[0]["total"];
}
$page_num = ceil($total/$page_size);
$limit_from = $page*$page_size;
$limit_from = ($page-1)*$page_size;
$sql="SELECT mw.code id,mw.title,mw.description,mw.url_play playUrl,mw.url_pic picUrl"
.",mw.year,mw.type,mw.score,mw.region,mw.actor,mw.director"
.",h.code hotelId,hm.status,hm.status_inject statusInject"
......@@ -179,21 +175,28 @@ class CenterAction extends Action
public function incrementCheck(){
$page_size = 10;
$spid = $_GET["spid"];
$start = date('Y-m-d H:i:s',strtotime($_GET["start"]));//date('Y-m-d H:i:s', strtotime($date))
$end = date('Y-m-d H:i:s',strtotime($_GET["end"]));
$page=$_GET["page"];
$rawData = @file_get_contents("php://input");
$json = json_decode($rawData, true);
if (isset($json["spid"])) {
$spid = $json["spid"];
$start = date('Y-m-d H:i:s', strtotime($json["start"]));//date('Y-m-d H:i:s', strtotime($date))
$end = date('Y-m-d H:i:s', strtotime($json["end"]));
}else{
$spid = $_GET["spid"];
$start = date('Y-m-d H:i:s', strtotime($_GET["start"]));//date('Y-m-d H:i:s', strtotime($date))
$end = date('Y-m-d H:i:s', strtotime($_GET["end"]));
}
$sqlTotal = "SELECT count(1) total FROM sh_hotel_media_map_$spid WHERE updatetime BETWEEN '$start' AND '$end';";
$totalArr = M("")->query($sqlTotal);
$total = 0;
if (count($totalArr)>0){
$total = $totalArr[0]["total"];
$total = (int)$totalArr[0]["total"];
}
$page_num = ceil($total/$page_size);
$result["total"]=$total;
$result["page_cur"]=$page;
$result["page_num"]=$page_num;
echo json_encode($result);
......@@ -201,47 +204,104 @@ class CenterAction extends Action
/**
* 增量媒资变更推送接口
* /Api/Center/incrementPush?spid=1&start=20190701120000&end=20190702120000&page=1
* /Api/Center/incrementPush
* 输入:
* spid : 合作方id
* start : 开始时间
* end : 结束时间
* page : 请求页
* page_num: 总共多少页
* url : 合作方接收地址
* key : 私钥
* 输出:
* {"code":0,"msg":"err msg"}
*/
public function incrementPush(){
public function incrementPush()
{
$page_size = 10;
$rawData = @file_get_contents("php://input");
$json = json_decode($rawData,true);
$rawData = @file_get_contents("php://input");
$json = json_decode($rawData, true);
$spid = $json["spid"];
$start = date('Y-m-d H:i:s',strtotime($json["start"]));//date('Y-m-d H:i:s', strtotime($date))
$end = date('Y-m-d H:i:s',strtotime($json["end"]));
$page=$json["page"];
$url=$json["url"];
$key=$json["key"];
$start = date('Y-m-d H:i:s', strtotime($json["start"]));
$end = date('Y-m-d H:i:s', strtotime($json["end"]));
$page = $json["page"];
$pageNum = $json["page_num"];
$url = $json["url"];
$key = $json["key"];
$result["code"] = 0;
$limit_from = $page*$page_size;
$sql="SELECT mw.code id,mw.title,mw.description,mw.url_play playUrl,mw.url_pic picUrl"
.",mw.year,mw.type,mw.score,mw.region,mw.actor,mw.director"
.",h.code hotelId,hm.status,hm.status_inject statusInject"
." FROM (SELECT media_id,hotel_id,status,status_inject FROM sh_hotel_media_map_$spid"
." WHERE updatetime BETWEEN'$start' AND '$end' ORDER BY updatetime ASC LIMIT $limit_from,$page_size) hm"
." JOIN sh_media_wasu mw ON mw.id=hm.media_id"
." JOIN sh_hotel h ON h.id=hm.hotel_id";
if($url!=""&&$key!="") {
// echo $sql;exit;
$list = M("")->query($sql);
$limit_from = ($page - 1) * $page_size;
$sql = "SELECT mw.code id,mw.title,mw.description,mw.url_play playUrl,mw.url_pic picUrl"
. ",mw.year,mw.type,mw.score,mw.region,mw.actor,mw.director"
. ",h.code hotelId,hm.status,hm.status_inject statusInject"
. " FROM (SELECT media_id,hotel_id,status,status_inject FROM sh_hotel_media_map_$spid"
. " WHERE updatetime BETWEEN'$start' AND '$end' ORDER BY updatetime ASC LIMIT $limit_from,$page_size) hm"
. " JOIN sh_media_wasu mw ON mw.id=hm.media_id"
. " JOIN sh_hotel h ON h.id=hm.hotel_id";
$url=
echo $sql;exit;
$list = M("")->query($sql);//获取增量媒资列表
$json = json_encode($list);
//请求合作方接口将变更列表推送
$sw_time = time();
$sw_sign = md5($sw_time . $json . $key);
$api_push = $url . "?sw_time=&sw_sign=$sw_sign";
$result["list"] = $list;
$data = $this->HttpPost($api_push, $json);
$jsonR = json_decode($data, true);
if ($jsonR["code"] == 0) {
//最后一页推送成功:更新offset
if ($page == $pageNum) {
M()->execute("UPDATE sh_sp SET push_offset='$end' WHERE id=$spid;");
}
}
if (!empty($jsonR) && $jsonR["code"]==0){
$result["code"]=0;
}else{
$result["code"]=2001;
$result["msg"]="合作方接口调用异常:".$jsonR["msg"];
}
}else{
$result["code"]=1001;
$result["msg"]="合作方配置不完整";
}
echo json_encode($result);
}
function HttpPost($url,$param){
$ch = curl_init();
//如果$param是数组的话直接用
curl_setopt($ch, CURLOPT_URL, $url);
//如果$param是json格式的数据,则打开下面这个注释
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($param))
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//如果用的协议是https则打开鞋面这个注释
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
\ No newline at end of file
......@@ -12,6 +12,55 @@
class FrontAction extends Action
{
/**
* 分前端配置接口
* 输入:
* code : 分前端唯一标识
* 输出:
* {"hid":"","spid":"",configs:{},devices:[{}]}
*/
public function config(){
$code = $_GET["code"];
$sql="SELECT sp.id spid,sp.code spcode,hotel.id hid,hotel.code hcode"
." FROM sh_hotel_device device"
." JOIN sh_hotel hotel ON hotel.id=device.hotel_id"
." JOIN sh_sp sp ON sp.id=hotel.sp_id"
." WHERE device.code='$code' AND device.hotel_id=hotel.id AND hotel.sp_id=sp.id;";
$arr=M("")->query($sql);
if (count($arr)>0){
$config=$arr[0];
//配置
$sql="SELECT type_code k,v FROM sh_sp_config WHERE sp_id=".$config["spid"]." AND status=0 AND type_code LIKE 'front_%';";
$arr=M()->query($sql);
foreach ($arr as $item){
$config["configs"][$item["k"]]=$item["v"];
}
//设备
$sql="SELECT device.code,device.type,device.ip,device.port,device.virtual_ip,device.netcard,storage.path,storage.size"
." FROM sh_hotel_device device,sh_hotel_device_storage storage"
." WHERE device.hotel_id=1 AND device.status=0 AND storage.device_id=device.id AND storage.status=0;";
$arr=M()->query($sql);
foreach ($arr as $item){
$config["devices"][$item["code"]]["type"]=$item["type"];
$config["devices"][$item["code"]]["ip"]=$item["ip"];
$config["devices"][$item["code"]]["port"]=$item["port"];
$config["devices"][$item["code"]]["vip"]=$item["virtual_ip"];
$config["devices"][$item["code"]]["netcard"]=$item["netcard"];
$storage["path"]=$item["path"];
$storage["size"]=$item["size"];
$config["devices"][$item["code"]]["storage"][]=$storage;
}
}
echo json_encode($config);
//输出
}
/**
* 分前端增量媒资变更列表
* /Api/Front/incrementList?hid=1&spid=1&start=xxx&end=xxx&page=1
......@@ -27,7 +76,7 @@ class FrontAction extends Action
$hid = $_GET["hid"];
$spid = $_GET["spid"];
$start = date('Y-m-d H:i:s',strtotime($_GET["start"]));//date('Y-m-d H:i:s', strtotime($date))
$start = date('Y-m-d H:i:s',strtotime($_GET["start"]));
$end = date('Y-m-d H:i:s',strtotime($_GET["end"]));
$page=$_GET["page"];
......@@ -39,13 +88,14 @@ class FrontAction extends Action
$total = $totalArr[0]["total"];
}
$page_num = ceil($total/$page_size);
$limit_from = $page*$page_size;
$limit_from = ($page-1)*$page_size;
$sql="SELECT mw.code,mw.url_play,hm.status,hm.status_inject"
." FROM (SELECT media_id,hotel_id,status,status_inject FROM sh_hotel_media_map_$spid"
." WHERE updatetime BETWEEN '$start' AND '$end' ORDER BY updatetime ASC LIMIT $limit_from,$page_size) hm"
." WHERE hotel_id=$hid AND updatetime BETWEEN '$start' AND '$end' ORDER BY updatetime ASC LIMIT $limit_from,$page_size) hm"
." JOIN sh_media_wasu mw ON mw.id=hm.media_id";
$list = M("")->query($sql);
$result["total"]=$total;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment